Player list is now sent in Game List New notification. Not shown in dialog yet.
This commit is contained in:
@@ -85,6 +85,8 @@ Server Notification: Game List New
|
|||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Game Mode | Game Name Length |
|
| Game Mode | Game Name Length |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Current Number of Players | Game Flags |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Game ID |
|
| Game ID |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Max Number of Players | Small Blind |
|
| Max Number of Players | Small Blind |
|
||||||
@@ -100,6 +102,12 @@ Server Notification: Game List New
|
|||||||
| +-------------------------------+
|
| +-------------------------------+
|
||||||
/ | padding |
|
/ | padding |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Player ID Slot #1 |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| \
|
||||||
|
\ Additional Player Slots /
|
||||||
|
/ |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
Game List notifications will be automatically sent if the player
|
Game List notifications will be automatically sent if the player
|
||||||
is in the lobby. If a game is joined/started, no more messages
|
is in the lobby. If a game is joined/started, no more messages
|
||||||
will be sent. As soon as the player leaves a game without
|
will be sent. As soon as the player leaves a game without
|
||||||
@@ -109,6 +117,8 @@ Game Mode:
|
|||||||
1: Game Created
|
1: Game Created
|
||||||
2: Game Started
|
2: Game Started
|
||||||
3: Game Closed (only for Game List Update)
|
3: Game Closed (only for Game List Update)
|
||||||
|
Game Flags:
|
||||||
|
0x01 set: Game is password protected
|
||||||
|
|
||||||
|
|
||||||
Server Notification: Game List Update
|
Server Notification: Game List Update
|
||||||
|
|||||||
+2
-1
@@ -21,7 +21,7 @@
|
|||||||
#ifndef _GAMEDATA_H_
|
#ifndef _GAMEDATA_H_
|
||||||
#define _GAMEDATA_H_
|
#define _GAMEDATA_H_
|
||||||
|
|
||||||
#include <string>
|
#include <playerdata.h>
|
||||||
|
|
||||||
enum GameMode
|
enum GameMode
|
||||||
{
|
{
|
||||||
@@ -49,6 +49,7 @@ struct GameInfo
|
|||||||
std::string name;
|
std::string name;
|
||||||
GameData data;
|
GameData data;
|
||||||
GameMode mode;
|
GameMode mode;
|
||||||
|
PlayerIdList players;
|
||||||
bool isPasswordProtected;
|
bool isPasswordProtected;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ using namespace std;
|
|||||||
|
|
||||||
#define NET_TYPE_ERROR 0x0400
|
#define NET_TYPE_ERROR 0x0400
|
||||||
|
|
||||||
|
#define NET_GAME_FLAG_PASSWORD_PROTECTED 0x01
|
||||||
|
|
||||||
#define NET_PLAYER_FLAG_HUMAN 0x01
|
#define NET_PLAYER_FLAG_HUMAN 0x01
|
||||||
#define NET_PLAYER_FLAG_ADMIN 0x02
|
#define NET_PLAYER_FLAG_ADMIN 0x02
|
||||||
|
|
||||||
@@ -112,6 +114,8 @@ struct GCC_PACKED NetPacketGameListNewData
|
|||||||
u_int32_t gameId;
|
u_int32_t gameId;
|
||||||
u_int16_t gameMode;
|
u_int16_t gameMode;
|
||||||
u_int16_t gameNameLength;
|
u_int16_t gameNameLength;
|
||||||
|
u_int16_t curNumberOfPlayers;
|
||||||
|
u_int16_t gameFlags;
|
||||||
u_int16_t maxNumberOfPlayers;
|
u_int16_t maxNumberOfPlayers;
|
||||||
u_int16_t smallBlind;
|
u_int16_t smallBlind;
|
||||||
u_int16_t handsBeforeRaise;
|
u_int16_t handsBeforeRaise;
|
||||||
@@ -1011,6 +1015,7 @@ void
|
|||||||
NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData)
|
NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData)
|
||||||
{
|
{
|
||||||
u_int16_t gameNameLen = (u_int16_t)inData.gameInfo.name.length();
|
u_int16_t gameNameLen = (u_int16_t)inData.gameInfo.name.length();
|
||||||
|
u_int16_t curNumPlayers = (u_int16_t)inData.gameInfo.players.size();
|
||||||
|
|
||||||
// Some basic checks, so we don't use up too much memory.
|
// Some basic checks, so we don't use up too much memory.
|
||||||
// The constructed packet will also be checked.
|
// The constructed packet will also be checked.
|
||||||
@@ -1019,7 +1024,10 @@ NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData)
|
|||||||
|
|
||||||
// Resize the packet so that the data fits in.
|
// Resize the packet so that the data fits in.
|
||||||
Resize((u_int16_t)
|
Resize((u_int16_t)
|
||||||
(sizeof(NetPacketGameListNewData) + ADD_PADDING(gameNameLen)));
|
(sizeof(NetPacketGameListNewData)
|
||||||
|
+ ADD_PADDING(gameNameLen)
|
||||||
|
+ curNumPlayers * sizeof(unsigned)
|
||||||
|
));
|
||||||
|
|
||||||
NetPacketGameListNewData *tmpData = (NetPacketGameListNewData *)GetRawData();
|
NetPacketGameListNewData *tmpData = (NetPacketGameListNewData *)GetRawData();
|
||||||
|
|
||||||
@@ -1027,6 +1035,8 @@ NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData)
|
|||||||
tmpData->gameId = htonl(inData.gameId);
|
tmpData->gameId = htonl(inData.gameId);
|
||||||
tmpData->gameMode = htons(inData.gameInfo.mode);
|
tmpData->gameMode = htons(inData.gameInfo.mode);
|
||||||
tmpData->gameNameLength = htons(gameNameLen);
|
tmpData->gameNameLength = htons(gameNameLen);
|
||||||
|
tmpData->curNumberOfPlayers = htons(curNumPlayers);
|
||||||
|
tmpData->gameFlags = htons(inData.gameInfo.isPasswordProtected ? NET_GAME_FLAG_PASSWORD_PROTECTED : 0);
|
||||||
tmpData->maxNumberOfPlayers = htons(inData.gameInfo.data.maxNumberOfPlayers);
|
tmpData->maxNumberOfPlayers = htons(inData.gameInfo.data.maxNumberOfPlayers);
|
||||||
tmpData->smallBlind = htons(inData.gameInfo.data.smallBlind);
|
tmpData->smallBlind = htons(inData.gameInfo.data.smallBlind);
|
||||||
tmpData->handsBeforeRaise = htons(inData.gameInfo.data.handsBeforeRaise);
|
tmpData->handsBeforeRaise = htons(inData.gameInfo.data.handsBeforeRaise);
|
||||||
@@ -1037,6 +1047,19 @@ NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData)
|
|||||||
char *gameNamePtr = (char *)tmpData + sizeof(NetPacketGameListNewData);
|
char *gameNamePtr = (char *)tmpData + sizeof(NetPacketGameListNewData);
|
||||||
memcpy(gameNamePtr, inData.gameInfo.name.c_str(), gameNameLen);
|
memcpy(gameNamePtr, inData.gameInfo.name.c_str(), gameNameLen);
|
||||||
|
|
||||||
|
PlayerIdList::const_iterator i = inData.gameInfo.players.begin();
|
||||||
|
PlayerIdList::const_iterator end = inData.gameInfo.players.end();
|
||||||
|
|
||||||
|
// Copy the player list to continous memory
|
||||||
|
unsigned *tmpPlayer =
|
||||||
|
(unsigned *)((char *)tmpData + sizeof(NetPacketGameListNewData) + ADD_PADDING(gameNameLen));
|
||||||
|
while (i != end)
|
||||||
|
{
|
||||||
|
*tmpPlayer = htonl(*i);
|
||||||
|
++tmpPlayer;
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
// Check the packet - just in case.
|
// Check the packet - just in case.
|
||||||
Check(GetRawData());
|
Check(GetRawData());
|
||||||
}
|
}
|
||||||
@@ -1050,6 +1073,8 @@ NetPacketGameListNew::GetData(NetPacketGameListNew::Data &outData) const
|
|||||||
outData.gameId = ntohl(tmpData->gameId);
|
outData.gameId = ntohl(tmpData->gameId);
|
||||||
outData.gameInfo.mode = static_cast<GameMode>(ntohs(tmpData->gameMode));
|
outData.gameInfo.mode = static_cast<GameMode>(ntohs(tmpData->gameMode));
|
||||||
u_int16_t gameNameLen = ntohs(tmpData->gameNameLength);
|
u_int16_t gameNameLen = ntohs(tmpData->gameNameLength);
|
||||||
|
u_int16_t curNumPlayers = ntohs(tmpData->curNumberOfPlayers);
|
||||||
|
outData.gameInfo.isPasswordProtected = ntohs(tmpData->gameFlags) == NET_GAME_FLAG_PASSWORD_PROTECTED;
|
||||||
outData.gameInfo.data.maxNumberOfPlayers = ntohs(tmpData->maxNumberOfPlayers);
|
outData.gameInfo.data.maxNumberOfPlayers = ntohs(tmpData->maxNumberOfPlayers);
|
||||||
outData.gameInfo.data.smallBlind = ntohs(tmpData->smallBlind);
|
outData.gameInfo.data.smallBlind = ntohs(tmpData->smallBlind);
|
||||||
outData.gameInfo.data.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
outData.gameInfo.data.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
|
||||||
@@ -1059,6 +1084,16 @@ NetPacketGameListNew::GetData(NetPacketGameListNew::Data &outData) const
|
|||||||
|
|
||||||
char *gameNamePtr = (char *)tmpData + sizeof(NetPacketGameListNewData);
|
char *gameNamePtr = (char *)tmpData + sizeof(NetPacketGameListNewData);
|
||||||
outData.gameInfo.name = string(gameNamePtr, gameNameLen);
|
outData.gameInfo.name = string(gameNamePtr, gameNameLen);
|
||||||
|
|
||||||
|
unsigned *tmpPlayer =
|
||||||
|
(unsigned *)((char *)tmpData + sizeof(NetPacketGameListNewData) + ADD_PADDING(gameNameLen));
|
||||||
|
|
||||||
|
// Store all available players.
|
||||||
|
for (int i = 0; i < curNumPlayers; i++)
|
||||||
|
{
|
||||||
|
outData.gameInfo.players.push_back(*tmpPlayer);
|
||||||
|
++tmpPlayer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const NetPacketGameListNew *
|
const NetPacketGameListNew *
|
||||||
@@ -1073,10 +1108,12 @@ NetPacketGameListNew::InternalCheck(const NetPacketHeader* data) const
|
|||||||
u_int16_t dataLen = ntohs(data->length);
|
u_int16_t dataLen = ntohs(data->length);
|
||||||
NetPacketGameListNewData *tmpData = (NetPacketGameListNewData *)data;
|
NetPacketGameListNewData *tmpData = (NetPacketGameListNewData *)data;
|
||||||
int gameNameLength = ntohs(tmpData->gameNameLength);
|
int gameNameLength = ntohs(tmpData->gameNameLength);
|
||||||
|
int curNumPlayers = ntohs(tmpData->curNumberOfPlayers);
|
||||||
// Exact checking of dynamic packet size.
|
// Exact checking of dynamic packet size.
|
||||||
if (dataLen !=
|
if (dataLen !=
|
||||||
sizeof(NetPacketGameListNewData)
|
sizeof(NetPacketGameListNewData)
|
||||||
+ ADD_PADDING(gameNameLength))
|
+ ADD_PADDING(gameNameLength)
|
||||||
|
+ curNumPlayers * sizeof(unsigned))
|
||||||
{
|
{
|
||||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -556,6 +556,7 @@ ServerLobbyThread::CreateNetPacketGameListNew(const ServerGameThread &game)
|
|||||||
packetData.gameInfo.mode = GAME_MODE_CREATED;
|
packetData.gameInfo.mode = GAME_MODE_CREATED;
|
||||||
packetData.gameInfo.name = game.GetName();
|
packetData.gameInfo.name = game.GetName();
|
||||||
packetData.gameInfo.data = game.GetGameData();
|
packetData.gameInfo.data = game.GetGameData();
|
||||||
|
packetData.gameInfo.players = game.GetSessionManager().GetPlayerIdList();
|
||||||
static_cast<NetPacketGameListNew *>(packet.get())->SetData(packetData);
|
static_cast<NetPacketGameListNew *>(packet.get())->SetData(packetData);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -219,6 +219,27 @@ SessionManager::GetPlayerDataList() const
|
|||||||
return playerList;
|
return playerList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PlayerIdList
|
||||||
|
SessionManager::GetPlayerIdList() const
|
||||||
|
{
|
||||||
|
PlayerIdList playerList;
|
||||||
|
boost::mutex::scoped_lock lock(m_sessionMapMutex);
|
||||||
|
|
||||||
|
SessionMap::const_iterator session_i = m_sessionMap.begin();
|
||||||
|
SessionMap::const_iterator session_end = m_sessionMap.end();
|
||||||
|
|
||||||
|
while (session_i != session_end)
|
||||||
|
{
|
||||||
|
// Get all players in the game.
|
||||||
|
if (session_i->second.sessionData->GetState() == SessionData::Game)
|
||||||
|
{
|
||||||
|
playerList.push_back(session_i->second.playerData->GetUniqueId());
|
||||||
|
}
|
||||||
|
++session_i;
|
||||||
|
}
|
||||||
|
return playerList;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
SessionManager::IsPlayerConnected(const string &playerName) const
|
SessionManager::IsPlayerConnected(const string &playerName) const
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ public:
|
|||||||
SessionWrapper GetSessionByUniquePlayerId(unsigned uniqueId) const;
|
SessionWrapper GetSessionByUniquePlayerId(unsigned uniqueId) const;
|
||||||
|
|
||||||
PlayerDataList GetPlayerDataList() const;
|
PlayerDataList GetPlayerDataList() const;
|
||||||
|
PlayerIdList GetPlayerIdList() const;
|
||||||
bool IsPlayerConnected(const std::string &playerName) const;
|
bool IsPlayerConnected(const std::string &playerName) const;
|
||||||
bool IsPlayerConnected(unsigned uniqueId) const;
|
bool IsPlayerConnected(unsigned uniqueId) const;
|
||||||
|
|
||||||
|
|||||||
@@ -93,6 +93,7 @@ private:
|
|||||||
boost::shared_ptr<SessionData> m_netSessionData;
|
boost::shared_ptr<SessionData> m_netSessionData;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::list<unsigned> PlayerIdList;
|
||||||
typedef std::list<boost::shared_ptr<PlayerData> > PlayerDataList;
|
typedef std::list<boost::shared_ptr<PlayerData> > PlayerDataList;
|
||||||
typedef std::map<unsigned, boost::shared_ptr<PlayerData> > PlayerDataMap;
|
typedef std::map<unsigned, boost::shared_ptr<PlayerData> > PlayerDataMap;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user