Send notification to clients when a game in the lobby was started. Mark games as running in lobby dialog.
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
#include <string>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <playerdata.h>
|
||||
#include <gamedata.h>
|
||||
|
||||
class Game;
|
||||
|
||||
@@ -40,6 +41,7 @@ public:
|
||||
|
||||
virtual void SignalNetClientGameListNew(unsigned gameId) = 0;
|
||||
virtual void SignalNetClientGameListRemove(unsigned gameId) = 0;
|
||||
virtual void SignalNetClientGameListUpdateMode(unsigned gameId, GameMode mode) = 0;
|
||||
virtual void SignalNetClientGameListPlayerJoined(unsigned gameId, unsigned playerId) = 0;
|
||||
virtual void SignalNetClientGameListPlayerLeft(unsigned gameId, unsigned playerId) = 0;
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ protected:
|
||||
|
||||
unsigned GetGameIdByName(const std::string &name) const;
|
||||
void AddGameInfo(unsigned gameId, const GameInfo &info);
|
||||
void UpdateGameInfoMode(unsigned gameId, GameMode mode);
|
||||
void RemoveGameInfo(unsigned gameId);
|
||||
void ModifyGameInfoAddPlayer(unsigned gameId, unsigned playerId);
|
||||
void ModifyGameInfoRemovePlayer(unsigned gameId, unsigned playerId);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -57,6 +57,7 @@ public:
|
||||
void SessionError(SessionWrapper session, int errorCode);
|
||||
void NotifyPlayerJoinedGame(unsigned gameId, unsigned playerId);
|
||||
void NotifyPlayerLeftGame(unsigned gameId, unsigned playerId);
|
||||
void NotifyStartingGame(unsigned gameId);
|
||||
|
||||
void HandleGameRetrievePlayerInfo(SessionWrapper session, const NetPacketRetrievePlayerInfo &tmpPacket);
|
||||
|
||||
@@ -115,7 +116,7 @@ protected:
|
||||
bool IsPlayerConnected(const std::string &name);
|
||||
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListNew(const ServerGameThread &game);
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListUpdate(const ServerGameThread &game, GameMode mode);
|
||||
static boost::shared_ptr<NetPacket> CreateNetPacketGameListUpdate(unsigned gameId, GameMode mode);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user