Added player disconnect protocol.

This commit is contained in:
Pontus Fransson 2014-02-20 15:47:11 +01:00
parent 8f3eb586c6
commit dedd0e87c7
5 changed files with 73 additions and 13 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ShowAllFiles>false</ShowAllFiles>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerWorkingDirectory>$(OutDir)</LocalDebuggerWorkingDirectory>

View File

@ -188,6 +188,7 @@ bool GameState::Render()
if( dynamicObject->second )
{
dynamicObject->second->Render();
}
}
@ -513,7 +514,8 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
this->privData->player.updateRBWorld();
// !RB DEBUG
}
else
{
C_DynamicObj *object = (*this->privData->dynamicObjects)[decoded.object_ID];
if( object )
@ -528,6 +530,7 @@ const GameClientState::NetEvent & GameState::DataRecieved( const GameClientState
// !RB DEBUG
}
}
}
return GameClientState::event_processed;
case protocol_Gameplay_ObjectEnabled: break; /** @todo TODO: implement */
case protocol_Gameplay_ObjectDisabled:
@ -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;
}
}

View File

@ -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

View File

@ -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

View File

@ -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;