Merge branch 'Network' of https://github.com/dean11/Danbias into GameLogic
This commit is contained in:
commit
623267ad1b
|
@ -222,6 +222,8 @@ void Translator::Pack(OysterByte &bytes, CustomNetProtocol& protocol)
|
||||||
|
|
||||||
bool Translator::Unpack(CustomNetProtocol& protocol, OysterByte &bytes)
|
bool Translator::Unpack(CustomNetProtocol& protocol, OysterByte &bytes)
|
||||||
{
|
{
|
||||||
|
privateData->headerString.clear();
|
||||||
|
|
||||||
if(!privateData->UnpackHeader(protocol, bytes))
|
if(!privateData->UnpackHeader(protocol, bytes))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -60,13 +60,14 @@ unsigned char* OysterByte::GetByteArray()
|
||||||
|
|
||||||
void OysterByte::AddSize(unsigned int size)
|
void OysterByte::AddSize(unsigned int size)
|
||||||
{
|
{
|
||||||
int oldSize = this->size;
|
int newCapacity = this->size + size;
|
||||||
this->size += size;
|
|
||||||
|
|
||||||
if(this->size >= capacity)
|
if(newCapacity >= capacity)
|
||||||
{
|
{
|
||||||
IncreaseCapacity(oldSize);
|
IncreaseCapacity(newCapacity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this->size += size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OysterByte::SetBytes(unsigned char* bytes)
|
void OysterByte::SetBytes(unsigned char* bytes)
|
||||||
|
@ -116,7 +117,7 @@ OysterByte& OysterByte::operator +=(const OysterByte& obj)
|
||||||
|
|
||||||
if(newSize >= (int)capacity)
|
if(newSize >= (int)capacity)
|
||||||
{
|
{
|
||||||
IncreaseCapacity(this->size);
|
IncreaseCapacity(newSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int i = size, j = 0; i < newSize; i++, j++)
|
for(int i = size, j = 0; i < newSize; i++, j++)
|
||||||
|
@ -133,12 +134,12 @@ OysterByte& OysterByte::operator +=(const OysterByte& obj)
|
||||||
// Private //
|
// Private //
|
||||||
/////////////
|
/////////////
|
||||||
|
|
||||||
void OysterByte::IncreaseCapacity(unsigned int oldSize)
|
void OysterByte::IncreaseCapacity(unsigned int newCapacity)
|
||||||
{
|
{
|
||||||
capacity = size * 2;
|
capacity = newCapacity * 2;
|
||||||
unsigned char* temp = new unsigned char[capacity];
|
unsigned char* temp = new unsigned char[capacity];
|
||||||
|
|
||||||
for(int i = 0; i < (int)oldSize; i++)
|
for(int i = 0; i < (int)this->size; i++)
|
||||||
{
|
{
|
||||||
temp[i] = byteArray[i];
|
temp[i] = byteArray[i];
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,7 +282,7 @@ namespace Oyster
|
||||||
char* UnpackCStr(unsigned char buffer[])
|
char* UnpackCStr(unsigned char buffer[])
|
||||||
{
|
{
|
||||||
short len = UnpackS(buffer);
|
short len = UnpackS(buffer);
|
||||||
char* str = new char[len];
|
char* str = new char[len+1];
|
||||||
|
|
||||||
buffer += 2;
|
buffer += 2;
|
||||||
for(int i = 0; i < len; i++)
|
for(int i = 0; i < len; i++)
|
||||||
|
@ -290,6 +290,8 @@ namespace Oyster
|
||||||
str[i] = buffer[i];
|
str[i] = buffer[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
str[len] = '\0';
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue