diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp index c2e65faf..fc26dd34 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp @@ -8,23 +8,20 @@ using namespace Oyster::Network::Protocols; MessageHeader::MessageHeader() { size = 0; - } MessageHeader::~MessageHeader() { - } void MessageHeader::Translate(ProtocolHeader& header, unsigned char msg[] ) { size = 0; - - AddInt(header.clientID, msg); - AddInt(header.packageType, msg); - AddInt(header.size, msg); - + AddInt(header.size, msg); + AddInt(header.packageType, msg); + AddInt(header.clientID, msg); + SetSize(msg); } void MessageHeader::Translate(unsigned char message[], ProtocolHeader& header) @@ -36,7 +33,6 @@ void MessageHeader::Translate(unsigned char message[], ProtocolHeader& header) header.size = GetInt(message); } - void MessageHeader::AddInt(int i, unsigned char msg[]) { Pack(&msg[size], i); @@ -61,4 +57,9 @@ std::string MessageHeader::GetStr(unsigned char message[]) std::string std = UnpackStr(&message[size]); size += 2 + std.length(); return std; +} + +void MessageHeader::SetSize(unsigned char msg[]) +{ + Pack(&msg[0], size); } \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.h b/Code/Network/NetworkDependencies/Messages/MessageHeader.h index 2705a062..af9be77f 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.h +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.h @@ -33,6 +33,8 @@ namespace Oyster int GetInt(unsigned char message[]); std::string GetStr(unsigned char message[]); + void SetSize(unsigned char msg[]); + private: int size; diff --git a/Code/Network/NetworkDependencies/Messages/MessageTest.cpp b/Code/Network/NetworkDependencies/Messages/MessageTest.cpp index e8ddcb57..2d3bbe10 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageTest.cpp +++ b/Code/Network/NetworkDependencies/Messages/MessageTest.cpp @@ -5,7 +5,6 @@ using namespace Oyster::Network::Protocols; MessageTest::MessageTest() { - } MessageTest::~MessageTest() @@ -17,6 +16,7 @@ void MessageTest::Translate(ProtocolHeader& header, unsigned char msg[]) MessageHeader::Translate(header, msg); AddStr(static_cast(&header)->textMessage, msg); + SetSize(msg); } void MessageTest::Translate(unsigned char message[], ProtocolHeader& header) diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 6d104944..2f954b69 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -41,8 +41,13 @@ int main() Client client2(clientSocket); cout << "Second client connected." << endl; - client1.Send((unsigned char*)"Hej"); ProtocolSet* set = new ProtocolSet; + ProtocolTest test; + test.clientID = 0; + test.textMessage = "hej"; + recvBuffer = t.Translate(test); + + client1.Send(recvBuffer); while(1) {