Flop/turn/river cards are now sent in a network game.
This commit is contained in:
@@ -40,7 +40,7 @@ public:
|
||||
int getPot() const { return pot;}
|
||||
void setPot(int theValue) { pot = theValue;}
|
||||
int getSets() const { return sets; }
|
||||
void setSets(int theValue) { sets = theValue; }
|
||||
void setSets(int theValue) { sets = theValue; }
|
||||
|
||||
void collectSets() ;
|
||||
void collectPot() ;
|
||||
|
||||
@@ -626,6 +626,38 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
||||
if (tmpPlayer->getMyID() == 0) // Is this the GUI player?
|
||||
client.GetGui().meInAction();
|
||||
}
|
||||
else if (packet->ToNetPacketDealFlopCards())
|
||||
{
|
||||
NetPacketDealFlopCards::Data cardsData;
|
||||
packet->ToNetPacketDealFlopCards()->GetData(cardsData);
|
||||
int tmpCards[5];
|
||||
tmpCards[0] = static_cast<int>(cardsData.flopCards[0]);
|
||||
tmpCards[1] = static_cast<int>(cardsData.flopCards[1]);
|
||||
tmpCards[2] = static_cast<int>(cardsData.flopCards[2]);
|
||||
tmpCards[3] = tmpCards[4] = 0;
|
||||
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
||||
client.GetGui().dealFlopCards();
|
||||
}
|
||||
else if (packet->ToNetPacketDealTurnCard())
|
||||
{
|
||||
NetPacketDealTurnCard::Data cardsData;
|
||||
packet->ToNetPacketDealTurnCard()->GetData(cardsData);
|
||||
int tmpCards[5];
|
||||
curGame->getCurrentHand()->getBoard()->getMyCards(tmpCards);
|
||||
tmpCards[3] = static_cast<int>(cardsData.turnCard);
|
||||
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
||||
client.GetGui().dealTurnCard();
|
||||
}
|
||||
else if (packet->ToNetPacketDealRiverCard())
|
||||
{
|
||||
NetPacketDealRiverCard::Data cardsData;
|
||||
packet->ToNetPacketDealRiverCard()->GetData(cardsData);
|
||||
int tmpCards[5];
|
||||
curGame->getCurrentHand()->getBoard()->getMyCards(tmpCards);
|
||||
tmpCards[4] = static_cast<int>(cardsData.riverCard);
|
||||
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
||||
client.GetGui().dealRiverCard();
|
||||
}
|
||||
}
|
||||
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
|
||||
+277
-17
@@ -37,8 +37,12 @@ using namespace std;
|
||||
#define NET_TYPE_PLAYERS_ACTION 0x0008
|
||||
#define NET_TYPE_PLAYERS_ACTION_DONE 0x0009
|
||||
#define NET_TYPE_PLAYERS_ACTION_REJECTED 0x000A
|
||||
#define NET_TYPE_SEND_CHAT_TEXT 0x000B
|
||||
#define NET_TYPE_CHAT_TEXT 0x000C
|
||||
#define NET_TYPE_DEAL_FLOP_CARDS 0x000B
|
||||
#define NET_TYPE_DEAL_TURN_CARD 0x000C
|
||||
#define NET_TYPE_DEAL_RIVER_CARD 0x000D
|
||||
|
||||
#define NET_TYPE_SEND_CHAT_TEXT 0x0200
|
||||
#define NET_TYPE_CHAT_TEXT 0x0201
|
||||
|
||||
#define NET_TYPE_ERROR 0x0400
|
||||
|
||||
@@ -125,7 +129,8 @@ struct GCC_PACKED NetPacketGameStartData
|
||||
struct GCC_PACKED NetPacketHandStartData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int16_t yourCards[2];
|
||||
u_int16_t yourCard1;
|
||||
u_int16_t yourCard2;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketPlayersTurnData
|
||||
@@ -166,6 +171,29 @@ struct GCC_PACKED NetPacketPlayersActionRejectedData
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketDealFlopCardsData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int16_t flopCard1;
|
||||
u_int16_t flopCard2;
|
||||
u_int16_t flopCard3;
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketDealTurnCardData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int16_t turnCard;
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketDealRiverCardData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
u_int16_t riverCard;
|
||||
u_int16_t reserved;
|
||||
};
|
||||
|
||||
struct GCC_PACKED NetPacketSendChatTextData
|
||||
{
|
||||
NetPacketHeader head;
|
||||
@@ -244,6 +272,15 @@ NetPacket::Create(char *data, unsigned &dataSize)
|
||||
case NET_TYPE_PLAYERS_ACTION_REJECTED:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketPlayersActionRejected);
|
||||
break;
|
||||
case NET_TYPE_DEAL_FLOP_CARDS:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketDealFlopCards);
|
||||
break;
|
||||
case NET_TYPE_DEAL_TURN_CARD:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketDealTurnCard);
|
||||
break;
|
||||
case NET_TYPE_DEAL_RIVER_CARD:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketDealRiverCard);
|
||||
break;
|
||||
case NET_TYPE_SEND_CHAT_TEXT:
|
||||
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketSendChatText);
|
||||
break;
|
||||
@@ -394,6 +431,24 @@ NetPacket::ToNetPacketPlayersActionRejected() const
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketDealFlopCards *
|
||||
NetPacket::ToNetPacketDealFlopCards() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketDealTurnCard *
|
||||
NetPacket::ToNetPacketDealTurnCard() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketDealRiverCard *
|
||||
NetPacket::ToNetPacketDealRiverCard() const
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const NetPacketSendChatText *
|
||||
NetPacket::ToNetPacketSendChatText() const
|
||||
{
|
||||
@@ -623,7 +678,7 @@ NetPacketJoinGameAck::Check(const NetPacketHeader* data) const
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketJoinGameAckData))
|
||||
if (dataLen != sizeof(NetPacketJoinGameAckData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
@@ -784,7 +839,7 @@ NetPacketPlayerLeft::Check(const NetPacketHeader* data) const
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketPlayerLeftData))
|
||||
if (dataLen != sizeof(NetPacketPlayerLeftData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
@@ -845,7 +900,7 @@ NetPacketGameStart::Check(const NetPacketHeader* data) const
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketGameStartData))
|
||||
if (dataLen != sizeof(NetPacketGameStartData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
@@ -882,8 +937,8 @@ NetPacketHandStart::SetData(const NetPacketHandStart::Data &inData)
|
||||
NetPacketHandStartData *tmpData = (NetPacketHandStartData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
tmpData->yourCards[0] = htons(inData.yourCards[0]);
|
||||
tmpData->yourCards[1] = htons(inData.yourCards[1]);
|
||||
tmpData->yourCard1 = htons(inData.yourCards[0]);
|
||||
tmpData->yourCard2 = htons(inData.yourCards[1]);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -892,8 +947,8 @@ NetPacketHandStart::GetData(NetPacketHandStart::Data &outData) const
|
||||
NetPacketHandStartData *tmpData = (NetPacketHandStartData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
outData.yourCards[0] = ntohs(tmpData->yourCards[0]);
|
||||
outData.yourCards[1] = ntohs(tmpData->yourCards[1]);
|
||||
outData.yourCards[0] = ntohs(tmpData->yourCard1);
|
||||
outData.yourCards[1] = ntohs(tmpData->yourCard2);
|
||||
}
|
||||
|
||||
const NetPacketHandStart *
|
||||
@@ -908,13 +963,13 @@ NetPacketHandStart::Check(const NetPacketHeader* data) const
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketHandStartData))
|
||||
if (dataLen != sizeof(NetPacketHandStartData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
|
||||
NetPacketHandStartData *tmpData = (NetPacketHandStartData *)data;
|
||||
if (ntohs(tmpData->yourCards[0]) > 51 || ntohs(tmpData->yourCards[1]) > 51)
|
||||
if (ntohs(tmpData->yourCard1) > 51 || ntohs(tmpData->yourCard2) > 51)
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
@@ -977,7 +1032,7 @@ NetPacketPlayersTurn::Check(const NetPacketHeader* data) const
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketPlayersTurnData))
|
||||
if (dataLen != sizeof(NetPacketPlayersTurnData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
@@ -1049,7 +1104,7 @@ NetPacketPlayersAction::Check(const NetPacketHeader* data) const
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketPlayersActionData))
|
||||
if (dataLen != sizeof(NetPacketPlayersActionData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
@@ -1134,7 +1189,7 @@ NetPacketPlayersActionDone::Check(const NetPacketHeader* data) const
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketPlayersActionDoneData))
|
||||
if (dataLen != sizeof(NetPacketPlayersActionDoneData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
@@ -1212,7 +1267,7 @@ NetPacketPlayersActionRejected::Check(const NetPacketHeader* data) const
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketPlayersActionRejectedData))
|
||||
if (dataLen != sizeof(NetPacketPlayersActionRejectedData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
@@ -1233,6 +1288,211 @@ NetPacketPlayersActionRejected::Check(const NetPacketHeader* data) const
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketDealFlopCards::NetPacketDealFlopCards()
|
||||
: NetPacket(NET_TYPE_DEAL_FLOP_CARDS, sizeof(NetPacketDealFlopCardsData))
|
||||
{
|
||||
}
|
||||
|
||||
NetPacketDealFlopCards::~NetPacketDealFlopCards()
|
||||
{
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
NetPacketDealFlopCards::Clone() const
|
||||
{
|
||||
boost::shared_ptr<NetPacket> newPacket(new NetPacketDealFlopCards);
|
||||
try
|
||||
{
|
||||
newPacket->SetRawData(GetRawData());
|
||||
} catch (const NetException &)
|
||||
{
|
||||
// Need to return the new packet anyway.
|
||||
}
|
||||
return newPacket;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketDealFlopCards::SetData(const NetPacketDealFlopCards::Data &inData)
|
||||
{
|
||||
NetPacketDealFlopCardsData *tmpData = (NetPacketDealFlopCardsData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
tmpData->flopCard1 = htons(inData.flopCards[0]);
|
||||
tmpData->flopCard2 = htons(inData.flopCards[1]);
|
||||
tmpData->flopCard3 = htons(inData.flopCards[2]);
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketDealFlopCards::GetData(NetPacketDealFlopCards::Data &outData) const
|
||||
{
|
||||
NetPacketDealFlopCardsData *tmpData = (NetPacketDealFlopCardsData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
outData.flopCards[0] = ntohs(tmpData->flopCard1);
|
||||
outData.flopCards[1] = ntohs(tmpData->flopCard2);
|
||||
outData.flopCards[2] = ntohs(tmpData->flopCard3);
|
||||
}
|
||||
|
||||
const NetPacketDealFlopCards *
|
||||
NetPacketDealFlopCards::ToNetPacketDealFlopCards() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketDealFlopCards::Check(const NetPacketHeader* data) const
|
||||
{
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen != sizeof(NetPacketDealFlopCardsData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
|
||||
NetPacketDealFlopCardsData *tmpData = (NetPacketDealFlopCardsData *)data;
|
||||
if (ntohs(tmpData->flopCard1) > 51 || ntohs(tmpData->flopCard2) > 51 || ntohs(tmpData->flopCard3) > 51)
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketDealTurnCard::NetPacketDealTurnCard()
|
||||
: NetPacket(NET_TYPE_DEAL_TURN_CARD, sizeof(NetPacketDealTurnCardData))
|
||||
{
|
||||
}
|
||||
|
||||
NetPacketDealTurnCard::~NetPacketDealTurnCard()
|
||||
{
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
NetPacketDealTurnCard::Clone() const
|
||||
{
|
||||
boost::shared_ptr<NetPacket> newPacket(new NetPacketDealTurnCard);
|
||||
try
|
||||
{
|
||||
newPacket->SetRawData(GetRawData());
|
||||
} catch (const NetException &)
|
||||
{
|
||||
// Need to return the new packet anyway.
|
||||
}
|
||||
return newPacket;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketDealTurnCard::SetData(const NetPacketDealTurnCard::Data &inData)
|
||||
{
|
||||
NetPacketDealTurnCardData *tmpData = (NetPacketDealTurnCardData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
tmpData->turnCard = htons(inData.turnCard);
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketDealTurnCard::GetData(NetPacketDealTurnCard::Data &outData) const
|
||||
{
|
||||
NetPacketDealTurnCardData *tmpData = (NetPacketDealTurnCardData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
outData.turnCard = ntohs(tmpData->turnCard);
|
||||
}
|
||||
|
||||
const NetPacketDealTurnCard *
|
||||
NetPacketDealTurnCard::ToNetPacketDealTurnCard() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketDealTurnCard::Check(const NetPacketHeader* data) const
|
||||
{
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen != sizeof(NetPacketDealTurnCardData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
|
||||
NetPacketDealTurnCardData *tmpData = (NetPacketDealTurnCardData *)data;
|
||||
if (ntohs(tmpData->turnCard) > 51)
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketDealRiverCard::NetPacketDealRiverCard()
|
||||
: NetPacket(NET_TYPE_DEAL_RIVER_CARD, sizeof(NetPacketDealRiverCardData))
|
||||
{
|
||||
}
|
||||
|
||||
NetPacketDealRiverCard::~NetPacketDealRiverCard()
|
||||
{
|
||||
}
|
||||
|
||||
boost::shared_ptr<NetPacket>
|
||||
NetPacketDealRiverCard::Clone() const
|
||||
{
|
||||
boost::shared_ptr<NetPacket> newPacket(new NetPacketDealRiverCard);
|
||||
try
|
||||
{
|
||||
newPacket->SetRawData(GetRawData());
|
||||
} catch (const NetException &)
|
||||
{
|
||||
// Need to return the new packet anyway.
|
||||
}
|
||||
return newPacket;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketDealRiverCard::SetData(const NetPacketDealRiverCard::Data &inData)
|
||||
{
|
||||
NetPacketDealRiverCardData *tmpData = (NetPacketDealRiverCardData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
tmpData->riverCard = htons(inData.riverCard);
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketDealRiverCard::GetData(NetPacketDealRiverCard::Data &outData) const
|
||||
{
|
||||
NetPacketDealRiverCardData *tmpData = (NetPacketDealRiverCardData *)GetRawData();
|
||||
assert(tmpData);
|
||||
|
||||
outData.riverCard = ntohs(tmpData->riverCard);
|
||||
}
|
||||
|
||||
const NetPacketDealRiverCard *
|
||||
NetPacketDealRiverCard::ToNetPacketDealRiverCard() const
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
void
|
||||
NetPacketDealRiverCard::Check(const NetPacketHeader* data) const
|
||||
{
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen != sizeof(NetPacketDealRiverCardData))
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
|
||||
NetPacketDealRiverCardData *tmpData = (NetPacketDealRiverCardData *)data;
|
||||
if (ntohs(tmpData->riverCard) > 51)
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
NetPacketSendChatText::NetPacketSendChatText()
|
||||
: NetPacket(NET_TYPE_SEND_CHAT_TEXT, sizeof(NetPacketSendChatTextData))
|
||||
{
|
||||
@@ -1531,7 +1791,7 @@ NetPacketError::Check(const NetPacketHeader* data) const
|
||||
assert(data);
|
||||
|
||||
u_int16_t dataLen = ntohs(data->length);
|
||||
if (dataLen < sizeof(NetPacketErrorData))
|
||||
if (dataLen < sizeof(NetPacketErrorData)) // graceful size checking only for error packets
|
||||
{
|
||||
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
|
||||
}
|
||||
|
||||
@@ -414,10 +414,16 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
|
||||
curRound = newRound;
|
||||
GameRun(curGame, curRound);
|
||||
newRound = curGame.getCurrentHand()->getActualRound();
|
||||
|
||||
// If round changes, deal cards if needed.
|
||||
if (newRound != curRound)
|
||||
SendNewRoundCards(server, curGame);
|
||||
} while (newRound != curRound);
|
||||
|
||||
// Retrieve current player.
|
||||
PlayerInterface *curPlayer = GetCurrentPlayer(curGame);
|
||||
assert(curPlayer); // TODO throw exception
|
||||
assert(curPlayer->getMyActiveStatus()); // TODO throw exception
|
||||
|
||||
boost::shared_ptr<NetPacket> notification(new NetPacketPlayersTurn);
|
||||
NetPacketPlayersTurn::Data playersTurnData;
|
||||
@@ -481,10 +487,56 @@ ServerRecvStateStartRound::GetCurrentPlayer(Game &curGame)
|
||||
//
|
||||
}
|
||||
}
|
||||
assert(curPlayerNum < curGame.getActualQuantityPlayers());
|
||||
assert(curPlayerNum < curGame.getActualQuantityPlayers()); // TODO: throw exception
|
||||
return curGame.getPlayerArray()[curPlayerNum];
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateStartRound::SendNewRoundCards(ServerRecvThread &server, Game &curGame)
|
||||
{
|
||||
// TODO: no switch needed here if game states are polymorphic
|
||||
switch(curGame.getCurrentHand()->getActualRound()) {
|
||||
case GAME_STATE_PREFLOP: {
|
||||
// nothing to do
|
||||
} break;
|
||||
case GAME_STATE_FLOP: {
|
||||
// deal flop cards
|
||||
int cards[5];
|
||||
curGame.getCurrentHand()->getBoard()->getMyCards(cards);
|
||||
boost::shared_ptr<NetPacket> notifyCards(new NetPacketDealFlopCards);
|
||||
NetPacketDealFlopCards::Data notifyCardsData;
|
||||
notifyCardsData.flopCards[0] = static_cast<unsigned>(cards[0]);
|
||||
notifyCardsData.flopCards[1] = static_cast<unsigned>(cards[1]);
|
||||
notifyCardsData.flopCards[2] = static_cast<unsigned>(cards[2]);
|
||||
static_cast<NetPacketDealFlopCards *>(notifyCards.get())->SetData(notifyCardsData);
|
||||
server.SendToAllPlayers(notifyCards);
|
||||
} break;
|
||||
case GAME_STATE_TURN: {
|
||||
// deal turn card
|
||||
int cards[5];
|
||||
curGame.getCurrentHand()->getBoard()->getMyCards(cards);
|
||||
boost::shared_ptr<NetPacket> notifyCards(new NetPacketDealTurnCard);
|
||||
NetPacketDealTurnCard::Data notifyCardsData;
|
||||
notifyCardsData.turnCard = static_cast<unsigned>(cards[3]);
|
||||
static_cast<NetPacketDealTurnCard *>(notifyCards.get())->SetData(notifyCardsData);
|
||||
server.SendToAllPlayers(notifyCards);
|
||||
} break;
|
||||
case GAME_STATE_RIVER: {
|
||||
// deal river card
|
||||
int cards[5];
|
||||
curGame.getCurrentHand()->getBoard()->getMyCards(cards);
|
||||
boost::shared_ptr<NetPacket> notifyCards(new NetPacketDealRiverCard);
|
||||
NetPacketDealRiverCard::Data notifyCardsData;
|
||||
notifyCardsData.riverCard = static_cast<unsigned>(cards[4]);
|
||||
static_cast<NetPacketDealRiverCard *>(notifyCards.get())->SetData(notifyCardsData);
|
||||
server.SendToAllPlayers(notifyCards);
|
||||
} break;
|
||||
default: {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateWaitPlayerAction &
|
||||
|
||||
@@ -114,6 +114,10 @@ ServerThread::Listen()
|
||||
if (IOCTLSOCKET(context.GetSocket(), FIONBIO, &mode) == SOCKET_ERROR)
|
||||
throw ServerException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO());
|
||||
|
||||
// The following call is optional. If it fails, we don't care.
|
||||
int reuse = 1;
|
||||
setsockopt(context.GetSocket(), SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse));
|
||||
|
||||
context.GetServerSockaddr()->ss_family = context.GetAddrFamily();
|
||||
|
||||
const char *localAddr = (context.GetAddrFamily() == AF_INET6) ? "::0" : "0.0.0.0";
|
||||
|
||||
@@ -48,6 +48,9 @@ class NetPacketPlayersTurn;
|
||||
class NetPacketPlayersAction;
|
||||
class NetPacketPlayersActionDone;
|
||||
class NetPacketPlayersActionRejected;
|
||||
class NetPacketDealFlopCards;
|
||||
class NetPacketDealTurnCard;
|
||||
class NetPacketDealRiverCard;
|
||||
class NetPacketSendChatText;
|
||||
class NetPacketChatText;
|
||||
class NetPacketError;
|
||||
@@ -79,6 +82,9 @@ public:
|
||||
virtual const NetPacketPlayersAction *ToNetPacketPlayersAction() const;
|
||||
virtual const NetPacketPlayersActionDone *ToNetPacketPlayersActionDone() const;
|
||||
virtual const NetPacketPlayersActionRejected *ToNetPacketPlayersActionRejected() const;
|
||||
virtual const NetPacketDealFlopCards *ToNetPacketDealFlopCards() const;
|
||||
virtual const NetPacketDealTurnCard *ToNetPacketDealTurnCard() const;
|
||||
virtual const NetPacketDealRiverCard *ToNetPacketDealRiverCard() const;
|
||||
virtual const NetPacketSendChatText *ToNetPacketSendChatText() const;
|
||||
virtual const NetPacketChatText *ToNetPacketChatText() const;
|
||||
virtual const NetPacketError *ToNetPacketError() const;
|
||||
@@ -348,6 +354,75 @@ protected:
|
||||
virtual void Check(const NetPacketHeader* data) const;
|
||||
};
|
||||
|
||||
class NetPacketDealFlopCards : public NetPacket
|
||||
{
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
u_int16_t flopCards[3];
|
||||
};
|
||||
|
||||
NetPacketDealFlopCards();
|
||||
virtual ~NetPacketDealFlopCards();
|
||||
|
||||
virtual boost::shared_ptr<NetPacket> Clone() const;
|
||||
|
||||
void SetData(const Data &inData);
|
||||
void GetData(Data &outData) const;
|
||||
|
||||
virtual const NetPacketDealFlopCards *ToNetPacketDealFlopCards() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void Check(const NetPacketHeader* data) const;
|
||||
};
|
||||
|
||||
class NetPacketDealTurnCard : public NetPacket
|
||||
{
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
u_int16_t turnCard;
|
||||
};
|
||||
|
||||
NetPacketDealTurnCard();
|
||||
virtual ~NetPacketDealTurnCard();
|
||||
|
||||
virtual boost::shared_ptr<NetPacket> Clone() const;
|
||||
|
||||
void SetData(const Data &inData);
|
||||
void GetData(Data &outData) const;
|
||||
|
||||
virtual const NetPacketDealTurnCard *ToNetPacketDealTurnCard() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void Check(const NetPacketHeader* data) const;
|
||||
};
|
||||
|
||||
class NetPacketDealRiverCard : public NetPacket
|
||||
{
|
||||
public:
|
||||
struct Data
|
||||
{
|
||||
u_int16_t riverCard;
|
||||
};
|
||||
|
||||
NetPacketDealRiverCard();
|
||||
virtual ~NetPacketDealRiverCard();
|
||||
|
||||
virtual boost::shared_ptr<NetPacket> Clone() const;
|
||||
|
||||
void SetData(const Data &inData);
|
||||
void GetData(Data &outData) const;
|
||||
|
||||
virtual const NetPacketDealRiverCard *ToNetPacketDealRiverCard() const;
|
||||
|
||||
protected:
|
||||
|
||||
virtual void Check(const NetPacketHeader* data) const;
|
||||
};
|
||||
|
||||
class NetPacketSendChatText : public NetPacket
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -153,6 +153,7 @@ protected:
|
||||
|
||||
static void GameRun(Game &curGame, int state);
|
||||
static PlayerInterface *GetCurrentPlayer(Game &curGame);
|
||||
static void SendNewRoundCards(ServerRecvThread &server, Game &curGame);
|
||||
};
|
||||
|
||||
// State: Wait for a player action.
|
||||
|
||||
Reference in New Issue
Block a user