Signals/callbacks when spectators join or leave.

This commit is contained in:
lotodore
2013-08-19 22:50:56 +02:00
parent ffafa23efc
commit 1d0b9fc5f2
15 changed files with 176 additions and 11 deletions
+46
View File
@@ -811,6 +811,20 @@ ClientThread::RetrieveAvatarIfNeeded(unsigned id, const PlayerInfo &info)
}
}
std::string
ClientThread::GetPlayerName(unsigned id)
{
PlayerInfo info;
if (!GetCachedPlayerInfo(id, info)) {
// Request player info.
ostringstream name;
name << "#" << id;
info.playerName = name.str();
RequestPlayerInfo(id);
}
return info.playerName;
}
void
ClientThread::AddTempAvatarFile(unsigned playerId, unsigned avatarSize, AvatarFileType type)
{
@@ -1407,6 +1421,38 @@ ClientThread::ModifyGameInfoRemovePlayer(unsigned gameId, unsigned playerId)
GetCallback().SignalNetClientGameListPlayerLeft(gameId, playerId);
}
void
ClientThread::ModifyGameInfoAddSpectator(unsigned gameId, unsigned playerId)
{
bool playerAdded = false;
{
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
if (pos != m_gameInfoMap.end()) {
pos->second.spectators.push_back(playerId);
playerAdded = true;
}
}
if (playerAdded)
GetCallback().SignalNetClientGameListSpectatorJoined(gameId, playerId);
}
void
ClientThread::ModifyGameInfoRemoveSpectator(unsigned gameId, unsigned playerId)
{
bool playerRemoved = false;
{
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
if (pos != m_gameInfoMap.end()) {
pos->second.spectators.remove(playerId);
playerRemoved = true;
}
}
if (playerRemoved)
GetCallback().SignalNetClientGameListSpectatorLeft(gameId, playerId);
}
void
ClientThread::ClearGameInfoMap()
{