Added player disconnect protocol.
This commit is contained in:
parent
8f3eb586c6
commit
dedd0e87c7
|
@ -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>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue