diff --git a/docs/net_protocol.txt b/docs/net_protocol.txt index 7703c716..a3ede212 100644 --- a/docs/net_protocol.txt +++ b/docs/net_protocol.txt @@ -64,7 +64,7 @@ Server Reply: Join Game ACK +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Hands before raise | Proposed GUI Speed | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Start Cash | + | Start Money | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Player Number: @@ -163,7 +163,7 @@ Client Reply/Request: Player's Action +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Game State | Player Action | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Cash Value | + | Player Bet | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ [ Game State is confirmed to ensure consistency. ] @@ -175,7 +175,7 @@ Player Action: 4 - Bet 5 - Raise 6 - All in -Cash Value: +Player Bet: 0 - states fold, check, call, all in > 0 - states bet, raise @@ -190,7 +190,13 @@ Server Notification: Player's Action Done +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Player Action | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Cash Value | + | Player Bet | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Current Player Money | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Pot Size | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Current Hand Bets | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -199,11 +205,11 @@ Server Reply: Player's Action Rejected 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 = 10 | Message Length = 16 | + | Message Type = 10 | Message Length = 16 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Game State | Player Action | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Cash Value | + | Player Bet | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Rejection Reason | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -216,9 +222,9 @@ Rejection Reason: 0x0005 - Raise not allowed. 0x0006 - All in not allowed. 0x0007 - Invalid game state. - 0x0008 - Invalid cash value for this game state. - 0x0009 - Cash value too small. - 0x0010 - Cash value too large. + 0x0008 - Invalid bet for this game state. + 0x0009 - Bet too small. + 0x0010 - Bet too large. 0xFFFF - Other reason diff --git a/src/engine/boardinterface.h b/src/engine/boardinterface.h index 4cf6fe62..62e2c62b 100644 --- a/src/engine/boardinterface.h +++ b/src/engine/boardinterface.h @@ -38,6 +38,7 @@ public: virtual int getPot() const=0; virtual void setPot(int theValue) =0; virtual int getSets() const=0; + virtual void setSets(int theValue) =0; // virtual void collectSets() =0; virtual void collectPot() =0; diff --git a/src/engine/handinterface.h b/src/engine/handinterface.h index 35ba80bb..80707a7c 100644 --- a/src/engine/handinterface.h +++ b/src/engine/handinterface.h @@ -76,8 +76,6 @@ public: virtual void setLastPlayersTurn(const int& theValue) =0; virtual int getLastPlayersTurn() const =0; - virtual void assignButtons() =0; - virtual void highlightRoundLabel() =0; virtual void switchRounds() =0; diff --git a/src/engine/local_engine/localboard.h b/src/engine/local_engine/localboard.h index 6f76a034..24e48a16 100755 --- a/src/engine/local_engine/localboard.h +++ b/src/engine/local_engine/localboard.h @@ -40,6 +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 collectSets() ; void collectPot() ; diff --git a/src/engine/network_engine/clientboard.h b/src/engine/network_engine/clientboard.h index 87d93a13..89e64d7b 100644 --- a/src/engine/network_engine/clientboard.h +++ b/src/engine/network_engine/clientboard.h @@ -39,6 +39,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 collectSets(); void collectPot(); diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index acd1910d..db409859 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -43,7 +43,19 @@ ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, Boar playerArray[i]->setMyRoundStartCash(playerArray[i]->getMyCash()); } - assignButtons(); + // remove all buttons + for (i=0; isetMyButton(0); } + + // assign dealer button + playerArray[dealerPosition]->setMyButton(1); + + // the rest of the buttons are assigned later as received from the server. + + // Preflop, Flop, Turn und River erstellen + myPreflop = myFactory->createPreflop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); + myFlop = myFactory->createFlop(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); + myTurn = myFactory->createTurn(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); + myRiver = myFactory->createRiver(this, myID, actualQuantityPlayers, dealerPosition, smallBlind); } @@ -57,47 +69,6 @@ ClientHand::start() { } -void -ClientHand::assignButtons() -{ - int i; - - //Aktive Spieler zählen - int activePlayersCounter = 0; - for (i=0; igetMyActiveStatus() == 1) activePlayersCounter++; - } - - // alle Buttons loeschen - for (i=0; isetMyButton(0); } - - // DealerButton zuweisen - playerArray[dealerPosition]->setMyButton(1); - - // assign Small Blind next to dealer. ATTENTION: in heads up it is big blind - i = dealerPosition; - do { - i = (i+1)%(MAX_NUMBER_OF_PLAYERS); - if(playerArray[i]->getMyActiveStatus()) { - if(activePlayersCounter > 2) playerArray[i]->setMyButton(2); //small blind normal - else playerArray[i]->setMyButton(3); //big blind in heads up - - } - - } while(!(playerArray[i]->getMyActiveStatus())); - - // assign big blind next to small blind. ATTENTION: in heads up it is small blind - do { - i = (i+1)%(MAX_NUMBER_OF_PLAYERS); - if(playerArray[i]->getMyActiveStatus()) { - if(activePlayersCounter > 2) playerArray[i]->setMyButton(3); //big blind normal - else playerArray[i]->setMyButton(2); //small blind in heads up - - } - - } while(!(playerArray[i]->getMyActiveStatus())); -} - void ClientHand::switchRounds() { diff --git a/src/engine/network_engine/clienthand.h b/src/engine/network_engine/clienthand.h index baf427df..31ed12bf 100644 --- a/src/engine/network_engine/clienthand.h +++ b/src/engine/network_engine/clienthand.h @@ -7,7 +7,7 @@ * (at your option) any later version. * * * * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * +` * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU General Public License for more details. * * * @@ -30,7 +30,8 @@ #include -class ClientHand : public HandInterface{ +class ClientHand : public HandInterface +{ public: ClientHand(boost::shared_ptr f, GuiInterface*, BoardInterface*, PlayerInterface**, int, int, int, int, int, int); ~ClientHand(); @@ -79,8 +80,6 @@ public: int getLastPlayersTurn() const { return lastPlayersTurn; } - void assignButtons(); - void highlightRoundLabel(); void switchRounds(); diff --git a/src/game.cpp b/src/game.cpp index a8ef058e..da1304e6 100755 --- a/src/game.cpp +++ b/src/game.cpp @@ -33,7 +33,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, const StartData &startData, int gameId) : myFactory(factory), myGui(gui), actualHand(0), actualBoard(0), startQuantityPlayers(gameData.numberOfPlayers), - startCash(gameData.startCash), startSmallBlind(gameData.smallBlind), + startCash(gameData.startMoney), startSmallBlind(gameData.smallBlind), startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise), myGameID(gameId), actualQuantityPlayers(gameData.numberOfPlayers), actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0) diff --git a/src/gamedata.h b/src/gamedata.h index 8cd8d051..f27587cb 100644 --- a/src/gamedata.h +++ b/src/gamedata.h @@ -25,10 +25,10 @@ struct GameData { - GameData() : numberOfPlayers(0), startCash(0), smallBlind(0), + GameData() : numberOfPlayers(0), startMoney(0), smallBlind(0), handsBeforeRaise(1), guiSpeed(4) {} int numberOfPlayers; - int startCash; + int startMoney; int smallBlind; int handsBeforeRaise; int guiSpeed; diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 1beccfcb..6b3ea54d 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -644,7 +644,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { if(v) { // Set Game Data gameData.numberOfPlayers = v->spinBox_quantityPlayers->value(); - gameData.startCash = v->spinBox_startCash->value(); + gameData.startMoney = v->spinBox_startCash->value(); gameData.smallBlind = v->spinBox_smallBlind->value(); gameData.handsBeforeRaise = v->spinBox_handsBeforeRaiseSmallBlind->value(); //Speeds @@ -654,7 +654,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { else { // Set Game Data gameData.numberOfPlayers = myConfig->readConfigInt("NumberOfPlayers"); - gameData.startCash = myConfig->readConfigInt("StartCash"); + gameData.startMoney = myConfig->readConfigInt("StartCash"); gameData.smallBlind = myConfig->readConfigInt("SmallBlind"); gameData.handsBeforeRaise = myConfig->readConfigInt("HandsBeforeRaiseSmallBlind"); //Speeds @@ -695,7 +695,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() { GameData gameData; gameData.numberOfPlayers = myCreateNetworkGameDialog->spinBox_quantityPlayers->value(); - gameData.startCash = myCreateNetworkGameDialog->spinBox_startCash->value(); + gameData.startMoney = myCreateNetworkGameDialog->spinBox_startCash->value(); gameData.smallBlind = myCreateNetworkGameDialog->spinBox_smallBlind->value(); gameData.handsBeforeRaise = myCreateNetworkGameDialog->spinBox_handsBeforeRaiseSmallBlind->value(); gameData.guiSpeed = myCreateNetworkGameDialog->spinBox_gameSpeed->value(); @@ -1374,14 +1374,15 @@ void mainWindowImpl::meInAction() { if(myConfig->readConfigInt("ShowStatusbarMessages")) { statusBar()->showMessage(tr("F1 - Fold/All-In | F2 - Check/Call | F3 - Bet/Raise"), 15000); } - HandInterface *currentHand = mySession->getCurrentGame()->getCurrentHand(); + Game *currentGame = mySession->getCurrentGame(); + HandInterface *currentHand = currentGame->getCurrentHand(); switch (currentHand->getActualRound()) { case 0: { - if (currentHand->getPlayerArray()[0]->getMyCash()+currentHand->getPlayerArray()[0]->getMySet() > currentHand->getPreflop()->getHighestSet()) { pushButton_BetRaise->setText("Raise"); } + if (currentGame->getPlayerArray()[0]->getMyCash()+currentGame->getPlayerArray()[0]->getMySet() > currentHand->getPreflop()->getHighestSet()) { pushButton_BetRaise->setText("Raise"); } - if ( currentHand->getPlayerArray()[0]->getMySet()== currentHand->getPreflop()->getHighestSet() && currentHand->getPlayerArray()[0]->getMyButton() == 3) { pushButton_CallCheckSet->setText("Check"); } + if (currentGame->getPlayerArray()[0]->getMySet()== currentHand->getPreflop()->getHighestSet() && currentGame->getPlayerArray()[0]->getMyButton() == 3) { pushButton_CallCheckSet->setText("Check"); } else { pushButton_CallCheckSet->setText("Call"); } pushButton_FoldAllin->setText("Fold"); } @@ -1395,9 +1396,9 @@ void mainWindowImpl::meInAction() { pushButton_CallCheckSet->setText("Check"); pushButton_BetRaise->setText("Bet"); } - if (currentHand->getFlop()->getHighestSet() > 0 && currentHand->getFlop()->getHighestSet() > currentHand->getPlayerArray()[0]->getMySet()) { + if (currentHand->getFlop()->getHighestSet() > 0 && currentHand->getFlop()->getHighestSet() > currentGame->getPlayerArray()[0]->getMySet()) { pushButton_CallCheckSet->setText("Call"); - if (currentHand->getPlayerArray()[0]->getMyCash()+currentHand->getPlayerArray()[0]->getMySet() > currentHand->getPreflop()->getHighestSet()) { pushButton_BetRaise->setText("Raise"); } + if (currentGame->getPlayerArray()[0]->getMyCash()+currentGame->getPlayerArray()[0]->getMySet() > currentHand->getPreflop()->getHighestSet()) { pushButton_BetRaise->setText("Raise"); } } } break; @@ -1410,9 +1411,9 @@ void mainWindowImpl::meInAction() { pushButton_CallCheckSet->setText("Check"); pushButton_BetRaise->setText("Bet"); } - if (currentHand->getTurn()->getHighestSet() > 0 && currentHand->getTurn()->getHighestSet() > currentHand->getPlayerArray()[0]->getMySet()) { + if (currentHand->getTurn()->getHighestSet() > 0 && currentHand->getTurn()->getHighestSet() > currentGame->getPlayerArray()[0]->getMySet()) { pushButton_CallCheckSet->setText("Call"); - if (currentHand->getPlayerArray()[0]->getMyCash()+currentHand->getPlayerArray()[0]->getMySet() > currentHand->getPreflop()->getHighestSet()) { pushButton_BetRaise->setText("Raise"); } + if (currentGame->getPlayerArray()[0]->getMyCash()+currentGame->getPlayerArray()[0]->getMySet() > currentHand->getPreflop()->getHighestSet()) { pushButton_BetRaise->setText("Raise"); } } } break; @@ -1425,9 +1426,9 @@ void mainWindowImpl::meInAction() { pushButton_CallCheckSet->setText("Check"); pushButton_BetRaise->setText("Bet"); } - if (currentHand->getRiver()->getHighestSet() > 0 && currentHand->getRiver()->getHighestSet() > currentHand->getPlayerArray()[0]->getMySet()) { + if (currentHand->getRiver()->getHighestSet() > 0 && currentHand->getRiver()->getHighestSet() > currentGame->getPlayerArray()[0]->getMySet()) { pushButton_CallCheckSet->setText("Call"); - if (currentHand->getPlayerArray()[0]->getMyCash()+currentHand->getPlayerArray()[0]->getMySet() > currentHand->getPreflop()->getHighestSet()) { pushButton_BetRaise->setText("Raise"); } + if (currentGame->getPlayerArray()[0]->getMyCash()+currentGame->getPlayerArray()[0]->getMySet() > currentHand->getPreflop()->getHighestSet()) { pushButton_BetRaise->setText("Raise"); } } } break; @@ -1690,12 +1691,15 @@ void mainWindowImpl::myAllIn(){ void mainWindowImpl::nextPlayerAnimation() { + // TODO ugliest hack ever + mySession->sendClientPlayerAction(); + HandInterface *currentHand = mySession->getCurrentGame()->getCurrentHand(); //refresh Change Player refreshSet(); refreshAction(currentHand->getLastPlayersTurn(), currentHand->getPlayerArray()[currentHand->getLastPlayersTurn()]->getMyAction()); - refreshCash(); + refreshCash(); nextPlayerAnimationTimer->start(nextPlayerSpeed1); } diff --git a/src/net/clientthread.h b/src/net/clientthread.h index ee5f9311..4e25a003 100644 --- a/src/net/clientthread.h +++ b/src/net/clientthread.h @@ -51,6 +51,8 @@ public: const std::string &pwd, const std::string &playerName); + void SendPlayerAction(); + ClientCallback &GetCallback(); GuiInterface &GetGui(); diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index ca02732b..a08fcdb3 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -520,27 +520,35 @@ ClientStateWaitHand::Process(ClientThread &client) } else if (tmpPacket->ToNetPacketPlayersActionDone()) { - NetPacketPlayersActionDone::Data tmpData; - tmpPacket->ToNetPacketPlayersActionDone()->GetData(tmpData); - PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(tmpData.playerId); - if (tmpPlayer) + NetPacketPlayersActionDone::Data actionDoneData; + tmpPacket->ToNetPacketPlayersActionDone()->GetData(actionDoneData); + PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(actionDoneData.playerId); + assert(tmpPlayer); // TODO: throw exception + + if (actionDoneData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND) + tmpPlayer->setMyButton(BUTTON_SMALL_BLIND); + else if (actionDoneData.gameState == GAME_STATE_PREFLOP_BIG_BLIND) + tmpPlayer->setMyButton(BUTTON_BIG_BLIND); + + tmpPlayer->setMyAction(actionDoneData.playerAction); + tmpPlayer->setMySet(actionDoneData.playerBet); + //assert(tmpPlayer->getMyCash() == actionDoneData.curPlayerMoney); // TODO: throw exception + client.GetGame()->getCurrentHand()->getBoard()->setPot(actionDoneData.potSize); + client.GetGame()->getCurrentHand()->getBoard()->setSets(actionDoneData.curHandBets); + client.GetGui().refreshSet(); + client.GetGui().refreshPot(); + client.GetGui().refreshAction(); + } + else if (tmpPacket->ToNetPacketPlayersTurn()) + { + NetPacketPlayersTurn::Data turnData; + tmpPacket->ToNetPacketPlayersTurn()->GetData(turnData); + PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(turnData.playerId); + assert(tmpPlayer); // TODO: throw exception + + if (tmpPlayer->getMyID() == 0) // Is this the GUI player? { - if (tmpData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND) - { - assert(tmpPlayer->getMyButton() == BUTTON_SMALL_BLIND); - tmpPlayer->setMyAction(tmpData.playerAction); - tmpPlayer->setMySet(tmpData.cashValue); - client.GetGui().refreshSet(); - client.GetGui().refreshPot(); - } - else if (tmpData.gameState == GAME_STATE_PREFLOP_BIG_BLIND) - { - assert(tmpPlayer->getMyButton() == BUTTON_BIG_BLIND); - tmpPlayer->setMyAction(tmpData.playerAction); - tmpPlayer->setMySet(tmpData.cashValue); - client.GetGui().refreshSet(); - client.GetGui().refreshPot(); - } + client.GetGui().meInAction(); } } } diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 7c750e6f..44003553 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -81,6 +81,20 @@ ClientThread::Init( context.SetPlayerName(playerName); } +void +ClientThread::SendPlayerAction() +{ + // TODO: ugly hack + + boost::shared_ptr action(new NetPacketPlayersAction); + NetPacketPlayersAction::Data actionData; + actionData.gameState = (GameState)GetGame()->getCurrentHand()->getActualRound(); + actionData.playerAction = (PlayerAction)GetGame()->getPlayerArray()[0]->getMyAction(); + actionData.playerBet = GetGame()->getPlayerArray()[0]->getMySet(); + static_cast(action.get())->SetData(actionData); + GetSender().Send(GetContext().GetSocket(), action); +} + ClientCallback & ClientThread::GetCallback() { diff --git a/src/net/common/netpacket.cpp b/src/net/common/netpacket.cpp index 7d804a5c..e88d19e4 100644 --- a/src/net/common/netpacket.cpp +++ b/src/net/common/netpacket.cpp @@ -88,7 +88,7 @@ struct GCC_PACKED NetPacketJoinGameAckData u_int16_t smallBlind; u_int16_t handsBeforeRaise; u_int16_t proposedGuiSpeed; - u_int32_t startCash; + u_int32_t startMoney; }; struct GCC_PACKED NetPacketJoinGameErrorData @@ -140,7 +140,7 @@ struct GCC_PACKED NetPacketPlayersActionData NetPacketHeader head; u_int16_t gameState; u_int16_t playerAction; - u_int32_t cashValue; + u_int32_t playerBet; }; struct GCC_PACKED NetPacketPlayersActionDoneData @@ -150,7 +150,10 @@ struct GCC_PACKED NetPacketPlayersActionDoneData u_int16_t playerId; u_int16_t playerAction; u_int16_t reserved; - u_int32_t cashValue; + u_int32_t playerBet; + u_int32_t curPlayerMoney; + u_int32_t potSize; + u_int32_t curHandBets; }; struct GCC_PACKED NetPacketPlayersActionRejectedData @@ -158,7 +161,7 @@ struct GCC_PACKED NetPacketPlayersActionRejectedData NetPacketHeader head; u_int16_t gameState; u_int16_t playerAction; - u_int32_t cashValue; + u_int32_t playerBet; u_int16_t rejectionReason; u_int16_t reserved; }; @@ -554,7 +557,7 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData) tmpData->smallBlind = htons(inData.gameData.smallBlind); tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise); tmpData->proposedGuiSpeed = htons(inData.gameData.guiSpeed); - tmpData->startCash = htonl(inData.gameData.startCash); + tmpData->startMoney = htonl(inData.gameData.startMoney); } void @@ -570,7 +573,7 @@ NetPacketJoinGameAck::GetData(NetPacketJoinGameAck::Data &outData) const outData.gameData.smallBlind = ntohs(tmpData->smallBlind); outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise); outData.gameData.guiSpeed = ntohs(tmpData->proposedGuiSpeed); - outData.gameData.startCash = ntohl(tmpData->startCash); + outData.gameData.startMoney = ntohl(tmpData->startMoney); } const NetPacketJoinGameAck * @@ -983,7 +986,7 @@ NetPacketPlayersAction::SetData(const NetPacketPlayersAction::Data &inData) tmpData->gameState = htons(inData.gameState); tmpData->playerAction = htons(inData.playerAction); - tmpData->cashValue = htonl(inData.cashValue); + tmpData->playerBet = htonl(inData.playerBet); } void @@ -994,7 +997,7 @@ NetPacketPlayersAction::GetData(NetPacketPlayersAction::Data &outData) const outData.gameState = static_cast(ntohs(tmpData->gameState)); outData.playerAction = static_cast(ntohs(tmpData->playerAction)); - outData.cashValue = ntohl(tmpData->cashValue); + outData.playerBet = ntohl(tmpData->playerBet); } const NetPacketPlayersAction * @@ -1061,7 +1064,10 @@ NetPacketPlayersActionDone::SetData(const NetPacketPlayersActionDone::Data &inDa tmpData->gameState = htons(inData.gameState); tmpData->playerId = htons(inData.playerId); tmpData->playerAction = htons(inData.playerAction); - tmpData->cashValue = htonl(inData.cashValue); + tmpData->playerBet = htonl(inData.playerBet); + tmpData->curPlayerMoney = htonl(inData.curPlayerMoney); + tmpData->potSize = htonl(inData.potSize); + tmpData->curHandBets = htonl(inData.curHandBets); } void @@ -1073,7 +1079,10 @@ NetPacketPlayersActionDone::GetData(NetPacketPlayersActionDone::Data &outData) c outData.gameState = static_cast(ntohs(tmpData->gameState)); outData.playerId = ntohs(tmpData->playerId); outData.playerAction = static_cast(ntohs(tmpData->playerAction)); - outData.cashValue = ntohl(tmpData->cashValue); + outData.playerBet = ntohl(tmpData->playerBet); + outData.curPlayerMoney = ntohl(tmpData->curPlayerMoney); + outData.potSize = ntohl(tmpData->potSize); + outData.curHandBets = ntohl(tmpData->curHandBets); } const NetPacketPlayersActionDone * @@ -1135,7 +1144,7 @@ NetPacketPlayersActionRejected::SetData(const NetPacketPlayersActionRejected::Da tmpData->gameState = htons(inData.gameState); tmpData->playerAction = htons(inData.playerAction); - tmpData->cashValue = htonl(inData.cashValue); + tmpData->playerBet = htonl(inData.playerBet); // TODO: set rejection reason tmpData->rejectionReason = htons(0); @@ -1149,7 +1158,7 @@ NetPacketPlayersActionRejected::GetData(NetPacketPlayersActionRejected::Data &ou outData.gameState = static_cast(ntohs(tmpData->gameState)); outData.playerAction = static_cast(ntohs(tmpData->playerAction)); - outData.cashValue = ntohl(tmpData->cashValue); + outData.playerBet = ntohl(tmpData->playerBet); // TODO: set rejection reason } diff --git a/src/net/common/serverrecvstate.cpp b/src/net/common/serverrecvstate.cpp index fcb2b0ae..5e36881b 100644 --- a/src/net/common/serverrecvstate.cpp +++ b/src/net/common/serverrecvstate.cpp @@ -294,6 +294,9 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server) server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards); } + // Start hand. + curGame.startHand(); + // Auto small blind / big blind at the beginning of hand. for (int i = 0; i < curGame.getActualQuantityPlayers(); i++) { @@ -304,7 +307,10 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server) actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND; actionDoneData.playerId = playerArray[i]->getMyUniqueID(); actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction(); - actionDoneData.cashValue = playerArray[i]->getMySet(); + actionDoneData.playerBet = playerArray[i]->getMySet(); + actionDoneData.curPlayerMoney = playerArray[i]->getMyCash(); + actionDoneData.potSize = curGame.getCurrentHand()->getBoard()->getPot(); + actionDoneData.curHandBets = playerArray[i]->getMySet(); // first bet only static_cast(notifySmallBlind.get())->SetData(actionDoneData); server.SendToAllPlayers(notifySmallBlind); break; @@ -319,16 +325,16 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server) actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND; actionDoneData.playerId = playerArray[i]->getMyUniqueID(); actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction(); - actionDoneData.cashValue = playerArray[i]->getMySet(); + actionDoneData.playerBet = playerArray[i]->getMySet(); + actionDoneData.curPlayerMoney = playerArray[i]->getMyCash(); + actionDoneData.potSize = curGame.getCurrentHand()->getBoard()->getPot(); + actionDoneData.curHandBets = curGame.getCurrentHand()->getBoard()->getSets(); static_cast(notifyBigBlind.get())->SetData(actionDoneData); server.SendToAllPlayers(notifyBigBlind); break; } } - // Start hand. - curGame.startHand(); - server.SetState(ServerRecvStateStartRound::Instance()); return MSG_NET_GAME_SERVER_HAND; @@ -386,7 +392,7 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server) server.SendToAllPlayers(notification); - server.SetState(ServerRecvStateFinal::Instance()); + server.SetState(ServerRecvStateWaitPlayerAction::Instance()); return MSG_NET_GAME_SERVER_ROUND; } @@ -444,6 +450,79 @@ ServerRecvStateStartRound::GetCurrentPlayer(Game &curGame) return curGame.getPlayerArray()[curPlayerNum]; } +//----------------------------------------------------------------------------- + +ServerRecvStateWaitPlayerAction & +ServerRecvStateWaitPlayerAction::Instance() +{ + static ServerRecvStateWaitPlayerAction state; + return state; +} + +ServerRecvStateWaitPlayerAction::ServerRecvStateWaitPlayerAction() +{ +} + +ServerRecvStateWaitPlayerAction::~ServerRecvStateWaitPlayerAction() +{ +} + +void +ServerRecvStateWaitPlayerAction::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr connData) +{ + // Do not accept new connections in this state. + server.RejectNewConnection(connData); +} + +int +ServerRecvStateWaitPlayerAction::Process(ServerRecvThread &server) +{ + int retVal = MSG_SOCK_INIT_DONE; + SOCKET recvSock = server.Select(); + + if (recvSock != INVALID_SOCKET) + { + SessionWrapper session = server.GetSession(recvSock); + boost::shared_ptr packet; + try + { + packet = server.GetReceiver().Recv(recvSock); + } catch (const NetException &) + { + if (session.sessionData.get()) + { + server.CloseSessionDelayed(session); + return retVal; + } + } + + // Ignore if no session / no packet. + if (packet.get() && session.sessionData.get()) + { + if (packet->ToNetPacketPlayersAction()) + { + NetPacketPlayersAction::Data actionData; + packet->ToNetPacketPlayersAction()->GetData(actionData); + + Game &curGame = server.GetGame(); + + boost::shared_ptr notifyActionDone(new NetPacketPlayersActionDone); + NetPacketPlayersActionDone::Data actionDoneData; + actionDoneData.gameState = GAME_STATE_PREFLOP; // TODO + actionDoneData.playerId = session.playerData->GetUniqueId(); + actionDoneData.playerAction = actionData.playerAction; + actionDoneData.playerBet = actionData.playerBet; + actionDoneData.curPlayerMoney = 0; + actionDoneData.potSize = curGame.getCurrentHand()->getBoard()->getPot(); + actionDoneData.curHandBets = curGame.getCurrentHand()->getBoard()->getSets(); + static_cast(notifyActionDone.get())->SetData(actionDoneData); + server.SendToAllPlayers(notifyActionDone); + } + } + } + + return MSG_SOCK_INTERNAL_PENDING; +} //----------------------------------------------------------------------------- diff --git a/src/net/common/serverrecvthread.cpp b/src/net/common/serverrecvthread.cpp index 5f1624cb..2df9973e 100644 --- a/src/net/common/serverrecvthread.cpp +++ b/src/net/common/serverrecvthread.cpp @@ -54,7 +54,7 @@ private: ServerRecvThread::ServerRecvThread(GuiInterface &gui, ConfigFile *playerConfig) -: m_curGameId(0), m_gui(gui), m_playerConfig(playerConfig) +: m_curGameId(1), m_gui(gui), m_playerConfig(playerConfig) { m_senderCallback.reset(new ServerSenderCallback(*this)); m_sender.reset(new SenderThread(GetSenderCallback())); diff --git a/src/net/netpacket.h b/src/net/netpacket.h index d2d0c8c2..207c20bb 100644 --- a/src/net/netpacket.h +++ b/src/net/netpacket.h @@ -269,7 +269,7 @@ public: { GameState gameState; PlayerAction playerAction; - u_int32_t cashValue; + u_int32_t playerBet; }; NetPacketPlayersAction(); @@ -295,7 +295,10 @@ public: GameState gameState; u_int16_t playerId; PlayerAction playerAction; - u_int32_t cashValue; + u_int32_t playerBet; + u_int32_t curPlayerMoney; + u_int32_t potSize; + u_int32_t curHandBets; }; NetPacketPlayersActionDone(); @@ -321,7 +324,7 @@ public: { GameState gameState; PlayerAction playerAction; - u_int32_t cashValue; + u_int32_t playerBet; int rejectionReason; }; diff --git a/src/net/serverrecvstate.h b/src/net/serverrecvstate.h index c594129a..ac7453cd 100644 --- a/src/net/serverrecvstate.h +++ b/src/net/serverrecvstate.h @@ -135,6 +135,28 @@ protected: PlayerInterface *GetCurrentPlayer(Game &curGame); }; +// State: Wait for a player action. +class ServerRecvStateWaitPlayerAction : public ServerRecvState +{ +public: + // Access the state singleton. + static ServerRecvStateWaitPlayerAction &Instance(); + + virtual ~ServerRecvStateWaitPlayerAction(); + + // + virtual void HandleNewConnection(ServerRecvThread &server, boost::shared_ptr data); + + // + virtual int Process(ServerRecvThread &server); + +protected: + + // Protected constructor - this is a singleton. + ServerRecvStateWaitPlayerAction(); +}; + + // State: Final. class ServerRecvStateFinal : public ServerRecvState { diff --git a/src/net/serverrecvthread.h b/src/net/serverrecvthread.h index a3fc5c9b..3246b780 100644 --- a/src/net/serverrecvthread.h +++ b/src/net/serverrecvthread.h @@ -166,6 +166,7 @@ friend class ServerRecvStateInit; friend class ServerRecvStateStartGame; friend class ServerRecvStateStartHand; friend class ServerRecvStateStartRound; +friend class ServerRecvStateWaitPlayerAction; friend class ServerRecvStateFinal; }; diff --git a/src/session.cpp b/src/session.cpp index af328f68..a4e46161 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -182,3 +182,10 @@ void Session::terminateNetworkServer() myNetServer = 0; } +void Session::sendClientPlayerAction() +{ + if (!myNetClient) + return; + myNetClient->SendPlayerAction(); +} + diff --git a/src/session.h b/src/session.h index 1eeffea7..94588de7 100755 --- a/src/session.h +++ b/src/session.h @@ -53,6 +53,8 @@ public: void initiateNetworkServerGame(); void terminateNetworkServer(); + void sendClientPlayerAction(); + void setCurrentGameID(const int& theValue) { currentGameID = theValue; } int getCurrentGameID() const { return currentGameID; }