diff --git a/Code/Network/NetworkDependencies/Connection.cpp b/Code/Network/NetworkDependencies/Connection.cpp index 9639329f..8a2081c0 100644 --- a/Code/Network/NetworkDependencies/Connection.cpp +++ b/Code/Network/NetworkDependencies/Connection.cpp @@ -3,15 +3,7 @@ #include #include -Connection::Connection() -{ - mySocket = NULL; -} - -Connection::Connection(int socket) -{ - mySocket = socket; -} +using namespace Oyster::Network; Connection::~Connection() { diff --git a/Code/Network/NetworkDependencies/Connection.h b/Code/Network/NetworkDependencies/Connection.h index 86ffda34..0070fed6 100644 --- a/Code/Network/NetworkDependencies/Connection.h +++ b/Code/Network/NetworkDependencies/Connection.h @@ -7,23 +7,30 @@ #include "IConnection.h" -class Connection : public ::Oyster::Network::IConnection +namespace Oyster { - private: - int mySocket; + namespace Network + { + class Connection : public IConnection + { - public: - Connection(); - Connection(int socket); - ~Connection(); + public: + Connection() { mySocket = 0; }; + Connection(int socket) { mySocket = socket; }; + ~Connection(); - virtual bool Connect( unsigned short port , const char serverName[] ); - virtual bool InitiateServer( unsigned short port ); - virtual void Disconnect(); - virtual bool Send(const char message[]); - virtual int Recieve(char message[]); - virtual int Listen(); + virtual bool Connect( unsigned short port , const char serverName[] ); + virtual bool InitiateServer( unsigned short port ); + virtual void Disconnect(); + virtual bool Send(const char message[]); + virtual int Recieve(char message[]); + virtual int Listen(); -}; + private: + int mySocket; + + }; + } +} #endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/IConnection.h b/Code/Network/NetworkDependencies/IConnection.h index b986c381..1443b781 100644 --- a/Code/Network/NetworkDependencies/IConnection.h +++ b/Code/Network/NetworkDependencies/IConnection.h @@ -11,13 +11,14 @@ namespace Oyster { class IConnection { - public: - virtual void Disconnect() = 0; - virtual bool Send( const char message[] ) = 0; - virtual int Recieve(char message[]) = 0; - virtual bool InitiateServer( unsigned short port ) { return false; }; - virtual int Listen() { return -1; }; - virtual bool Connect( unsigned short port, const char serverName[] ) { return false; }; + + public: + virtual void Disconnect() = 0; + virtual bool Send( const char message[] ) = 0; + virtual int Recieve(char message[]) = 0; + virtual bool InitiateServer( unsigned short port ) { return false; }; + virtual int Listen() { return -1; }; + virtual bool Connect( unsigned short port, const char serverName[] ) { return false; }; }; } } diff --git a/Code/Network/NetworkDependencies/ITranslate.h b/Code/Network/NetworkDependencies/ITranslate.h new file mode 100644 index 00000000..e974df54 --- /dev/null +++ b/Code/Network/NetworkDependencies/ITranslate.h @@ -0,0 +1,18 @@ +#ifndef NETWORK_DEPENDENCIES_I_TRANSLATE +#define NETWORK_DEPENDENCIES_I_TRANSLATE + +namespace Oyster +{ + namespace Network + { + class ITranslate + { + + public: + virtual char* Translate (const Protocols::ProtocolHeader &header ) = 0; + virtual Protocols::ProtocolHeader& Translate ( char message[] ) = 0; + + }; + } +} +#endif \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj index 4c42ba1d..4413823d 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj @@ -153,10 +153,14 @@ + + + + diff --git a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters index 57da6b71..ac82be77 100644 --- a/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters +++ b/Code/Network/NetworkDependencies/NetworkDependencies.vcxproj.filters @@ -21,6 +21,9 @@ Source Files + + Source Files + @@ -29,5 +32,14 @@ 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 new file mode 100644 index 00000000..962c3602 --- /dev/null +++ b/Code/Network/NetworkDependencies/Protocols.h @@ -0,0 +1,35 @@ +#include "string"; + +namespace Oyster +{ + namespace Network + { + namespace Protocols + { + enum PackageType + { + package_type_header, + package_type_test, + package_type_input, + package_type_update_position + + }; + + + struct ProtocolHeader + { + int size; + int packageType; + int clientID; + + ProtocolHeader() { this->packageType = package_type_header; } + }; + + struct ProtocolTest : public ProtocolHeader + { + std::string textMessage; + ProtocolTest() { this->packageType = package_type_test; } + }; + } + } +} \ No newline at end of file diff --git a/Code/Network/NetworkDependencies/Translator.cpp b/Code/Network/NetworkDependencies/Translator.cpp new file mode 100644 index 00000000..0fad1b06 --- /dev/null +++ b/Code/Network/NetworkDependencies/Translator.cpp @@ -0,0 +1,50 @@ +//#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(); +//} + + diff --git a/Code/Network/NetworkDependencies/Translator.h b/Code/Network/NetworkDependencies/Translator.h new file mode 100644 index 00000000..866ae932 --- /dev/null +++ b/Code/Network/NetworkDependencies/Translator.h @@ -0,0 +1,27 @@ +//#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 diff --git a/Code/Network/OysterNetworkClient/Client.cpp b/Code/Network/OysterNetworkClient/Client.cpp index a947beea..a32f0996 100644 --- a/Code/Network/OysterNetworkClient/Client.cpp +++ b/Code/Network/OysterNetworkClient/Client.cpp @@ -1,5 +1,7 @@ #include "Client.h" +using namespace Oyster::Network::Client; + Client::Client() { connection = new Connection(); diff --git a/Code/Network/OysterNetworkClient/Client.h b/Code/Network/OysterNetworkClient/Client.h index 1fd9f1f6..a6042fa0 100644 --- a/Code/Network/OysterNetworkClient/Client.h +++ b/Code/Network/OysterNetworkClient/Client.h @@ -7,20 +7,28 @@ #include "../NetworkDependencies/Connection.h" -class Client +namespace Oyster { -public: - Client(); - ~Client(); + namespace Network + { + namespace Client + { + class Client + { + public: + Client(); + ~Client(); - bool Connect(unsigned int port, char filename[]); + bool Connect(unsigned int port, char filename[]); - void Send(char msg[]); - void Recv(char msg[]); + void Send(char msg[]); + void Recv(char msg[]); -private: - Connection* connection; - -}; + private: + ::Oyster::Network::Connection* connection; + }; + } + } +} #endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index cc9a786f..a6002d0a 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -2,6 +2,7 @@ #include "Client.h" #include using namespace std; +using namespace Oyster::Network::Client; #pragma comment(lib, "ws2_32.lib") void ShutdownSockets(); diff --git a/Code/Network/OysterNetworkServer/Client.cpp b/Code/Network/OysterNetworkServer/Client.cpp index 50ce3b8c..f86d37b8 100644 --- a/Code/Network/OysterNetworkServer/Client.cpp +++ b/Code/Network/OysterNetworkServer/Client.cpp @@ -1,5 +1,7 @@ #include "Client.h" +using namespace Oyster::Network::Server; + Client::Client(unsigned int socket) { connection = new Connection(socket); diff --git a/Code/Network/OysterNetworkServer/Client.h b/Code/Network/OysterNetworkServer/Client.h index 3c29c620..8c25ec45 100644 --- a/Code/Network/OysterNetworkServer/Client.h +++ b/Code/Network/OysterNetworkServer/Client.h @@ -7,19 +7,29 @@ #include "../NetworkDependencies/Connection.h" -class Client +namespace Oyster { -public: - Client(unsigned int socket); - ~Client(); + namespace Network + { + namespace Server + { + class Client + { - void Send(char buffer[]); - void Recv(char buffer[]); + public: + Client(unsigned int socket); + ~Client(); + + void Send(char buffer[]); + void Recv(char buffer[]); -private: - Connection* connection; + private: + ::Oyster::Network::Connection* connection; + }; + } + } }; #endif \ No newline at end of file diff --git a/Code/Network/OysterNetworkServer/Listener.cpp b/Code/Network/OysterNetworkServer/Listener.cpp index 7b340441..5bda043f 100644 --- a/Code/Network/OysterNetworkServer/Listener.cpp +++ b/Code/Network/OysterNetworkServer/Listener.cpp @@ -1,5 +1,7 @@ #include "Listener.h" +using namespace Oyster::Network; + Listener::Listener() { diff --git a/Code/Network/OysterNetworkServer/Listener.h b/Code/Network/OysterNetworkServer/Listener.h index 8e5f99b7..d91fb98b 100644 --- a/Code/Network/OysterNetworkServer/Listener.h +++ b/Code/Network/OysterNetworkServer/Listener.h @@ -18,7 +18,7 @@ public: int Accept(); private: - Connection* connection; + ::Oyster::Network::Connection* connection; }; diff --git a/Code/Network/OysterNetworkServer/ServerMain.cpp b/Code/Network/OysterNetworkServer/ServerMain.cpp index 4fbe8ece..e531798e 100644 --- a/Code/Network/OysterNetworkServer/ServerMain.cpp +++ b/Code/Network/OysterNetworkServer/ServerMain.cpp @@ -3,6 +3,7 @@ #include "Listener.h" #include "Client.h" using namespace std; +using namespace Oyster::Network::Server; #pragma comment(lib, "ws2_32.lib")