From dedd0e87c74d9602d9d283575e3081f982eb0781 Mon Sep 17 00:00:00 2001 From: Pontus Fransson Date: Thu, 20 Feb 2014 15:47:11 +0100 Subject: [PATCH] Added player disconnect protocol. --- Code/Game/GameClient/GameClient.vcxproj.user | 2 +- .../GameClient/GameClientState/GameState.cpp | 39 +++++++++++++------ Code/Game/GameProtocols/ObjectProtocols.h | 32 +++++++++++++++ .../GameProtocols/ProtocolIdentificationID.h | 2 + .../Implementation/GameSession_Gameplay.cpp | 11 ++++++ 5 files changed, 73 insertions(+), 13 deletions(-) diff --git a/Code/Game/GameClient/GameClient.vcxproj.user b/Code/Game/GameClient/GameClient.vcxproj.user index 4b847ee6..2e28d6f7 100644 --- a/Code/Game/GameClient/GameClient.vcxproj.user +++ b/Code/Game/GameClient/GameClient.vcxproj.user @@ -1,7 +1,7 @@  - false + true $(OutDir) diff --git a/Code/Game/GameClient/GameClientState/GameState.cpp b/Code/Game/GameClient/GameClientState/GameState.cpp index 532bd29d..4313b563 100644 --- a/Code/Game/GameClient/GameClientState/GameState.cpp +++ b/Code/Game/GameClient/GameClientState/GameState.cpp @@ -188,6 +188,7 @@ bool GameState::Render() if( dynamicObject->second ) { dynamicObject->second->Render(); + } } @@ -513,19 +514,21 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState this->privData->player.updateRBWorld(); // !RB DEBUG } - - C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; - - if( object ) + else { - object->setPos( position ); - object->setRot( rotation ); - object->updateWorld(); - // RB DEBUG - object->setRBPos ( position ); - object->setRBRot ( rotation ); - object->updateRBWorld(); - // !RB DEBUG + C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID]; + + if( object ) + { + object->setPos( position ); + object->setRot( rotation ); + object->updateWorld(); + // RB DEBUG + object->setRBPos ( position ); + object->setRBRot ( rotation ); + object->updateRBWorld(); + // !RB DEBUG + } } } return GameClientState::event_processed; @@ -584,6 +587,18 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState case protocol_Gameplay_ObjectWeaponEnergy: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectRespawn: break; /** @todo TODO: implement */ case protocol_Gameplay_ObjectDie: break; /** @todo TODO: implement */ + case protocol_Gameplay_ObjectDisconnectPlayer: + { + //Removes + Protocol_ObjectDisconnectPlayer decoded(data); + auto object = this->privData->dynamicObjects->find( decoded.objectID ); + if( object != this->privData->dynamicObjects->end() ) + { + object->second = nullptr; + this->privData->dynamicObjects->erase( object ); + } + } + return GameClientState::event_processed; default: break; } } diff --git a/Code/Game/GameProtocols/ObjectProtocols.h b/Code/Game/GameProtocols/ObjectProtocols.h index fc02a4bd..cae7c7f5 100644 --- a/Code/Game/GameProtocols/ObjectProtocols.h +++ b/Code/Game/GameProtocols/ObjectProtocols.h @@ -892,6 +892,38 @@ namespace GameLogic Oyster::Network::CustomNetProtocol protocol; }; + //#define protocol_Gameplay_ObjectDisconnectPlayer 367 + struct Protocol_ObjectDisconnectPlayer :public Oyster::Network::CustomProtocolObject + { + int objectID; + + Protocol_ObjectDisconnectPlayer() + { + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value.netShort = protocol_Gameplay_ObjectDisconnectPlayer; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->objectID = 0; + } + Protocol_ObjectDisconnectPlayer(int objectID) + { + this->protocol[0].type = Oyster::Network::NetAttributeType_Short; + this->protocol[0].value.netShort = protocol_Gameplay_ObjectDisconnectPlayer; + this->protocol[1].type = Oyster::Network::NetAttributeType_Int; + this->objectID = objectID; + } + Protocol_ObjectDisconnectPlayer(Oyster::Network::CustomNetProtocol& p) + { + this->objectID = p[1].value.netInt; + } + Oyster::Network::CustomNetProtocol GetProtocol() override + { + this->protocol[1].value = this->objectID; + return protocol; + } + + private: + Oyster::Network::CustomNetProtocol protocol; + }; } #endif // !GAMELOGIC_PLAYER_PROTOCOLS_H \ No newline at end of file diff --git a/Code/Game/GameProtocols/ProtocolIdentificationID.h b/Code/Game/GameProtocols/ProtocolIdentificationID.h index 4394a1a1..cb630012 100644 --- a/Code/Game/GameProtocols/ProtocolIdentificationID.h +++ b/Code/Game/GameProtocols/ProtocolIdentificationID.h @@ -69,6 +69,8 @@ #define protocol_Gameplay_ObjectWeaponEnergy 364 #define protocol_Gameplay_ObjectRespawn 365 #define protocol_Gameplay_ObjectDie 366 +//Disconnect +#define protocol_Gameplay_ObjectDisconnectPlayer 367 #define protocol_GameplayMAX 399 diff --git a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp index e2a2961d..0c52dfff 100644 --- a/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp +++ b/Code/Game/GameServer/Implementation/GameSession_Gameplay.cpp @@ -61,8 +61,19 @@ using namespace DanBias; switch (e.args.type) { case NetworkClient::ClientEventArgs::EventType_Disconnect: + { + //Send disconnect message to all the other players so the player can be removed from the client. + Protocol_ObjectDisconnectPlayer dp(cl->GetClient()->GetID()); + for(int i = 0; i < this->gClients.Size(); i++) + { + if(this->gClients[i] && this->gClients[i] != cl) + { + this->gClients[i]->GetClient()->Send(dp); + } + } printf("\t(%i : %s) - EventType_Disconnect\n", cl->GetClient()->GetID(), e.sender->GetIpAddress().c_str()); this->gClients[temp]->Invalidate(); + } break; case NetworkClient::ClientEventArgs::EventType_ProtocolFailedToRecieve: break;