Networking should mostly be working now. Some small issues concerning the display of pot/sets, and some delays are still needed.

This commit is contained in:
lotodore
2007-05-26 17:06:03 +00:00
parent 9c2d3a9723
commit 5cb5509dec
29 changed files with 901 additions and 295 deletions
+75 -20
View File
@@ -540,7 +540,7 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptr<Net
client.GetGui().dealHoleCards();
client.SetState(ClientStateRunHand::Instance());
retVal = MSG_NET_GAME_CLIENT_HAND;
retVal = MSG_NET_GAME_CLIENT_HAND_START;
}
return MSG_SOCK_INTERNAL_PENDING;
@@ -566,6 +566,7 @@ ClientStateRunHand::~ClientStateRunHand()
int
ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetPacket> packet)
{
int retVal = MSG_SOCK_INTERNAL_PENDING;
ClientContext &context = client.GetContext();
if (packet.get())
@@ -601,6 +602,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
client.GetGui().refreshSet();
client.GetGui().refreshAction();
client.GetGui().refreshCash();
client.GetGui().refreshButton();
}
else if (packet->ToNetPacketPlayersTurn())
{
@@ -612,21 +614,21 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
// Set round.
if (curGame->getCurrentHand()->getActualRound() != turnData.gameState)
{
// Reset player actions
for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++)
{
int action = curGame->getPlayerArray()[i]->getMyAction();
if (action != 1 && action != 6)
curGame->getPlayerArray()[i]->setMyAction(0);
}
// Move sets to pot
curGame->getCurrentHand()->getBoard()->collectSets();
curGame->getCurrentHand()->getBoard()->collectPot();
client.GetGui().refreshPot();
client.GetGui().refreshSet();
client.GetGui().refreshAction();
client.GetGui().refreshCash();
// Reset player actions
for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++)
{
int action = curGame->getPlayerArray()[i]->getMyAction();
if (action != 1 && action != 6)
curGame->getPlayerArray()[i]->setMyAction(0);
}
// Move sets to pot
curGame->getCurrentHand()->getBoard()->collectSets();
curGame->getCurrentHand()->getBoard()->collectPot();
client.GetGui().refreshPot();
client.GetGui().refreshSet();
client.GetGui().refreshAction();
client.GetGui().refreshCash();
curGame->getCurrentHand()->setActualRound(turnData.gameState);
}
@@ -650,9 +652,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
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]);
for (int num = 0; num < 3; num++)
tmpCards[num] = static_cast<int>(cardsData.flopCards[num]);
tmpCards[3] = tmpCards[4] = 0;
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
client.GetGui().dealFlopCards();
@@ -677,9 +678,63 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
client.GetGui().dealRiverCard();
}
else if (packet->ToNetPacketEndOfHandHideCards())
{
// End of Hand, but keep cards hidden.
NetPacketEndOfHandHideCards::Data endHandData;
packet->ToNetPacketEndOfHandHideCards()->GetData(endHandData);
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(endHandData.playerId);
assert(tmpPlayer); // TODO: throw exception
tmpPlayer->setMyCash(endHandData.playerMoney);
// TODO use moneyWon
client.GetGui().postRiverRunAnimation1();
// Wait for next Hand.
client.SetState(ClientStateWaitHand::Instance());
retVal = MSG_NET_GAME_SERVER_HAND_END;
}
else if (packet->ToNetPacketEndOfHandShowCards())
{
// End of Hand, show cards.
NetPacketEndOfHandShowCards::Data endHandData;
packet->ToNetPacketEndOfHandShowCards()->GetData(endHandData);
NetPacketEndOfHandShowCards::PlayerResultList::const_iterator i
= endHandData.playerResults.begin();
NetPacketEndOfHandShowCards::PlayerResultList::const_iterator end
= endHandData.playerResults.end();
int highestValueOfCards = 0;
while (i != end)
{
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId((*i).playerId);
assert(tmpPlayer); // TODO: throw exception
int tmpCards[2];
tmpCards[0] = static_cast<int>((*i).cards[0]);
tmpCards[1] = static_cast<int>((*i).cards[1]);
tmpPlayer->setMyCards(tmpCards);
for (int num = 0; num < 5; num++)
tmpPlayer->getMyBestHandPosition()[num] = (*i).bestHandPos[num];
tmpPlayer->setMyCardsValueInt((*i).valueOfCards);
if (tmpPlayer->getMyCardsValueInt() > highestValueOfCards)
highestValueOfCards = tmpPlayer->getMyCardsValueInt();
tmpPlayer->setMyCash((*i).playerMoney);
// TODO use moneyWon
++i;
}
client.GetGame()->getCurrentHand()->getRiver()->setHighestCardsValue(highestValueOfCards);
client.GetGui().postRiverRunAnimation1();
// Wait for next Hand.
client.SetState(ClientStateWaitHand::Instance());
retVal = MSG_NET_GAME_SERVER_HAND_END;
}
}
return MSG_SOCK_INTERNAL_PENDING;
return retVal;
}
+244
View File
@@ -40,6 +40,8 @@ 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_SEND_CHAT_TEXT 0x0200
#define NET_TYPE_CHAT_TEXT 0x0201
@@ -194,6 +196,37 @@ struct GCC_PACKED NetPacketDealRiverCardData
u_int16_t reserved;
};
struct GCC_PACKED NetPacketEndOfHandShowCardsData
{
NetPacketHeader head;
u_int16_t numberOfPlayerResults;
u_int16_t reserved;
};
struct GCC_PACKED PlayerResultData
{
u_int16_t playerId;
u_int16_t card1;
u_int16_t card2;
u_int16_t bestHandPos1;
u_int16_t bestHandPos2;
u_int16_t bestHandPos3;
u_int16_t bestHandPos4;
u_int16_t bestHandPos5;
u_int32_t valueOfCards;
u_int32_t moneyWon;
u_int32_t playerMoney;
};
struct GCC_PACKED NetPacketEndOfHandHideCardsData
{
NetPacketHeader head;
u_int16_t playerId;
u_int16_t reserved;
u_int32_t moneyWon;
u_int32_t playerMoney;
};
struct GCC_PACKED NetPacketSendChatTextData
{
NetPacketHeader head;
@@ -281,6 +314,12 @@ NetPacket::Create(char *data, unsigned &dataSize)
case NET_TYPE_DEAL_RIVER_CARD:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketDealRiverCard);
break;
case NET_TYPE_END_OF_HAND_SHOW_CARDS:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketEndOfHandShowCards);
break;
case NET_TYPE_END_OF_HAND_HIDE_CARDS:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketEndOfHandHideCards);
break;
case NET_TYPE_SEND_CHAT_TEXT:
tmpPacket = boost::shared_ptr<NetPacket>(new NetPacketSendChatText);
break;
@@ -449,6 +488,18 @@ NetPacket::ToNetPacketDealRiverCard() const
return NULL;
}
const NetPacketEndOfHandShowCards *
NetPacket::ToNetPacketEndOfHandShowCards() const
{
return NULL;
}
const NetPacketEndOfHandHideCards *
NetPacket::ToNetPacketEndOfHandHideCards() const
{
return NULL;
}
const NetPacketSendChatText *
NetPacket::ToNetPacketSendChatText() const
{
@@ -1493,6 +1544,199 @@ NetPacketDealRiverCard::Check(const NetPacketHeader* data) const
//-----------------------------------------------------------------------------
NetPacketEndOfHandShowCards::NetPacketEndOfHandShowCards()
: NetPacket(NET_TYPE_END_OF_HAND_SHOW_CARDS, sizeof(NetPacketEndOfHandShowCardsData))
{
}
NetPacketEndOfHandShowCards::~NetPacketEndOfHandShowCards()
{
}
boost::shared_ptr<NetPacket>
NetPacketEndOfHandShowCards::Clone() const
{
boost::shared_ptr<NetPacket> newPacket(new NetPacketEndOfHandShowCards);
try
{
newPacket->SetRawData(GetRawData());
} catch (const NetException &)
{
// Need to return the new packet anyway.
}
return newPacket;
}
void
NetPacketEndOfHandShowCards::SetData(const NetPacketEndOfHandShowCards::Data &inData)
{
u_int16_t numPlayerResults = (u_int16_t)inData.playerResults.size();
if (!numPlayerResults || numPlayerResults > MAX_NUM_PLAYER_RESULTS)
throw NetException(ERR_NET_INVALID_PLAYER_RESULTS, 0);
// Resize the packet so that the data fits in.
Resize((u_int16_t)
(sizeof(NetPacketEndOfHandShowCardsData) + numPlayerResults * sizeof(PlayerResultData)));
NetPacketEndOfHandShowCardsData *tmpData = (NetPacketEndOfHandShowCardsData *)GetRawData();
assert(tmpData);
tmpData->numberOfPlayerResults = htons(numPlayerResults);
PlayerResultList::const_iterator i = inData.playerResults.begin();
PlayerResultList::const_iterator end = inData.playerResults.end();
// Copy the player result data to continous memory
PlayerResultData *curPlayerResultData =
(PlayerResultData *)((char *)tmpData + sizeof(NetPacketEndOfHandShowCardsData));
while (i != end)
{
curPlayerResultData->playerId = htons((*i).playerId);
curPlayerResultData->card1 = htons((*i).cards[0]);
curPlayerResultData->card2 = htons((*i).cards[1]);
curPlayerResultData->bestHandPos1 = htons((*i).bestHandPos[0]);
curPlayerResultData->bestHandPos2 = htons((*i).bestHandPos[1]);
curPlayerResultData->bestHandPos3 = htons((*i).bestHandPos[2]);
curPlayerResultData->bestHandPos4 = htons((*i).bestHandPos[3]);
curPlayerResultData->bestHandPos5 = htons((*i).bestHandPos[4]);
curPlayerResultData->valueOfCards = htonl((*i).valueOfCards);
curPlayerResultData->moneyWon = htonl((*i).moneyWon);
curPlayerResultData->playerMoney = htonl((*i).playerMoney);
++curPlayerResultData;
++i;
}
}
void
NetPacketEndOfHandShowCards::GetData(NetPacketEndOfHandShowCards::Data &outData) const
{
NetPacketEndOfHandShowCardsData *tmpData = (NetPacketEndOfHandShowCardsData *)GetRawData();
assert(tmpData);
outData.playerResults.clear();
u_int16_t numPlayerResults = ntohs(tmpData->numberOfPlayerResults);
PlayerResultData *curPlayerResultData =
(PlayerResultData *)((char *)tmpData + sizeof(NetPacketEndOfHandShowCardsData));
// Store all available player results.
for (int i = 0; i < numPlayerResults; i++)
{
PlayerResult tmpPlayerResult;
tmpPlayerResult.playerId = ntohs(curPlayerResultData->playerId);
tmpPlayerResult.cards[0] = ntohs(curPlayerResultData->card1);
tmpPlayerResult.cards[1] = ntohs(curPlayerResultData->card2);
tmpPlayerResult.bestHandPos[0] = ntohs(curPlayerResultData->bestHandPos1);
tmpPlayerResult.bestHandPos[1] = ntohs(curPlayerResultData->bestHandPos2);
tmpPlayerResult.bestHandPos[2] = ntohs(curPlayerResultData->bestHandPos3);
tmpPlayerResult.bestHandPos[3] = ntohs(curPlayerResultData->bestHandPos4);
tmpPlayerResult.bestHandPos[4] = ntohs(curPlayerResultData->bestHandPos5);
tmpPlayerResult.valueOfCards = ntohl(curPlayerResultData->valueOfCards);
tmpPlayerResult.moneyWon = ntohl(curPlayerResultData->moneyWon);
tmpPlayerResult.playerMoney = ntohl(curPlayerResultData->playerMoney);
outData.playerResults.push_back(tmpPlayerResult);
++curPlayerResultData;
}
}
const NetPacketEndOfHandShowCards *
NetPacketEndOfHandShowCards::ToNetPacketEndOfHandShowCards() const
{
return this;
}
void
NetPacketEndOfHandShowCards::Check(const NetPacketHeader* data) const
{
assert(data);
u_int16_t dataLen = ntohs(data->length);
if (dataLen < sizeof(NetPacketEndOfHandShowCardsData))
{
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
}
NetPacketEndOfHandShowCardsData *tmpData = (NetPacketEndOfHandShowCardsData *)data;
int numPlayerResults = ntohs(tmpData->numberOfPlayerResults);
if (dataLen !=
sizeof(NetPacketEndOfHandShowCardsData)
+ numPlayerResults * sizeof(PlayerResultData))
{
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
}
// TODO: semantic checks within PlayerResultData
}
//-----------------------------------------------------------------------------
NetPacketEndOfHandHideCards::NetPacketEndOfHandHideCards()
: NetPacket(NET_TYPE_END_OF_HAND_HIDE_CARDS, sizeof(NetPacketEndOfHandHideCardsData))
{
}
NetPacketEndOfHandHideCards::~NetPacketEndOfHandHideCards()
{
}
boost::shared_ptr<NetPacket>
NetPacketEndOfHandHideCards::Clone() const
{
boost::shared_ptr<NetPacket> newPacket(new NetPacketEndOfHandHideCards);
try
{
newPacket->SetRawData(GetRawData());
} catch (const NetException &)
{
// Need to return the new packet anyway.
}
return newPacket;
}
void
NetPacketEndOfHandHideCards::SetData(const NetPacketEndOfHandHideCards::Data &inData)
{
NetPacketEndOfHandHideCardsData *tmpData = (NetPacketEndOfHandHideCardsData *)GetRawData();
assert(tmpData);
tmpData->playerId = htons(inData.playerId);
tmpData->moneyWon = htonl(inData.moneyWon);
tmpData->playerMoney = htonl(inData.playerMoney);
}
void
NetPacketEndOfHandHideCards::GetData(NetPacketEndOfHandHideCards::Data &outData) const
{
NetPacketEndOfHandHideCardsData *tmpData = (NetPacketEndOfHandHideCardsData *)GetRawData();
assert(tmpData);
outData.playerId = ntohs(tmpData->playerId);
outData.moneyWon = ntohl(tmpData->moneyWon);
outData.playerMoney = ntohl(tmpData->playerMoney);
}
const NetPacketEndOfHandHideCards *
NetPacketEndOfHandHideCards::ToNetPacketEndOfHandHideCards() const
{
return this;
}
void
NetPacketEndOfHandHideCards::Check(const NetPacketHeader* data) const
{
assert(data);
u_int16_t dataLen = ntohs(data->length);
if (dataLen != sizeof(NetPacketEndOfHandHideCardsData))
{
throw NetException(ERR_SOCK_INVALID_PACKET, 0);
}
}
//-----------------------------------------------------------------------------
NetPacketSendChatText::NetPacketSendChatText()
: NetPacket(NET_TYPE_SEND_CHAT_TEXT, sizeof(NetPacketSendChatTextData))
{
+155 -26
View File
@@ -33,6 +33,7 @@
using namespace std;
#define SERVER_WAIT_TIMEOUT_MSEC 50
#define SERVER_NEXT_HAND_DELAY_SEC 5
ServerRecvState::~ServerRecvState()
@@ -319,6 +320,11 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
Game &curGame = server.GetGame();
curGame.initHand();
// HACK: Skip GUI notification run
curGame.getCurrentHand()->getFlop()->resetFirstRun();
curGame.getCurrentHand()->getTurn()->resetFirstRun();
curGame.getCurrentHand()->getRiver()->resetFirstRun();
PlayerInterface **playerArray = curGame.getPlayerArray();
// Send cards to all players.
@@ -380,7 +386,7 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
server.SetState(ServerRecvStateStartRound::Instance());
return MSG_NET_GAME_SERVER_HAND;
return MSG_NET_GAME_SERVER_HAND_START;
}
//-----------------------------------------------------------------------------
@@ -403,51 +409,142 @@ ServerRecvStateStartRound::~ServerRecvStateStartRound()
int
ServerRecvStateStartRound::Process(ServerRecvThread &server)
{
int retVal = MSG_SOCK_INTERNAL_PENDING;
Game &curGame = server.GetGame();
curGame.getCurrentHand()->switchRounds();
// Call main loop - if state changes, call again.
int newRound = curGame.getCurrentHand()->getActualRound();
int curRound;
do
{
curRound = newRound;
GameRun(curGame, curRound);
curGame.getCurrentHand()->switchRounds();
if (!curGame.getCurrentHand()->getAllInCondition())
GameRun(curGame);
newRound = curGame.getCurrentHand()->getActualRound();
// If round changes, deal cards if needed.
if (newRound != curRound)
{
// HACK: Skip GUI notification run
GameRun(curGame, newRound);
SendNewRoundCards(server, curGame);
assert(newRound > curRound);
SendNewRoundCards(server, curGame, newRound);
}
} while (newRound != curRound);
// Retrieve current player.
PlayerInterface *curPlayer = GetCurrentPlayer(curGame);
assert(curPlayer); // TODO throw exception
assert(curPlayer->getMyActiveStatus()); // TODO throw exception
if (newRound != GAME_STATE_POST_RIVER) // continue hand
{
if (!curGame.getCurrentHand()->getAllInCondition())
{
// 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;
playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getActualRound();
playersTurnData.playerId = curPlayer->getMyUniqueID();
static_cast<NetPacketPlayersTurn *>(notification.get())->SetData(playersTurnData);
boost::shared_ptr<NetPacket> notification(new NetPacketPlayersTurn);
NetPacketPlayersTurn::Data playersTurnData;
playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getActualRound();
playersTurnData.playerId = curPlayer->getMyUniqueID();
static_cast<NetPacketPlayersTurn *>(notification.get())->SetData(playersTurnData);
server.SendToAllPlayers(notification);
server.SendToAllPlayers(notification);
server.SetState(ServerRecvStateWaitPlayerAction::Instance());
server.SetState(ServerRecvStateWaitPlayerAction::Instance());
return MSG_NET_GAME_SERVER_ROUND;
retVal = MSG_NET_GAME_SERVER_ROUND;
}
}
else // hand is over
{
// Let the engine find out the winner(s).
curGame.getCurrentHand()->getRiver()->postRiverRun();
// Count active players. If only one player is left, no cards are shown.
int activePlayersCounter = 0;
std::list<PlayerInterface *> activePlayers;
for (int i = 0; i < curGame.getActualQuantityPlayers() ; i++)
{
if (curGame.getPlayerArray()[i]->getMyActiveStatus()
&& curGame.getPlayerArray()[i]->getMyAction() != PLAYER_ACTION_FOLD)
{
activePlayersCounter++;
activePlayers.push_back(curGame.getPlayerArray()[i]);
}
}
assert(activePlayersCounter);
assert(!activePlayers.empty());
if (activePlayersCounter == 1)
{
// End of Hand, but keep cards hidden.
PlayerInterface *player = activePlayers.front();
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandHideCards);
NetPacketEndOfHandHideCards::Data endHandData;
endHandData.playerId = player->getMyUniqueID();
endHandData.moneyWon = 0; // TODO
endHandData.playerMoney = player->getMyCash();
static_cast<NetPacketEndOfHandHideCards *>(endHand.get())->SetData(endHandData);
server.SendToAllPlayers(endHand);
}
else
{
// End of Hand - show cards of active players.
boost::shared_ptr<NetPacket> endHand(new NetPacketEndOfHandShowCards);
NetPacketEndOfHandShowCards::Data endHandData;
std::list<PlayerInterface *>::iterator i = activePlayers.begin();
std::list<PlayerInterface *>::iterator end = activePlayers.end();
while (i != end)
{
NetPacketEndOfHandShowCards::PlayerResult tmpPlayerResult;
tmpPlayerResult.playerId = (*i)->getMyUniqueID();
int tmpCards[2];
(*i)->getMyCards(tmpCards);
tmpPlayerResult.cards[0] = static_cast<u_int16_t>(tmpCards[0]);
tmpPlayerResult.cards[1] = static_cast<u_int16_t>(tmpCards[1]);
for (int num = 0; num < 5; num++)
tmpPlayerResult.bestHandPos[num] = (*i)->getMyBestHandPosition()[num];
tmpPlayerResult.valueOfCards = (*i)->getMyCardsValueInt();
tmpPlayerResult.moneyWon = 0; // TODO
tmpPlayerResult.playerMoney = (*i)->getMyCash();
endHandData.playerResults.push_back(tmpPlayerResult);
++i;
}
static_cast<NetPacketEndOfHandShowCards *>(endHand.get())->SetData(endHandData);
server.SendToAllPlayers(endHand);
}
// Start next hand - if enough players are left.
int playersPositiveCashCounter = 0;
for (int i = 0; i < curGame.getStartQuantityPlayers(); i++)
{
if (curGame.getCurrentHand()->getPlayerArray()[i]->getMyCash() > 0)
playersPositiveCashCounter++;
}
if (playersPositiveCashCounter == 1)
server.SetState(ServerRecvStateFinal::Instance()); // TODO
else
{
boost::microsec_timer delayTimer;
delayTimer.start();
ServerRecvStateNextHand::Instance().SetTimer(delayTimer);
server.SetState(ServerRecvStateNextHand::Instance());
retVal = MSG_NET_GAME_SERVER_HAND_END;
}
}
return retVal;
}
void
ServerRecvStateStartRound::GameRun(Game &curGame, int state)
ServerRecvStateStartRound::GameRun(Game &curGame)
{
// TODO: no switch needed here if game states are polymorphic
switch(state) {
switch(curGame.getCurrentHand()->getActualRound()) {
case GAME_STATE_PREFLOP: {
// Preflop starten
curGame.getCurrentHand()->getPreflop()->preflopRun();
@@ -497,10 +594,10 @@ ServerRecvStateStartRound::GetCurrentPlayer(Game &curGame)
}
void
ServerRecvStateStartRound::SendNewRoundCards(ServerRecvThread &server, Game &curGame)
ServerRecvStateStartRound::SendNewRoundCards(ServerRecvThread &server, Game &curGame, int state)
{
// TODO: no switch needed here if game states are polymorphic
switch(curGame.getCurrentHand()->getActualRound()) {
switch(state) {
case GAME_STATE_PREFLOP: {
// nothing to do
} break;
@@ -510,9 +607,8 @@ ServerRecvStateStartRound::SendNewRoundCards(ServerRecvThread &server, Game &cur
curGame.getCurrentHand()->getBoard()->getMyCards(cards);
boost::shared_ptr<NetPacket> notifyCards(new NetPacketDealFlopCards);
NetPacketDealFlopCards::Data notifyCardsData;
notifyCardsData.flopCards[0] = static_cast<u_int16_t>(cards[0]);
notifyCardsData.flopCards[1] = static_cast<u_int16_t>(cards[1]);
notifyCardsData.flopCards[2] = static_cast<u_int16_t>(cards[2]);
for (int num = 0; num < 3; num++)
notifyCardsData.flopCards[num] = static_cast<u_int16_t>(cards[num]);
static_cast<NetPacketDealFlopCards *>(notifyCards.get())->SetData(notifyCardsData);
server.SendToAllPlayers(notifyCards);
} break;
@@ -658,6 +754,39 @@ ServerRecvStateWaitPlayerAction::SetHighestSet(Game &curGame, int highestSet)
//-----------------------------------------------------------------------------
ServerRecvStateNextHand &
ServerRecvStateNextHand::Instance()
{
static ServerRecvStateNextHand state;
return state;
}
ServerRecvStateNextHand::ServerRecvStateNextHand()
{
}
ServerRecvStateNextHand::~ServerRecvStateNextHand()
{
}
void
ServerRecvStateNextHand::SetTimer(const boost::microsec_timer &timer)
{
m_delayTimer = timer;
}
int
ServerRecvStateNextHand::Process(ServerRecvThread &server)
{
if (m_delayTimer.elapsed().seconds() >= SERVER_NEXT_HAND_DELAY_SEC)
server.SetState(ServerRecvStateStartHand::Instance());
Thread::Msleep(10);
return MSG_SOCK_INTERNAL_PENDING;
}
//-----------------------------------------------------------------------------
ServerRecvStateFinal &
ServerRecvStateFinal::Instance()
{
+65
View File
@@ -34,6 +34,7 @@
#define MAX_NAME_SIZE 64
#define MAX_PASSWORD_SIZE 64
#define MAX_CHAT_TEXT_SIZE 128
#define MAX_NUM_PLAYER_RESULTS MAX_NUMBER_OF_PLAYERS
struct NetPacketHeader;
@@ -51,6 +52,8 @@ class NetPacketPlayersActionRejected;
class NetPacketDealFlopCards;
class NetPacketDealTurnCard;
class NetPacketDealRiverCard;
class NetPacketEndOfHandShowCards;
class NetPacketEndOfHandHideCards;
class NetPacketSendChatText;
class NetPacketChatText;
class NetPacketError;
@@ -85,6 +88,8 @@ public:
virtual const NetPacketDealFlopCards *ToNetPacketDealFlopCards() const;
virtual const NetPacketDealTurnCard *ToNetPacketDealTurnCard() const;
virtual const NetPacketDealRiverCard *ToNetPacketDealRiverCard() const;
virtual const NetPacketEndOfHandShowCards *ToNetPacketEndOfHandShowCards() const;
virtual const NetPacketEndOfHandHideCards *ToNetPacketEndOfHandHideCards() const;
virtual const NetPacketSendChatText *ToNetPacketSendChatText() const;
virtual const NetPacketChatText *ToNetPacketChatText() const;
virtual const NetPacketError *ToNetPacketError() const;
@@ -423,6 +428,66 @@ protected:
virtual void Check(const NetPacketHeader* data) const;
};
class NetPacketEndOfHandShowCards : public NetPacket
{
public:
struct PlayerResult
{
u_int16_t playerId;
u_int16_t cards[2];
u_int16_t bestHandPos[5];
u_int32_t valueOfCards;
u_int32_t moneyWon;
u_int32_t playerMoney;
};
typedef std::list<PlayerResult> PlayerResultList;
struct Data
{
PlayerResultList playerResults;
};
NetPacketEndOfHandShowCards();
virtual ~NetPacketEndOfHandShowCards();
virtual boost::shared_ptr<NetPacket> Clone() const;
void SetData(const Data &inData);
void GetData(Data &outData) const;
virtual const NetPacketEndOfHandShowCards *ToNetPacketEndOfHandShowCards() const;
protected:
virtual void Check(const NetPacketHeader* data) const;
};
class NetPacketEndOfHandHideCards : public NetPacket
{
public:
struct Data
{
u_int16_t playerId;
u_int32_t moneyWon;
u_int32_t playerMoney;
};
NetPacketEndOfHandHideCards();
virtual ~NetPacketEndOfHandHideCards();
virtual boost::shared_ptr<NetPacket> Clone() const;
void SetData(const Data &inData);
void GetData(Data &outData) const;
virtual const NetPacketEndOfHandHideCards *ToNetPacketEndOfHandHideCards() const;
protected:
virtual void Check(const NetPacketHeader* data) const;
};
class NetPacketSendChatText : public NetPacket
{
public:
+27 -3
View File
@@ -81,7 +81,7 @@ protected:
private:
unsigned m_curUniquePlayerId;
u_int16_t m_curUniquePlayerId;
};
// Abstract State: Game is running.
@@ -151,9 +151,9 @@ protected:
// Protected constructor - this is a singleton.
ServerRecvStateStartRound();
static void GameRun(Game &curGame, int state);
static void GameRun(Game &curGame);
static PlayerInterface *GetCurrentPlayer(Game &curGame);
static void SendNewRoundCards(ServerRecvThread &server, Game &curGame);
static void SendNewRoundCards(ServerRecvThread &server, Game &curGame, int state);
};
// State: Wait for a player action.
@@ -178,6 +178,30 @@ protected:
static void SetHighestSet(Game &curGame, int highestSet);
};
// State: Final.
class ServerRecvStateNextHand : public ServerRecvStateRunning
{
public:
// Access the state singleton.
static ServerRecvStateNextHand &Instance();
virtual ~ServerRecvStateNextHand();
void SetTimer(const boost::microsec_timer &timer);
//
virtual int Process(ServerRecvThread &server);
protected:
// Protected constructor - this is a singleton.
ServerRecvStateNextHand();
private:
boost::microsec_timer m_delayTimer;
};
// State: Final.
class ServerRecvStateFinal : public ServerRecvStateRunning
+1
View File
@@ -169,6 +169,7 @@ friend class ServerRecvStateStartGame;
friend class ServerRecvStateStartHand;
friend class ServerRecvStateStartRound;
friend class ServerRecvStateWaitPlayerAction;
friend class ServerRecvStateNextHand;
};
#endif
+7 -4
View File
@@ -48,7 +48,8 @@
#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_CHAT_TEXT 108
#define ERR_NET_INVALID_PLAYER_RESULTS 108
#define ERR_NET_INVALID_CHAT_TEXT 109
// This is an internal message which is not reported.
#define MSG_SOCK_INTERNAL_PENDING 0
@@ -65,9 +66,11 @@
// The following messages are game messages.
#define MSG_NET_GAME_CLIENT_START 5
#define MSG_NET_GAME_SERVER_START 6
#define MSG_NET_GAME_CLIENT_HAND 7
#define MSG_NET_GAME_SERVER_HAND 8
#define MSG_NET_GAME_SERVER_ROUND 10
#define MSG_NET_GAME_CLIENT_HAND_START 7
#define MSG_NET_GAME_CLIENT_HAND_END 8
#define MSG_NET_GAME_SERVER_HAND_START 9
#define MSG_NET_GAME_SERVER_HAND_END 10
#define MSG_NET_GAME_SERVER_ROUND 11
#define MSG_NET_GAME_SERVER_ACTION 12
#endif