Delay after showing cards when all in condition is true. Added option TCP_NODELAY. Round is now shown before dealing cards.
This commit is contained in:
@@ -355,7 +355,7 @@ void LocalHand::switchRounds() {
|
|||||||
//unhighlight actual players groupbox
|
//unhighlight actual players groupbox
|
||||||
if(playerArray[lastPlayersTurn]->getMyActiveStatus() == 1) myGui->refreshGroupbox(lastPlayersTurn,1);
|
if(playerArray[lastPlayersTurn]->getMyActiveStatus() == 1) myGui->refreshGroupbox(lastPlayersTurn,1);
|
||||||
|
|
||||||
myGui->refreshGameLabels();
|
myGui->refreshGameLabels((GameState)getActualRound());
|
||||||
// /*/*/*/*cout <<*/*/*/*/ "NextPlayerSpeed1 stop" << endl;
|
// /*/*/*/*cout <<*/*/*/*/ "NextPlayerSpeed1 stop" << endl;
|
||||||
//
|
//
|
||||||
// cout << "NextPlayerSpeed2 start" << endl;
|
// cout << "NextPlayerSpeed2 start" << endl;
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ void ServerGuiWrapper::refreshPot() const {}
|
|||||||
void ServerGuiWrapper::refreshGroupbox(int playerID, int status) const {}
|
void ServerGuiWrapper::refreshGroupbox(int playerID, int status) const {}
|
||||||
void ServerGuiWrapper::refreshPlayerName() const {}
|
void ServerGuiWrapper::refreshPlayerName() const {}
|
||||||
void ServerGuiWrapper::refreshButton() const {}
|
void ServerGuiWrapper::refreshButton() const {}
|
||||||
void ServerGuiWrapper::refreshGameLabels() const {}
|
void ServerGuiWrapper::refreshGameLabels(GameState state) const {}
|
||||||
|
|
||||||
void ServerGuiWrapper::dealHoleCards() {}
|
void ServerGuiWrapper::dealHoleCards() {}
|
||||||
void ServerGuiWrapper::dealFlopCards() {}
|
void ServerGuiWrapper::dealFlopCards() {}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
void refreshAll() const;
|
void refreshAll() const;
|
||||||
void refreshPlayerName() const;
|
void refreshPlayerName() const;
|
||||||
void refreshButton() const;
|
void refreshButton() const;
|
||||||
void refreshGameLabels() const;
|
void refreshGameLabels(GameState state) const;
|
||||||
|
|
||||||
void dealHoleCards();
|
void dealHoleCards();
|
||||||
void dealFlopCards();
|
void dealFlopCards();
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public:
|
|||||||
virtual void refreshAll() const=0;
|
virtual void refreshAll() const=0;
|
||||||
virtual void refreshPlayerName() const=0;
|
virtual void refreshPlayerName() const=0;
|
||||||
virtual void refreshButton() const =0;
|
virtual void refreshButton() const =0;
|
||||||
virtual void refreshGameLabels() const=0;
|
virtual void refreshGameLabels(GameState state) const=0;
|
||||||
|
|
||||||
// // Karten-Funktionen
|
// // Karten-Funktionen
|
||||||
virtual void dealHoleCards()=0;
|
virtual void dealHoleCards()=0;
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ void GuiWrapper::refreshPot() const { myW->signalRefreshPot(); }
|
|||||||
void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->signalRefreshGroupbox(playerID, status); }
|
void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->signalRefreshGroupbox(playerID, status); }
|
||||||
void GuiWrapper::refreshPlayerName() const { myW->signalRefreshPlayerName(); }
|
void GuiWrapper::refreshPlayerName() const { myW->signalRefreshPlayerName(); }
|
||||||
void GuiWrapper::refreshButton() const { myW->signalRefreshButton(); }
|
void GuiWrapper::refreshButton() const { myW->signalRefreshButton(); }
|
||||||
void GuiWrapper::refreshGameLabels() const { myW->signalRefreshGameLabels(); }
|
void GuiWrapper::refreshGameLabels(GameState state) const { myW->signalRefreshGameLabels(state); }
|
||||||
|
|
||||||
void GuiWrapper::dealHoleCards() { myW->signalDealHoleCards(); }
|
void GuiWrapper::dealHoleCards() { myW->signalDealHoleCards(); }
|
||||||
void GuiWrapper::dealFlopCards() { myW->signalDealFlopCards0(); }
|
void GuiWrapper::dealFlopCards() { myW->signalDealFlopCards0(); }
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public:
|
|||||||
void refreshAll() const;
|
void refreshAll() const;
|
||||||
void refreshPlayerName() const;
|
void refreshPlayerName() const;
|
||||||
void refreshButton() const;
|
void refreshButton() const;
|
||||||
void refreshGameLabels() const;
|
void refreshGameLabels(GameState state) const;
|
||||||
|
|
||||||
void dealHoleCards();
|
void dealHoleCards();
|
||||||
void dealFlopCards();
|
void dealFlopCards();
|
||||||
|
|||||||
@@ -582,7 +582,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent)
|
|||||||
connect(this, SIGNAL(signalRefreshAll()), this, SLOT(refreshAll()));
|
connect(this, SIGNAL(signalRefreshAll()), this, SLOT(refreshAll()));
|
||||||
connect(this, SIGNAL(signalRefreshPlayerName()), this, SLOT(refreshPlayerName()));
|
connect(this, SIGNAL(signalRefreshPlayerName()), this, SLOT(refreshPlayerName()));
|
||||||
connect(this, SIGNAL(signalRefreshButton()), this, SLOT(refreshButton()));
|
connect(this, SIGNAL(signalRefreshButton()), this, SLOT(refreshButton()));
|
||||||
connect(this, SIGNAL(signalRefreshGameLabels()), this, SLOT(refreshGameLabels()));
|
connect(this, SIGNAL(signalRefreshGameLabels(int)), this, SLOT(refreshGameLabels(int)));
|
||||||
|
|
||||||
connect(this, SIGNAL(signalMeInAction()), this, SLOT(meInAction()));
|
connect(this, SIGNAL(signalMeInAction()), this, SLOT(meInAction()));
|
||||||
|
|
||||||
@@ -1186,9 +1186,9 @@ void mainWindowImpl::refreshGroupbox(int playerID, int status) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainWindowImpl::refreshGameLabels() {
|
void mainWindowImpl::refreshGameLabels(int gameState) {
|
||||||
|
|
||||||
switch(mySession->getCurrentGame()->getCurrentHand()->getActualRound()) {
|
switch(gameState) {
|
||||||
case 0: {
|
case 0: {
|
||||||
textLabel_handLabel->setText("Preflop");
|
textLabel_handLabel->setText("Preflop");
|
||||||
} break;
|
} break;
|
||||||
|
|||||||
@@ -84,6 +84,7 @@ signals:
|
|||||||
void signalRefreshAll();
|
void signalRefreshAll();
|
||||||
void signalRefreshPlayerName();
|
void signalRefreshPlayerName();
|
||||||
void signalRefreshButton();
|
void signalRefreshButton();
|
||||||
|
void signalRefreshGameLabels(int);
|
||||||
|
|
||||||
void signalMeInAction();
|
void signalMeInAction();
|
||||||
|
|
||||||
@@ -92,7 +93,6 @@ signals:
|
|||||||
void signalDealTurnCards0();
|
void signalDealTurnCards0();
|
||||||
void signalDealRiverCards0();
|
void signalDealRiverCards0();
|
||||||
|
|
||||||
void signalRefreshGameLabels();
|
|
||||||
void signalNextPlayerAnimation();
|
void signalNextPlayerAnimation();
|
||||||
|
|
||||||
void signalPreflopAnimation1();
|
void signalPreflopAnimation1();
|
||||||
@@ -134,7 +134,7 @@ public slots:
|
|||||||
void refreshGroupbox(int =-1, int =-1);
|
void refreshGroupbox(int =-1, int =-1);
|
||||||
void refreshAll();
|
void refreshAll();
|
||||||
void refreshPlayerName();
|
void refreshPlayerName();
|
||||||
void refreshGameLabels();
|
void refreshGameLabels(int);
|
||||||
void refreshButton();
|
void refreshButton();
|
||||||
void refreshPlayerAvatar();
|
void refreshPlayerAvatar();
|
||||||
|
|
||||||
|
|||||||
@@ -255,6 +255,7 @@ protected:
|
|||||||
static void SetHighestSet(Game &curGame, int highestSet);
|
static void SetHighestSet(Game &curGame, int highestSet);
|
||||||
static int GetPlayersTurn(Game &curGame);
|
static int GetPlayersTurn(Game &curGame);
|
||||||
static void SetPlayersTurn(Game &curGame, int playersTurn);
|
static void SetPlayersTurn(Game &curGame, int playersTurn);
|
||||||
|
static void ResetPlayerActions(Game &curGame);
|
||||||
};
|
};
|
||||||
|
|
||||||
// State: Final (just for testing, should not be used).
|
// State: Final (just for testing, should not be used).
|
||||||
|
|||||||
@@ -66,8 +66,8 @@ ClientStateInit::Process(ClientThread &client)
|
|||||||
if (context.GetServerAddr().empty())
|
if (context.GetServerAddr().empty())
|
||||||
throw ClientException(ERR_SOCK_SERVERADDR_NOT_SET, 0);
|
throw ClientException(ERR_SOCK_SERVERADDR_NOT_SET, 0);
|
||||||
|
|
||||||
// if (context.GetServerPort() < 1024)
|
if (context.GetServerPort() < 1024)
|
||||||
// throw ClientException(ERR_SOCK_INVALID_PORT, 0);
|
throw ClientException(ERR_SOCK_INVALID_PORT, 0);
|
||||||
|
|
||||||
context.SetSocket(socket(context.GetAddrFamily(), SOCK_STREAM, context.GetProtocol()));
|
context.SetSocket(socket(context.GetAddrFamily(), SOCK_STREAM, context.GetProtocol()));
|
||||||
if (!IS_VALID_SOCKET(context.GetSocket()))
|
if (!IS_VALID_SOCKET(context.GetSocket()))
|
||||||
@@ -77,6 +77,10 @@ ClientStateInit::Process(ClientThread &client)
|
|||||||
if (IOCTLSOCKET(context.GetSocket(), FIONBIO, &mode) == SOCKET_ERROR)
|
if (IOCTLSOCKET(context.GetSocket(), FIONBIO, &mode) == SOCKET_ERROR)
|
||||||
throw ClientException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO());
|
throw ClientException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO());
|
||||||
|
|
||||||
|
// The following call is optional - the return value is not checked.
|
||||||
|
int nodelay = 1;
|
||||||
|
setsockopt(context.GetSocket(), SOL_SOCKET, TCP_NODELAY, (char *)&nodelay, sizeof(nodelay));
|
||||||
|
|
||||||
client.SetState(ClientStateStartResolve::Instance());
|
client.SetState(ClientStateStartResolve::Instance());
|
||||||
|
|
||||||
return MSG_SOCK_INIT_DONE;
|
return MSG_SOCK_INIT_DONE;
|
||||||
@@ -558,7 +562,7 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptr<Net
|
|||||||
client.GetGame()->initHand();
|
client.GetGame()->initHand();
|
||||||
client.GetGame()->startHand();
|
client.GetGame()->startHand();
|
||||||
client.GetGui().dealHoleCards();
|
client.GetGui().dealHoleCards();
|
||||||
client.GetGui().refreshGameLabels();
|
client.GetGui().refreshGameLabels(GAME_STATE_PREFLOP);
|
||||||
client.SetState(ClientStateRunHand::Instance());
|
client.SetState(ClientStateRunHand::Instance());
|
||||||
|
|
||||||
retVal = MSG_NET_GAME_CLIENT_HAND_START;
|
retVal = MSG_NET_GAME_CLIENT_HAND_START;
|
||||||
@@ -637,22 +641,10 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
|||||||
// Set round.
|
// Set round.
|
||||||
if (curGame->getCurrentHand()->getActualRound() != turnData.gameState)
|
if (curGame->getCurrentHand()->getActualRound() != turnData.gameState)
|
||||||
{
|
{
|
||||||
// Reset player actions
|
ResetPlayerActions(*curGame);
|
||||||
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);
|
|
||||||
curGame->getPlayerArray()[i]->setMySetNull();
|
|
||||||
}
|
|
||||||
|
|
||||||
curGame->getCurrentHand()->setActualRound(turnData.gameState);
|
curGame->getCurrentHand()->setActualRound(turnData.gameState);
|
||||||
|
// Refresh actions.
|
||||||
client.GetGui().refreshPot();
|
|
||||||
client.GetGui().refreshSet();
|
|
||||||
client.GetGui().refreshAction();
|
client.GetGui().refreshAction();
|
||||||
client.GetGui().refreshCash();
|
|
||||||
client.GetGui().refreshGameLabels();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Next player's turn.
|
// Next player's turn.
|
||||||
@@ -678,6 +670,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
|||||||
tmpCards[num] = static_cast<int>(cardsData.flopCards[num]);
|
tmpCards[num] = static_cast<int>(cardsData.flopCards[num]);
|
||||||
tmpCards[3] = tmpCards[4] = 0;
|
tmpCards[3] = tmpCards[4] = 0;
|
||||||
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
||||||
|
|
||||||
|
client.GetGui().refreshGameLabels(GAME_STATE_FLOP);
|
||||||
client.GetGui().dealFlopCards();
|
client.GetGui().dealFlopCards();
|
||||||
}
|
}
|
||||||
else if (packet->ToNetPacketDealTurnCard())
|
else if (packet->ToNetPacketDealTurnCard())
|
||||||
@@ -688,6 +682,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
|||||||
curGame->getCurrentHand()->getBoard()->getMyCards(tmpCards);
|
curGame->getCurrentHand()->getBoard()->getMyCards(tmpCards);
|
||||||
tmpCards[3] = static_cast<int>(cardsData.turnCard);
|
tmpCards[3] = static_cast<int>(cardsData.turnCard);
|
||||||
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
||||||
|
|
||||||
|
client.GetGui().refreshGameLabels(GAME_STATE_TURN);
|
||||||
client.GetGui().dealTurnCard();
|
client.GetGui().dealTurnCard();
|
||||||
}
|
}
|
||||||
else if (packet->ToNetPacketDealRiverCard())
|
else if (packet->ToNetPacketDealRiverCard())
|
||||||
@@ -698,6 +694,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptr<NetP
|
|||||||
curGame->getCurrentHand()->getBoard()->getMyCards(tmpCards);
|
curGame->getCurrentHand()->getBoard()->getMyCards(tmpCards);
|
||||||
tmpCards[4] = static_cast<int>(cardsData.riverCard);
|
tmpCards[4] = static_cast<int>(cardsData.riverCard);
|
||||||
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards);
|
||||||
|
|
||||||
|
client.GetGui().refreshGameLabels(GAME_STATE_RIVER);
|
||||||
client.GetGui().dealRiverCard();
|
client.GetGui().dealRiverCard();
|
||||||
}
|
}
|
||||||
else if (packet->ToNetPacketAllInShowCards())
|
else if (packet->ToNetPacketAllInShowCards())
|
||||||
@@ -888,6 +886,19 @@ ClientStateRunHand::SetPlayersTurn(Game &curGame, int playersTurn)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ClientStateRunHand::ResetPlayerActions(Game &curGame)
|
||||||
|
{
|
||||||
|
// 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);
|
||||||
|
curGame.getPlayerArray()[i]->setMySetNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
ClientStateFinal &
|
ClientStateFinal &
|
||||||
|
|||||||
@@ -33,12 +33,15 @@
|
|||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
#define SERVER_WAIT_TIMEOUT_MSEC 50
|
#define SERVER_WAIT_TIMEOUT_MSEC 50
|
||||||
#define SERVER_NEXT_HAND_DELAY_SEC 10
|
#define SERVER_DELAY_NEXT_HAND_SEC 10
|
||||||
#define SERVER_DEAL_FLOP_CARDS_SEC 5
|
#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5
|
||||||
#define SERVER_DEAL_TURN_CARD_SEC 3
|
#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2
|
||||||
#define SERVER_DEAL_RIVER_CARD_SEC 3
|
#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 2
|
||||||
|
#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 1
|
||||||
|
#define SERVER_SHOW_CARDS_DELAY_SEC 2
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
|
// TODO: these are hacks.
|
||||||
|
|
||||||
static PlayerInterface *GetCurrentPlayer(Game &curGame)
|
static PlayerInterface *GetCurrentPlayer(Game &curGame)
|
||||||
{
|
{
|
||||||
@@ -65,6 +68,50 @@ static PlayerInterface *GetCurrentPlayer(Game &curGame)
|
|||||||
return curGame.getPlayerArray()[curPlayerNum];
|
return curGame.getPlayerArray()[curPlayerNum];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void SendNewRoundCards(ServerRecvThread &server, Game &curGame, int state)
|
||||||
|
{
|
||||||
|
// TODO: no switch needed here if game states are polymorphic
|
||||||
|
switch(state) {
|
||||||
|
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;
|
||||||
|
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;
|
||||||
|
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<u_int16_t>(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<u_int16_t>(cards[4]);
|
||||||
|
static_cast<NetPacketDealRiverCard *>(notifyCards.get())->SetData(notifyCardsData);
|
||||||
|
server.SendToAllPlayers(notifyCards);
|
||||||
|
} break;
|
||||||
|
default: {
|
||||||
|
//
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
ServerRecvState::~ServerRecvState()
|
ServerRecvState::~ServerRecvState()
|
||||||
@@ -454,14 +501,12 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
|
|||||||
if (newRound != curRound)
|
if (newRound != curRound)
|
||||||
{
|
{
|
||||||
assert(newRound > curRound);
|
assert(newRound > curRound);
|
||||||
|
|
||||||
if (curGame.getCurrentHand()->getAllInCondition()
|
|
||||||
&& !curGame.getCurrentHand()->getCardsShown())
|
|
||||||
{
|
|
||||||
// Retrieve active players. If only one player is left, no cards are shown.
|
// Retrieve active players. If only one player is left, no cards are shown.
|
||||||
std::list<PlayerInterface *> activePlayers = GetActivePlayers(curGame);
|
std::list<PlayerInterface *> activePlayers = GetActivePlayers(curGame);
|
||||||
assert(!activePlayers.empty());
|
|
||||||
if (activePlayers.size() > 1)
|
if (curGame.getCurrentHand()->getAllInCondition()
|
||||||
|
&& !curGame.getCurrentHand()->getCardsShown()
|
||||||
|
&& activePlayers.size() > 1)
|
||||||
{
|
{
|
||||||
// Send cards of all active players to all players (all in).
|
// Send cards of all active players to all players (all in).
|
||||||
boost::shared_ptr<NetPacket> allIn(new NetPacketAllInShowCards);
|
boost::shared_ptr<NetPacket> allIn(new NetPacketAllInShowCards);
|
||||||
@@ -485,11 +530,16 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
|
|||||||
}
|
}
|
||||||
static_cast<NetPacketAllInShowCards *>(allIn.get())->SetData(allInData);
|
static_cast<NetPacketAllInShowCards *>(allIn.get())->SetData(allInData);
|
||||||
server.SendToAllPlayers(allIn);
|
server.SendToAllPlayers(allIn);
|
||||||
|
|
||||||
curGame.getCurrentHand()->setCardsShown(true);
|
curGame.getCurrentHand()->setCardsShown(true);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
boost::microsec_timer delayTimer;
|
||||||
|
delayTimer.start();
|
||||||
|
ServerRecvStateShowCardsDelay::Instance().SetTimer(delayTimer);
|
||||||
|
server.SetState(ServerRecvStateShowCardsDelay::Instance());
|
||||||
|
retVal = MSG_NET_GAME_SERVER_CARDS_DELAY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
SendNewRoundCards(server, curGame, newRound);
|
SendNewRoundCards(server, curGame, newRound);
|
||||||
|
|
||||||
boost::microsec_timer delayTimer;
|
boost::microsec_timer delayTimer;
|
||||||
@@ -498,6 +548,7 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
|
|||||||
server.SetState(ServerRecvStateDealCardsDelay::Instance());
|
server.SetState(ServerRecvStateDealCardsDelay::Instance());
|
||||||
retVal = MSG_NET_GAME_SERVER_CARDS_DELAY;
|
retVal = MSG_NET_GAME_SERVER_CARDS_DELAY;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (newRound != GAME_STATE_POST_RIVER) // continue hand
|
if (newRound != GAME_STATE_POST_RIVER) // continue hand
|
||||||
@@ -625,51 +676,6 @@ ServerRecvStateStartRound::GameRun(Game &curGame)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
|
||||||
ServerRecvStateStartRound::SendNewRoundCards(ServerRecvThread &server, Game &curGame, int state)
|
|
||||||
{
|
|
||||||
// TODO: no switch needed here if game states are polymorphic
|
|
||||||
switch(state) {
|
|
||||||
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;
|
|
||||||
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;
|
|
||||||
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<u_int16_t>(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<u_int16_t>(cards[4]);
|
|
||||||
static_cast<NetPacketDealRiverCard *>(notifyCards.get())->SetData(notifyCardsData);
|
|
||||||
server.SendToAllPlayers(notifyCards);
|
|
||||||
} break;
|
|
||||||
default: {
|
|
||||||
//
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::list<PlayerInterface *>
|
std::list<PlayerInterface *>
|
||||||
ServerRecvStateStartRound::GetActivePlayers(Game &curGame)
|
ServerRecvStateStartRound::GetActivePlayers(Game &curGame)
|
||||||
{
|
{
|
||||||
@@ -857,20 +863,20 @@ ServerRecvStateDealCardsDelay::Process(ServerRecvThread &server)
|
|||||||
|
|
||||||
Game &curGame = server.GetGame();
|
Game &curGame = server.GetGame();
|
||||||
|
|
||||||
int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? 1 : 0;
|
int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0;
|
||||||
|
|
||||||
switch(curGame.getCurrentHand()->getActualRound())
|
switch(curGame.getCurrentHand()->getActualRound())
|
||||||
{
|
{
|
||||||
case GAME_STATE_FLOP:
|
case GAME_STATE_FLOP:
|
||||||
if (m_delayTimer.elapsed().seconds() >= SERVER_DEAL_FLOP_CARDS_SEC - allInDelay)
|
if (m_delayTimer.elapsed().seconds() >= SERVER_DEAL_FLOP_CARDS_DELAY_SEC + allInDelay)
|
||||||
server.SetState(ServerRecvStateStartRound::Instance());
|
server.SetState(ServerRecvStateStartRound::Instance());
|
||||||
break;
|
break;
|
||||||
case GAME_STATE_TURN:
|
case GAME_STATE_TURN:
|
||||||
if (m_delayTimer.elapsed().seconds() >= SERVER_DEAL_TURN_CARD_SEC /*+ allInDelay*/)
|
if (m_delayTimer.elapsed().seconds() >= SERVER_DEAL_TURN_CARD_DELAY_SEC)
|
||||||
server.SetState(ServerRecvStateStartRound::Instance());
|
server.SetState(ServerRecvStateStartRound::Instance());
|
||||||
break;
|
break;
|
||||||
case GAME_STATE_RIVER:
|
case GAME_STATE_RIVER:
|
||||||
if (m_delayTimer.elapsed().seconds() >= SERVER_DEAL_RIVER_CARD_SEC /*+ allInDelay*/)
|
if (m_delayTimer.elapsed().seconds() >= SERVER_DEAL_RIVER_CARD_DELAY_SEC)
|
||||||
server.SetState(ServerRecvStateStartRound::Instance());
|
server.SetState(ServerRecvStateStartRound::Instance());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -887,6 +893,56 @@ ServerRecvStateDealCardsDelay::InternalProcess(ServerRecvThread &server, Session
|
|||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
ServerRecvStateShowCardsDelay &
|
||||||
|
ServerRecvStateShowCardsDelay::Instance()
|
||||||
|
{
|
||||||
|
static ServerRecvStateShowCardsDelay state;
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerRecvStateShowCardsDelay::ServerRecvStateShowCardsDelay()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerRecvStateShowCardsDelay::~ServerRecvStateShowCardsDelay()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ServerRecvStateShowCardsDelay::SetTimer(const boost::microsec_timer &timer)
|
||||||
|
{
|
||||||
|
m_delayTimer = timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ServerRecvStateShowCardsDelay::Process(ServerRecvThread &server)
|
||||||
|
{
|
||||||
|
int retVal = ServerRecvStateReceiving::Process(server);
|
||||||
|
|
||||||
|
Game &curGame = server.GetGame();
|
||||||
|
|
||||||
|
if (m_delayTimer.elapsed().seconds() >= SERVER_SHOW_CARDS_DELAY_SEC)
|
||||||
|
{
|
||||||
|
SendNewRoundCards(server, curGame, curGame.getCurrentHand()->getActualRound());
|
||||||
|
|
||||||
|
boost::microsec_timer delayTimer;
|
||||||
|
delayTimer.start();
|
||||||
|
ServerRecvStateDealCardsDelay::Instance().SetTimer(delayTimer);
|
||||||
|
server.SetState(ServerRecvStateDealCardsDelay::Instance());
|
||||||
|
retVal = MSG_NET_GAME_SERVER_CARDS_DELAY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
ServerRecvStateShowCardsDelay::InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet)
|
||||||
|
{
|
||||||
|
return MSG_SOCK_INTERNAL_PENDING;
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
|
||||||
ServerRecvStateNextHand &
|
ServerRecvStateNextHand &
|
||||||
ServerRecvStateNextHand::Instance()
|
ServerRecvStateNextHand::Instance()
|
||||||
{
|
{
|
||||||
@@ -913,7 +969,7 @@ ServerRecvStateNextHand::Process(ServerRecvThread &server)
|
|||||||
{
|
{
|
||||||
int retVal = ServerRecvStateReceiving::Process(server);
|
int retVal = ServerRecvStateReceiving::Process(server);
|
||||||
|
|
||||||
if (m_delayTimer.elapsed().seconds() >= SERVER_NEXT_HAND_DELAY_SEC)
|
if (m_delayTimer.elapsed().seconds() >= SERVER_DELAY_NEXT_HAND_SEC)
|
||||||
server.SetState(ServerRecvStateStartHand::Instance());
|
server.SetState(ServerRecvStateStartHand::Instance());
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
|
|||||||
@@ -115,9 +115,11 @@ ServerThread::Listen()
|
|||||||
if (IOCTLSOCKET(context.GetSocket(), FIONBIO, &mode) == SOCKET_ERROR)
|
if (IOCTLSOCKET(context.GetSocket(), FIONBIO, &mode) == SOCKET_ERROR)
|
||||||
throw ServerException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO());
|
throw ServerException(ERR_SOCK_CREATION_FAILED, SOCKET_ERRNO());
|
||||||
|
|
||||||
// The following call is optional. If it fails, we don't care.
|
// The following two calls are optional. If they fail, we don't care.
|
||||||
int reuse = 1;
|
int reuse = 1;
|
||||||
setsockopt(context.GetSocket(), SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse));
|
setsockopt(context.GetSocket(), SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse));
|
||||||
|
int nodelay = 1;
|
||||||
|
setsockopt(context.GetSocket(), SOL_SOCKET, TCP_NODELAY, (char *)&nodelay, sizeof(nodelay));
|
||||||
|
|
||||||
context.GetServerSockaddr()->ss_family = context.GetAddrFamily();
|
context.GetServerSockaddr()->ss_family = context.GetAddrFamily();
|
||||||
|
|
||||||
|
|||||||
@@ -157,7 +157,6 @@ protected:
|
|||||||
ServerRecvStateStartRound();
|
ServerRecvStateStartRound();
|
||||||
|
|
||||||
static void GameRun(Game &curGame);
|
static void GameRun(Game &curGame);
|
||||||
static void SendNewRoundCards(ServerRecvThread &server, Game &curGame, int state);
|
|
||||||
static std::list<PlayerInterface *> GetActivePlayers(Game &curGame);
|
static std::list<PlayerInterface *> GetActivePlayers(Game &curGame);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,6 +210,32 @@ private:
|
|||||||
boost::microsec_timer m_delayTimer;
|
boost::microsec_timer m_delayTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// State: Delay after showing cards (all in)
|
||||||
|
class ServerRecvStateShowCardsDelay : public ServerRecvStateReceiving, public ServerRecvStateRunning
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// Access the state singleton.
|
||||||
|
static ServerRecvStateShowCardsDelay &Instance();
|
||||||
|
|
||||||
|
virtual ~ServerRecvStateShowCardsDelay();
|
||||||
|
|
||||||
|
// Overwrite default processing
|
||||||
|
virtual int Process(ServerRecvThread &server);
|
||||||
|
|
||||||
|
void SetTimer(const boost::microsec_timer &timer);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
// Protected constructor - this is a singleton.
|
||||||
|
ServerRecvStateShowCardsDelay();
|
||||||
|
|
||||||
|
virtual int InternalProcess(ServerRecvThread &server, SessionWrapper session, boost::shared_ptr<NetPacket> packet);
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
boost::microsec_timer m_delayTimer;
|
||||||
|
};
|
||||||
|
|
||||||
// State: Delay before next hand.
|
// State: Delay before next hand.
|
||||||
class ServerRecvStateNextHand : public ServerRecvStateReceiving, public ServerRecvStateRunning
|
class ServerRecvStateNextHand : public ServerRecvStateReceiving, public ServerRecvStateRunning
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ public:
|
|||||||
|
|
||||||
ServerCallback &GetCallback();
|
ServerCallback &GetCallback();
|
||||||
|
|
||||||
|
void SendError(SOCKET s, int errorCode);
|
||||||
|
void SendToAllPlayers(boost::shared_ptr<NetPacket> packet);
|
||||||
|
void SendToAllButOnePlayers(boost::shared_ptr<NetPacket> packet, SOCKET except);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
struct Notification
|
struct Notification
|
||||||
@@ -114,10 +118,6 @@ protected:
|
|||||||
|
|
||||||
int GetNextPlayerNumber() const;
|
int GetNextPlayerNumber() const;
|
||||||
|
|
||||||
void SendError(SOCKET s, int errorCode);
|
|
||||||
void SendToAllPlayers(boost::shared_ptr<NetPacket> packet);
|
|
||||||
void SendToAllButOnePlayers(boost::shared_ptr<NetPacket> packet, SOCKET except);
|
|
||||||
|
|
||||||
ServerRecvState &GetState();
|
ServerRecvState &GetState();
|
||||||
void SetState(ServerRecvState &newState);
|
void SetState(ServerRecvState &newState);
|
||||||
|
|
||||||
@@ -169,6 +169,7 @@ friend class ServerRecvStateStartGame;
|
|||||||
friend class ServerRecvStateStartHand;
|
friend class ServerRecvStateStartHand;
|
||||||
friend class ServerRecvStateStartRound;
|
friend class ServerRecvStateStartRound;
|
||||||
friend class ServerRecvStateWaitPlayerAction;
|
friend class ServerRecvStateWaitPlayerAction;
|
||||||
|
friend class ServerRecvStateShowCardsDelay;
|
||||||
friend class ServerRecvStateDealCardsDelay;
|
friend class ServerRecvStateDealCardsDelay;
|
||||||
friend class ServerRecvStateNextHand;
|
friend class ServerRecvStateNextHand;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,6 +52,7 @@
|
|||||||
#define ERR_NET_INVALID_PLAYER_RESULTS 109
|
#define ERR_NET_INVALID_PLAYER_RESULTS 109
|
||||||
#define ERR_NET_INVALID_CHAT_TEXT 110
|
#define ERR_NET_INVALID_CHAT_TEXT 110
|
||||||
#define ERR_NET_UNKNOWN_PLAYER_ID 111
|
#define ERR_NET_UNKNOWN_PLAYER_ID 111
|
||||||
|
#define ERR_NET_INVALID_ROUND 112
|
||||||
|
|
||||||
// This is an internal message which is not reported.
|
// This is an internal message which is not reported.
|
||||||
#define MSG_SOCK_INTERNAL_PENDING 0
|
#define MSG_SOCK_INTERNAL_PENDING 0
|
||||||
|
|||||||
Reference in New Issue
Block a user