From ce6f489fbaadc224d9de125cc2995128f775b927 Mon Sep 17 00:00:00 2001 From: lotodore Date: Tue, 5 Jun 2007 23:04:51 +0000 Subject: [PATCH] Added additional packet for showing cards when allInCondition is true. --- docs/net_protocol.txt | 26 ++++++- src/net/common/netpacket.cpp | 141 ++++++++++++++++++++++++++++++++++- src/net/netpacket.h | 34 +++++++++ src/net/socket_msg.h | 7 +- 4 files changed, 201 insertions(+), 7 deletions(-) diff --git a/docs/net_protocol.txt b/docs/net_protocol.txt index 2499235d..fb58aac2 100644 --- a/docs/net_protocol.txt +++ b/docs/net_protocol.txt @@ -266,13 +266,35 @@ Server Notification: Deal River Card +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -Server Notification: End Of Hand Show Cards +Server Notification: All In Show Cards 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Message Type = 14 | Message Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Number Of PlayerCards Records | Reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | \ + \ PlayerCards Records / + / | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +PlayerCards Record + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Player Id | 1st Card | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | 2nd Card | Reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + +Server Notification: End Of Hand Show Cards + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Message Type = 15 | Message Length | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |Number Of PlayerResult Records | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | \ @@ -303,7 +325,7 @@ Server Notification: End Of Hand Hide Cards 0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Message Type = 15 | Message Length = 16 | + | Message Type = 16 | Message Length = 16 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Player Id | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ diff --git a/src/net/common/netpacket.cpp b/src/net/common/netpacket.cpp index 747ad331..80588d21 100644 --- a/src/net/common/netpacket.cpp +++ b/src/net/common/netpacket.cpp @@ -40,8 +40,9 @@ using namespace std; #define NET_TYPE_DEAL_FLOP_CARDS 0x000B #define NET_TYPE_DEAL_TURN_CARD 0x000C #define NET_TYPE_DEAL_RIVER_CARD 0x000D -#define NET_TYPE_END_OF_HAND_SHOW_CARDS 0x000E -#define NET_TYPE_END_OF_HAND_HIDE_CARDS 0x000F +#define NET_TYPE_ALL_IN_SHOW_CARDS 0x000E +#define NET_TYPE_END_OF_HAND_SHOW_CARDS 0x000F +#define NET_TYPE_END_OF_HAND_HIDE_CARDS 0x0010 #define NET_TYPE_SEND_CHAT_TEXT 0x0200 #define NET_TYPE_CHAT_TEXT 0x0201 @@ -196,6 +197,21 @@ struct GCC_PACKED NetPacketDealRiverCardData u_int16_t reserved; }; +struct GCC_PACKED NetPacketAllInShowCardsData +{ + NetPacketHeader head; + u_int16_t numberOfPlayerCards; + u_int16_t reserved; +}; + +struct GCC_PACKED PlayerCardsData +{ + u_int16_t playerId; + u_int16_t card1; + u_int16_t card2; + u_int16_t reserved; +}; + struct GCC_PACKED NetPacketEndOfHandShowCardsData { NetPacketHeader head; @@ -314,6 +330,9 @@ NetPacket::Create(char *data, unsigned &dataSize) case NET_TYPE_DEAL_RIVER_CARD: tmpPacket = boost::shared_ptr(new NetPacketDealRiverCard); break; + case NET_TYPE_ALL_IN_SHOW_CARDS: + tmpPacket = boost::shared_ptr(new NetPacketAllInShowCards); + break; case NET_TYPE_END_OF_HAND_SHOW_CARDS: tmpPacket = boost::shared_ptr(new NetPacketEndOfHandShowCards); break; @@ -488,6 +507,12 @@ NetPacket::ToNetPacketDealRiverCard() const return NULL; } +const NetPacketAllInShowCards * +NetPacket::ToNetPacketAllInShowCards() const +{ + return NULL; +} + const NetPacketEndOfHandShowCards * NetPacket::ToNetPacketEndOfHandShowCards() const { @@ -1544,6 +1569,118 @@ NetPacketDealRiverCard::Check(const NetPacketHeader* data) const //----------------------------------------------------------------------------- +NetPacketAllInShowCards::NetPacketAllInShowCards() +: NetPacket(NET_TYPE_ALL_IN_SHOW_CARDS, sizeof(NetPacketAllInShowCardsData)) +{ +} + +NetPacketAllInShowCards::~NetPacketAllInShowCards() +{ +} + +boost::shared_ptr +NetPacketAllInShowCards::Clone() const +{ + boost::shared_ptr newPacket(new NetPacketAllInShowCards); + try + { + newPacket->SetRawData(GetRawData()); + } catch (const NetException &) + { + // Need to return the new packet anyway. + } + return newPacket; +} + +void +NetPacketAllInShowCards::SetData(const NetPacketAllInShowCards::Data &inData) +{ + u_int16_t numPlayerCards = (u_int16_t)inData.playerCards.size(); + + if (!numPlayerCards || numPlayerCards > MAX_NUM_PLAYER_CARDS) + throw NetException(ERR_NET_INVALID_PLAYER_CARDS, 0); + + // Resize the packet so that the data fits in. + Resize((u_int16_t) + (sizeof(NetPacketAllInShowCardsData) + numPlayerCards * sizeof(PlayerCardsData))); + + NetPacketAllInShowCardsData *tmpData = (NetPacketAllInShowCardsData *)GetRawData(); + assert(tmpData); + + tmpData->numberOfPlayerCards = htons(numPlayerCards); + + PlayerCardsList::const_iterator i = inData.playerCards.begin(); + PlayerCardsList::const_iterator end = inData.playerCards.end(); + + // Copy the player cards data to continous memory + PlayerCardsData *curPlayerCardsData = + (PlayerCardsData *)((char *)tmpData + sizeof(NetPacketAllInShowCardsData)); + while (i != end) + { + curPlayerCardsData->playerId = htons((*i).playerId); + curPlayerCardsData->card1 = htons((*i).cards[0]); + curPlayerCardsData->card2 = htons((*i).cards[1]); + ++curPlayerCardsData; + ++i; + } +} + +void +NetPacketAllInShowCards::GetData(NetPacketAllInShowCards::Data &outData) const +{ + NetPacketAllInShowCardsData *tmpData = (NetPacketAllInShowCardsData *)GetRawData(); + assert(tmpData); + + outData.playerCards.clear(); + + u_int16_t numPlayerCards = ntohs(tmpData->numberOfPlayerCards); + PlayerCardsData *curPlayerCardsData = + (PlayerCardsData *)((char *)tmpData + sizeof(NetPacketAllInShowCardsData)); + + // Store all available player cards. + for (int i = 0; i < numPlayerCards; i++) + { + PlayerCards tmpPlayerCards; + tmpPlayerCards.playerId = ntohs(curPlayerCardsData->playerId); + tmpPlayerCards.cards[0] = ntohs(curPlayerCardsData->card1); + tmpPlayerCards.cards[1] = ntohs(curPlayerCardsData->card2); + + outData.playerCards.push_back(tmpPlayerCards); + ++curPlayerCardsData; + } +} + +const NetPacketAllInShowCards * +NetPacketAllInShowCards::ToNetPacketAllInShowCards() const +{ + return this; +} + +void +NetPacketAllInShowCards::Check(const NetPacketHeader* data) const +{ + assert(data); + + u_int16_t dataLen = ntohs(data->length); + if (dataLen < sizeof(NetPacketAllInShowCardsData)) + { + throw NetException(ERR_SOCK_INVALID_PACKET, 0); + } + + NetPacketAllInShowCardsData *tmpData = (NetPacketAllInShowCardsData *)data; + int numPlayerCards = ntohs(tmpData->numberOfPlayerCards); + + if (dataLen != + sizeof(NetPacketAllInShowCardsData) + + numPlayerCards * sizeof(PlayerCardsData)) + { + throw NetException(ERR_SOCK_INVALID_PACKET, 0); + } + // TODO: semantic checks within PlayerCardsData +} + +//----------------------------------------------------------------------------- + NetPacketEndOfHandShowCards::NetPacketEndOfHandShowCards() : NetPacket(NET_TYPE_END_OF_HAND_SHOW_CARDS, sizeof(NetPacketEndOfHandShowCardsData)) { diff --git a/src/net/netpacket.h b/src/net/netpacket.h index de41cca1..b5ba8fc4 100644 --- a/src/net/netpacket.h +++ b/src/net/netpacket.h @@ -35,6 +35,7 @@ #define MAX_PASSWORD_SIZE 64 #define MAX_CHAT_TEXT_SIZE 128 #define MAX_NUM_PLAYER_RESULTS MAX_NUMBER_OF_PLAYERS +#define MAX_NUM_PLAYER_CARDS MAX_NUMBER_OF_PLAYERS struct NetPacketHeader; @@ -52,6 +53,7 @@ class NetPacketPlayersActionRejected; class NetPacketDealFlopCards; class NetPacketDealTurnCard; class NetPacketDealRiverCard; +class NetPacketAllInShowCards; class NetPacketEndOfHandShowCards; class NetPacketEndOfHandHideCards; class NetPacketSendChatText; @@ -88,6 +90,7 @@ public: virtual const NetPacketDealFlopCards *ToNetPacketDealFlopCards() const; virtual const NetPacketDealTurnCard *ToNetPacketDealTurnCard() const; virtual const NetPacketDealRiverCard *ToNetPacketDealRiverCard() const; + virtual const NetPacketAllInShowCards *ToNetPacketAllInShowCards() const; virtual const NetPacketEndOfHandShowCards *ToNetPacketEndOfHandShowCards() const; virtual const NetPacketEndOfHandHideCards *ToNetPacketEndOfHandHideCards() const; virtual const NetPacketSendChatText *ToNetPacketSendChatText() const; @@ -428,6 +431,37 @@ protected: virtual void Check(const NetPacketHeader* data) const; }; +class NetPacketAllInShowCards : public NetPacket +{ +public: + struct PlayerCards + { + u_int16_t playerId; + u_int16_t cards[2]; + }; + + typedef std::list PlayerCardsList; + + struct Data + { + PlayerCardsList playerCards; + }; + + NetPacketAllInShowCards(); + virtual ~NetPacketAllInShowCards(); + + virtual boost::shared_ptr Clone() const; + + void SetData(const Data &inData); + void GetData(Data &outData) const; + + virtual const NetPacketAllInShowCards *ToNetPacketAllInShowCards() const; + +protected: + + virtual void Check(const NetPacketHeader* data) const; +}; + class NetPacketEndOfHandShowCards : public NetPacket { public: diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index b0cb7b37..54d172ab 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -48,9 +48,10 @@ #define ERR_NET_INVALID_PASSWORD_STR 105 #define ERR_NET_PLAYER_NAME_IN_USE 106 #define ERR_NET_INVALID_PLAYER_NAME 107 -#define ERR_NET_INVALID_PLAYER_RESULTS 108 -#define ERR_NET_INVALID_CHAT_TEXT 109 -#define ERR_NET_UNKNOWN_PLAYER_ID 110 +#define ERR_NET_INVALID_PLAYER_CARDS 108 +#define ERR_NET_INVALID_PLAYER_RESULTS 109 +#define ERR_NET_INVALID_CHAT_TEXT 110 +#define ERR_NET_UNKNOWN_PLAYER_ID 111 // This is an internal message which is not reported. #define MSG_SOCK_INTERNAL_PENDING 0