diff --git a/Code/Network/NetworkDependencies/ITranslate.h b/Code/Network/NetworkDependencies/ITranslate.h index e974df54..6f24cd72 100644 --- a/Code/Network/NetworkDependencies/ITranslate.h +++ b/Code/Network/NetworkDependencies/ITranslate.h @@ -9,8 +9,8 @@ namespace Oyster { public: - virtual char* Translate (const Protocols::ProtocolHeader &header ) = 0; - virtual Protocols::ProtocolHeader& Translate ( char message[] ) = 0; + virtual unsigned char* Translate (Protocols::ProtocolHeader &header ) = 0; + virtual Protocols::ProtocolHeader& Translate ( unsigned char message[] ) = 0; }; } diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp index 16468bd7..cf2d2b22 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.cpp @@ -3,6 +3,7 @@ using namespace Oyster::Network::Messages; using namespace Oyster::Network::Packing; +using namespace Oyster::Network::Protocols; MessageHeader::MessageHeader() { @@ -15,22 +16,22 @@ MessageHeader::~MessageHeader() delete[] msg; } -void MessageHeader::Translate(/*Message& msg*/) +void MessageHeader::Translate(ProtocolHeader& header) { size = 0; - AddInt(4); - AddInt(5); - AddInt(6); + AddInt(header.clientID); + AddInt(header.packageType); + AddInt(header.size); } -void MessageHeader::Translate(unsigned char message[]) +void MessageHeader::Translate(unsigned char message[], ProtocolHeader& header) { size = 0; - int i = GetInt(message); - int j = GetInt(message); - int k = GetInt(message); + header.clientID = GetInt(message); + header.packageType = GetInt(message); + header.size = GetInt(message); } unsigned char* MessageHeader::GetMsg() diff --git a/Code/Network/NetworkDependencies/Messages/MessageHeader.h b/Code/Network/NetworkDependencies/Messages/MessageHeader.h index d6d79597..0aa22dff 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageHeader.h +++ b/Code/Network/NetworkDependencies/Messages/MessageHeader.h @@ -6,6 +6,7 @@ ///////////////////////////////////////////////////////////////////// #include +#include "../Protocols.h" namespace Oyster { @@ -19,8 +20,8 @@ namespace Oyster MessageHeader(); virtual ~MessageHeader(); - virtual void Translate(/*Message& msg*/); - virtual void Translate(unsigned char message[]); + virtual void Translate(Protocols::ProtocolHeader& header); + virtual void Translate(unsigned char message[], Protocols::ProtocolHeader& header); unsigned char* GetMsg(); diff --git a/Code/Network/NetworkDependencies/Messages/MessageTest.cpp b/Code/Network/NetworkDependencies/Messages/MessageTest.cpp index ba15c464..89fb2911 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageTest.cpp +++ b/Code/Network/NetworkDependencies/Messages/MessageTest.cpp @@ -1,6 +1,7 @@ #include "MessageTest.h" using namespace Oyster::Network::Messages; +using namespace Oyster::Network::Protocols; MessageTest::MessageTest() { @@ -11,16 +12,16 @@ MessageTest::~MessageTest() { } -void MessageTest::Translate() +void MessageTest::Translate(ProtocolHeader& header) { - MessageHeader::Translate(); + MessageHeader::Translate(header); - AddStr("Hej hur mår du idag?"); + AddStr(static_cast(&header)->textMessage); } -void MessageTest::Translate(unsigned char message[]) +void MessageTest::Translate(unsigned char message[], ProtocolHeader& header) { - MessageHeader::Translate(message); + MessageHeader::Translate(message, header); - std::string str = GetStr(message); + static_cast(&header)->textMessage = GetStr(message); } \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Messages/MessageTest.h b/Code/Network/NetworkDependencies/Messages/MessageTest.h index 8aebda05..e01847c9 100644 --- a/Code/Network/NetworkDependencies/Messages/MessageTest.h +++ b/Code/Network/NetworkDependencies/Messages/MessageTest.h @@ -19,8 +19,8 @@ namespace Oyster MessageTest(); virtual ~MessageTest(); - virtual void Translate(); - virtual void Translate(unsigned char message[]); + virtual void Translate(Protocols::ProtocolHeader& header); + virtual void Translate(unsigned char message[], Protocols::ProtocolHeader& header); private: diff --git a/Code/Network/NetworkDependencies/Messages/MessagesInclude.h b/Code/Network/NetworkDependencies/Messages/MessagesInclude.h new file mode 100644 index 00000000..4e1980ba --- /dev/null +++ b/Code/Network/NetworkDependencies/Messages/MessagesInclude.h @@ -0,0 +1,7 @@ +#ifndef NETWORK_DEPENDENCIES_MESSAGES_INCLUDE_H +#define NETWORK_DEPENDENCIES_MESSAGES_INCLUDE_H + +#include "MessageHeader.h" +#include "MessageTest.h" + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index ff978779..8c215717 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -162,6 +162,7 @@ + diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index 7ff2f960..0bb7c6e2 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -1,59 +1,22 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hpp;hxx;hm;inl;inc;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - + + + + + + - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - Header Files - - - Header Files - - - Header Files - + + + + + + + + + \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Protocols.h b/Code/Network/NetworkDependencies/Protocols.h index 962c3602..3f783790 100644 --- a/Code/Network/NetworkDependencies/Protocols.h +++ b/Code/Network/NetworkDependencies/Protocols.h @@ -1,4 +1,7 @@ -#include "string"; +#ifndef NETWORK_DEPENDENCIES_PROTOCOLS_H +#define NETWORK_DEPENDENCIES_PROTOCOLS_H + +#include namespace Oyster { @@ -12,7 +15,6 @@ namespace Oyster package_type_test, package_type_input, package_type_update_position - }; @@ -32,4 +34,6 @@ namespace Oyster }; } } -} \ No newline at end of file +} + +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Translator.cpp b/Code/Network/NetworkDependencies/Translator.cpp index 0fad1b06..30e1e273 100644 --- a/Code/Network/NetworkDependencies/Translator.cpp +++ b/Code/Network/NetworkDependencies/Translator.cpp @@ -1,50 +1,52 @@ -//#include "Translator.h" -// -//using namespace Oyster::Network; -//using namespace ::Protocols; -//using namespace ::Messages; -// -//char* Translate ( const ProtocolHeader &header ) -//{ -// MessageHeader *message; -// -// switch(header.packageType) -// { -// -// case package_type_header: -// message = new MessageHeader(); -// break; -// -// case package_type_test: -// message = new MessageTest(); -// break; -// } -// -// message->Translate(header); -// return message->GetMsg(); -//} -// -//ProtocolHeader& Translator::Translate( char msg[] ) -//{ -// ProtocolHeader header; -// MessageHeader *message = new MessageHeader(); -// -// header = message->translate(message); -// -// switch(header.packageType) -// { -// -// case package_type_header: -// message = new MessageHeader(); -// break; -// -// case package_type_test: -// message = new MessageTest(); -// break; -// } -// -// message->Translate(msg); -// return message->GetProtocol(); -//} +#include "Translator.h" + +using namespace Oyster::Network; +using namespace ::Protocols; +using namespace ::Messages; + +unsigned char* Translator::Translate( ProtocolHeader &header ) +{ + MessageHeader *message = NULL; + + switch(header.packageType) + { + + case package_type_header: + message = new MessageHeader(); + break; + + case package_type_test: + message = new MessageTest(); + break; + } + + message->Translate(header); + + return message->GetMsg(); +} + +ProtocolHeader& Translator::Translate(unsigned char msg[] ) +{ + ProtocolHeader* header = new ProtocolHeader(); + MessageHeader *message = new MessageHeader(); + + message->Translate(msg, *header); + + switch(header->packageType) + { + case package_type_header: + message = new MessageHeader(); + header = new ProtocolHeader(); + break; + + case package_type_test: + message = new MessageTest(); + header = new ProtocolTest(); + break; + } + + message->Translate(msg, *header); + return *header; +} diff --git a/Code/Network/NetworkDependencies/Translator.h b/Code/Network/NetworkDependencies/Translator.h index 866ae932..c9eb7362 100644 --- a/Code/Network/NetworkDependencies/Translator.h +++ b/Code/Network/NetworkDependencies/Translator.h @@ -1,27 +1,24 @@ -//#ifndef NETWORK_DEPENDENCIES_TRANSLATOR_H -//#define NETWORK_DEPENDENCIES_TRANSLATOR_H -// -////#include "MessageHeader.h" -//#include "Protocols.h" -//#include "ITranslate.h" -// -//namespace Oyster -//{ -// namespace Network -// { -// namespace Messages -// { -// class Translator -// { -// public: -// Translator (){}; -// ~Translator(){}; -// -// char* Translate (const Protocols::ProtocolHeader &header ); -// Protocols::ProtocolHeader& Translate ( char msg[] ); -// }; -// } -// } -//} -// -//#endif \ No newline at end of file +#ifndef NETWORK_DEPENDENCIES_TRANSLATOR_H +#define NETWORK_DEPENDENCIES_TRANSLATOR_H + +#include "Messages/MessagesInclude.h" +#include "Protocols.h" +#include "ITranslate.h" + +namespace Oyster +{ + namespace Network + { + class Translator : public ITranslate + { + public: + Translator (){}; + ~Translator(){}; + + unsigned char* Translate (Protocols::ProtocolHeader &header ); + Protocols::ProtocolHeader& Translate (unsigned char msg[] ); + }; + } +} + +#endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index e7bfcab6..a399dc62 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -10,19 +10,34 @@ using namespace Oyster::Network::Server; void ShutdownSockets(); bool InitSockets(); -#include "../NetworkDependencies/Messages/MessageTest.h" -using namespace Oyster::Network::Messages; +#include "../NetworkDependencies/Translator.h" +using namespace Oyster::Network; +using namespace ::Protocols; int main() { + unsigned char* recvBuffer; + Translator t; + ProtocolTest header; + header.clientID = 1; + header.packageType = package_type_test; + header.size = 12; + header.textMessage = "Hej"; + + recvBuffer = t.Translate(header); + + ProtocolHeader& asd = t.Translate(recvBuffer); + switch(asd.packageType) + { + case package_type_test: + + break; + } + cout << static_cast(&asd)->textMessage << endl; + + cout << "Server" << endl; - unsigned char* recvBuffer = new unsigned char[255]; - - MessageTest msg; - msg.Translate(); - recvBuffer = msg.GetMsg(); - msg.Translate(recvBuffer); if(!InitSockets()) {