Move spectators to lobby before closing a game.

This commit is contained in:
lotodore
2013-10-05 12:49:21 +02:00
parent 3710f94c1e
commit bc7f34a2a6
9 changed files with 37 additions and 2 deletions
+3
View File
@@ -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;
+15
View File
@@ -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)
{
+1
View File
@@ -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;
}
+1
View File
@@ -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;
+1
View File
@@ -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