Add spectator list during the game (when lobby messages are disabled).

This commit is contained in:
lotodore
2013-09-29 13:15:37 +02:00
parent 8baecdf9e0
commit d82c9a510d
5 changed files with 63 additions and 8 deletions
+3
View File
@@ -218,6 +218,9 @@ protected:
void ModifyGameInfoRemovePlayer(unsigned gameId, unsigned playerId);
void ModifyGameInfoAddSpectator(unsigned gameId, unsigned playerId);
void ModifyGameInfoRemoveSpectator(unsigned gameId, unsigned playerId);
void ModifyGameInfoClearSpectatorsDuringGame();
void ModifyGameInfoAddSpectatorDuringGame(unsigned playerId);
void ModifyGameInfoRemoveSpectatorDuringGame(unsigned playerId, int removeReason);
void ClearGameInfoMap();
void StartPetition(unsigned petitionId, unsigned proposingPlayerId, unsigned kickPlayerId, int timeoutSec, int numVotesToKick);
+8 -2
View File
@@ -631,7 +631,12 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
} else if (tmpPacket->GetMsg()->messagetype() == PokerTHMessage::Type_GameSpectatorJoinedMessage) {
// Another spectator joined the network game.
const GameSpectatorJoinedMessage &netSpectatorJoined = tmpPacket->GetMsg()->gamespectatorjoinedmessage();
client->GetCallback().SignalNetClientSpectatorJoined(netSpectatorJoined.playerid(), client->GetPlayerName(netSpectatorJoined.playerid()));
// Request player info if needed.
PlayerInfo info;
if (!client->GetCachedPlayerInfo(netSpectatorJoined.playerid(), info)) {
client->RequestPlayerInfo(netSpectatorJoined.playerid());
}
client->ModifyGameInfoAddSpectatorDuringGame(netSpectatorJoined.playerid());
} else if (tmpPacket->GetMsg()->messagetype() == PokerTHMessage::Type_GameSpectatorLeftMessage) {
// A spectator left the network game.
const GameSpectatorLeftMessage &netSpectatorLeft = tmpPacket->GetMsg()->gamespectatorleftmessage();
@@ -645,7 +650,7 @@ AbstractClientStateReceiving::HandlePacket(boost::shared_ptr<ClientThread> clien
removeReason = NTF_NET_REMOVED_ON_REQUEST;
break;
}
client->GetCallback().SignalNetClientSpectatorLeft(netSpectatorLeft.playerid(), client->GetPlayerName(netSpectatorLeft.playerid()), removeReason);
client->ModifyGameInfoRemoveSpectatorDuringGame(netSpectatorLeft.playerid(), removeReason);
} else if (tmpPacket->GetMsg()->messagetype() == PokerTHMessage::Type_TimeoutWarningMessage) {
const TimeoutWarningMessage &tmpTimeout = tmpPacket->GetMsg()->timeoutwarningmessage();
client->GetCallback().SignalNetClientShowTimeoutDialog((NetTimeoutReason)tmpTimeout.timeoutreason(), tmpTimeout.remainingseconds());
@@ -1252,6 +1257,7 @@ ClientStateWaitJoin::InternalHandlePacket(boost::shared_ptr<ClientThread> client
GameData tmpData;
NetPacket::GetGameData(netJoinAck.gameinfo(), tmpData);
client->SetGameData(tmpData);
client->ModifyGameInfoClearSpectatorsDuringGame();
// Player number is 0 on init. Will be set when the game starts.
boost::shared_ptr<PlayerData> playerData(
+42
View File
@@ -1454,6 +1454,48 @@ ClientThread::ModifyGameInfoRemoveSpectator(unsigned gameId, unsigned playerId)
GetCallback().SignalNetClientGameListSpectatorLeft(gameId, playerId);
}
void
ClientThread::ModifyGameInfoClearSpectatorsDuringGame()
{
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
GameInfoMap::iterator pos = m_gameInfoMap.find(GetGameId());
if (pos != m_gameInfoMap.end()) {
pos->second.spectatorsDuringGame.clear();
}
}
void
ClientThread::ModifyGameInfoAddSpectatorDuringGame(unsigned playerId)
{
bool spectatorAdded = false;
{
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
GameInfoMap::iterator pos = m_gameInfoMap.find(GetGameId());
if (pos != m_gameInfoMap.end()) {
pos->second.spectatorsDuringGame.push_back(playerId);
spectatorAdded = true;
}
}
if (spectatorAdded)
GetCallback().SignalNetClientSpectatorJoined(playerId, GetPlayerName(playerId));
}
void
ClientThread::ModifyGameInfoRemoveSpectatorDuringGame(unsigned playerId, int removeReason)
{
bool spectatorRemoved = false;
{
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
GameInfoMap::iterator pos = m_gameInfoMap.find(GetGameId());
if (pos != m_gameInfoMap.end()) {
pos->second.spectatorsDuringGame.remove(playerId);
spectatorRemoved = true;
}
}
if (spectatorRemoved)
GetCallback().SignalNetClientSpectatorLeft(playerId, GetPlayerName(playerId), removeReason);
}
void
ClientThread::ClearGameInfoMap()
{