2013-12-09 14:23:30 +01:00
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
// Created by [Dennis Andersen] [2013]
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
#include "CustomNetProtocol.h"
|
|
|
|
#include <map>
|
2013-12-11 21:45:43 +01:00
|
|
|
#include "Translator.h"
|
2014-02-04 16:07:10 +01:00
|
|
|
#include <DynamicArray.h>
|
2013-12-11 21:45:43 +01:00
|
|
|
using namespace Oyster::Network;
|
2014-01-29 10:18:01 +01:00
|
|
|
using namespace Utility::DynamicMemory;
|
2013-12-09 14:23:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
struct CustomNetProtocol::PrivateData
|
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
//std::map<int, NetAttributeContainer> attributes; //...Im an idiot
|
|
|
|
DynamicArray<NetAttributeContainer> attributes; //...Im an idiot
|
2014-01-31 22:52:52 +01:00
|
|
|
|
2013-12-09 14:23:30 +01:00
|
|
|
PrivateData()
|
2014-01-31 22:52:52 +01:00
|
|
|
{ }
|
2014-01-29 10:18:01 +01:00
|
|
|
|
2013-12-09 14:23:30 +01:00
|
|
|
~PrivateData()
|
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
attributes.Clear();
|
2013-12-09 14:23:30 +01:00
|
|
|
}
|
2014-02-04 16:07:10 +01:00
|
|
|
void RemoveAttribute(NetAttributeContainer* i)
|
2013-12-09 14:23:30 +01:00
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
if(!i) return;
|
2013-12-09 14:23:30 +01:00
|
|
|
|
2014-02-04 16:07:10 +01:00
|
|
|
switch (i->type)
|
2013-12-09 14:23:30 +01:00
|
|
|
{
|
|
|
|
case NetAttributeType_CharArray:
|
2014-02-04 16:07:10 +01:00
|
|
|
delete [] i->value.netCharPtr;
|
2013-12-09 14:23:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//Do network stuff
|
|
|
|
};
|
|
|
|
|
|
|
|
CustomNetProtocol::CustomNetProtocol()
|
|
|
|
{
|
|
|
|
this->privateData = new PrivateData();
|
|
|
|
}
|
2014-02-04 16:07:10 +01:00
|
|
|
CustomNetProtocol::CustomNetProtocol(CustomNetProtocol& o)
|
2013-12-12 12:17:39 +01:00
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
this->privateData = new PrivateData();
|
|
|
|
this->privateData->attributes = o.privateData->attributes;
|
2013-12-12 12:17:39 +01:00
|
|
|
}
|
2014-02-04 16:07:10 +01:00
|
|
|
const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o)
|
2013-12-12 12:17:39 +01:00
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
if(this->privateData)
|
|
|
|
{
|
|
|
|
delete this->privateData;
|
|
|
|
this->privateData = 0;
|
|
|
|
}
|
|
|
|
this->privateData = new PrivateData();
|
|
|
|
this->privateData->attributes = o.privateData->attributes;
|
2013-12-12 12:17:39 +01:00
|
|
|
return *this;
|
|
|
|
}
|
2013-12-09 14:23:30 +01:00
|
|
|
CustomNetProtocol::~CustomNetProtocol()
|
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
delete this->privateData;
|
|
|
|
this->privateData = 0;
|
2013-12-09 14:23:30 +01:00
|
|
|
}
|
|
|
|
NetAttributeContainer& CustomNetProtocol::operator[](int ID)
|
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
//if(!this->privateData) this->privateData = new PrivateData();
|
|
|
|
if((unsigned int)ID >= this->privateData->attributes.Size())
|
2013-12-09 14:23:30 +01:00
|
|
|
{
|
2014-02-04 16:07:10 +01:00
|
|
|
NetAttributeContainer temp;
|
|
|
|
|
|
|
|
temp.type = NetAttributeType_UNKNOWN;
|
|
|
|
memset(&temp.value, 0, sizeof(NetAttributeValue));
|
|
|
|
|
|
|
|
this->privateData->attributes.Push(ID, temp);
|
2013-12-09 14:23:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this->privateData->attributes[ID];
|
2014-01-22 15:22:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void CustomNetProtocol::Set(int ID, Oyster::Network::NetAttributeValue val, Oyster::Network::NetAttributeType type)
|
|
|
|
{
|
|
|
|
this->privateData->attributes[ID].type = type;
|
|
|
|
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case Oyster::Network::NetAttributeType_Bool:
|
|
|
|
case Oyster::Network::NetAttributeType_Char:
|
|
|
|
case Oyster::Network::NetAttributeType_UnsignedChar:
|
|
|
|
case Oyster::Network::NetAttributeType_Short:
|
|
|
|
case Oyster::Network::NetAttributeType_UnsignedShort:
|
|
|
|
case Oyster::Network::NetAttributeType_Int:
|
|
|
|
case Oyster::Network::NetAttributeType_UnsignedInt:
|
|
|
|
case Oyster::Network::NetAttributeType_Int64:
|
|
|
|
case Oyster::Network::NetAttributeType_UnsignedInt64:
|
|
|
|
case Oyster::Network::NetAttributeType_Float:
|
|
|
|
case Oyster::Network::NetAttributeType_Double:
|
|
|
|
this->privateData->attributes[ID].value = val;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void CustomNetProtocol::Set(int ID, std::string s)
|
|
|
|
{
|
|
|
|
if(s.size() == 0) return;
|
|
|
|
|
|
|
|
this->privateData->attributes[ID].type = Oyster::Network::NetAttributeType_CharArray;
|
|
|
|
|
|
|
|
this->privateData->attributes[ID].value.netCharPtr = new char[s.size() + 1];
|
|
|
|
memcpy(&this->privateData->attributes[ID].value.netCharPtr[0], &s[0], s.size() + 1);
|
|
|
|
}
|
|
|
|
const NetAttributeContainer& CustomNetProtocol::Get(int id)
|
|
|
|
{
|
|
|
|
return this->privateData->attributes[id];
|
2014-02-04 16:07:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
//// Created by [Dennis Andersen] [2013]
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
//#include "CustomNetProtocol.h"
|
|
|
|
//#include <map>
|
|
|
|
//#include "Translator.h"
|
|
|
|
//#include <DynamicArray.h>
|
|
|
|
//using namespace Oyster::Network;
|
|
|
|
//using namespace Utility::DynamicMemory;
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//struct CustomNetProtocol::PrivateData
|
|
|
|
//{
|
|
|
|
// Utility::DynamicMemory::DynamicArray<NetAttributeContainer> attributes; //...Im an idiot
|
|
|
|
//
|
|
|
|
// PrivateData()
|
|
|
|
// { }
|
|
|
|
//
|
|
|
|
// ~PrivateData()
|
|
|
|
// {
|
|
|
|
// for (unsigned int i = 0; i < attributes.Size(); i++)
|
|
|
|
// {
|
|
|
|
// RemoveAttribute(i);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// attributes.Clear();
|
|
|
|
// }
|
|
|
|
// void RemoveAttribute(int i)
|
|
|
|
// {
|
|
|
|
// switch (attributes[i].type)
|
|
|
|
// {
|
|
|
|
// case NetAttributeType_CharArray:
|
|
|
|
// delete [] attributes[i].value.netCharPtr;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// //Do network stuff
|
|
|
|
//};
|
|
|
|
//
|
|
|
|
//
|
|
|
|
//CustomNetProtocol::CustomNetProtocol()
|
|
|
|
//{
|
|
|
|
// this->privateData = new PrivateData();
|
|
|
|
//}
|
|
|
|
//CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o)
|
|
|
|
//{
|
|
|
|
// this->privateData = o.privateData;
|
|
|
|
//}
|
|
|
|
//const CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o)
|
|
|
|
//{
|
|
|
|
// this->privateData = o.privateData;
|
|
|
|
// return *this;
|
|
|
|
//}
|
|
|
|
//CustomNetProtocol::~CustomNetProtocol()
|
|
|
|
//{
|
|
|
|
//}
|
|
|
|
//NetAttributeContainer& CustomNetProtocol::operator[](int ID)
|
|
|
|
//{
|
|
|
|
// if(ID >= this->privateData->attributes.Size())
|
|
|
|
// this->privateData->attributes.Resize(
|
|
|
|
// if(this->privateData->attributes.find(ID) == this->privateData->attributes.end())
|
|
|
|
// {
|
|
|
|
// this->privateData->attributes[ID];
|
|
|
|
// this->privateData->attributes[ID].type = NetAttributeType_UNKNOWN;
|
|
|
|
// memset(&this->privateData->attributes[ID].value, 0, sizeof(NetAttributeValue));
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// return this->privateData->attributes[ID];
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//void CustomNetProtocol::Set(int ID, Oyster::Network::NetAttributeValue val, Oyster::Network::NetAttributeType type)
|
|
|
|
//{
|
|
|
|
// this->privateData->attributes[ID].type = type;
|
|
|
|
//
|
|
|
|
// switch (type)
|
|
|
|
// {
|
|
|
|
// case Oyster::Network::NetAttributeType_Bool:
|
|
|
|
// case Oyster::Network::NetAttributeType_Char:
|
|
|
|
// case Oyster::Network::NetAttributeType_UnsignedChar:
|
|
|
|
// case Oyster::Network::NetAttributeType_Short:
|
|
|
|
// case Oyster::Network::NetAttributeType_UnsignedShort:
|
|
|
|
// case Oyster::Network::NetAttributeType_Int:
|
|
|
|
// case Oyster::Network::NetAttributeType_UnsignedInt:
|
|
|
|
// case Oyster::Network::NetAttributeType_Int64:
|
|
|
|
// case Oyster::Network::NetAttributeType_UnsignedInt64:
|
|
|
|
// case Oyster::Network::NetAttributeType_Float:
|
|
|
|
// case Oyster::Network::NetAttributeType_Double:
|
|
|
|
// this->privateData->attributes[ID].value = val;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//void CustomNetProtocol::Set(int ID, std::string s)
|
|
|
|
//{
|
|
|
|
// if(s.size() == 0) return;
|
|
|
|
//
|
|
|
|
// this->privateData->attributes[ID].type = Oyster::Network::NetAttributeType_CharArray;
|
|
|
|
//
|
|
|
|
// this->privateData->attributes[ID].value.netCharPtr = new char[s.size() + 1];
|
|
|
|
// memcpy(&this->privateData->attributes[ID].value.netCharPtr[0], &s[0], s.size() + 1);
|
|
|
|
//}
|
|
|
|
//const NetAttributeContainer& CustomNetProtocol::Get(int id)
|
|
|
|
//{
|
|
|
|
// return this->privateData->attributes[id];
|
|
|
|
//}
|