From 9663a225d54df82348ad339b7cd8e9814801a97f Mon Sep 17 00:00:00 2001 From: lotodore Date: Thu, 11 Oct 2007 21:15:04 +0000 Subject: [PATCH] Fixed two bugs concerning lobby player notifications: Game state is now set correctly after a game was finished and reopened, for players which are joining afterwards. Computer players are now properly removed from finished games. --- src/net/common/servergamestate.cpp | 2 + src/net/common/servergamethread.cpp | 67 +++++++++++++++++------------ src/net/servergamethread.h | 3 ++ 3 files changed, 45 insertions(+), 27 deletions(-) diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index dfc8adc6..eeeb9f10 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -1184,6 +1184,8 @@ ServerGameStateNextGameDelay::Process(ServerGameThread &server) server.SendToAllPlayers(endGame, SessionData::Game); // Wait for the start of a new game. + server.ResetComputerPlayerList(); + server.ResetGame(); server.SetState(ServerGameStateInit::Instance()); server.GetLobbyThread().NotifyReopeningGame(server.GetId()); } diff --git a/src/net/common/servergamethread.cpp b/src/net/common/servergamethread.cpp index 8804229c..bd9f104f 100644 --- a/src/net/common/servergamethread.cpp +++ b/src/net/common/servergamethread.cpp @@ -199,6 +199,12 @@ ServerGameThread::InternalStartGame() GetLobbyThread().NotifyStartingGame(GetId()); } +void +ServerGameThread::ResetGame() +{ + m_game.reset(); +} + void ServerGameThread::InternalKickPlayer(unsigned playerId) { @@ -292,6 +298,7 @@ ServerGameThread::ResetComputerPlayerList() while (i != end) { GetLobbyThread().RemoveComputerPlayer(*i); + RemovePlayerData(*i); ++i; } @@ -307,36 +314,42 @@ ServerGameThread::GracefulRemoveSession(SessionWrapper session) boost::shared_ptr tmpPlayerData = session.playerData; if (tmpPlayerData.get() && !tmpPlayerData->GetName().empty()) { - // Send "Player Left" to clients. - boost::shared_ptr thisPlayerLeft(new NetPacketPlayerLeft); - NetPacketPlayerLeft::Data thisPlayerLeftData; - thisPlayerLeftData.playerId = tmpPlayerData->GetUniqueId(); - static_cast(thisPlayerLeft.get())->SetData(thisPlayerLeftData); - GetSessionManager().SendToAllSessions(GetSender(), thisPlayerLeft, SessionData::Game); - - if (tmpPlayerData->GetRights() == PLAYER_RIGHTS_ADMIN) - { - // Find new admin for the game - PlayerDataList playerList(GetSessionManager().GetPlayerDataList()); - if (!playerList.empty()) - { - boost::shared_ptr newAdmin = playerList.front(); - newAdmin->SetRights(PLAYER_RIGHTS_ADMIN); - // Send "Game Admin Changed" to clients. - boost::shared_ptr adminChanged(new NetPacketGameAdminChanged); - NetPacketGameAdminChanged::Data adminChangedData; - adminChangedData.playerId = newAdmin->GetUniqueId(); // Choose next player as admin. - static_cast(adminChanged.get())->SetData(adminChangedData); - GetSessionManager().SendToAllSessions(GetSender(), adminChanged, SessionData::Game); - } - } - // Reset player rights. - tmpPlayerData->SetRights(PLAYER_RIGHTS_NORMAL); - - GetLobbyThread().NotifyPlayerLeftGame(GetId(), session.playerData->GetUniqueId()); + RemovePlayerData(tmpPlayerData); } } +void +ServerGameThread::RemovePlayerData(boost::shared_ptr player) +{ + // Send "Player Left" to clients. + boost::shared_ptr thisPlayerLeft(new NetPacketPlayerLeft); + NetPacketPlayerLeft::Data thisPlayerLeftData; + thisPlayerLeftData.playerId = player->GetUniqueId(); + static_cast(thisPlayerLeft.get())->SetData(thisPlayerLeftData); + GetSessionManager().SendToAllSessions(GetSender(), thisPlayerLeft, SessionData::Game); + + if (player->GetRights() == PLAYER_RIGHTS_ADMIN) + { + // Find new admin for the game + PlayerDataList playerList(GetSessionManager().GetPlayerDataList()); + if (!playerList.empty()) + { + boost::shared_ptr newAdmin = playerList.front(); + newAdmin->SetRights(PLAYER_RIGHTS_ADMIN); + // Send "Game Admin Changed" to clients. + boost::shared_ptr adminChanged(new NetPacketGameAdminChanged); + NetPacketGameAdminChanged::Data adminChangedData; + adminChangedData.playerId = newAdmin->GetUniqueId(); // Choose next player as admin. + static_cast(adminChanged.get())->SetData(adminChangedData); + GetSessionManager().SendToAllSessions(GetSender(), adminChanged, SessionData::Game); + } + } + // Reset player rights. + player->SetRights(PLAYER_RIGHTS_NORMAL); + + GetLobbyThread().NotifyPlayerLeftGame(GetId(), player->GetUniqueId()); +} + void ServerGameThread::ErrorRemoveSession(SessionWrapper session) { diff --git a/src/net/servergamethread.h b/src/net/servergamethread.h index c97ba7b9..d0ff709d 100644 --- a/src/net/servergamethread.h +++ b/src/net/servergamethread.h @@ -80,6 +80,8 @@ protected: virtual void Main(); void InternalStartGame(); + void ResetGame(); + void InternalKickPlayer(unsigned playerId); PlayerDataList GetFullPlayerDataList() const; @@ -88,6 +90,7 @@ protected: void ResetComputerPlayerList(); void GracefulRemoveSession(SessionWrapper session); + void RemovePlayerData(boost::shared_ptr player); void ErrorRemoveSession(SessionWrapper session); void SessionError(SessionWrapper session, int errorCode); void MoveSessionToLobby(SessionWrapper session, int reason);