Information about the game is now shown in lobby, when selecting a game.
Some GUI modifications, GUI update is working properly now if the dialog is shown the second time (after clearing items). List of players for the game is still missing. With the new on-demand model for player id/player name, this is kind of hard to implement.
This commit is contained in:
@@ -62,11 +62,13 @@ public:
|
||||
void SendJoinGame(const std::string &name, const std::string &password);
|
||||
void SendCreateGame(const GameData &gameData, const std::string &name, const std::string &password);
|
||||
|
||||
GameInfo GetGameInfo(const std::string &game) const;
|
||||
|
||||
ClientCallback &GetCallback();
|
||||
GuiInterface &GetGui();
|
||||
|
||||
protected:
|
||||
typedef std::map<unsigned, std::string> GameMap;
|
||||
typedef std::map<unsigned, GameInfo> GameInfoMap;
|
||||
typedef std::list<boost::shared_ptr<NetPacket> > NetPacketList;
|
||||
typedef std::map<unsigned, PlayerInfo> PlayerInfoMap;
|
||||
|
||||
@@ -110,8 +112,8 @@ protected:
|
||||
void RemoveDisconnectedPlayers();
|
||||
|
||||
unsigned GetGameIdByName(const std::string &name) const;
|
||||
void AddGameInformation(unsigned id, const std::string &name);
|
||||
void RemoveGameInformation(unsigned id);
|
||||
void AddGameInfo(unsigned id, const GameInfo &info);
|
||||
void RemoveGameInfo(unsigned id);
|
||||
|
||||
bool IsSessionEstablished() const;
|
||||
void SetSessionEstablished(bool flag);
|
||||
@@ -133,8 +135,8 @@ private:
|
||||
StartData m_startData;
|
||||
PlayerDataList m_playerDataList;
|
||||
|
||||
GameMap m_gameMap;
|
||||
mutable boost::mutex m_gameMapMutex;
|
||||
GameInfoMap m_gameInfoMap;
|
||||
mutable boost::mutex m_gameInfoMapMutex;
|
||||
|
||||
boost::shared_ptr<Game> m_game;
|
||||
PlayerInfoMap m_playerInfoMap;
|
||||
|
||||
@@ -485,7 +485,7 @@ ClientStateWaitJoin::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
||||
// A new game was created on the server.
|
||||
NetPacketGameListNew::Data gameListNewData;
|
||||
packet->ToNetPacketGameListNew()->GetData(gameListNewData);
|
||||
client.AddGameInformation(gameListNewData.gameId, gameListNewData.gameName);
|
||||
client.AddGameInfo(gameListNewData.gameId, gameListNewData.gameInfo);
|
||||
}
|
||||
else if (packet->ToNetPacketGameListUpdate())
|
||||
{
|
||||
@@ -493,7 +493,7 @@ ClientStateWaitJoin::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
||||
NetPacketGameListUpdate::Data gameListUpdateData;
|
||||
packet->ToNetPacketGameListUpdate()->GetData(gameListUpdateData);
|
||||
if (gameListUpdateData.gameMode == GAME_MODE_CLOSED)
|
||||
client.RemoveGameInformation(gameListUpdateData.gameId);
|
||||
client.RemoveGameInfo(gameListUpdateData.gameId);
|
||||
}
|
||||
else if (packet->ToNetPacketJoinGameAck())
|
||||
{
|
||||
|
||||
@@ -216,6 +216,26 @@ ClientThread::SendCreateGame(const GameData &gameData, const std::string &name,
|
||||
}
|
||||
}
|
||||
|
||||
GameInfo
|
||||
ClientThread::GetGameInfo(const string &game) const
|
||||
{
|
||||
GameInfo tmpInfo;
|
||||
try
|
||||
{
|
||||
unsigned id = GetGameIdByName(game);
|
||||
|
||||
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
||||
GameInfoMap::const_iterator pos = m_gameInfoMap.find(id);
|
||||
if (pos != m_gameInfoMap.end())
|
||||
{
|
||||
tmpInfo = pos->second;
|
||||
}
|
||||
} catch (const NetException &)
|
||||
{
|
||||
}
|
||||
return tmpInfo;
|
||||
}
|
||||
|
||||
ClientCallback &
|
||||
ClientThread::GetCallback()
|
||||
{
|
||||
@@ -469,7 +489,13 @@ ClientThread::RemovePlayerData(unsigned playerId)
|
||||
}
|
||||
|
||||
if (!playerName.empty())
|
||||
{
|
||||
// Remove name and id string.
|
||||
GetCallback().SignalNetClientPlayerLeft(playerName);
|
||||
ostringstream name;
|
||||
name << "#" << playerId;
|
||||
GetCallback().SignalNetClientPlayerLeft(name.str());
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@@ -581,12 +607,12 @@ unsigned
|
||||
ClientThread::GetGameIdByName(const std::string &name) const
|
||||
{
|
||||
// Find the game.
|
||||
boost::mutex::scoped_lock lock(m_gameMapMutex);
|
||||
GameMap::const_iterator i = m_gameMap.begin();
|
||||
GameMap::const_iterator end = m_gameMap.end();
|
||||
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
||||
GameInfoMap::const_iterator i = m_gameInfoMap.begin();
|
||||
GameInfoMap::const_iterator end = m_gameInfoMap.end();
|
||||
while (i != end)
|
||||
{
|
||||
if (i->second == name)
|
||||
if (i->second.name == name)
|
||||
break;
|
||||
++i;
|
||||
}
|
||||
@@ -597,29 +623,26 @@ ClientThread::GetGameIdByName(const std::string &name) const
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::AddGameInformation(unsigned id, const std::string &name)
|
||||
ClientThread::AddGameInfo(unsigned id, const GameInfo &info)
|
||||
{
|
||||
if (!name.empty())
|
||||
{
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_gameMapMutex);
|
||||
m_gameMap.insert(GameMap::value_type(id, name));
|
||||
}
|
||||
GetCallback().SignalNetClientGameListNew(name);
|
||||
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
||||
m_gameInfoMap.insert(GameInfoMap::value_type(id, info));
|
||||
}
|
||||
GetCallback().SignalNetClientGameListNew(info.name);
|
||||
}
|
||||
|
||||
void
|
||||
ClientThread::RemoveGameInformation(unsigned id)
|
||||
ClientThread::RemoveGameInfo(unsigned id)
|
||||
{
|
||||
string name;
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_gameMapMutex);
|
||||
GameMap::iterator pos = m_gameMap.find(id);
|
||||
if (pos != m_gameMap.end())
|
||||
boost::mutex::scoped_lock lock(m_gameInfoMapMutex);
|
||||
GameInfoMap::iterator pos = m_gameInfoMap.find(id);
|
||||
if (pos != m_gameInfoMap.end())
|
||||
{
|
||||
name = pos->second;
|
||||
m_gameMap.erase(pos);
|
||||
name = pos->second.name;
|
||||
m_gameInfoMap.erase(pos);
|
||||
}
|
||||
}
|
||||
if (!name.empty())
|
||||
|
||||
@@ -1010,7 +1010,7 @@ NetPacketGameListNew::Clone() const
|
||||
void
|
||||
NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData)
|
||||
{
|
||||
u_int16_t gameNameLen = (u_int16_t)inData.gameName.length();
|
||||
u_int16_t gameNameLen = (u_int16_t)inData.gameInfo.name.length();
|
||||
|
||||
// Some basic checks, so we don't use up too much memory.
|
||||
// The constructed packet will also be checked.
|
||||
@@ -1025,17 +1025,17 @@ NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData)
|
||||
|
||||
// Set the data.
|
||||
tmpData->gameId = htonl(inData.gameId);
|
||||
tmpData->gameMode = htons(inData.gameMode);
|
||||
tmpData->gameMode = htons(inData.gameInfo.mode);
|
||||
tmpData->gameNameLength = htons(gameNameLen);
|
||||
tmpData->maxNumberOfPlayers = htons(inData.gameData.maxNumberOfPlayers);
|
||||
tmpData->smallBlind = htons(inData.gameData.smallBlind);
|
||||
tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise);
|
||||
tmpData->proposedGuiSpeed = htons(inData.gameData.guiSpeed);
|
||||
tmpData->playerActionTimeout = htons(inData.gameData.playerActionTimeoutSec);
|
||||
tmpData->startMoney = htonl(inData.gameData.startMoney);
|
||||
tmpData->maxNumberOfPlayers = htons(inData.gameInfo.data.maxNumberOfPlayers);
|
||||
tmpData->smallBlind = htons(inData.gameInfo.data.smallBlind);
|
||||
tmpData->handsBeforeRaise = htons(inData.gameInfo.data.handsBeforeRaise);
|
||||
tmpData->proposedGuiSpeed = htons(inData.gameInfo.data.guiSpeed);
|
||||
tmpData->playerActionTimeout = htons(inData.gameInfo.data.playerActionTimeoutSec);
|
||||
tmpData->startMoney = htonl(inData.gameInfo.data.startMoney);
|
||||
|
||||
char *gameNamePtr = (char *)tmpData + sizeof(NetPacketGameListNewData);
|
||||
memcpy(gameNamePtr, inData.gameName.c_str(), gameNameLen);
|
||||
memcpy(gameNamePtr, inData.gameInfo.name.c_str(), gameNameLen);
|
||||
|
||||
// Check the packet - just in case.
|
||||
Check(GetRawData());
|
||||
@@ -1047,18 +1047,18 @@ NetPacketGameListNew::GetData(NetPacketGameListNew::Data &outData) const
|
||||
// We assume that the data is valid. Validity has already been checked.
|
||||
NetPacketGameListNewData *tmpData = (NetPacketGameListNewData *)GetRawData();
|
||||
|
||||
outData.gameId = ntohl(tmpData->gameId);
|
||||
outData.gameMode = static_cast<GameMode>(ntohs(tmpData->gameMode));
|
||||
u_int16_t gameNameLen = ntohs(tmpData->gameNameLength);
|
||||
outData.gameData.maxNumberOfPlayers = ntohs(tmpData->maxNumberOfPlayers);
|
||||
outData.gameData.smallBlind = ntohs(tmpData->smallBlind);
|
||||
outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
||||
outData.gameData.guiSpeed = ntohs(tmpData->proposedGuiSpeed);
|
||||
outData.gameData.playerActionTimeoutSec = ntohs(tmpData->playerActionTimeout);
|
||||
outData.gameData.startMoney = ntohl(tmpData->startMoney);
|
||||
outData.gameId = ntohl(tmpData->gameId);
|
||||
outData.gameInfo.mode = static_cast<GameMode>(ntohs(tmpData->gameMode));
|
||||
u_int16_t gameNameLen = ntohs(tmpData->gameNameLength);
|
||||
outData.gameInfo.data.maxNumberOfPlayers = ntohs(tmpData->maxNumberOfPlayers);
|
||||
outData.gameInfo.data.smallBlind = ntohs(tmpData->smallBlind);
|
||||
outData.gameInfo.data.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
||||
outData.gameInfo.data.guiSpeed = ntohs(tmpData->proposedGuiSpeed);
|
||||
outData.gameInfo.data.playerActionTimeoutSec= ntohs(tmpData->playerActionTimeout);
|
||||
outData.gameInfo.data.startMoney = ntohl(tmpData->startMoney);
|
||||
|
||||
char *gameNamePtr = (char *)tmpData + sizeof(NetPacketGameListNewData);
|
||||
outData.gameName = string(gameNamePtr, gameNameLen);
|
||||
outData.gameInfo.name = string(gameNamePtr, gameNameLen);
|
||||
}
|
||||
|
||||
const NetPacketGameListNew *
|
||||
|
||||
@@ -225,6 +225,7 @@ ServerLobbyThread::HandleNetPacketInit(SessionWrapper session, const NetPacketIn
|
||||
// Partly, this is also done in netpacket.
|
||||
// However, some disallowed names are checked only here.
|
||||
if (initData.playerName.empty() || initData.playerName.size() > MAX_NAME_SIZE
|
||||
|| initData.playerName[0] == '#'
|
||||
|| initData.playerName.substr(0, sizeof(SERVER_COMPUTER_PLAYER_NAME) - 1) == SERVER_COMPUTER_PLAYER_NAME)
|
||||
{
|
||||
SessionError(session, ERR_NET_INVALID_PLAYER_NAME);
|
||||
@@ -552,9 +553,9 @@ ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
|
||||
boost::shared_ptr<NetPacket> packet(new NetPacketGameListNew);
|
||||
NetPacketGameListNew::Data packetData;
|
||||
packetData.gameId = game.GetId();
|
||||
packetData.gameMode = GAME_MODE_CREATED;
|
||||
packetData.gameName = game.GetName();
|
||||
packetData.gameData = game.GetGameData();
|
||||
packetData.gameInfo.mode = GAME_MODE_CREATED;
|
||||
packetData.gameInfo.name = game.GetName();
|
||||
packetData.gameInfo.data = game.GetGameData();
|
||||
static_cast<NetPacketGameListNew *>(packet.get())->SetData(packetData);
|
||||
return packet;
|
||||
}
|
||||
|
||||
+1
-3
@@ -191,9 +191,7 @@ public:
|
||||
struct Data
|
||||
{
|
||||
u_int32_t gameId;
|
||||
GameMode gameMode;
|
||||
std::string gameName;
|
||||
GameData gameData;
|
||||
GameInfo gameInfo;
|
||||
};
|
||||
|
||||
NetPacketGameListNew();
|
||||
|
||||
Reference in New Issue
Block a user