Pre-merge with network, (again)

This commit is contained in:
dean11 2013-12-12 12:17:39 +01:00
parent 2ea252919a
commit 9b9a92556a
7 changed files with 51 additions and 4 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -82,6 +82,8 @@ namespace Oyster
public:
CustomNetProtocol();
~CustomNetProtocol();
CustomNetProtocol(const CustomNetProtocol& o);
const CustomNetProtocol& operator=(const CustomNetProtocol& o);
NetAttributeContainer& operator[](int ID);

View File

@ -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
{

View File

@ -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<OysterByte> &bytes, CustomNetProtocol& protocol)
{

View File

@ -48,6 +48,8 @@ namespace Oyster
public:
Translator ();
~Translator();
Translator(const Translator& obj);
const Translator& operator=(const Translator& obj);
void Pack(Utility::DynamicMemory::SmartPointer<OysterByte> &bytes, CustomNetProtocol& protocol);