From 9eb8fcba40e4dec4f338cd012ba69bc15d456cc9 Mon Sep 17 00:00:00 2001 From: dean11 Date: Mon, 16 Dec 2013 09:00:11 +0100 Subject: [PATCH] Gamelogic - Publication to others... --- Code/Game/DanBiasServer/DanBiasServer.vcxproj | 1 + Code/Game/DanBiasServer/GameServer.cpp | 1 - .../ServerObjects/ClientObject.h | 7 +++-- .../ServerObjects/Lobby/MainLobby.cpp | 23 +++++++++++++-- .../ServerObjects/Lobby/MainLobby.h | 4 +-- .../ServerObjects/NetworkSession.cpp | 28 +++++++++++++++++-- .../ServerObjects/NetworkSession.h | 15 ++++++---- Code/Game/GameProtocols/GameProtocols.vcxproj | 1 + .../GameProtocols/ProtocolIdentificationID.h | 17 ++++++++--- Code/Network/NetworkAPI/NetworkClient.cpp | 10 +++++++ Code/Network/NetworkAPI/NetworkClient.h | 3 ++ .../OysterNetworkClient/ClientMain.cpp | 2 +- 12 files changed, 90 insertions(+), 22 deletions(-) diff --git a/Code/Game/DanBiasServer/DanBiasServer.vcxproj b/Code/Game/DanBiasServer/DanBiasServer.vcxproj index f0763732..af26345b 100644 --- a/Code/Game/DanBiasServer/DanBiasServer.vcxproj +++ b/Code/Game/DanBiasServer/DanBiasServer.vcxproj @@ -187,6 +187,7 @@ + diff --git a/Code/Game/DanBiasServer/GameServer.cpp b/Code/Game/DanBiasServer/GameServer.cpp index 0c4836d6..c0601b30 100644 --- a/Code/Game/DanBiasServer/GameServer.cpp +++ b/Code/Game/DanBiasServer/GameServer.cpp @@ -54,7 +54,6 @@ namespace DanBias if(!this->server->Init(serverDesc)) return DanBiasServerReturn_Error; if(!WindowShell::CreateConsoleWindow()) return DanBiasServerReturn_Error; - if(!WindowShell::CreateWin(WindowShell::WINDOW_INIT_DESC())) return DanBiasServerReturn_Error; this->initiated = true; return DanBiasServerReturn_Sucess; diff --git a/Code/Game/DanBiasServer/ServerObjects/ClientObject.h b/Code/Game/DanBiasServer/ServerObjects/ClientObject.h index c1cab669..83327d1b 100644 --- a/Code/Game/DanBiasServer/ServerObjects/ClientObject.h +++ b/Code/Game/DanBiasServer/ServerObjects/ClientObject.h @@ -9,7 +9,8 @@ namespace DanBias { - class ClientObject :public Oyster::Network::ProtocolRecieverObject + class ClientObject + :public Oyster::Network::ProtocolRecieverObject { public: ClientObject(const Oyster::Network::NetworkClient& client); @@ -20,8 +21,8 @@ namespace DanBias GameLogic::Player* Logic_Object(); Oyster::Network::NetworkClient* NetClient_Object(); - private: - void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) override; + /** This method is NOT threadsafe. */ + virtual void ProtocolRecievedCallback(Oyster::Network::CustomNetProtocol& protocol) override; private: GameLogic::Player logicPlayer; diff --git a/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp index f4c8b439..e7edddd4 100644 --- a/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.cpp @@ -1,5 +1,5 @@ #include "MainLobby.h" - +#include namespace DanBias { @@ -13,14 +13,31 @@ namespace DanBias } void MainLobby::Release() { - this->clients.clear(); + this->DetachClient(); } void MainLobby::Frame() { if(!this->box.IsEmpty()) { - + NetEvent &e = this->box.Fetch(); + ParseEvent(e); } } + +//////// Private + void MainLobby::ParseEvent(NetEvent& e) + { + static const short i = MAXSHORT; + if(e.protocol[0].type != Oyster::Network::NetAttributeType_Short) return; + + short f = e.protocol[0].value.netShort; + + switch (f) + { + default: + break; + } + } + }//End namespace DanBias \ No newline at end of file diff --git a/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.h b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.h index 9308a4d4..8e8b520a 100644 --- a/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.h +++ b/Code/Game/DanBiasServer/ServerObjects/Lobby/MainLobby.h @@ -2,8 +2,6 @@ #define DANBIASSERVER_MAINLOBBY_H #include "..\NetworkSession.h" -#include -#include namespace DanBias { @@ -17,7 +15,7 @@ namespace DanBias void Frame(); private: - + void ParseEvent(NetEvent& e); }; }//End namespace DanBias diff --git a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp index 24de1dfe..c33af5e0 100644 --- a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp +++ b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.cpp @@ -1,3 +1,4 @@ + #include "ClientObject.h" #include "NetworkSession.h" #include @@ -20,15 +21,38 @@ namespace DanBias if(!this->clients[i]) { this->clients[i] = client; - //this->clients[i]->SetPostbox(&this->box); + this->clients[i]->SetPostbox(&this->box); return; } } this->clients.push_back(client); } + + void NetworkSession::DetachClient(Oyster::Network::NetworkClient* client) + { + for (unsigned int i = 0; i < this->clients.size(); i++) + { + if(this->clients[0]->NetClient_Object()->Id() == client->Id()) + this->clients[i] = 0; + } + } + void NetworkSession::DetachClient(ClientObject* client) + { + for (unsigned int i = 0; i < this->clients.size(); i++) + { + if(this->clients[0]->NetClient_Object()->Id() == client->NetClient_Object()->Id()) + this->clients[i] = 0; + } + + } void NetworkSession::DetachClient(short ID) { - //this->clients[0]->NetClient_Object()-> + for (unsigned int i = 0; i < this->clients.size(); i++) + { + if(this->clients[0]->NetClient_Object()->Id() == ID) + this->clients[i] = 0; + } + } void NetworkSession::DetachClient() { diff --git a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.h b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.h index 43a7bde4..9ff9b016 100644 --- a/Code/Game/DanBiasServer/ServerObjects/NetworkSession.h +++ b/Code/Game/DanBiasServer/ServerObjects/NetworkSession.h @@ -1,10 +1,14 @@ +///////////////////////////////////////////////////////////////////// +// Created by [Dennis Andersen] [2013] +///////////////////////////////////////////////////////////////////// #ifndef DANBIASSERVER_NETWORK_SESSION_H #define DANBIASSERVER_NETWORK_SESSION_H #define NOMINMAX #include "Utilities.h" #include -#include +#include +#include #include namespace DanBias @@ -13,12 +17,10 @@ namespace DanBias class NetworkSession { public: - struct ClientEvent + struct NetEvent { ClientObject* reciever; Oyster::Network::CustomNetProtocol protocol; - ClientEvent() { reciever = 0; } - ~ClientEvent() { } }; public: @@ -27,6 +29,8 @@ namespace DanBias void AttachClient(Utility::DynamicMemory::SmartPointer client); + void DetachClient(Oyster::Network::NetworkClient* client); + void DetachClient(ClientObject* client); void DetachClient(short ID); void DetachClient(); @@ -36,10 +40,11 @@ namespace DanBias void Send(Oyster::Network::CustomNetProtocol& protocol, int ID); //TODO: Do more lobby features + //virtual void protected: std::vector> clients; - Oyster::PostBox box; + Oyster::PostBox box; }; }//End namespace DanBias #endif // !DANBIASSERVER_NETWORK_SESSION_H diff --git a/Code/Game/GameProtocols/GameProtocols.vcxproj b/Code/Game/GameProtocols/GameProtocols.vcxproj index 12584afb..4b0d7c39 100644 --- a/Code/Game/GameProtocols/GameProtocols.vcxproj +++ b/Code/Game/GameProtocols/GameProtocols.vcxproj @@ -154,6 +154,7 @@ + diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index b872618a..09f1aeed 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -1,12 +1,21 @@ +///////////////////////////////////////////////////////////////////// +// Created 2013 by: +// [Dennis Andersen], [Linda Andersson] +///////////////////////////////////////////////////////////////////// #ifndef GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H #define GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H /* THERE CAN ABSOLUTLEY NOT BE TWO DEFINITIONS WITH THE SAME ID!! */ -#define protocol_PlayerNavigation 0 -#define protocol_PlayerPosition 1 -#define protocol_ObjectPosition 2 +#define protocol_PlayerNavigation 0 +#define protocol_PlayerPosition 1 +#define protocol_ObjectPosition 2 -#define PROTOCOL_TEST 1000 +#define protocol_Lobby_Msg 60 + +#define protocol_General_Disconnect 100 +#define protocol_General_Ping 101 + +#define PROTOCOL_TEST 1000 #endif // !GAMEPROTOCOL_PROTOCOL_DEFINITION_ID_H diff --git a/Code/Network/NetworkAPI/NetworkClient.cpp b/Code/Network/NetworkAPI/NetworkClient.cpp index e9de4297..aed1046f 100644 --- a/Code/Network/NetworkAPI/NetworkClient.cpp +++ b/Code/Network/NetworkAPI/NetworkClient.cpp @@ -245,4 +245,14 @@ void NetworkClient::SetRecieverObject(RecieverObject recvObj, NetworkProtocolCal bool NetworkClient::operator ==(const NetworkClient& obj) { return (this->privateData->data->ID == obj.privateData->data->ID); +} + +bool NetworkClient::operator ==(const int& ID) +{ + return this->privateData->data->ID == ID; +} + +int NetworkClient::Id() const +{ + return this->privateData->data->ID; } \ No newline at end of file diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 5c08e794..95463d1c 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -45,6 +45,9 @@ namespace Oyster //Compares the internal ID. bool operator ==(const NetworkClient& obj); + bool operator ==(const int& ID); + + int Id() const; private: struct PrivateData; diff --git a/Code/Network/OysterNetworkClient/ClientMain.cpp b/Code/Network/OysterNetworkClient/ClientMain.cpp index 3f451315..2274fb5e 100644 --- a/Code/Network/OysterNetworkClient/ClientMain.cpp +++ b/Code/Network/OysterNetworkClient/ClientMain.cpp @@ -41,7 +41,7 @@ int main() //Connect to server //errorCode = client->Connect(15151, "193.11.186.101"); - errorCode = client->Connect(15151, "127.0.0.1"); + errorCode = client.Connect(15151, "127.0.0.1"); client.SetRecieverObject(proc, NetworkProtocolCallbackType_Function); if(errorCode != 0)