From 49cfbbebd5b506cd4e58834db923cf015ce404f0 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Thu, 12 Dec 2013 10:32:43 +0100 Subject: [PATCH] Network - Changed to CustomProtocolObject on send. --- Code/Network/NetworkAPI/NetworkCallbackHelper.h | 16 ++++++++++++---- Code/Network/NetworkAPI/NetworkClient.cpp | 4 ++-- Code/Network/NetworkAPI/NetworkClient.h | 3 ++- Code/Network/NetworkAPI/Translator.cpp | 1 + Code/Network/OysterNetworkClient/ClientMain.cpp | 2 +- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Code/Network/NetworkAPI/NetworkCallbackHelper.h b/Code/Network/NetworkAPI/NetworkCallbackHelper.h index 5ad2b948..a458760e 100644 --- a/Code/Network/NetworkAPI/NetworkCallbackHelper.h +++ b/Code/Network/NetworkAPI/NetworkCallbackHelper.h @@ -5,6 +5,8 @@ // Created by Dennis Andersen 2013 // ///////////////////////////////////// +#include + namespace Oyster { namespace Network @@ -37,10 +39,16 @@ namespace Oyster union RecieverObject { - ClientConnectCallbackMethod clientConnectFnc; - ProtocolRecieverFunction protocolRecieverFnc; - ClientConnectedObject *clientConnectObject; - ProtocolRecieverObject *protocolRecievedObject; + ClientConnectCallbackMethod clientConnectFnc; // !< A function pointer for sending or recieving NetworkClient + ProtocolRecieverFunction protocolRecieverFnc; // !< A function pointer for sending or recieving CustomNetProtocol + ClientConnectedObject *clientConnectObject; // !< An object for sending or recieving NetworkClient + ProtocolRecieverObject *protocolRecievedObject; // !< An object for sending or recieving CustomNetProtocol + + RecieverObject() { memset(this, 0, sizeof(RecieverObject)); } + RecieverObject(ClientConnectCallbackMethod o) { clientConnectFnc = o; } + RecieverObject(ProtocolRecieverFunction o) { protocolRecieverFnc = o; } + RecieverObject(ClientConnectedObject* o) { clientConnectObject = o; } + RecieverObject(ProtocolRecieverObject* o) { protocolRecievedObject = o; } }; } } diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index 72edaa8a..697cb897 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -233,9 +233,9 @@ bool NetworkClient::IsConnected() return privateData->connection->IsConnected(); } -void NetworkClient::Send(CustomNetProtocol& protocol) +void NetworkClient::Send(CustomProtocolObject& protocol) { - this->privateData->Send(protocol); + this->privateData->Send(*protocol.GetProtocol()); } void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type) diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 48fd404d..353b51b6 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -19,6 +19,7 @@ namespace Oyster { extern "C" { + struct CustomProtocolObject; class NET_PROTOCOL_EXPORT NetworkClient { public: @@ -33,7 +34,7 @@ namespace Oyster bool IsConnected(); - void Send(CustomNetProtocol& protocol); + void Send(CustomProtocolObject& protocol); void SetRecieverObject(RecieverObject recvObj, NetworkProtocolCallbackType type); diff --git a/Code/Network/NetworkAPI/Translator.cpp b/Code/Network/NetworkAPI/Translator.cpp index 001d521d..eb2a3d17 100644 --- a/Code/Network/NetworkAPI/Translator.cpp +++ b/Code/Network/NetworkAPI/Translator.cpp @@ -8,6 +8,7 @@ #include "../NetworkDependencies/Messages/MessageHeader.h" #include "../NetworkDependencies/OysterByte.h" + using namespace Oyster::Network; using namespace ::Messages; using namespace Utility::DynamicMemory; diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 63e9c95c..bc70190d 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -34,7 +34,7 @@ int main() ThreadedClient* client = new ThreadedClient; //Connect to server - errorCode = client->Connect(9876, "localhost"); + errorCode = client->Connect(15151, "193.11.186.101"); if(errorCode != 0) {