diff --git a/Code/Game/DanBiasServer/GameServer.cpp b/Code/Game/DanBiasServer/GameServer.cpp index a2c487d8..1cddc318 100644 --- a/Code/Game/DanBiasServer/GameServer.cpp +++ b/Code/Game/DanBiasServer/GameServer.cpp @@ -13,7 +13,7 @@ namespace DanBias { using namespace Oyster::Network; - void GameServer::ClientConnectCallback(NetworkClient &client) + void GameServer::ClientConnectCallback(NetworkClient client) { printf("Client connected!\n"); GameLogic::Protocol_TEST t; diff --git a/Code/Game/DanBiasServer/GameServer.h b/Code/Game/DanBiasServer/GameServer.h index b46891db..6354aa35 100644 --- a/Code/Game/DanBiasServer/GameServer.h +++ b/Code/Game/DanBiasServer/GameServer.h @@ -25,7 +25,7 @@ namespace DanBias private: //static void ClientConnectCallbackFunction(Oyster::Network::NetworkClient& connectedClient); - void ClientConnectCallback(Oyster::Network::NetworkClient &client) override; + void ClientConnectCallback(Oyster::Network::NetworkClient client) override; bool initiated; bool running; diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp index 6160d674..1933d907 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.cpp +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -13,12 +13,34 @@ struct CustomNetProtocol::PrivateData PrivateData() { } + PrivateData( const CustomNetProtocol::PrivateData& o) + { + for (auto i = o.attributes.begin(); i != o.attributes.end(); i++) + { + if(i->second.type == NetAttributeType_CharArray) + { + size_t size = strlen(i->second.value.netCharPtr); + if(size == 0) continue; + + attributes[i->first]; + attributes[i->first].value.netCharPtr = new char[size + 1]; + //strcpy_s(attributes[i->first].value.netCharPtr, size + 1, i->second.value.netCharPtr); + memcpy(&attributes[i->first].value.netCharPtr[0], &i->second.value.netCharPtr[0], size + 1); + } + else + { + attributes[i->first] = i->second; + } + } + attributes = o.attributes; + } ~PrivateData() { for (auto i = attributes.begin(); i != attributes.end(); i++) { RemoveAttribute(i->first); } + attributes.clear(); } void RemoveAttribute(int ID) { @@ -28,7 +50,8 @@ struct CustomNetProtocol::PrivateData switch (i->second.type) { case NetAttributeType_CharArray: - delete [] i->second.value.netCharPtr; + //delete [] i->second.value.netCharPtr; + i->second.value.netCharPtr = 0; break; } } @@ -41,6 +64,16 @@ CustomNetProtocol::CustomNetProtocol() { this->privateData = new PrivateData(); } +CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o) +{ + this->privateData = new PrivateData(*o.privateData); +} +const CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o) +{ + delete this->privateData; + this->privateData = new PrivateData(*o.privateData); + return *this; +} CustomNetProtocol::~CustomNetProtocol() { delete this->privateData; diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h index c1678cf9..4f01fb58 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.h +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -82,6 +82,8 @@ namespace Oyster public: CustomNetProtocol(); ~CustomNetProtocol(); + CustomNetProtocol(const CustomNetProtocol& o); + const CustomNetProtocol& operator=(const CustomNetProtocol& o); NetAttributeContainer& operator[](int ID); diff --git a/Code/Network/NetworkAPI/NetworkCallbackHelper.h b/Code/Network/NetworkAPI/NetworkCallbackHelper.h index a458760e..b0e3194d 100644 --- a/Code/Network/NetworkAPI/NetworkCallbackHelper.h +++ b/Code/Network/NetworkAPI/NetworkCallbackHelper.h @@ -30,7 +30,7 @@ namespace Oyster typedef void(*ProtocolRecieverFunction)(CustomNetProtocol& protocol); struct ClientConnectedObject { - virtual void ClientConnectCallback(NetworkClient &client) = 0; + virtual void ClientConnectCallback(NetworkClient client) = 0; }; struct ProtocolRecieverObject { diff --git a/Code/Network/NetworkAPI/Translator.cpp b/Code/Network/NetworkAPI/Translator.cpp index eb2a3d17..40f80d5f 100644 --- a/Code/Network/NetworkAPI/Translator.cpp +++ b/Code/Network/NetworkAPI/Translator.cpp @@ -220,6 +220,16 @@ Translator::~Translator() privateData = NULL; } } +Translator::Translator(const Translator& obj) +{ + this->privateData = new PrivateData(*obj.privateData); +} +const Translator& Translator::operator=(const Translator& obj) +{ + delete this->privateData; + this->privateData = new PrivateData(*obj.privateData); + return *this; +} void Translator::Pack(SmartPointer &bytes, CustomNetProtocol& protocol) { diff --git a/Code/Network/NetworkAPI/Translator.h b/Code/Network/NetworkAPI/Translator.h index 3f5fe673..ccbe43e2 100644 --- a/Code/Network/NetworkAPI/Translator.h +++ b/Code/Network/NetworkAPI/Translator.h @@ -48,6 +48,8 @@ namespace Oyster public: Translator (); ~Translator(); + Translator(const Translator& obj); + const Translator& operator=(const Translator& obj); void Pack(Utility::DynamicMemory::SmartPointer &bytes, CustomNetProtocol& protocol);