From 5b4758d2ae478bd3b9d1913bd78a069e643b4592 Mon Sep 17 00:00:00 2001 From: Dennis Andersen Date: Tue, 18 Feb 2014 08:55:38 +0100 Subject: [PATCH 1/5] Broekn --- .../GameClientState/NetLoadState.cpp | 2 +- Code/Game/GameProtocols/LobbyProtocols.h | 68 ++-- Code/Game/GameServer/GameClient.h | 20 +- Code/Game/GameServer/GameLobby.h | 25 +- Code/Game/GameServer/GameSession.h | 14 +- .../GameServer/Implementation/GameClient.cpp | 55 +-- .../GameServer/Implementation/GameLobby.cpp | 8 +- .../GameLobby_ProtocolParser.cpp | 62 +-- .../Implementation/GameSession_Gameplay.cpp | 6 +- .../Implementation/GameSession_General.cpp | 354 ++++++++++-------- Code/Network/NetworkAPI/NetworkClient.h | 8 +- 11 files changed, 306 insertions(+), 316 deletions(-) diff --git a/Code/Game/GameClient/GameClientState/NetLoadState.cpp b/Code/Game/GameClient/GameClientState/NetLoadState.cpp index 3463182e..ab492797 100644 --- a/Code/Game/GameClient/GameClientState/NetLoadState.cpp +++ b/Code/Game/GameClient/GameClientState/NetLoadState.cpp @@ -81,7 +81,7 @@ void NetLoadState::DataRecieved( NetEventprivData->loading ) { - this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).modelName ); + this->LoadGame( Protocol_LobbyCreateGame(e.args.data.protocol).mapName ); } } diff --git a/Code/Game/GameProtocols/LobbyProtocols.h b/Code/Game/GameProtocols/LobbyProtocols.h index 71202898..26909bbf 100644 --- a/Code/Game/GameProtocols/LobbyProtocols.h +++ b/Code/Game/GameProtocols/LobbyProtocols.h @@ -41,61 +41,41 @@ namespace GameLogic struct Protocol_LobbyCreateGame :public Oyster::Network::CustomProtocolObject { - short clientID; // The unuiqe id reprsenting a specific client - std::string modelName; - float worldMatrix[16]; - + char majorVersion; + char minorVersion; + std::string mapName; + Protocol_LobbyCreateGame() { - int c = 0; - this->protocol[c].value = protocol_Lobby_CreateGame; - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; - - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; - for (int i = 0; i <= 16; i++) - { - this->protocol[c++].type = Oyster::Network::NetAttributeType_Float; - } - this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray; + this->protocol[0].value = protocol_Lobby_CreateGame; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Char; + this->protocol[2].type = Oyster::Network::NetAttributeType_Char; + this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray; } - Protocol_LobbyCreateGame(short _clientID, std::string name, float world[16]) + Protocol_LobbyCreateGame(char majorVersion, char minorVersion, std::string name) { - int c = 0; - this->protocol[c].value = protocol_Lobby_CreateGame; - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value = protocol_Lobby_CreateGame; + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[1].type = Oyster::Network::NetAttributeType_Char; + this->protocol[2].type = Oyster::Network::NetAttributeType_Char; + this->protocol[3].type = Oyster::Network::NetAttributeType_CharArray; - this->protocol[c++].type = Oyster::Network::NetAttributeType_Short; - for (int i = 0; i <= 16; i++) - { - this->protocol[c++].type = Oyster::Network::NetAttributeType_Float; - } - - this->protocol[c++].type = Oyster::Network::NetAttributeType_CharArray; - - clientID = _clientID; - modelName = name; - memcpy(&worldMatrix[0], &world[0], sizeof(float) * 16); + this->majorVersion = majorVersion; + this->minorVersion = minorVersion; + this->mapName = name; } Protocol_LobbyCreateGame(Oyster::Network::CustomNetProtocol o) { - int c = 1; - clientID = o[c++].value.netInt; - for (int i = 0; i <= 16; i++) - { - this->worldMatrix[i] = o[c++].value.netFloat; - } - modelName.assign(o[c++].value.netCharPtr); + this->majorVersion = o[1].value.netChar; + this->minorVersion = o[2].value.netChar; + this->mapName.assign(o[3].value.netCharPtr); } Oyster::Network::CustomNetProtocol GetProtocol() override { - int c = 1; - protocol[c++].value = clientID; - - for (int i = 0; i <= 16; i++) - { - this->protocol[c++].value = this->worldMatrix[i]; - } - protocol.Set(c++, this->modelName); + protocol[1].value = this->majorVersion; + protocol[2].value = this->minorVersion; + protocol.Set(3, this->mapName); return protocol; } diff --git a/Code/Game/GameServer/GameClient.h b/Code/Game/GameServer/GameClient.h index a9c33cf3..09b3bc40 100644 --- a/Code/Game/GameServer/GameClient.h +++ b/Code/Game/GameServer/GameClient.h @@ -25,19 +25,31 @@ namespace DanBias Utility::DynamicMemory::SmartPointer GetClient(); Utility::DynamicMemory::SmartPointer ReleaseClient(); - float GetSinceLastResponse() const; - bool IsReady() const; - bool Equals(const Oyster::Network::NetworkClient* c); + inline bool operator==(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; } + inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->GetID()); } + inline float GetSinceLastResponse() const { return this->secondsSinceLastResponse; } + inline std::wstring GetAlias() const { return this->alias; } + inline std::wstring GetCharacter() const { return this->character; } + inline bool IsReady() const { return this->isReady; } + inline GameLogic::IPlayerData* GetPlayer() const { return this->player; } + + + void SetPlayer(GameLogic::IPlayerData* player); void SetReadyState(bool isReady); + void SetAlias(std::wstring alias); + void SetCharacter(std::wstring character); void SetSinceLastResponse(float seconds); private: GameLogic::IPlayerData* player; Utility::DynamicMemory::SmartPointer client; + bool isReady; float secondsSinceLastResponse; - }; + std::wstring alias; + std::wstring character; + }; }//End namespace DanBias #endif // !DANBIASSERVER_CLIENT_OBJECT_H diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index d0cbbcc3..ac4db486 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -36,25 +36,24 @@ namespace DanBias private: void ParseProtocol(Oyster::Network::CustomNetProtocol& p, Oyster::Network::NetworkClient* c); - void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status: - void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text: - //void LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Create: - void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start: - //void LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Join: - void LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login: - void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh: - void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData: - void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData: - void LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: - void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType: + void GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Status: + void GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c); //id = protocol_General_Text: + void LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Start: + void LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Login: + void LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_Refresh: + void LobbyGameData(GameLogic::Protocol_LobbyGameData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_GameData: + void LobbyMainData(GameLogic::Protocol_LobbyClientData& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_MainData: + void LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_ClientReadyState: + void LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c); //id = protocol_Lobby_QuerryGameType: private: void ClientEventCallback(Oyster::Network::NetEvent e) override; void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) override; private: - Utility::WinTimer timer; - float refreshFrequency; + //Utility::WinTimer timer; + //float refreshFrequency; + Utility::DynamicMemory::LinkedList readyList; GameSession gameSession; LobbyLevelData description; diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 3d86ea78..8cd04048 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -31,10 +31,10 @@ namespace DanBias */ struct GameDescription { - int maxClients; - int mapNumber; - int gameMode; - int gameTime; + unsigned int maxClients; + std::string mapName; + std::string gameMode; + int gameTimeMinutes; Oyster::Network::NetworkSession* owner; Utility::DynamicMemory::DynamicArray clients; }; @@ -61,14 +61,14 @@ namespace DanBias //Private member functions private: - // TODO: find out what this method does.. + // Client event callback function void ClientEventCallback(Oyster::Network::NetEvent e) override; - //Sends a client to the owner, if obj is NULL then all clients is sent + //Sends a client to the owner, if param is NULL then all clients is sent void SendToOwner(DanBias::GameClient* obj); //Derived from IThreadObject - void ThreadEntry() override; + void ThreadEntry( ) override; bool DoWork ( ) override; diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 3956fe57..6e68b1e8 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -12,51 +12,26 @@ using namespace DanBias; using namespace GameLogic; -GameClient::GameClient(SmartPointer client, GameLogic::IPlayerData* player) +GameClient::GameClient() { - this->client = client; - this->player = player; + this->player = 0; isReady = false; + this->character = L"Unknown"; + this->alias = L"Unknown"; + this->secondsSinceLastResponse = 0.0f; } GameClient::~GameClient() { - this->client->Disconnect(); this->player = 0; - isReady = false; + this->isReady = false; + this->character = L"Unknown"; + this->alias = L"Unknown"; + this->secondsSinceLastResponse = 0.0f; } -GameLogic::IPlayerData* GameClient::GetPlayer() +void GameClient::SetPlayer(GameLogic::IPlayerData* player) { - return this->player; -} -GameLogic::IPlayerData* GameClient::ReleasePlayer() -{ - GameLogic::IPlayerData *temp = this->player; - this->player = 0; - return temp; -} -SmartPointer GameClient::GetClient() -{ - return this->client; -} -SmartPointer GameClient::ReleaseClient() -{ - SmartPointer temp = this->client; - this->client = 0; - return temp; -} - -float GameClient::GetSinceLastResponse() const -{ - return this->secondsSinceLastResponse; -} -bool GameClient::IsReady() const -{ - return this->isReady; -} -bool GameClient::Equals(const NetworkClient* c) -{ - return (c->GetID() == this->client->GetID()); + this->player = player; } void GameClient::SetReadyState(bool r) { @@ -66,5 +41,13 @@ void GameClient::SetSinceLastResponse(float s) { this->secondsSinceLastResponse = s; } +void GameClient::SetAlias(std::wstring alias) +{ + this->alias = alias; +} +void GameClient::SetCharacter(std::wstring character) +{ + this->character = character; +} diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 6f4f0a47..2a297e2f 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -56,13 +56,13 @@ bool GameLobby::StartGameSession( ) GameSession::GameDescription desc; desc.maxClients = this->description.maxClients; desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; + desc.gameTimeMinutes = this->description.gameTime; + //desc.mapName = this->description.mapNumber; desc.owner = this; desc.clients = this->clients; - if(desc.gameTime == 0.0f) - desc.gameTime = (int)(60.0f * 10.0f); //note: should be fetched from somewhere. + if(desc.gameTimeMinutes == 0) + desc.gameTimeMinutes = 10; //note: should be fetched from somewhere. if(desc.maxClients == 0) desc.maxClients = 10; //note: should be fetched somewhere else.. diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp index d49f83fc..81758480 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -12,27 +12,23 @@ void GameLobby::ParseProtocol(Oyster::Network::CustomNetProtocol& p, NetworkClie { switch (p[0].value.netShort) { - case protocol_General_Status: this->GeneralStatus (Protocol_General_Status (p), c); + case protocol_General_Status: this->GeneralStatus (Protocol_General_Status (p), c); break; - case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c); + case protocol_General_Text: this->GeneralText (Protocol_General_Text (p), c); break; - //case protocol_Lobby_Create: this->LobbyCreateGame (Protocol_LobbyCreateGame (p), c); - //break; - case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); + case protocol_Lobby_StartGame: this->LobbyStartGame (Protocol_LobbyStartGame (p), c); break; - //case protocol_Lobby_Join: this->LobbyJoin (Protocol_LobbyJoin (p), c); - //break; - case protocol_Lobby_Login: this->LobbyLogin (Protocol_LobbyJoinGame (p), c); + case protocol_Lobby_JoinGame: this->LobbyJoin (Protocol_LobbyJoinGame (p), c); break; - case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); + case protocol_Lobby_Refresh: this->LobbyRefresh (Protocol_LobbyRefresh (p), c); break; - case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); + case protocol_Lobby_GameData: this->LobbyGameData (Protocol_LobbyGameData (p), c); break; - case protocol_Lobby_ClientData: this->LobbyMainData (Protocol_LobbyClientData (p), c); + case protocol_Lobby_ClientData: this->LobbyMainData (Protocol_LobbyClientData (p), c); break; - case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); + case protocol_Lobby_ClientReadyState: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); break; - case protocol_Lobby_QuerryGameType: this->LobbyReady (Protocol_LobbyClientReadyState (p), c); + case protocol_Lobby_QuerryGameType: this->LobbyQuerryGameData (Protocol_QuerryGameType (), c); break; } } @@ -59,37 +55,40 @@ void GameLobby::GeneralStatus(GameLogic::Protocol_General_Status& p, Oyster::Net } void GameLobby::GeneralText(GameLogic::Protocol_General_Text& p, Oyster::Network::NetworkClient* c) { + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + if(this->clients[i]) + { + this->clients[i]->Send(p); + } + } printf(p.text.c_str()); } -//void GameLobby::LobbyCreateGame(GameLogic::Protocol_LobbyCreateGame& p, Oyster::Network::NetworkClient* c) -//{ -// -//} void GameLobby::LobbyStartGame(GameLogic::Protocol_LobbyStartGame& p, Oyster::Network::NetworkClient* c) { if(this->sessionOwner->GetClient()->GetID() == c->GetID()) { - + //Send countdown timer before lobby shuts down + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + this->clients[i]->Send(Protocol_LobbyStartGame(3.0f)); + } } else { //Someone else tried to start the server.. } } -//void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoin& p, Oyster::Network::NetworkClient* c) -//{ -// //for (unsigned int i = 0; i < this->gameLobby.Size(); i++) -// //{ -// // if (this->gameLobby[i]->GetID() == p.value) -// // { -// // this->gameLobby[i]->Attach(Detach(c)); -// // return; -// // } -// //} -//} -void GameLobby::LobbyLogin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c) +void GameLobby::LobbyJoin(GameLogic::Protocol_LobbyJoinGame& p, Oyster::Network::NetworkClient* c) { - + //for (unsigned int i = 0; i < this->gameLobby.Size(); i++) + //{ + // if (this->gameLobby[i]->GetID() == p.value) + // { + // this->gameLobby[i]->Attach(Detach(c)); + // return; + // } + //} } void GameLobby::LobbyRefresh(GameLogic::Protocol_LobbyRefresh& p, Oyster::Network::NetworkClient* c) { @@ -112,6 +111,7 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster: else { this->readyList.Remove(c); + } } void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c) diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index ca1572a1..d0cf5190 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -19,11 +19,8 @@ using namespace Oyster; using namespace Oyster::Network; using namespace Oyster::Thread; using namespace GameLogic; +using namespace DanBias; -namespace DanBias -{ - Utility::WinTimer testTimer; - int testID = -1; bool GameSession::DoWork( ) { @@ -246,7 +243,6 @@ namespace DanBias printf("Message recieved from (%i):\t %s\n", c->GetClient()->GetID(), p.text.c_str()); } -}//End namespace DanBias diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index cf82cc61..cd89dc9a 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -24,217 +24,243 @@ using namespace Oyster; using namespace Oyster::Network; using namespace Oyster::Thread; using namespace GameLogic; +using namespace DanBias; -namespace DanBias +GameSession* GameSession::gameSession = nullptr; + +GameSession::GameSession() + :gameInstance(GameAPI::Instance()) { - GameSession* GameSession::gameSession = nullptr; + this->owner = 0; + this->isCreated = false; + this->isRunning = false; + this->gameSession = this; + this->logicFrameTime = DELTA_TIME_20; + this->networkFrameTime = DELTA_TIME_20; + this->networkTimer.reset(); + this->logicTimer.reset(); - GameSession::GameSession() - :gameInstance(GameAPI::Instance()) + memset(&this->description, 0, sizeof(GameDescription)); +} + +GameSession::~GameSession() +{ + this->worker.Terminate(); + this->clients.Clear(); + this->gameInstance; + this->owner = 0; + this->isCreated = false; + this->isRunning = false; +} + +bool GameSession::Create(GameDescription& desc) +{ + this->description = desc; +/* Do some error checking */ + if(desc.clients.Size() == 0) return false; + if(!desc.owner) return false; + if(this->isCreated) return false; + +/* standard initialization of some data */ + NetworkSession::clients = desc.clients; + NetworkSession::clients.Resize((unsigned int)desc.maxClients); + this->clients.Resize((unsigned int)desc.maxClients); + this->owner = desc.owner; + +/* Initiate the game instance */ + if(!this->gameInstance.Initiate()) { - this->owner = 0; - this->isCreated = false; - this->isRunning = false; - this->gameSession = this; - this->logicFrameTime = DELTA_TIME_20; - this->networkFrameTime = DELTA_TIME_20; - this->networkTimer.reset(); - this->logicTimer.reset(); - - memset(&this->description, 0, sizeof(GameDescription)); + printf("Failed to initiate the game instance\n"); } - GameSession::~GameSession() +/* Create the players in the game instance */ + GameLogic::IPlayerData* p = 0; + for (unsigned int i = 0; i < desc.clients.Size(); i++) { - this->worker.Terminate(); - this->clients.Clear(); - this->gameInstance; - this->owner = 0; - this->isCreated = false; - this->isRunning = false; - } - - bool GameSession::Create(GameDescription& desc) - { - this->description = desc; - /* Do some error checking */ - if(desc.clients.Size() == 0) return false; - if(!desc.owner) return false; - if(this->isCreated) return false; - - /* standard initialization of some data */ - NetworkSession::clients = desc.clients; - NetworkSession::clients.Resize((unsigned int)desc.maxClients); - this->clients.Resize((unsigned int)desc.maxClients); - this->owner = desc.owner; - - /* Initiate the game instance */ - if(!this->gameInstance.Initiate()) + if(desc.clients[i]) { - printf("Failed to initiate the game instance\n"); - } - - /* Create the players in the game instance */ - GameLogic::IPlayerData* p = 0; - for (unsigned int i = 0; i < desc.clients.Size(); i++) - { - if(desc.clients[i]) + if( (p = this->gameInstance.CreatePlayer()) ) { - if( (p = this->gameInstance.CreatePlayer()) ) - { - desc.clients[i]->SetOwner(this); - this->clients[i] = (new GameClient(desc.clients[i], p)); - } - else - { - printf("Failed to create player (%i)\n", i); - } + desc.clients[i]->SetOwner(this); + this->clients[i] = (new GameClient(desc.clients[i], p)); + } + else + { + printf("Failed to create player (%i)\n", i); } } - - /* Create the game level */ - if(!(this->levelData = this->gameInstance.CreateLevel())) - { - printf("Level not created!"); - return false; - } - - /* Set some game instance data options */ - this->gameInstance.SetSubscription(GameSession::ObjectMove); - this->gameInstance.SetSubscription(GameSession::ObjectDisabled); - this->gameInstance.SetFPS(60); - - this->description.clients.Clear(); - - this->isCreated = true; - - /* Create the worker thread */ - if(this->worker.Create(this, false) != OYSTER_THREAD_ERROR_SUCCESS) - return false; - - return this->isCreated; } - void GameSession::Run() +/* Create the game level */ + if(!(this->levelData = this->gameInstance.CreateLevel())) { - if(this->isRunning) return; - - if(this->clients.Size() > 0) - { - this->worker.Start(); - this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1); - this->isRunning = true; - } + printf("Level not created!"); + return false; } - void GameSession::ThreadEntry( ) - { - //List with clients that we are waiting on.. - DynamicArray> readyList;// = this->clients; +/* Set some game instance data options */ + this->gameInstance.SetSubscription(GameSession::ObjectMove); + this->gameInstance.SetSubscription(GameSession::ObjectDisabled); + this->gameInstance.SetFPS(60); - //First we need to clean invalid clients, if any, and tell them to start loading game data - for (unsigned int i = 0; i < this->clients.Size(); i++) + this->description.clients.Clear(); + + this->isCreated = true; + + /* Create the worker thread */ + if(this->worker.Create(this, false) != OYSTER_THREAD_ERROR_SUCCESS) + return false; + + return this->isCreated; +} + +void GameSession::Run() +{ + if(this->isRunning) return; + + if(this->clients.Size() > 0) + { + this->worker.Start(); + this->worker.SetPriority(OYSTER_THREAD_PRIORITY_1); + this->isRunning = true; + } +} + +void GameSession::ThreadEntry( ) +{ +//List with clients that we are waiting on.. + DynamicArray> readyList;// = this->clients; + +//First we need to clean invalid clients, if any, and tell them to start loading game data + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + if(this->clients[i]) { - if(this->clients[i]) - { - if(this->clients[i]->IsReady()) - { - readyList.Push(this->clients[i]); - Protocol_LobbyCreateGame p(readyList[i]->GetPlayer()->GetID(), "char_white.dan", readyList[i]->GetPlayer()->GetOrientation()); - readyList[readyList.Size() - 1]->GetClient()->Send(p); - } - } + readyList.Push(this->clients[i]); + Protocol_LobbyCreateGame p((char)1, (char)0, this->description.mapName); + readyList[readyList.Size() - 1]->GetClient()->Send(p); } + } - unsigned int readyCounter = readyList.Size(); + unsigned int readyCounter = readyList.Size(); - //Sync with clients - while (readyCounter != 0) +//Sync with clients + while (readyCounter != 0) + { + this->ProcessClients(); + for (unsigned int i = 0; i < readyList.Size(); i++) { - this->ProcessClients(); - for (unsigned int i = 0; i < readyList.Size(); i++) + if(readyList[i] && readyList[i]->IsReady()) { - if(readyList[i] && readyList[i]->IsReady()) + //Need to send information about other players, to all players + for (unsigned int k = 0; k < this->clients.Size(); k++) { - //Need to send information about other players, to all players - for (unsigned int k = 0; k < this->clients.Size(); k++) + if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID()) { - if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID()) - { - //Protocol_ObjectCreatePlayer - Protocol_ObjectCreate p( this->clients[k]->GetPlayer()->GetPosition(), - this->clients[k]->GetPlayer()->GetRotation(), - this->clients[k]->GetPlayer()->GetScale(), - this->clients[k]->GetPlayer()->GetID(), "char_white.dan"); //The model name will be custom later.. - readyList[i]->GetClient()->Send(p); - } + IPlayerData* pl = this->clients[k]->GetPlayer(); + Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(), + pl->GetID(), true, this->clients[k]->GetPlayer()->GetTeamID(), + /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + readyList[i]->GetClient()->Send(p); } - - readyCounter-- ; - readyList[i] = 0; } + + readyCounter-- ; + readyList[i] = 0; } - Sleep(5); //TODO: This might not be needed here. } + Sleep(5); //TODO: This might not be needed here. + } +//Sync with clients before starting countdown + + for (unsigned int i = 0; i < this->clients.Size(); i++) + { + if(this->clients[i]) + { + this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5)); + } + } +} + +bool GameSession::Attach(Utility::DynamicMemory::SmartPointer networkClient) +{ + if(!this->isCreated) return false; + if(this->GetClientCount() == this->clients.Capacity()) return false; + + networkClient->SetOwner(this); + + IPlayerData* playerData = this->gameInstance.CreatePlayer(); + if(!playerData) return false; + + SmartPointer gameClient = new GameClient(networkClient, playerData); + NetworkClient* nwClient = gameClient->GetClient(); + +// Send the level information + { + Protocol_LobbyCreateGame lcg((char)1, (char)0, this->description.mapName); + nwClient->Send(lcg); + } + +// Send the player data only + { + Protocol_ObjectCreatePlayer oc( playerData->GetPosition(), playerData->GetRotation(), playerData->GetScale(), + playerData->GetID(), true, playerData->GetTeamID(), + /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + nwClient->Send(oc); + } + +// Send information about other clients + { for (unsigned int i = 0; i < this->clients.Size(); i++) { - if(this->clients[i]) + if(clients[i]) { - this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5)); + IPlayerData* temp = clients[i]->GetPlayer(); + Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), + temp->GetID(), false, temp->GetTeamID(), + /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); + nwClient->Send(oc); } } } - bool GameSession::Attach(Utility::DynamicMemory::SmartPointer client) +//TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client { - if(!this->isCreated) return false; - if(this->GetClientCount() == this->clients.Capacity()) return false; - client->SetOwner(this); + } - IPlayerData* player = this->gameInstance.CreatePlayer(); - if(!player) return false; - - SmartPointer obj = new GameClient(client, player); - - // Send the chosen mesh name - Protocol_LobbyCreateGame lcg(obj->GetPlayer()->GetID(), "char_white.dan", obj->GetPlayer()->GetOrientation()); - obj->GetClient()->Send(lcg); - - // Send the player data only - for (unsigned int i = 0; i < this->clients.Capacity(); i++) - { - if(this->clients[i]) - { - IPlayerData* p = this->clients[i]->GetPlayer(); - Protocol_ObjectCreate oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); - //Protocol_ObjectCreatePlayer oc(p->GetPosition(), p->GetRotation(), p->GetScale(), p->GetID(), "char_white.dan"); - this->clients[i]->GetClient()->Send(oc); - } - } - - obj->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(0)); - - for (unsigned int i = 0; i < this->clients.Size(); i++) +// Insert the new client to the update list + { + bool added = false; + for (unsigned int i = 0; !added && i < this->clients.Size(); i++) { if(!clients[i]) { - NetworkSession::clients[i] = client; - clients[i] = obj; - return true; + NetworkSession::clients[i] = networkClient; + clients[i] = gameClient; + added = true; } } - - return true; + if(!added) + { + NetworkSession::clients.Push( networkClient ); + clients.Push( gameClient ); + } } - - void GameSession::CloseSession( bool dissconnectClients ) +// Send the start signal { - this->worker.Terminate(); - NetworkSession::CloseSession(true); - this->clients.Clear(); + nwClient->Send(GameLogic::Protocol_LobbyStartGame(0)); } -}//End namespace DanBias + return true; +} + +void GameSession::CloseSession( bool dissconnectClients ) +{ + this->worker.Terminate(); + NetworkSession::CloseSession(true); + this->clients.Clear(); +} + diff --git a/Code/Network/NetworkAPI/NetworkClient.h b/Code/Network/NetworkAPI/NetworkClient.h index 58d81360..6f037117 100644 --- a/Code/Network/NetworkAPI/NetworkClient.h +++ b/Code/Network/NetworkAPI/NetworkClient.h @@ -133,13 +133,7 @@ namespace Oyster */ virtual void DataRecieved(NetEvent e); - /** ! Deprecate ! - * Do not use this furthermore, instead use void DataRecieved(NetEvent e); - * @see DataRecieved - */ - //virtual void NetworkCallback(Oyster::Network::CustomNetProtocol& p); - - virtual std::string GetIpAddress(); + std::string GetIpAddress(); private: NetworkClient(const NetworkClient& obj); From 06ddb86b17d19b35fd3fc107d4bb8c935001fc42 Mon Sep 17 00:00:00 2001 From: Erik Persson Date: Tue, 18 Feb 2014 11:33:36 +0100 Subject: [PATCH 2/5] GL - GetAllDynamicObjects , dennis order --- Code/Game/GameLogic/Game.h | 2 ++ Code/Game/GameLogic/GameAPI.h | 2 ++ Code/Game/GameLogic/Game_LevelData.cpp | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index 93e130f5..b8f6d4b3 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -61,6 +61,8 @@ namespace GameLogic ObjectSpecialType GetObjectType() const override; int getNrOfDynamicObj()const override; IObjectData* GetObjectAt(int ID) const override; + Utility::DynamicMemory::DynamicArray GetAllDynamicObjects() const override; + Level *level; }; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 30e86e8c..2a24c99e 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -13,6 +13,7 @@ #include "GameLogicStates.h" #include #include "LevelLoader\ObjectDefines.h" +#include "DynamicArray.h" namespace GameLogic @@ -107,6 +108,7 @@ namespace GameLogic public: virtual int getNrOfDynamicObj()const = 0; virtual IObjectData* GetObjectAt(int ID) const = 0; + virtual Utility::DynamicMemory::DynamicArray GetAllDynamicObjects() const = 0; }; class DANBIAS_GAMELOGIC_DLL GameAPI diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index b007ce01..4529e787 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -50,4 +50,16 @@ int Game::LevelData::getNrOfDynamicObj()const IObjectData* Game::LevelData::GetObjectAt(int ID) const { return this->level->GetObj(ID); +} + +Utility::DynamicMemory::DynamicArray Game::LevelData::GetAllDynamicObjects() const +{ + Utility::DynamicMemory::DynamicArray objects(level->dynamicObjects.Size()); + + for(int i = 0; i < level->dynamicObjects.Size(); i++) + { + objects[i] = level->dynamicObjects[i]; + } + + return objects; } \ No newline at end of file From f6f183d6e7453c399063160a45a833ebbd55fa16 Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 18 Feb 2014 11:34:24 +0100 Subject: [PATCH 3/5] GameServer - Added inititiate protocols --- Code/Game/GameServer/GameClient.h | 34 ++++-- Code/Game/GameServer/GameLobby.h | 19 ++- Code/Game/GameServer/GameServerAPI.h | 17 +-- Code/Game/GameServer/GameSession.h | 19 +-- .../GameServer/Implementation/GameClient.cpp | 25 +++- .../GameServer/Implementation/GameLobby.cpp | 98 +++++++++++++--- .../GameLobby_ProtocolParser.cpp | 37 +++--- .../GameServer/Implementation/GameServer.cpp | 51 ++++---- .../Implementation/GameSession_Gameplay.cpp | 22 ++-- .../Implementation/GameSession_General.cpp | 110 ++++++++++-------- .../StandaloneGameServerCLI.cpp | 26 +++-- .../StandaloneGameServerCLI.h | 8 +- Code/Network/NetworkAPI/NetworkSession.h | 4 +- 13 files changed, 311 insertions(+), 159 deletions(-) diff --git a/Code/Game/GameServer/GameClient.h b/Code/Game/GameServer/GameClient.h index 09b3bc40..422df933 100644 --- a/Code/Game/GameServer/GameClient.h +++ b/Code/Game/GameServer/GameClient.h @@ -5,6 +5,7 @@ #define DANBIASSERVER_CLIENT_OBJECT_H #include +#include #include #include #include @@ -17,22 +18,21 @@ namespace DanBias class GameClient { public: - GameClient(Utility::DynamicMemory::SmartPointer client, GameLogic::IPlayerData* player); + GameClient(Utility::DynamicMemory::SmartPointer nwClient); virtual~GameClient(); - GameLogic::IPlayerData* GetPlayer(); - GameLogic::IPlayerData* ReleasePlayer(); - Utility::DynamicMemory::SmartPointer GetClient(); - Utility::DynamicMemory::SmartPointer ReleaseClient(); - inline bool operator==(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; } - inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->GetID()); } + inline bool operator==(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); } - inline float GetSinceLastResponse() const { return this->secondsSinceLastResponse; } - inline std::wstring GetAlias() const { return this->alias; } - inline std::wstring GetCharacter() const { return this->character; } - inline bool IsReady() const { return this->isReady; } - inline GameLogic::IPlayerData* GetPlayer() const { return this->player; } + inline bool Equals(const GameLogic::IPlayerData* c) { return (this->player) ? (c->GetID() == this->player->GetID()) : false ; } + inline bool Equals(const Oyster::Network::NetworkClient* c) { return (c->GetID() == this->client->GetID()); } + + inline float GetSinceLastResponse() const { return this->secondsSinceLastResponse; } + inline std::wstring GetAlias() const { return this->alias; } + inline std::wstring GetCharacter() const { return this->character; } + inline bool IsReady() const { return this->isReady; } + inline GameLogic::IPlayerData* GetPlayer() const { return this->player; } + Oyster::Network::NetClient GetClient() const { return this->client; } void SetPlayer(GameLogic::IPlayerData* player); @@ -41,6 +41,13 @@ namespace DanBias void SetCharacter(std::wstring character); void SetSinceLastResponse(float seconds); + GameLogic::IPlayerData* ReleasePlayer(); + Oyster::Network::NetClient ReleaseClient(); + + //NetworkSpecific + void SetOwner(Oyster::Network::NetworkSession* owner); + void UpdateClient(); + private: GameLogic::IPlayerData* player; Utility::DynamicMemory::SmartPointer client; @@ -52,4 +59,7 @@ namespace DanBias std::wstring character; }; }//End namespace DanBias + +typedef Utility::DynamicMemory::SmartPointer gClient; + #endif // !DANBIASSERVER_CLIENT_OBJECT_H diff --git a/Code/Game/GameServer/GameLobby.h b/Code/Game/GameServer/GameLobby.h index ac4db486..9281dcd6 100644 --- a/Code/Game/GameServer/GameLobby.h +++ b/Code/Game/GameServer/GameLobby.h @@ -15,11 +15,18 @@ namespace DanBias { struct LobbyLevelData { - int mapNumber; int maxClients; - int gameMode; - int gameTime; - std::string gameName; + int gameTimeInMinutes; + std::wstring gameMode; + std::wstring mapName; + std::wstring gameName; + LobbyLevelData() + : maxClients(10) + , gameTimeInMinutes(10) + , gameMode(L"unknown") + , mapName(L"unknown") + , gameName(L"unknown") + { } }; class GameLobby :public Oyster::Network::NetworkSession { @@ -49,6 +56,8 @@ namespace DanBias private: void ClientEventCallback(Oyster::Network::NetEvent e) override; void ClientConnectedEvent(Utility::DynamicMemory::SmartPointer client) override; + void ProcessClients() override; + bool Attach(Utility::DynamicMemory::SmartPointer client) override; private: //Utility::WinTimer timer; @@ -58,7 +67,7 @@ namespace DanBias GameSession gameSession; LobbyLevelData description; Utility::DynamicMemory::SmartPointer sessionOwner; - + Utility::DynamicMemory::DynamicArray> gClients; }; }//End namespace DanBias #endif // !DANBIASGAME_GAMELOBBY_H diff --git a/Code/Game/GameServer/GameServerAPI.h b/Code/Game/GameServer/GameServerAPI.h index a9e8c63f..eb5316c4 100644 --- a/Code/Game/GameServer/GameServerAPI.h +++ b/Code/Game/GameServer/GameServerAPI.h @@ -55,15 +55,18 @@ namespace DanBias static void NotifyWhenClientConnect(ClientConnectedNotify func); static void NotifyWhenClientDisconnect(ClientDisconnectedNotify func); - static void GameSetMapName(const wchar_t* val); - static void GameSetMaxClients(const int& val); - static void GameSetGameMode(const wchar_t* val); static void GameSetGameTime(const int& val); - static int GameGetMapId(); - static int GameGetMaxClients(); - static int GameGetGameMode(); + static void GameSetMaxClients(const int& val); + static void GameSetGameName(const wchar_t* val); + static void GameSetMapName(const wchar_t* val); + static void GameSetGameMode(const wchar_t* val); + static int GameGetGameTime(); - static const char* GameGetGameName(); + static int GameGetMaxClients(); + static const wchar_t* GameGetGameMode(); + static const wchar_t* GameGetGameName(); + static const wchar_t* GameGetMapName(); + static bool GameStart(); diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 8cd04048..200bed9b 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -32,11 +32,11 @@ namespace DanBias struct GameDescription { unsigned int maxClients; - std::string mapName; - std::string gameMode; + std::wstring mapName; + std::wstring gameMode; int gameTimeMinutes; Oyster::Network::NetworkSession* owner; - Utility::DynamicMemory::DynamicArray clients; + Utility::DynamicMemory::DynamicArray> clients; }; public: @@ -52,17 +52,19 @@ namespace DanBias /** Join an existing/running game session * @param client The client to attach to the session */ - bool Attach(Oyster::Network::NetClient client) override; - void CloseSession( bool dissconnectClients ) override; + bool Join(gClient client); + + //void CloseSession( bool dissconnectClients ) override; inline bool IsCreated() const { return this->isCreated; } inline bool IsRunning() const { return this->isRunning; } - operator bool() { return (this->isCreated && this->isCreated); } + operator bool() { return (this->isCreated && this->isRunning); } //Private member functions private: // Client event callback function void ClientEventCallback(Oyster::Network::NetEvent e) override; + void ProcessClients() override; //Sends a client to the owner, if param is NULL then all clients is sent void SendToOwner(DanBias::GameClient* obj); @@ -98,8 +100,8 @@ namespace DanBias //Private member variables private: - Utility::DynamicMemory::DynamicArray> clients; - Utility::DynamicMemory::SmartPointer sessionOwner; + Utility::DynamicMemory::DynamicArray gClients; + gClient sessionOwner; Oyster::Thread::OysterThread worker; GameLogic::GameAPI& gameInstance; GameLogic::ILevelData *levelData; @@ -115,6 +117,7 @@ namespace DanBias //TODO: Remove this uggly hax static GameSession* gameSession; + };//End GameSession }//End namespace DanBias #endif // !DANBIASSERVER_GAME_SESSION_H \ No newline at end of file diff --git a/Code/Game/GameServer/Implementation/GameClient.cpp b/Code/Game/GameServer/Implementation/GameClient.cpp index 6e68b1e8..7ef4a338 100644 --- a/Code/Game/GameServer/Implementation/GameClient.cpp +++ b/Code/Game/GameServer/Implementation/GameClient.cpp @@ -12,8 +12,9 @@ using namespace DanBias; using namespace GameLogic; -GameClient::GameClient() +GameClient::GameClient(Utility::DynamicMemory::SmartPointer nwClient) { + this->client = nwClient; this->player = 0; isReady = false; this->character = L"Unknown"; @@ -51,3 +52,25 @@ void GameClient::SetCharacter(std::wstring character) } +void GameClient::SetOwner(Oyster::Network::NetworkSession* owner) +{ + this->client->SetOwner(owner); +} +void GameClient::UpdateClient() +{ + this->client->Update(); +} + + +IPlayerData* GameClient::ReleasePlayer() +{ + IPlayerData* temp = this->player; + this->player = 0; + return temp; +} +NetClient GameClient::ReleaseClient() +{ + NetClient temp = this->client; + this->client = 0; + return temp; +} diff --git a/Code/Game/GameServer/Implementation/GameLobby.cpp b/Code/Game/GameServer/Implementation/GameLobby.cpp index 2a297e2f..f2467750 100644 --- a/Code/Game/GameServer/Implementation/GameLobby.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby.cpp @@ -14,7 +14,7 @@ using namespace GameLogic; using namespace DanBias; GameLobby::GameLobby() -{ } +{ } GameLobby::~GameLobby() { this->clients.Clear(); @@ -37,16 +37,33 @@ void GameLobby::Update() void GameLobby::SetGameDesc(const LobbyLevelData& desc) { this->description.gameMode = desc.gameMode; - this->description.gameTime = desc.gameTime; - this->description.mapNumber = desc.mapNumber; + this->description.gameName = desc.gameName; + this->description.mapName = desc.mapName; + this->description.gameTimeInMinutes = desc.gameTimeInMinutes; this->description.maxClients = desc.maxClients; + + if(this->gClients.Size() > (unsigned int)desc.maxClients) + { + //Kick overflow + for (unsigned int i = (unsigned int)desc.maxClients - 1; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + this->gClients[i]->GetClient()->Disconnect(); + } + } + } + this->gClients.Resize((unsigned int)desc.maxClients); + } void GameLobby::GetGameDesc(LobbyLevelData& desc) { - desc.gameMode = this->description.gameMode; - desc.gameTime = this->description.gameTime; - desc.mapNumber = this->description.mapNumber; + desc.gameTimeInMinutes = this->description.gameTimeInMinutes; desc.maxClients = this->description.maxClients; + desc.mapName = this->description.mapName; + desc.gameName = this->description.gameName; + desc.gameMode = this->description.gameMode; + } bool GameLobby::StartGameSession( ) { @@ -56,10 +73,10 @@ bool GameLobby::StartGameSession( ) GameSession::GameDescription desc; desc.maxClients = this->description.maxClients; desc.gameMode = this->description.gameMode; - desc.gameTimeMinutes = this->description.gameTime; + desc.gameTimeMinutes = this->description.gameTimeInMinutes; //desc.mapName = this->description.mapNumber; desc.owner = this; - desc.clients = this->clients; + desc.clients = this->gClients; if(desc.gameTimeMinutes == 0) desc.gameTimeMinutes = 10; //note: should be fetched from somewhere. @@ -67,7 +84,7 @@ bool GameLobby::StartGameSession( ) if(desc.maxClients == 0) desc.maxClients = 10; //note: should be fetched somewhere else.. - this->clients.Clear(); //Remove clients from lobby list + this->gClients.Clear(); //Remove clients from lobby list if(this->gameSession.Create(desc)) { @@ -96,8 +113,8 @@ void GameLobby::ClientEventCallback(NetEventGetID(), e.sender->GetIpAddress().c_str()); e.sender->Disconnect(); - this->readyList.Remove(e.sender); - this->clients.Remove(e.sender); + //this->readyList.Remove(e.sender); + //this->gClients.Remove(e.sender); break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: printf("\t(%i : %s) - EventType_ProtocolRecieved\n", e.sender->GetID(), e.sender->GetIpAddress().c_str()); @@ -111,21 +128,30 @@ void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointergameSession) { - Attach(client); + if(!this->Attach(client)) + { + client->Disconnect(); + } } else { - Attach(client); + if(!this->Attach(client)) + { + //Send message that lobby full + client->Disconnect(); + return; + } + Protocol_LobbyClientData p1; Protocol_LobbyGameData p2; - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]) + if(this->gClients[i]) { Protocol_LobbyClientData::PlayerData t; - t.id = this->clients[i]->GetID(); - t.ip = this->clients[i]->GetIpAddress(); + t.id = client->GetID(); + t.ip = client->GetIpAddress(); t.team = 0; t.name = "Dennis är kung tycker Erik!"; p1.list.Push(t); @@ -139,4 +165,42 @@ void GameLobby::ClientConnectedEvent(Utility::DynamicMemory::SmartPointerSend(p2.GetProtocol()); } } +void GameLobby::ProcessClients() +{ + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + this->gClients[i]->UpdateClient(); + } + } +} +bool GameLobby::Attach(Utility::DynamicMemory::SmartPointer client) +{ + if(this->clientCount = this->description.maxClients) return false; + + bool added = false; + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(!this->gClients[i]) + { + added = true; + this->gClients[i] = new GameClient(client); + } + } + + if(!added) + { + this->gClients.Push(new GameClient(client)); + } + return true; +} + + + + + + + + diff --git a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp index 81758480..ebcfb8bf 100644 --- a/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp +++ b/Code/Game/GameServer/Implementation/GameLobby_ProtocolParser.cpp @@ -116,27 +116,34 @@ void GameLobby::LobbyReady(GameLogic::Protocol_LobbyClientReadyState& p, Oyster: } void GameLobby::LobbyQuerryGameData(GameLogic::Protocol_QuerryGameType& p, Oyster::Network::NetworkClient* c) { - NetClient temp; - bool found = false; - - //find client in waiting list - for (unsigned int i = 0; !found && i < this->clients.Size(); i++) + if(this->gameSession) { - if(this->clients[i]->GetID() == c->GetID()) + gClient temp; + bool found = false; + + //find client in waiting list + for (unsigned int i = 0; !found && i < this->clients.Size(); i++) { - temp = this->clients[i]; - found = true; + if(this->gClients[i]->GetClient()->GetID() == c->GetID()) + { + temp = this->gClients[i]; + found = true; + } } - } - //Something is wrong - if(!found) - { - c->Disconnect(); + //Something is wrong + if(!found) + { + c->Disconnect(); + } + else + { + //Send game data + this->gameSession.Join(temp); + } } else { - //Send game data - this->gameSession.Attach(temp); + } } diff --git a/Code/Game/GameServer/Implementation/GameServer.cpp b/Code/Game/GameServer/Implementation/GameServer.cpp index 087fa7ff..8fbf2111 100644 --- a/Code/Game/GameServer/Implementation/GameServer.cpp +++ b/Code/Game/GameServer/Implementation/GameServer.cpp @@ -118,65 +118,74 @@ void GameServerAPI::NotifyWhenClientDisconnect(ClientDisconnectedNotify func) else clientDisconnectedCallback = func; } -void GameServerAPI::GameSetMapName(const wchar_t* val) +void GameServerAPI::GameSetMapName(const wchar_t* val) { LobbyLevelData d; lobby.GetGameDesc(d); - //d.mapNumber = val; //TODO: implement + d.mapName = val; lobby.SetGameDesc(d); } -void GameServerAPI::GameSetMaxClients(const int& val) +void GameServerAPI::GameSetGameMode(const wchar_t* val) +{ + LobbyLevelData d; + lobby.GetGameDesc(d); + d.gameMode = val; + lobby.SetGameDesc(d); +} +void GameServerAPI::GameSetGameName(const wchar_t* val) +{ + LobbyLevelData d; + lobby.GetGameDesc(d); + d.gameName = val; + lobby.SetGameDesc(d); +} +void GameServerAPI::GameSetMaxClients(const int& val) { LobbyLevelData d; lobby.GetGameDesc(d); d.maxClients = val; lobby.SetGameDesc(d); } -void GameServerAPI::GameSetGameMode(const wchar_t* val) +void GameServerAPI::GameSetGameTime(const int& val) { LobbyLevelData d; lobby.GetGameDesc(d); - //d.gameMode = val; //TODO: implement + d.gameTimeInMinutes = val; lobby.SetGameDesc(d); } -void GameServerAPI::GameSetGameTime(const int& val) + +const wchar_t* GameServerAPI::GameGetMapName() { LobbyLevelData d; lobby.GetGameDesc(d); - d.gameTime = val; - lobby.SetGameDesc(d); + return d.mapName.c_str(); } -int GameServerAPI::GameGetMapId() -{ - LobbyLevelData d; - lobby.GetGameDesc(d); - return d.mapNumber; -} -int GameServerAPI::GameGetMaxClients() +int GameServerAPI::GameGetMaxClients() { LobbyLevelData d; lobby.GetGameDesc(d); return d.maxClients; } -int GameServerAPI::GameGetGameMode() +const wchar_t* GameServerAPI::GameGetGameMode() { LobbyLevelData d; lobby.GetGameDesc(d); - return d.gameMode; + return d.gameMode.c_str(); } -int GameServerAPI::GameGetGameTime() +int GameServerAPI::GameGetGameTime() { LobbyLevelData d; lobby.GetGameDesc(d); - return d.gameTime; + return d.gameTimeInMinutes; } -const char* GameServerAPI::GameGetGameName() +const wchar_t* GameServerAPI::GameGetGameName() { LobbyLevelData d; lobby.GetGameDesc(d); return d.gameName.c_str(); } -bool GameServerAPI::GameStart() + +bool GameServerAPI::GameStart() { if(lobby.StartGameSession()) { diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index d0cf5190..c3319eb3 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -43,9 +43,9 @@ using namespace DanBias; { int temp = -1; //Find the idiot - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]->Equals(e.sender)) + if(this->gClients[i]->Equals(e.sender)) { temp = i; } @@ -56,7 +56,7 @@ using namespace DanBias; this->Detach(e.sender)->Disconnect(); return; } - SmartPointer cl = this->clients[temp]; + SmartPointer cl = this->gClients[temp]; switch (e.args.type) { @@ -70,15 +70,21 @@ using namespace DanBias; break; case NetworkClient::ClientEventArgs::EventType_ProtocolRecieved: printf("\t(%i : %s) - EventType_ProtocolRecieved\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); - testID = 2; - if(cl->GetPlayer()->GetID() == testID)//TODO: TEST - { - testTimer.reset(); - } this->ParseProtocol(e.args.data.protocol, cl); break; } } + void GameSession::ProcessClients() + { + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + this->gClients[i]->UpdateClient(); + } + } + } + void GameSession::ObjectMove(GameLogic::IObjectData* movedObject) { diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index cd89dc9a..d0ad30f4 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -3,6 +3,7 @@ ///////////////////////////////////////////////////////////////////// #include "..\GameSession.h" #include "..\GameClient.h" +#include "..\GameLobby.h" #include #include #include @@ -62,9 +63,16 @@ bool GameSession::Create(GameDescription& desc) if(this->isCreated) return false; /* standard initialization of some data */ - NetworkSession::clients = desc.clients; - NetworkSession::clients.Resize((unsigned int)desc.maxClients); - this->clients.Resize((unsigned int)desc.maxClients); + this->gClients.Resize((unsigned int)desc.maxClients); + for (unsigned int i = 0; i < desc.clients.Size(); i++) + { + if(desc.clients[i]) + { + this->clientCount++; + this->gClients[i] = desc.clients[i]; + this->gClients[i]->SetOwner(this); + } + } this->owner = desc.owner; /* Initiate the game instance */ @@ -75,14 +83,13 @@ bool GameSession::Create(GameDescription& desc) /* Create the players in the game instance */ GameLogic::IPlayerData* p = 0; - for (unsigned int i = 0; i < desc.clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(desc.clients[i]) + if(this->gClients[i]) { if( (p = this->gameInstance.CreatePlayer()) ) { - desc.clients[i]->SetOwner(this); - this->clients[i] = (new GameClient(desc.clients[i], p)); + this->gClients[i]->SetPlayer(p); } else { @@ -129,15 +136,15 @@ void GameSession::Run() void GameSession::ThreadEntry( ) { //List with clients that we are waiting on.. - DynamicArray> readyList;// = this->clients; + DynamicArray readyList;// = this->clients; //First we need to clean invalid clients, if any, and tell them to start loading game data - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]) + if(this->gClients[i]) { - readyList.Push(this->clients[i]); - Protocol_LobbyCreateGame p((char)1, (char)0, this->description.mapName); + readyList.Push(this->gClients[i]); + Protocol_LobbyCreateGame p((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string())); readyList[readyList.Size() - 1]->GetClient()->Send(p); } } @@ -153,13 +160,13 @@ void GameSession::ThreadEntry( ) if(readyList[i] && readyList[i]->IsReady()) { //Need to send information about other players, to all players - for (unsigned int k = 0; k < this->clients.Size(); k++) + for (unsigned int k = 0; k < this->gClients.Size(); k++) { - if((this->clients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->clients[k]->GetClient()->GetID()) + if((this->gClients[k] && readyList[i]) && readyList[i]->GetClient()->GetID() != this->gClients[k]->GetClient()->GetID()) { - IPlayerData* pl = this->clients[k]->GetPlayer(); + IPlayerData* pl = this->gClients[k]->GetPlayer(); Protocol_ObjectCreatePlayer p( pl->GetPosition(), pl->GetRotation(), pl->GetScale(), - pl->GetID(), true, this->clients[k]->GetPlayer()->GetTeamID(), + pl->GetID(), true, this->gClients[k]->GetPlayer()->GetTeamID(), /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); readyList[i]->GetClient()->Send(p); } @@ -173,32 +180,31 @@ void GameSession::ThreadEntry( ) } //Sync with clients before starting countdown - - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(this->clients[i]) + if(this->gClients[i]) { - this->clients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5)); + this->gClients[i]->GetClient()->Send(GameLogic::Protocol_LobbyStartGame(5.0f)); } } } -bool GameSession::Attach(Utility::DynamicMemory::SmartPointer networkClient) +bool GameSession::Join(gClient gameClient) { if(!this->isCreated) return false; - if(this->GetClientCount() == this->clients.Capacity()) return false; + if(this->GetClientCount() == this->gClients.Capacity()) return false; - networkClient->SetOwner(this); + gameClient->SetOwner(this); IPlayerData* playerData = this->gameInstance.CreatePlayer(); if(!playerData) return false; - SmartPointer gameClient = new GameClient(networkClient, playerData); + gameClient->SetPlayer(playerData); NetworkClient* nwClient = gameClient->GetClient(); // Send the level information { - Protocol_LobbyCreateGame lcg((char)1, (char)0, this->description.mapName); + Protocol_LobbyCreateGame lcg((char)1, (char)0, Utility::String::WStringToString(this->description.mapName, std::string())); nwClient->Send(lcg); } @@ -212,11 +218,11 @@ bool GameSession::Attach(Utility::DynamicMemory::SmartPointer net // Send information about other clients { - for (unsigned int i = 0; i < this->clients.Size(); i++) + for (unsigned int i = 0; i < this->gClients.Size(); i++) { - if(clients[i]) + if(this->gClients[i]) { - IPlayerData* temp = clients[i]->GetPlayer(); + IPlayerData* temp = this->gClients[i]->GetPlayer(); Protocol_ObjectCreatePlayer oc( temp->GetPosition(), temp->GetRotation(), temp->GetScale(), temp->GetID(), false, temp->GetTeamID(), /*nwClient->GetAlias()*/"", /*playerData->GetMesh()*/"char_white.dan"); @@ -227,40 +233,44 @@ bool GameSession::Attach(Utility::DynamicMemory::SmartPointer net //TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client { - + } // Insert the new client to the update list + bool added = false; { - bool added = false; - for (unsigned int i = 0; !added && i < this->clients.Size(); i++) + for (unsigned int i = 0; !added && i < this->gClients.Size(); i++) { - if(!clients[i]) + if(!this->gClients[i]) { - NetworkSession::clients[i] = networkClient; - clients[i] = gameClient; + this->gClients[i] = gameClient; + // Send the start signal + { + nwClient->Send(GameLogic::Protocol_LobbyStartGame(0)); + } added = true; + this->clientCount++; } } - if(!added) - { - NetworkSession::clients.Push( networkClient ); - clients.Push( gameClient ); - } - } -// Send the start signal - { - nwClient->Send(GameLogic::Protocol_LobbyStartGame(0)); } - return true; + return added; } -void GameSession::CloseSession( bool dissconnectClients ) -{ - this->worker.Terminate(); - NetworkSession::CloseSession(true); - this->clients.Clear(); -} +//DynamicArray GameSession::CloseSession( bool dissconnectClients ) +//{ +// this->worker.Terminate(); +// //TODO: Send clients to lobby +// +// //for (unsigned int i = 0; i < this->gClients.Size(); i++) +// //{ +// // if(this->gClients[i]) +// // { +// // ((GameLobby*)this->owner)-> this->gClients[i] +// // } +// //} +// +// this->gClients.Clear(); +//} diff --git a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp index 3a10b6ce..0c913a56 100644 --- a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp +++ b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.cpp @@ -72,26 +72,32 @@ void StandaloneGameServerCLI::GameSetMapName(String^ value) pin_ptr wch = PtrToStringChars(value); DanBias::GameServerAPI::GameSetMapName(wch); } +void StandaloneGameServerCLI::GameSetGameMode(String^ value) +{ + pin_ptr wch = PtrToStringChars(value); + DanBias::GameServerAPI::GameSetGameMode(wch); +} +void StandaloneGameServerCLI::GameSetGameName(String^ value) +{ + pin_ptr wch = PtrToStringChars(value); + DanBias::GameServerAPI::GameSetGameName(wch); +} void StandaloneGameServerCLI::GameSetMaxClients(const int val) { DanBias::GameServerAPI::GameSetMaxClients(val); } -void StandaloneGameServerCLI::GameSetGameMode(String^ value) -{ - pin_ptr wch = PtrToStringChars(value); - DanBias::GameServerAPI::GameSetGameMode(wch); -} + void StandaloneGameServerCLI::GameSetGameTime(const int val) { DanBias::GameServerAPI::GameSetGameTime(val); } -int StandaloneGameServerCLI::GameGetMapId() +String^ StandaloneGameServerCLI::GameGetMapName() { - return DanBias::GameServerAPI::GameGetMapId(); + return gcnew String( DanBias::GameServerAPI::GameGetMapName()); } int StandaloneGameServerCLI::GameGetMaxClients() @@ -99,9 +105,9 @@ int StandaloneGameServerCLI::GameGetMaxClients() return DanBias::GameServerAPI::GameGetMaxClients(); } -int StandaloneGameServerCLI::GameGetGameMode() +String^ StandaloneGameServerCLI::GameGetGameMode() { - return DanBias::GameServerAPI::GameGetGameMode(); + return gcnew String( DanBias::GameServerAPI::GameGetGameMode()); } int StandaloneGameServerCLI::GameGetGameTime() @@ -111,7 +117,7 @@ int StandaloneGameServerCLI::GameGetGameTime() String^ StandaloneGameServerCLI::GameGetGameName() { - return gcnew String(DanBias::GameServerAPI::GameGetGameName()); + return gcnew String( DanBias::GameServerAPI::GameGetGameName()); } bool StandaloneGameServerCLI::GameStart() diff --git a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h index 3fdd0713..d71a23b8 100644 --- a/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h +++ b/Code/Game/LanServer/CLIStandaloneServer/StandaloneGameServerCLI.h @@ -47,13 +47,15 @@ namespace System { namespace Windows { namespace Interop bool ServerIsRunning(); void GameSetMapName(String^ val); - void GameSetMaxClients(const int val); void GameSetGameMode(String^ val); + void GameSetGameName(String^ val); + void GameSetMaxClients(const int val); void GameSetGameTime(const int val); - int GameGetMapId(); + int GameGetMaxClients(); - int GameGetGameMode(); int GameGetGameTime(); + System::String^ GameGetMapName(); + System::String^ GameGetGameMode(); System::String^ GameGetGameName(); bool GameStart(); }; diff --git a/Code/Network/NetworkAPI/NetworkSession.h b/Code/Network/NetworkAPI/NetworkSession.h index f0677c77..b4e8e8fe 100644 --- a/Code/Network/NetworkAPI/NetworkSession.h +++ b/Code/Network/NetworkAPI/NetworkSession.h @@ -98,9 +98,9 @@ namespace Oyster protected: NetClientList clients; - - private: int clientCount; + + private: struct PrivateSessionData; PrivateSessionData* data; }; From 484b055338ba41254141983a112a393cea7a4bf7 Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 18 Feb 2014 11:44:02 +0100 Subject: [PATCH 4/5] GL - Call by reference instead --- Code/Game/GameLogic/Game.h | 4 ++-- Code/Game/GameLogic/GameAPI.h | 2 +- Code/Game/GameLogic/Game_LevelData.cpp | 8 ++------ 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Code/Game/GameLogic/Game.h b/Code/Game/GameLogic/Game.h index b8f6d4b3..9c21ec1b 100644 --- a/Code/Game/GameLogic/Game.h +++ b/Code/Game/GameLogic/Game.h @@ -58,10 +58,10 @@ namespace GameLogic Oyster::Math::Float3 GetScale() override; Oyster::Math::Float4x4 GetOrientation() override; int GetID() const override; - ObjectSpecialType GetObjectType() const override; + ObjectSpecialType GetObjectType() const override; int getNrOfDynamicObj()const override; IObjectData* GetObjectAt(int ID) const override; - Utility::DynamicMemory::DynamicArray GetAllDynamicObjects() const override; + void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const override; Level *level; }; diff --git a/Code/Game/GameLogic/GameAPI.h b/Code/Game/GameLogic/GameAPI.h index 2a24c99e..3325115f 100644 --- a/Code/Game/GameLogic/GameAPI.h +++ b/Code/Game/GameLogic/GameAPI.h @@ -108,7 +108,7 @@ namespace GameLogic public: virtual int getNrOfDynamicObj()const = 0; virtual IObjectData* GetObjectAt(int ID) const = 0; - virtual Utility::DynamicMemory::DynamicArray GetAllDynamicObjects() const = 0; + virtual void GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& destMem) const = 0; }; class DANBIAS_GAMELOGIC_DLL GameAPI diff --git a/Code/Game/GameLogic/Game_LevelData.cpp b/Code/Game/GameLogic/Game_LevelData.cpp index 4529e787..80220d5f 100644 --- a/Code/Game/GameLogic/Game_LevelData.cpp +++ b/Code/Game/GameLogic/Game_LevelData.cpp @@ -52,14 +52,10 @@ IObjectData* Game::LevelData::GetObjectAt(int ID) const return this->level->GetObj(ID); } -Utility::DynamicMemory::DynamicArray Game::LevelData::GetAllDynamicObjects() const +void Game::LevelData::GetAllDynamicObjects(Utility::DynamicMemory::DynamicArray& mem) const { - Utility::DynamicMemory::DynamicArray objects(level->dynamicObjects.Size()); - for(int i = 0; i < level->dynamicObjects.Size(); i++) { - objects[i] = level->dynamicObjects[i]; + mem[i] = level->dynamicObjects[i]; } - - return objects; } \ No newline at end of file From cec27408966d688d822a1ea906ba011d8f26ccd1 Mon Sep 17 00:00:00 2001 From: dean11 Date: Tue, 18 Feb 2014 11:56:36 +0100 Subject: [PATCH 5/5] GameServer - Fixed minor miss with inheritance --- Code/Game/GameServer/GameSession.h | 2 ++ .../Implementation/GameSession_Gameplay.cpp | 27 +++++++++++++++++++ .../Implementation/GameSession_General.cpp | 9 ++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/Code/Game/GameServer/GameSession.h b/Code/Game/GameServer/GameSession.h index 200bed9b..e6c8a4f9 100644 --- a/Code/Game/GameServer/GameSession.h +++ b/Code/Game/GameServer/GameSession.h @@ -65,6 +65,8 @@ namespace DanBias // Client event callback function void ClientEventCallback(Oyster::Network::NetEvent e) override; void ProcessClients() override; + bool Send(Oyster::Network::CustomNetProtocol& message) override; + bool Send(Oyster::Network::CustomNetProtocol& protocol, int ID) override; //Sends a client to the owner, if param is NULL then all clients is sent void SendToOwner(DanBias::GameClient* obj); diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index c3319eb3..61ccf9c8 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -84,6 +84,33 @@ using namespace DanBias; } } } + bool GameSession::Send(Oyster::Network::CustomNetProtocol& message) + { + bool returnValue = false; + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i]) + { + this->gClients[i]->GetClient()->Send(message); + returnValue = true; + } + } + + return returnValue; + + } + bool GameSession::Send(Oyster::Network::CustomNetProtocol& protocol, int ID) + { + for (unsigned int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i] && this->gClients[i]->GetClient()->GetID() == ID) + { + this->gClients[i]->GetClient()->Send(protocol); + return true; + } + } + return false; + } void GameSession::ObjectMove(GameLogic::IObjectData* movedObject) diff --git a/Code/Game/GameServer/Implementation/GameSession_General.cpp b/Code/Game/GameServer/Implementation/GameSession_General.cpp index d0ad30f4..43f088dd 100644 --- a/Code/Game/GameServer/Implementation/GameSession_General.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_General.cpp @@ -233,7 +233,14 @@ bool GameSession::Join(gClient gameClient) //TODO: Need to be able to get the current gameplay data from the logic, to sync it with the client { - + DynamicArray objects; + this->levelData->GetAllDynamicObjects(objects); + for (unsigned int i = 0; i < objects.Size(); i++) + { + //Protocol_ObjectPosition p(movedObject->GetPosition(), id); + Protocol_ObjectPositionRotation p(objects[i]->GetPosition(), objects[i]->GetRotation(), objects[i]->GetID()); + GameSession::gameSession->Send(p.GetProtocol()); + } } // Insert the new client to the update list