Send spectator list to joining players.
This commit is contained in:
@@ -460,6 +460,15 @@ AbstractServerGameStateReceiving::AcceptNewSession(boost::shared_ptr<ServerGame>
|
|||||||
++player_i;
|
++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.
|
// Send "Player Joined"/"Spectator Joined" to other fully connected clients.
|
||||||
if (spectateOnly) {
|
if (spectateOnly) {
|
||||||
server->SendToAllPlayers(CreateNetPacketSpectatorJoined(server->GetId(), *session->GetPlayerData()), SessionData::Game | SessionData::Spectating | SessionData::SpectatorWaiting);
|
server->SendToAllPlayers(CreateNetPacketSpectatorJoined(server->GetId(), *session->GetPlayerData()), SessionData::Game | SessionData::Spectating | SessionData::SpectatorWaiting);
|
||||||
|
|||||||
@@ -161,6 +161,28 @@ SessionManager::GetPlayerDataList() const
|
|||||||
return playerList;
|
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
|
PlayerIdList
|
||||||
SessionManager::GetPlayerIdList(int state) const
|
SessionManager::GetPlayerIdList(int state) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public:
|
|||||||
boost::shared_ptr<SessionData> GetSessionByUniquePlayerId(unsigned uniqueId, bool initSessions = false) const;
|
boost::shared_ptr<SessionData> GetSessionByUniquePlayerId(unsigned uniqueId, bool initSessions = false) const;
|
||||||
|
|
||||||
PlayerDataList GetPlayerDataList() const;
|
PlayerDataList GetPlayerDataList() const;
|
||||||
|
PlayerDataList GetSpectatorDataList() const;
|
||||||
PlayerIdList GetPlayerIdList(int state) const;
|
PlayerIdList GetPlayerIdList(int state) const;
|
||||||
bool IsPlayerConnected(const std::string &playerName) const;
|
bool IsPlayerConnected(const std::string &playerName) const;
|
||||||
bool IsPlayerConnected(unsigned uniqueId) const;
|
bool IsPlayerConnected(unsigned uniqueId) const;
|
||||||
|
|||||||
Reference in New Issue
Block a user