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.
This commit is contained in:
@@ -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());
|
||||
}
|
||||
|
||||
@@ -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<PlayerData> tmpPlayerData = session.playerData;
|
||||
if (tmpPlayerData.get() && !tmpPlayerData->GetName().empty())
|
||||
{
|
||||
// Send "Player Left" to clients.
|
||||
boost::shared_ptr<NetPacket> thisPlayerLeft(new NetPacketPlayerLeft);
|
||||
NetPacketPlayerLeft::Data thisPlayerLeftData;
|
||||
thisPlayerLeftData.playerId = tmpPlayerData->GetUniqueId();
|
||||
static_cast<NetPacketPlayerLeft *>(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<PlayerData> newAdmin = playerList.front();
|
||||
newAdmin->SetRights(PLAYER_RIGHTS_ADMIN);
|
||||
// Send "Game Admin Changed" to clients.
|
||||
boost::shared_ptr<NetPacket> adminChanged(new NetPacketGameAdminChanged);
|
||||
NetPacketGameAdminChanged::Data adminChangedData;
|
||||
adminChangedData.playerId = newAdmin->GetUniqueId(); // Choose next player as admin.
|
||||
static_cast<NetPacketGameAdminChanged *>(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<PlayerData> player)
|
||||
{
|
||||
// Send "Player Left" to clients.
|
||||
boost::shared_ptr<NetPacket> thisPlayerLeft(new NetPacketPlayerLeft);
|
||||
NetPacketPlayerLeft::Data thisPlayerLeftData;
|
||||
thisPlayerLeftData.playerId = player->GetUniqueId();
|
||||
static_cast<NetPacketPlayerLeft *>(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<PlayerData> newAdmin = playerList.front();
|
||||
newAdmin->SetRights(PLAYER_RIGHTS_ADMIN);
|
||||
// Send "Game Admin Changed" to clients.
|
||||
boost::shared_ptr<NetPacket> adminChanged(new NetPacketGameAdminChanged);
|
||||
NetPacketGameAdminChanged::Data adminChangedData;
|
||||
adminChangedData.playerId = newAdmin->GetUniqueId(); // Choose next player as admin.
|
||||
static_cast<NetPacketGameAdminChanged *>(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)
|
||||
{
|
||||
|
||||
@@ -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<PlayerData> player);
|
||||
void ErrorRemoveSession(SessionWrapper session);
|
||||
void SessionError(SessionWrapper session, int errorCode);
|
||||
void MoveSessionToLobby(SessionWrapper session, int reason);
|
||||
|
||||
Reference in New Issue
Block a user