Players should now be able to leave a network game, the other players can continue the game (if it wasn't the server who left).

This commit is contained in:
lotodore
2007-06-03 14:57:33 +00:00
parent 1fcb0c80fd
commit f932e39983
4 changed files with 125 additions and 56 deletions
+27 -7
View File
@@ -385,6 +385,33 @@ AbstractClientStateReceiving::Process(ClientThread &client)
if (tmpPlayer.get())
client.GetCallback().SignalNetClientChatMsg(tmpPlayer->GetName(), chatData.text);
}
else if (tmpPacket->ToNetPacketPlayerLeft())
{
// A player left the game.
NetPacketPlayerLeft::Data playerLeftData;
tmpPacket->ToNetPacketPlayerLeft()->GetData(playerLeftData);
// Signal to GUI.
client.RemovePlayerData(playerLeftData.playerId);
// If the game is running, deactivate player.
boost::shared_ptr<Game> curGame = client.GetGame();
if (curGame.get())
{
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(playerLeftData.playerId);
if (!tmpPlayer)
throw ClientException(ERR_NET_UNKNOWN_PLAYER_ID, 0);
// Reset his action and his cash.
tmpPlayer->setMyAction(PLAYER_ACTION_FOLD);
tmpPlayer->setMyCash(0);
// Player is now inactive.
tmpPlayer->setMyActiveStatus(false);
client.GetGui().refreshAction();
client.GetGui().refreshCash();
}
}
else
retVal = InternalProcess(client, tmpPacket);
}
@@ -490,13 +517,6 @@ ClientStateWaitGame::InternalProcess(ClientThread &client, boost::shared_ptr<Net
playerData->SetName(netPlayerData.playerName);
client.AddPlayerData(playerData);
}
else if (packet->ToNetPacketPlayerLeft())
{
// Another player left the network game.
NetPacketPlayerLeft::Data netPlayerData;
packet->ToNetPacketPlayerLeft()->GetData(netPlayerData);
client.RemovePlayerData(netPlayerData.playerId);
}
// TODO: handle error packet (kicked from server)
return retVal;