Send notification to clients when a game in the lobby was started. Mark games as running in lobby dialog.
This commit is contained in:
@@ -458,6 +458,8 @@ AbstractClientStateReceiving::Process(ClientThread &client)
|
||||
tmpPacket->ToNetPacketGameListUpdate()->GetData(gameListUpdateData);
|
||||
if (gameListUpdateData.gameMode == GAME_MODE_CLOSED)
|
||||
client.RemoveGameInfo(gameListUpdateData.gameId);
|
||||
else
|
||||
client.UpdateGameInfoMode(gameListUpdateData.gameId, gameListUpdateData.gameMode);
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketGameListPlayerJoined())
|
||||
{
|
||||
|
||||
@@ -673,19 +673,36 @@ ClientThread::AddGameInfo(unsigned gameId, const GameInfo &info)
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::RemoveGameInfo(unsigned gameId)
|
||||
ClientThread::UpdateGameInfoMode(unsigned gameId, GameMode mode)
|
||||
{
|
||||
string name;
|
||||
bool found = false;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
||||
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
||||
if (pos != m_gameInfoMap.end())
|
||||
{
|
||||
name = pos->second.name;
|
||||
found = true;
|
||||
(*pos).second.mode = mode;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
GetCallback().SignalNetClientGameListUpdateMode(gameId, mode);
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::RemoveGameInfo(unsigned gameId)
|
||||
{
|
||||
bool found = false;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
||||
GameInfoMap::iterator pos = m_gameInfoMap.find(gameId);
|
||||
if (pos != m_gameInfoMap.end())
|
||||
{
|
||||
found = true;
|
||||
m_gameInfoMap.erase(pos);
|
||||
}
|
||||
}
|
||||
if (!name.empty())
|
||||
if (found)
|
||||
GetCallback().SignalNetClientGameListRemove(gameId);
|
||||
}
|
||||
|
||||
|
||||
@@ -158,6 +158,8 @@ ServerGameThread::Main()
|
||||
void
|
||||
ServerGameThread::InternalStartGame()
|
||||
{
|
||||
GetLobbyThread().NotifyStartingGame(GetId());
|
||||
|
||||
// Set order of players.
|
||||
AssignPlayerNumbers();
|
||||
|
||||
@@ -180,19 +182,16 @@ ServerGameThread::InternalStartGame()
|
||||
PlayerDataList::const_iterator player_i = playerData.begin();
|
||||
PlayerDataList::const_iterator player_end = playerData.end();
|
||||
|
||||
bool randDealerFound = false;
|
||||
int tmpPos = 0;
|
||||
while (player_i != player_end)
|
||||
{
|
||||
if ((*player_i)->GetNumber() == tmpDealerPos)
|
||||
{
|
||||
// Get ID of the dealer.
|
||||
startData.startDealerPlayerId = static_cast<unsigned>((*player_i)->GetUniqueId());
|
||||
randDealerFound = true;
|
||||
startData.startDealerPlayerId = static_cast<unsigned>((*player_i)->GetUniqueId());
|
||||
if (tmpPos == tmpDealerPos)
|
||||
break;
|
||||
}
|
||||
++tmpPos;
|
||||
++player_i;
|
||||
}
|
||||
assert(randDealerFound); // TODO: Throw exception.
|
||||
assert(player_i != player_end);
|
||||
|
||||
SetStartData(startData);
|
||||
|
||||
|
||||
@@ -153,6 +153,14 @@ ServerLobbyThread::NotifyPlayerLeftGame(unsigned gameId, unsigned playerId)
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::NotifyStartingGame(unsigned gameId)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> packet = CreateNetPacketGameListUpdate(gameId, GAME_MODE_STARTED);
|
||||
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||
}
|
||||
|
||||
void
|
||||
ServerLobbyThread::HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket)
|
||||
{
|
||||
@@ -485,8 +493,9 @@ ServerLobbyThread::InternalRemoveGame(boost::shared_ptr<ServerGameThread> game)
|
||||
// Remove all sessions left in the game.
|
||||
game->RemoveAllSessions();
|
||||
// Notify all players.
|
||||
m_sessionManager.SendToAllSessions(GetSender(), CreateNetPacketGameListUpdate(*game, GAME_MODE_CLOSED), SessionData::Established);
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), CreateNetPacketGameListUpdate(*game, GAME_MODE_CLOSED), SessionData::Game);
|
||||
boost::shared_ptr<NetPacket> packet = CreateNetPacketGameListUpdate(game->GetId(), GAME_MODE_CLOSED);
|
||||
m_sessionManager.SendToAllSessions(GetSender(), packet, SessionData::Established);
|
||||
m_gameSessionManager.SendToAllSessions(GetSender(), packet, SessionData::Game);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -672,11 +681,11 @@ ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
ServerLobbyThread::CreateNetPacketGameListUpdate(const ServerGameThread &game, GameMode mode)
|
||||
ServerLobbyThread::CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode)
|
||||
{
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacketGameListUpdate);
|
||||
NetPacketGameListUpdate::Data packetData;
|
||||
packetData.gameId = game.GetId();
|
||||
packetData.gameId = gameId;
|
||||
packetData.gameMode = mode;
|
||||
static_cast<NetPacketGameListUpdate *>(packet.get())->SetData(packetData);
|
||||
return packet;
|
||||
|
||||
Reference in New Issue
Block a user