diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.cpp b/Code/Network/NetworkAPI/CustomNetProtocol.cpp index ecb57bf9..90fb100d 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.cpp +++ b/Code/Network/NetworkAPI/CustomNetProtocol.cpp @@ -40,12 +40,13 @@ CustomNetProtocol::CustomNetProtocol() { this->privateData = new PrivateData(); } -CustomNetProtocol::CustomNetProtocol(CustomNetProtocol& o) +CustomNetProtocol::CustomNetProtocol(const CustomNetProtocol& o) { this->privateData = new PrivateData(); this->privateData->attributes = o.privateData->attributes; } -const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o) + +CustomNetProtocol& CustomNetProtocol::operator=(const CustomNetProtocol& o) { if(this->privateData) { @@ -56,11 +57,29 @@ const CustomNetProtocol& CustomNetProtocol::operator=(CustomNetProtocol& o) this->privateData->attributes = o.privateData->attributes; return *this; } + CustomNetProtocol::~CustomNetProtocol() { delete this->privateData; this->privateData = 0; } + +const NetAttributeContainer& CustomNetProtocol::operator[](int ID) const +{ + //if(!this->privateData) this->privateData = new PrivateData(); + if((unsigned int)ID >= this->privateData->attributes.Size()) + { + NetAttributeContainer temp; + + temp.type = NetAttributeType_UNKNOWN; + memset(&temp.value, 0, sizeof(NetAttributeValue)); + + this->privateData->attributes.Push(ID, temp); + } + + return this->privateData->attributes[ID]; +} + NetAttributeContainer& CustomNetProtocol::operator[](int ID) { //if(!this->privateData) this->privateData = new PrivateData(); diff --git a/Code/Network/NetworkAPI/CustomNetProtocol.h b/Code/Network/NetworkAPI/CustomNetProtocol.h index 48feb3a9..24df6ebf 100644 --- a/Code/Network/NetworkAPI/CustomNetProtocol.h +++ b/Code/Network/NetworkAPI/CustomNetProtocol.h @@ -130,10 +130,12 @@ namespace Oyster public: CustomNetProtocol(); ~CustomNetProtocol(); - CustomNetProtocol(CustomNetProtocol& o); - const CustomNetProtocol& operator=(CustomNetProtocol& o); + CustomNetProtocol( const CustomNetProtocol& o); + CustomNetProtocol& operator=(const CustomNetProtocol& o); + + const NetAttributeContainer& operator[](int ID) const; + NetAttributeContainer& operator[](int ID); - NetAttributeContainer& operator[](int ID); void Set(int id, Oyster::Network::NetAttributeValue val, Oyster::Network::NetAttributeType type); void Set(int ID, std::string s); const NetAttributeContainer& Get(int id);