Move spectators to lobby before closing a game.
This commit is contained in:
@@ -589,6 +589,9 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
|
||||
case RemovedFromGameMessage::removedStartFailed :
|
||||
removeReason = NTF_NET_REMOVED_START_FAILED;
|
||||
break;
|
||||
case RemovedFromGameMessage::gameClosed :
|
||||
removeReason = NTF_NET_REMOVED_GAME_CLOSED;
|
||||
break;
|
||||
default :
|
||||
removeReason = NTF_NET_REMOVED_ON_REQUEST;
|
||||
break;
|
||||
|
||||
@@ -198,6 +198,21 @@ ServerGame::RemoveAllSessions()
|
||||
SetState(ServerGameStateFinal::Instance());
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::MoveSpectatorsToLobby()
|
||||
{
|
||||
PlayerIdList spectatorList = GetSpectatorIdList();
|
||||
PlayerIdList::const_iterator i = spectatorList.begin();
|
||||
PlayerIdList::const_iterator end = spectatorList.end();
|
||||
while (i != end) {
|
||||
boost::shared_ptr<SessionData> tmpSession = GetSessionManager().GetSessionByUniquePlayerId(*i);
|
||||
// Only remove if the spectator was found.
|
||||
if (tmpSession)
|
||||
MoveSessionToLobby(tmpSession, NTF_NET_REMOVED_GAME_CLOSED);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ServerGame::TimerVoteKick(const boost::system::error_code &ec)
|
||||
{
|
||||
|
||||
@@ -1835,6 +1835,7 @@ ServerLobbyThread::TimerRemoveGame(const boost::system::error_code &ec)
|
||||
++next;
|
||||
boost::shared_ptr<ServerGame> tmpGame = i->second;
|
||||
if (!tmpGame->GetSessionManager().HasSessionWithState(SessionData::Game))
|
||||
tmpGame->MoveSpectatorsToLobby();
|
||||
InternalRemoveGame(tmpGame); // This will delete the game.
|
||||
i = next;
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ public:
|
||||
void SendToAllPlayers(boost::shared_ptr<NetPacket> packet, int state);
|
||||
void SendToAllButOnePlayers(boost::shared_ptr<NetPacket> packet, SessionId except, int state);
|
||||
void RemoveAllSessions();
|
||||
void MoveSpectatorsToLobby();
|
||||
|
||||
bool IsPasswordProtected() const;
|
||||
bool CheckPassword(const std::string &password) const;
|
||||
|
||||
@@ -116,6 +116,7 @@
|
||||
#define NTF_NET_REMOVED_KICKED 205
|
||||
#define NTF_NET_REMOVED_TIMEOUT 206
|
||||
#define NTF_NET_REMOVED_START_FAILED 207
|
||||
#define NTF_NET_REMOVED_GAME_CLOSED 208
|
||||
|
||||
// Notifications - join failed
|
||||
#define NTF_NET_JOIN_GAME_INVALID 210
|
||||
|
||||
Reference in New Issue
Block a user