Send spectator list to joining players.

This commit is contained in:
lotodore
2013-09-28 18:58:43 +02:00
parent a304903883
commit 8baecdf9e0
3 changed files with 32 additions and 0 deletions
+9
View File
@@ -460,6 +460,15 @@ AbstractServerGameStateReceiving::AcceptNewSession(boost::shared_ptr<ServerGame>
++player_i;
}
// Send notifications for connected spectators to client.
PlayerDataList tmpSpectatorList(server->GetSessionManager().GetSpectatorDataList());
PlayerDataList::iterator spectator_i = tmpSpectatorList.begin();
PlayerDataList::iterator spectator_end = tmpSpectatorList.end();
while (spectator_i != spectator_end) {
server->GetLobbyThread().GetSender().Send(session, CreateNetPacketSpectatorJoined(server->GetId(), *(*spectator_i)));
++spectator_i;
}
// Send "Player Joined"/"Spectator Joined" to other fully connected clients.
if (spectateOnly) {
server->SendToAllPlayers(CreateNetPacketSpectatorJoined(server->GetId(), *session->GetPlayerData()), SessionData::Game | SessionData::Spectating | SessionData::SpectatorWaiting);
+22
View File
@@ -161,6 +161,28 @@ SessionManager::GetPlayerDataList() const
return playerList;
}
PlayerDataList
SessionManager::GetSpectatorDataList() const
{
PlayerDataList spectatorList;
boost::recursive_mutex::scoped_lock lock(m_sessionMapMutex);
SessionMap::const_iterator session_i = m_sessionMap.begin();
SessionMap::const_iterator session_end = m_sessionMap.end();
while (session_i != session_end) {
// Get all spectators of the game.
if (session_i->second->GetState() == SessionData::Spectating || session_i->second->GetState() == SessionData::SpectatorWaiting) {
boost::shared_ptr<PlayerData> tmpPlayer(session_i->second->GetPlayerData());
if (!tmpPlayer.get() || tmpPlayer->GetName().empty())
throw ServerException(__FILE__, __LINE__, ERR_NET_INVALID_SESSION, 0);
spectatorList.push_back(tmpPlayer);
}
++session_i;
}
return spectatorList;
}
PlayerIdList
SessionManager::GetPlayerIdList(int state) const
{
+1
View File
@@ -59,6 +59,7 @@ public:
boost::shared_ptr<SessionData> GetSessionByUniquePlayerId(unsigned uniqueId, bool initSessions = false) const;
PlayerDataList GetPlayerDataList() const;
PlayerDataList GetSpectatorDataList() const;
PlayerIdList GetPlayerIdList(int state) const;
bool IsPlayerConnected(const std::string &playerName) const;
bool IsPlayerConnected(unsigned uniqueId) const;