|
|
|
@@ -31,26 +31,30 @@ using namespace std;
|
|
|
|
|
#define NET_TYPE_INIT_ACK 0x0002
|
|
|
|
|
#define NET_TYPE_GAME_LIST_NEW 0x0003
|
|
|
|
|
#define NET_TYPE_GAME_LIST_UPDATE 0x0004
|
|
|
|
|
#define NET_TYPE_CREATE_GAME 0x0005
|
|
|
|
|
#define NET_TYPE_JOIN_GAME 0x0006
|
|
|
|
|
#define NET_TYPE_JOIN_GAME_ACK 0x0007
|
|
|
|
|
#define NET_TYPE_PLAYER_JOINED 0x0008
|
|
|
|
|
#define NET_TYPE_PLAYER_LEFT 0x0009
|
|
|
|
|
#define NET_TYPE_KICK_PLAYER 0x000A
|
|
|
|
|
#define NET_TYPE_START_EVENT 0x000B
|
|
|
|
|
#define NET_TYPE_GAME_START 0x000C
|
|
|
|
|
#define NET_TYPE_HAND_START 0x000D
|
|
|
|
|
#define NET_TYPE_PLAYERS_TURN 0x000E
|
|
|
|
|
#define NET_TYPE_PLAYERS_ACTION 0x000F
|
|
|
|
|
#define NET_TYPE_PLAYERS_ACTION_DONE 0x0010
|
|
|
|
|
#define NET_TYPE_PLAYERS_ACTION_REJECTED 0x0011
|
|
|
|
|
#define NET_TYPE_DEAL_FLOP_CARDS 0x0012
|
|
|
|
|
#define NET_TYPE_DEAL_TURN_CARD 0x0013
|
|
|
|
|
#define NET_TYPE_DEAL_RIVER_CARD 0x0014
|
|
|
|
|
#define NET_TYPE_ALL_IN_SHOW_CARDS 0x0015
|
|
|
|
|
#define NET_TYPE_END_OF_HAND_SHOW_CARDS 0x0016
|
|
|
|
|
#define NET_TYPE_END_OF_HAND_HIDE_CARDS 0x0017
|
|
|
|
|
#define NET_TYPE_END_OF_GAME 0x0018
|
|
|
|
|
#define NET_TYPE_GAME_LIST_PLAYER_JOINED 0x0005
|
|
|
|
|
#define NET_TYPE_GAME_LIST_PLAYER_LEFT 0x0006
|
|
|
|
|
#define NET_TYPE_RETRIEVE_PLAYER_INFO 0x0007
|
|
|
|
|
#define NET_TYPE_PLAYER_INFO 0x0008
|
|
|
|
|
#define NET_TYPE_CREATE_GAME 0x0009
|
|
|
|
|
#define NET_TYPE_JOIN_GAME 0x000A
|
|
|
|
|
#define NET_TYPE_JOIN_GAME_ACK 0x000B
|
|
|
|
|
#define NET_TYPE_PLAYER_JOINED 0x000C
|
|
|
|
|
#define NET_TYPE_PLAYER_LEFT 0x000D
|
|
|
|
|
#define NET_TYPE_KICK_PLAYER 0x000E
|
|
|
|
|
#define NET_TYPE_START_EVENT 0x000F
|
|
|
|
|
#define NET_TYPE_GAME_START 0x0010
|
|
|
|
|
#define NET_TYPE_HAND_START 0x0011
|
|
|
|
|
#define NET_TYPE_PLAYERS_TURN 0x0012
|
|
|
|
|
#define NET_TYPE_PLAYERS_ACTION 0x0013
|
|
|
|
|
#define NET_TYPE_PLAYERS_ACTION_DONE 0x0014
|
|
|
|
|
#define NET_TYPE_PLAYERS_ACTION_REJECTED 0x0015
|
|
|
|
|
#define NET_TYPE_DEAL_FLOP_CARDS 0x0016
|
|
|
|
|
#define NET_TYPE_DEAL_TURN_CARD 0x0017
|
|
|
|
|
#define NET_TYPE_DEAL_RIVER_CARD 0x0018
|
|
|
|
|
#define NET_TYPE_ALL_IN_SHOW_CARDS 0x0019
|
|
|
|
|
#define NET_TYPE_END_OF_HAND_SHOW_CARDS 0x001A
|
|
|
|
|
#define NET_TYPE_END_OF_HAND_HIDE_CARDS 0x001B
|
|
|
|
|
#define NET_TYPE_END_OF_GAME 0x001C
|
|
|
|
|
|
|
|
|
|
#define NET_TYPE_SEND_CHAT_TEXT 0x0200
|
|
|
|
|
#define NET_TYPE_CHAT_TEXT 0x0201
|
|
|
|
@@ -108,6 +112,13 @@ struct GCC_PACKED NetPacketGameListNewData
|
|
|
|
|
u_int32_t gameId;
|
|
|
|
|
u_int16_t gameMode;
|
|
|
|
|
u_int16_t gameNameLength;
|
|
|
|
|
u_int16_t maxNumberOfPlayers;
|
|
|
|
|
u_int16_t smallBlind;
|
|
|
|
|
u_int16_t handsBeforeRaise;
|
|
|
|
|
u_int16_t proposedGuiSpeed;
|
|
|
|
|
u_int16_t playerActionTimeout;
|
|
|
|
|
u_int16_t reserved;
|
|
|
|
|
u_int32_t startMoney;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GCC_PACKED NetPacketGameListUpdateData
|
|
|
|
@@ -118,6 +129,34 @@ struct GCC_PACKED NetPacketGameListUpdateData
|
|
|
|
|
u_int16_t reserved;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GCC_PACKED NetPacketGameListPlayerJoinedData
|
|
|
|
|
{
|
|
|
|
|
NetPacketHeader head;
|
|
|
|
|
u_int32_t gameId;
|
|
|
|
|
u_int32_t playerId;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GCC_PACKED NetPacketGameListPlayerLeftData
|
|
|
|
|
{
|
|
|
|
|
NetPacketHeader head;
|
|
|
|
|
u_int32_t gameId;
|
|
|
|
|
u_int32_t playerId;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GCC_PACKED NetPacketRetrievePlayerInfoData
|
|
|
|
|
{
|
|
|
|
|
NetPacketHeader head;
|
|
|
|
|
u_int32_t playerId;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GCC_PACKED NetPacketPlayerInfoData
|
|
|
|
|
{
|
|
|
|
|
NetPacketHeader head;
|
|
|
|
|
u_int32_t playerId;
|
|
|
|
|
u_int16_t playerFlags;
|
|
|
|
|
u_int16_t playerNameLength;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct GCC_PACKED NetPacketCreateGameData
|
|
|
|
|
{
|
|
|
|
|
NetPacketHeader head;
|
|
|
|
@@ -157,9 +196,7 @@ struct GCC_PACKED NetPacketPlayerJoinedData
|
|
|
|
|
{
|
|
|
|
|
NetPacketHeader head;
|
|
|
|
|
u_int32_t playerId;
|
|
|
|
|
u_int16_t playerFlags;
|
|
|
|
|
u_int16_t playerRights;
|
|
|
|
|
u_int16_t playerNameLength;
|
|
|
|
|
u_int16_t reserved;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -377,6 +414,18 @@ NetPacket::Create(char *data, unsigned &dataSize)
|
|
|
|
|
case NET_TYPE_GAME_LIST_UPDATE:
|
|
|
|
|
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketGameListUpdate);
|
|
|
|
|
break;
|
|
|
|
|
case NET_TYPE_GAME_LIST_PLAYER_JOINED:
|
|
|
|
|
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketGameListPlayerJoined);
|
|
|
|
|
break;
|
|
|
|
|
case NET_TYPE_GAME_LIST_PLAYER_LEFT:
|
|
|
|
|
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketGameListPlayerLeft);
|
|
|
|
|
break;
|
|
|
|
|
case NET_TYPE_RETRIEVE_PLAYER_INFO:
|
|
|
|
|
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketRetrievePlayerInfo);
|
|
|
|
|
break;
|
|
|
|
|
case NET_TYPE_PLAYER_INFO:
|
|
|
|
|
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketPlayerInfo);
|
|
|
|
|
break;
|
|
|
|
|
case NET_TYPE_CREATE_GAME:
|
|
|
|
|
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketCreateGame);
|
|
|
|
|
break;
|
|
|
|
@@ -554,6 +603,30 @@ NetPacket::ToNetPacketGameListUpdate() const
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketGameListPlayerJoined *
|
|
|
|
|
NetPacket::ToNetPacketGameListPlayerJoined() const
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketGameListPlayerLeft *
|
|
|
|
|
NetPacket::ToNetPacketGameListPlayerLeft() const
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketRetrievePlayerInfo *
|
|
|
|
|
NetPacket::ToNetPacketRetrievePlayerInfo() const
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketPlayerInfo *
|
|
|
|
|
NetPacket::ToNetPacketPlayerInfo() const
|
|
|
|
|
{
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketCreateGame *
|
|
|
|
|
NetPacket::ToNetPacketCreateGame() const
|
|
|
|
|
{
|
|
|
|
@@ -951,9 +1024,16 @@ NetPacketGameListNew::SetData(const NetPacketGameListNew::Data &inData)
|
|
|
|
|
NetPacketGameListNewData *tmpData = (NetPacketGameListNewData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
// Set the data.
|
|
|
|
|
tmpData->gameId = htonl(inData.gameId);
|
|
|
|
|
tmpData->gameMode = htons(inData.gameMode);
|
|
|
|
|
tmpData->gameNameLength = htons(gameNameLen);
|
|
|
|
|
tmpData->gameId = htonl(inData.gameId);
|
|
|
|
|
tmpData->gameMode = htons(inData.gameMode);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
char *gameNamePtr = (char *)tmpData + sizeof(NetPacketGameListNewData);
|
|
|
|
|
memcpy(gameNamePtr, inData.gameName.c_str(), gameNameLen);
|
|
|
|
|
|
|
|
|
@@ -967,9 +1047,16 @@ 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.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);
|
|
|
|
|
|
|
|
|
|
char *gameNamePtr = (char *)tmpData + sizeof(NetPacketGameListNewData);
|
|
|
|
|
outData.gameName = string(gameNamePtr, gameNameLen);
|
|
|
|
|
}
|
|
|
|
@@ -1069,6 +1156,273 @@ NetPacketGameListUpdate::InternalCheck(const NetPacketHeader* data) const
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
NetPacketGameListPlayerJoined::NetPacketGameListPlayerJoined()
|
|
|
|
|
: NetPacket(NET_TYPE_GAME_LIST_PLAYER_JOINED, sizeof(NetPacketGameListPlayerJoinedData), sizeof(NetPacketGameListPlayerJoinedData))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetPacketGameListPlayerJoined::~NetPacketGameListPlayerJoined()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket>
|
|
|
|
|
NetPacketGameListPlayerJoined::Clone() const
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> newPacket(new NetPacketGameListPlayerJoined);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
newPacket->SetRawData(GetRawData());
|
|
|
|
|
} catch (const NetException &)
|
|
|
|
|
{
|
|
|
|
|
// Need to return the new packet anyway.
|
|
|
|
|
}
|
|
|
|
|
return newPacket;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketGameListPlayerJoined::SetData(const NetPacketGameListPlayerJoined::Data &inData)
|
|
|
|
|
{
|
|
|
|
|
NetPacketGameListPlayerJoinedData *tmpData = (NetPacketGameListPlayerJoinedData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
// Set the data.
|
|
|
|
|
tmpData->gameId = htonl(inData.gameId);
|
|
|
|
|
tmpData->playerId = htonl(inData.playerId);
|
|
|
|
|
|
|
|
|
|
// Check the packet - just in case.
|
|
|
|
|
Check(GetRawData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketGameListPlayerJoined::GetData(NetPacketGameListPlayerJoined::Data &outData) const
|
|
|
|
|
{
|
|
|
|
|
// We assume that the data is valid. Validity has already been checked.
|
|
|
|
|
NetPacketGameListPlayerJoinedData *tmpData = (NetPacketGameListPlayerJoinedData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
outData.gameId = ntohl(tmpData->gameId);
|
|
|
|
|
outData.playerId = ntohl(tmpData->playerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketGameListPlayerJoined *
|
|
|
|
|
NetPacketGameListPlayerJoined::ToNetPacketGameListPlayerJoined() const
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketGameListPlayerJoined::InternalCheck(const NetPacketHeader* data) const
|
|
|
|
|
{
|
|
|
|
|
// Nothing to do.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
NetPacketGameListPlayerLeft::NetPacketGameListPlayerLeft()
|
|
|
|
|
: NetPacket(NET_TYPE_GAME_LIST_PLAYER_LEFT, sizeof(NetPacketGameListPlayerLeftData), sizeof(NetPacketGameListPlayerLeftData))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetPacketGameListPlayerLeft::~NetPacketGameListPlayerLeft()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket>
|
|
|
|
|
NetPacketGameListPlayerLeft::Clone() const
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> newPacket(new NetPacketGameListPlayerLeft);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
newPacket->SetRawData(GetRawData());
|
|
|
|
|
} catch (const NetException &)
|
|
|
|
|
{
|
|
|
|
|
// Need to return the new packet anyway.
|
|
|
|
|
}
|
|
|
|
|
return newPacket;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketGameListPlayerLeft::SetData(const NetPacketGameListPlayerLeft::Data &inData)
|
|
|
|
|
{
|
|
|
|
|
NetPacketGameListPlayerLeftData *tmpData = (NetPacketGameListPlayerLeftData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
// Set the data.
|
|
|
|
|
tmpData->gameId = htonl(inData.gameId);
|
|
|
|
|
tmpData->playerId = htonl(inData.playerId);
|
|
|
|
|
|
|
|
|
|
// Check the packet - just in case.
|
|
|
|
|
Check(GetRawData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketGameListPlayerLeft::GetData(NetPacketGameListPlayerLeft::Data &outData) const
|
|
|
|
|
{
|
|
|
|
|
// We assume that the data is valid. Validity has already been checked.
|
|
|
|
|
NetPacketGameListPlayerLeftData *tmpData = (NetPacketGameListPlayerLeftData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
outData.gameId = ntohl(tmpData->gameId);
|
|
|
|
|
outData.playerId = ntohl(tmpData->playerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketGameListPlayerLeft *
|
|
|
|
|
NetPacketGameListPlayerLeft::ToNetPacketGameListPlayerLeft() const
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketGameListPlayerLeft::InternalCheck(const NetPacketHeader* data) const
|
|
|
|
|
{
|
|
|
|
|
// Nothing to do.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
NetPacketRetrievePlayerInfo::NetPacketRetrievePlayerInfo()
|
|
|
|
|
: NetPacket(NET_TYPE_RETRIEVE_PLAYER_INFO, sizeof(NetPacketRetrievePlayerInfoData), sizeof(NetPacketRetrievePlayerInfoData))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetPacketRetrievePlayerInfo::~NetPacketRetrievePlayerInfo()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket>
|
|
|
|
|
NetPacketRetrievePlayerInfo::Clone() const
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> newPacket(new NetPacketRetrievePlayerInfo);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
newPacket->SetRawData(GetRawData());
|
|
|
|
|
} catch (const NetException &)
|
|
|
|
|
{
|
|
|
|
|
// Need to return the new packet anyway.
|
|
|
|
|
}
|
|
|
|
|
return newPacket;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketRetrievePlayerInfo::SetData(const NetPacketRetrievePlayerInfo::Data &inData)
|
|
|
|
|
{
|
|
|
|
|
NetPacketRetrievePlayerInfoData *tmpData = (NetPacketRetrievePlayerInfoData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
// Set the data.
|
|
|
|
|
tmpData->playerId = htonl(inData.playerId);
|
|
|
|
|
|
|
|
|
|
// Check the packet - just in case.
|
|
|
|
|
Check(GetRawData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketRetrievePlayerInfo::GetData(NetPacketRetrievePlayerInfo::Data &outData) const
|
|
|
|
|
{
|
|
|
|
|
// We assume that the data is valid. Validity has already been checked.
|
|
|
|
|
NetPacketRetrievePlayerInfoData *tmpData = (NetPacketRetrievePlayerInfoData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
outData.playerId = ntohl(tmpData->playerId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketRetrievePlayerInfo *
|
|
|
|
|
NetPacketRetrievePlayerInfo::ToNetPacketRetrievePlayerInfo() const
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketRetrievePlayerInfo::InternalCheck(const NetPacketHeader* data) const
|
|
|
|
|
{
|
|
|
|
|
// Nothing to do.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
NetPacketPlayerInfo::NetPacketPlayerInfo()
|
|
|
|
|
: NetPacket(NET_TYPE_PLAYER_INFO, sizeof(NetPacketPlayerInfoData), MAX_PACKET_SIZE)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NetPacketPlayerInfo::~NetPacketPlayerInfo()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boost::shared_ptr<NetPacket>
|
|
|
|
|
NetPacketPlayerInfo::Clone() const
|
|
|
|
|
{
|
|
|
|
|
boost::shared_ptr<NetPacket> newPacket(new NetPacketPlayerInfo);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
newPacket->SetRawData(GetRawData());
|
|
|
|
|
} catch (const NetException &)
|
|
|
|
|
{
|
|
|
|
|
// Need to return the new packet anyway.
|
|
|
|
|
}
|
|
|
|
|
return newPacket;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketPlayerInfo::SetData(const NetPacketPlayerInfo::Data &inData)
|
|
|
|
|
{
|
|
|
|
|
u_int16_t playerNameLen = (u_int16_t)inData.playerInfo.playerName.length();
|
|
|
|
|
|
|
|
|
|
if (!playerNameLen || playerNameLen > MAX_NAME_SIZE)
|
|
|
|
|
throw NetException(ERR_NET_INVALID_PLAYER_NAME, 0);
|
|
|
|
|
|
|
|
|
|
// Resize the packet so that the data fits in.
|
|
|
|
|
Resize((u_int16_t)
|
|
|
|
|
(sizeof(NetPacketPlayerInfoData) + ADD_PADDING(playerNameLen)));
|
|
|
|
|
|
|
|
|
|
NetPacketPlayerInfoData *tmpData = (NetPacketPlayerInfoData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
// Set the data.
|
|
|
|
|
tmpData->playerId = htonl(inData.playerId);
|
|
|
|
|
tmpData->playerFlags = htons(inData.playerInfo.ptype);
|
|
|
|
|
tmpData->playerNameLength = htons(playerNameLen);
|
|
|
|
|
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerInfoData);
|
|
|
|
|
memcpy(namePtr, inData.playerInfo.playerName.c_str(), playerNameLen);
|
|
|
|
|
|
|
|
|
|
// Check the packet - just in case.
|
|
|
|
|
Check(GetRawData());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketPlayerInfo::GetData(NetPacketPlayerInfo::Data &outData) const
|
|
|
|
|
{
|
|
|
|
|
// We assume that the data is valid. Validity has already been checked.
|
|
|
|
|
NetPacketPlayerInfoData *tmpData = (NetPacketPlayerInfoData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
outData.playerId = ntohl(tmpData->playerId);
|
|
|
|
|
outData.playerInfo.ptype = static_cast<PlayerType>(ntohs(tmpData->playerFlags));
|
|
|
|
|
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerInfoData);
|
|
|
|
|
outData.playerInfo.playerName = string(namePtr, ntohs(tmpData->playerNameLength));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketPlayerInfo *
|
|
|
|
|
NetPacketPlayerInfo::ToNetPacketPlayerInfo() const
|
|
|
|
|
{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
NetPacketPlayerInfo::InternalCheck(const NetPacketHeader* data) const
|
|
|
|
|
{
|
|
|
|
|
u_int16_t dataLen = ntohs(data->length);
|
|
|
|
|
NetPacketPlayerInfoData *tmpData = (NetPacketPlayerInfoData *)data;
|
|
|
|
|
int playerNameLength = ntohs(tmpData->playerNameLength);
|
|
|
|
|
// Exact checking this time.
|
|
|
|
|
if (dataLen !=
|
|
|
|
|
sizeof(NetPacketPlayerInfoData)
|
|
|
|
|
+ ADD_PADDING(playerNameLength))
|
|
|
|
|
{
|
|
|
|
|
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
|
|
|
|
}
|
|
|
|
|
// Check string sizes.
|
|
|
|
|
if (!playerNameLength
|
|
|
|
|
|| playerNameLength > MAX_NAME_SIZE)
|
|
|
|
|
{
|
|
|
|
|
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
NetPacketCreateGame::NetPacketCreateGame()
|
|
|
|
|
: NetPacket(NET_TYPE_CREATE_GAME, sizeof(NetPacketCreateGameData), MAX_PACKET_SIZE)
|
|
|
|
|
{
|
|
|
|
@@ -1377,7 +1731,7 @@ NetPacketJoinGameAck::InternalCheck(const NetPacketHeader* data) const
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
NetPacketPlayerJoined::NetPacketPlayerJoined()
|
|
|
|
|
: NetPacket(NET_TYPE_PLAYER_JOINED, sizeof(NetPacketPlayerJoinedData), MAX_PACKET_SIZE)
|
|
|
|
|
: NetPacket(NET_TYPE_PLAYER_JOINED, sizeof(NetPacketPlayerJoinedData), sizeof(NetPacketPlayerJoinedData))
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1402,24 +1756,11 @@ NetPacketPlayerJoined::Clone() const
|
|
|
|
|
void
|
|
|
|
|
NetPacketPlayerJoined::SetData(const NetPacketPlayerJoined::Data &inData)
|
|
|
|
|
{
|
|
|
|
|
u_int16_t playerNameLen = (u_int16_t)inData.playerName.length();
|
|
|
|
|
|
|
|
|
|
if (!playerNameLen || playerNameLen > MAX_NAME_SIZE)
|
|
|
|
|
throw NetException(ERR_NET_INVALID_PLAYER_NAME, 0);
|
|
|
|
|
|
|
|
|
|
// Resize the packet so that the data fits in.
|
|
|
|
|
Resize((u_int16_t)
|
|
|
|
|
(sizeof(NetPacketPlayerJoinedData) + ADD_PADDING(playerNameLen)));
|
|
|
|
|
|
|
|
|
|
NetPacketPlayerJoinedData *tmpData = (NetPacketPlayerJoinedData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
// Set the data.
|
|
|
|
|
tmpData->playerId = htonl(inData.playerId);
|
|
|
|
|
tmpData->playerFlags = htons(inData.ptype);
|
|
|
|
|
tmpData->playerRights = htons(inData.prights);
|
|
|
|
|
tmpData->playerNameLength = htons(playerNameLen);
|
|
|
|
|
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerJoinedData);
|
|
|
|
|
memcpy(namePtr, inData.playerName.c_str(), playerNameLen);
|
|
|
|
|
|
|
|
|
|
// Check the packet - just in case.
|
|
|
|
|
Check(GetRawData());
|
|
|
|
@@ -1432,10 +1773,7 @@ NetPacketPlayerJoined::GetData(NetPacketPlayerJoined::Data &outData) const
|
|
|
|
|
NetPacketPlayerJoinedData *tmpData = (NetPacketPlayerJoinedData *)GetRawData();
|
|
|
|
|
|
|
|
|
|
outData.playerId = ntohl(tmpData->playerId);
|
|
|
|
|
outData.ptype = static_cast<PlayerType>(ntohs(tmpData->playerFlags));
|
|
|
|
|
outData.prights = static_cast<PlayerRights>(ntohs(tmpData->playerRights));
|
|
|
|
|
char *namePtr = (char *)tmpData + sizeof(NetPacketPlayerJoinedData);
|
|
|
|
|
outData.playerName = string(namePtr, ntohs(tmpData->playerNameLength));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NetPacketPlayerJoined *
|
|
|
|
@@ -1447,22 +1785,7 @@ NetPacketPlayerJoined::ToNetPacketPlayerJoined() const
|
|
|
|
|
void
|
|
|
|
|
NetPacketPlayerJoined::InternalCheck(const NetPacketHeader* data) const
|
|
|
|
|
{
|
|
|
|
|
u_int16_t dataLen = ntohs(data->length);
|
|
|
|
|
NetPacketPlayerJoinedData *tmpData = (NetPacketPlayerJoinedData *)data;
|
|
|
|
|
int playerNameLength = ntohs(tmpData->playerNameLength);
|
|
|
|
|
// Exact checking this time.
|
|
|
|
|
if (dataLen !=
|
|
|
|
|
sizeof(NetPacketPlayerJoinedData)
|
|
|
|
|
+ ADD_PADDING(playerNameLength))
|
|
|
|
|
{
|
|
|
|
|
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
|
|
|
|
}
|
|
|
|
|
// Check string sizes.
|
|
|
|
|
if (!playerNameLength
|
|
|
|
|
|| playerNameLength > MAX_NAME_SIZE)
|
|
|
|
|
{
|
|
|
|
|
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
|
|
|
|
}
|
|
|
|
|
// Nothing to do.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|