First try: Transferring client action.

This commit is contained in:
lotodore
2007-05-23 22:31:56 +00:00
parent f9ad1b6b75
commit 2556f43340
21 changed files with 243 additions and 115 deletions
+14 -8
View File
@@ -64,7 +64,7 @@ Server Reply: Join Game ACK
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Hands before raise | Proposed GUI Speed | | Hands before raise | Proposed GUI Speed |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Start Cash | | Start Money |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Player Number: Player Number:
@@ -163,7 +163,7 @@ Client Reply/Request: Player's Action
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Game State | Player Action | | Game State | Player Action |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cash Value | | Player Bet |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
[ Game State is confirmed to ensure consistency. ] [ Game State is confirmed to ensure consistency. ]
@@ -175,7 +175,7 @@ Player Action:
4 - Bet 4 - Bet
5 - Raise 5 - Raise
6 - All in 6 - All in
Cash Value: Player Bet:
0 - states fold, check, call, all in 0 - states fold, check, call, all in
> 0 - states bet, raise > 0 - states bet, raise
@@ -190,7 +190,13 @@ Server Notification: Player's Action Done
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Player Action | Reserved | | Player Action | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cash Value | | Player Bet |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Current Player Money |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Pot Size |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Current Hand Bets |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -203,7 +209,7 @@ Server Reply: Player's Action Rejected
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Game State | Player Action | | Game State | Player Action |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cash Value | | Player Bet |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Rejection Reason | Reserved | | Rejection Reason | Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -216,9 +222,9 @@ Rejection Reason:
0x0005 - Raise not allowed. 0x0005 - Raise not allowed.
0x0006 - All in not allowed. 0x0006 - All in not allowed.
0x0007 - Invalid game state. 0x0007 - Invalid game state.
0x0008 - Invalid cash value for this game state. 0x0008 - Invalid bet for this game state.
0x0009 - Cash value too small. 0x0009 - Bet too small.
0x0010 - Cash value too large. 0x0010 - Bet too large.
0xFFFF - Other reason 0xFFFF - Other reason
+1
View File
@@ -38,6 +38,7 @@ public:
virtual int getPot() const=0; virtual int getPot() const=0;
virtual void setPot(int theValue) =0; virtual void setPot(int theValue) =0;
virtual int getSets() const=0; virtual int getSets() const=0;
virtual void setSets(int theValue) =0;
// //
virtual void collectSets() =0; virtual void collectSets() =0;
virtual void collectPot() =0; virtual void collectPot() =0;
-2
View File
@@ -76,8 +76,6 @@ public:
virtual void setLastPlayersTurn(const int& theValue) =0; virtual void setLastPlayersTurn(const int& theValue) =0;
virtual int getLastPlayersTurn() const =0; virtual int getLastPlayersTurn() const =0;
virtual void assignButtons() =0;
virtual void highlightRoundLabel() =0; virtual void highlightRoundLabel() =0;
virtual void switchRounds() =0; virtual void switchRounds() =0;
+1
View File
@@ -40,6 +40,7 @@ public:
int getPot() const { return pot;} int getPot() const { return pot;}
void setPot(int theValue) { pot = theValue;} void setPot(int theValue) { pot = theValue;}
int getSets() const { return sets; } int getSets() const { return sets; }
void setSets(int theValue) { sets = theValue; }
void collectSets() ; void collectSets() ;
void collectPot() ; void collectPot() ;
+1
View File
@@ -39,6 +39,7 @@ public:
int getPot() const { return pot;} int getPot() const { return pot;}
void setPot(int theValue) { pot = theValue;} void setPot(int theValue) { pot = theValue;}
int getSets() const { return sets; } int getSets() const { return sets; }
void setSets(int theValue) { sets = theValue; }
void collectSets(); void collectSets();
void collectPot(); void collectPot();
+13 -42
View File
@@ -43,7 +43,19 @@ ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, Boar
playerArray[i]->setMyRoundStartCash(playerArray[i]->getMyCash()); playerArray[i]->setMyRoundStartCash(playerArray[i]->getMyCash());
} }
assignButtons(); // remove all buttons
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) { playerArray[i]->setMyButton(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; i<MAX_NUMBER_OF_PLAYERS; i++) {
if (playerArray[i]->getMyActiveStatus() == 1) activePlayersCounter++;
}
// alle Buttons loeschen
for (i=0; i<MAX_NUMBER_OF_PLAYERS; i++) { playerArray[i]->setMyButton(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 void
ClientHand::switchRounds() ClientHand::switchRounds()
{ {
+3 -4
View File
@@ -7,7 +7,7 @@
* (at your option) any later version. * * (at your option) any later version. *
* * * *
* This program is distributed in the hope that it will be useful, * * 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 * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. * * GNU General Public License for more details. *
* * * *
@@ -30,7 +30,8 @@
#include <riverinterface.h> #include <riverinterface.h>
class ClientHand : public HandInterface{ class ClientHand : public HandInterface
{
public: public:
ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface*, BoardInterface*, PlayerInterface**, int, int, int, int, int, int); ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface*, BoardInterface*, PlayerInterface**, int, int, int, int, int, int);
~ClientHand(); ~ClientHand();
@@ -79,8 +80,6 @@ public:
int getLastPlayersTurn() const { return lastPlayersTurn; } int getLastPlayersTurn() const { return lastPlayersTurn; }
void assignButtons();
void highlightRoundLabel(); void highlightRoundLabel();
void switchRounds(); void switchRounds();
+1 -1
View File
@@ -33,7 +33,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
const StartData &startData, int gameId) const StartData &startData, int gameId)
: myFactory(factory), myGui(gui), actualHand(0), actualBoard(0), : myFactory(factory), myGui(gui), actualHand(0), actualBoard(0),
startQuantityPlayers(gameData.numberOfPlayers), startQuantityPlayers(gameData.numberOfPlayers),
startCash(gameData.startCash), startSmallBlind(gameData.smallBlind), startCash(gameData.startMoney), startSmallBlind(gameData.smallBlind),
startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise), startHandsBeforeRaiseSmallBlind(gameData.handsBeforeRaise),
myGameID(gameId), actualQuantityPlayers(gameData.numberOfPlayers), myGameID(gameId), actualQuantityPlayers(gameData.numberOfPlayers),
actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0) actualSmallBlind(gameData.smallBlind), actualHandID(0), dealerPosition(0)
+2 -2
View File
@@ -25,10 +25,10 @@
struct GameData struct GameData
{ {
GameData() : numberOfPlayers(0), startCash(0), smallBlind(0), GameData() : numberOfPlayers(0), startMoney(0), smallBlind(0),
handsBeforeRaise(1), guiSpeed(4) {} handsBeforeRaise(1), guiSpeed(4) {}
int numberOfPlayers; int numberOfPlayers;
int startCash; int startMoney;
int smallBlind; int smallBlind;
int handsBeforeRaise; int handsBeforeRaise;
int guiSpeed; int guiSpeed;
+16 -12
View File
@@ -644,7 +644,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) {
if(v) { if(v) {
// Set Game Data // Set Game Data
gameData.numberOfPlayers = v->spinBox_quantityPlayers->value(); 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.smallBlind = v->spinBox_smallBlind->value();
gameData.handsBeforeRaise = v->spinBox_handsBeforeRaiseSmallBlind->value(); gameData.handsBeforeRaise = v->spinBox_handsBeforeRaiseSmallBlind->value();
//Speeds //Speeds
@@ -654,7 +654,7 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) {
else { else {
// Set Game Data // Set Game Data
gameData.numberOfPlayers = myConfig->readConfigInt("NumberOfPlayers"); gameData.numberOfPlayers = myConfig->readConfigInt("NumberOfPlayers");
gameData.startCash = myConfig->readConfigInt("StartCash"); gameData.startMoney = myConfig->readConfigInt("StartCash");
gameData.smallBlind = myConfig->readConfigInt("SmallBlind"); gameData.smallBlind = myConfig->readConfigInt("SmallBlind");
gameData.handsBeforeRaise = myConfig->readConfigInt("HandsBeforeRaiseSmallBlind"); gameData.handsBeforeRaise = myConfig->readConfigInt("HandsBeforeRaiseSmallBlind");
//Speeds //Speeds
@@ -695,7 +695,7 @@ void mainWindowImpl::callCreateNetworkGameDialog() {
GameData gameData; GameData gameData;
gameData.numberOfPlayers = myCreateNetworkGameDialog->spinBox_quantityPlayers->value(); 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.smallBlind = myCreateNetworkGameDialog->spinBox_smallBlind->value();
gameData.handsBeforeRaise = myCreateNetworkGameDialog->spinBox_handsBeforeRaiseSmallBlind->value(); gameData.handsBeforeRaise = myCreateNetworkGameDialog->spinBox_handsBeforeRaiseSmallBlind->value();
gameData.guiSpeed = myCreateNetworkGameDialog->spinBox_gameSpeed->value(); gameData.guiSpeed = myCreateNetworkGameDialog->spinBox_gameSpeed->value();
@@ -1374,14 +1374,15 @@ void mainWindowImpl::meInAction() {
if(myConfig->readConfigInt("ShowStatusbarMessages")) { if(myConfig->readConfigInt("ShowStatusbarMessages")) {
statusBar()->showMessage(tr("F1 - Fold/All-In | F2 - Check/Call | F3 - Bet/Raise"), 15000); 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()) { switch (currentHand->getActualRound()) {
case 0: { 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"); } else { pushButton_CallCheckSet->setText("Call"); }
pushButton_FoldAllin->setText("Fold"); pushButton_FoldAllin->setText("Fold");
} }
@@ -1395,9 +1396,9 @@ void mainWindowImpl::meInAction() {
pushButton_CallCheckSet->setText("Check"); pushButton_CallCheckSet->setText("Check");
pushButton_BetRaise->setText("Bet"); 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"); 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; break;
@@ -1410,9 +1411,9 @@ void mainWindowImpl::meInAction() {
pushButton_CallCheckSet->setText("Check"); pushButton_CallCheckSet->setText("Check");
pushButton_BetRaise->setText("Bet"); 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"); 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; break;
@@ -1425,9 +1426,9 @@ void mainWindowImpl::meInAction() {
pushButton_CallCheckSet->setText("Check"); pushButton_CallCheckSet->setText("Check");
pushButton_BetRaise->setText("Bet"); 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"); 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; break;
@@ -1690,6 +1691,9 @@ void mainWindowImpl::myAllIn(){
void mainWindowImpl::nextPlayerAnimation() { void mainWindowImpl::nextPlayerAnimation() {
// TODO ugliest hack ever
mySession->sendClientPlayerAction();
HandInterface *currentHand = mySession->getCurrentGame()->getCurrentHand(); HandInterface *currentHand = mySession->getCurrentGame()->getCurrentHand();
//refresh Change Player //refresh Change Player
+2
View File
@@ -51,6 +51,8 @@ public:
const std::string &pwd, const std::string &pwd,
const std::string &playerName); const std::string &playerName);
void SendPlayerAction();
ClientCallback &GetCallback(); ClientCallback &GetCallback();
GuiInterface &GetGui(); GuiInterface &GetGui();
+25 -17
View File
@@ -520,27 +520,35 @@ ClientStateWaitHand::Process(ClientThread &client)
} }
else if (tmpPacket->ToNetPacketPlayersActionDone()) else if (tmpPacket->ToNetPacketPlayersActionDone())
{ {
NetPacketPlayersActionDone::Data tmpData; NetPacketPlayersActionDone::Data actionDoneData;
tmpPacket->ToNetPacketPlayersActionDone()->GetData(tmpData); tmpPacket->ToNetPacketPlayersActionDone()->GetData(actionDoneData);
PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(tmpData.playerId); PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(actionDoneData.playerId);
if (tmpPlayer) assert(tmpPlayer); // TODO: throw exception
{
if (tmpData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND) if (actionDoneData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND)
{ tmpPlayer->setMyButton(BUTTON_SMALL_BLIND);
assert(tmpPlayer->getMyButton() == BUTTON_SMALL_BLIND); else if (actionDoneData.gameState == GAME_STATE_PREFLOP_BIG_BLIND)
tmpPlayer->setMyAction(tmpData.playerAction); tmpPlayer->setMyButton(BUTTON_BIG_BLIND);
tmpPlayer->setMySet(tmpData.cashValue);
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().refreshSet();
client.GetGui().refreshPot(); client.GetGui().refreshPot();
client.GetGui().refreshAction();
} }
else if (tmpData.gameState == GAME_STATE_PREFLOP_BIG_BLIND) else if (tmpPacket->ToNetPacketPlayersTurn())
{ {
assert(tmpPlayer->getMyButton() == BUTTON_BIG_BLIND); NetPacketPlayersTurn::Data turnData;
tmpPlayer->setMyAction(tmpData.playerAction); tmpPacket->ToNetPacketPlayersTurn()->GetData(turnData);
tmpPlayer->setMySet(tmpData.cashValue); PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(turnData.playerId);
client.GetGui().refreshSet(); assert(tmpPlayer); // TODO: throw exception
client.GetGui().refreshPot();
} if (tmpPlayer->getMyID() == 0) // Is this the GUI player?
{
client.GetGui().meInAction();
} }
} }
} }
+14
View File
@@ -81,6 +81,20 @@ ClientThread::Init(
context.SetPlayerName(playerName); context.SetPlayerName(playerName);
} }
void
ClientThread::SendPlayerAction()
{
// TODO: ugly hack
boost::shared_ptr<NetPacket> 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<NetPacketPlayersAction *>(action.get())->SetData(actionData);
GetSender().Send(GetContext().GetSocket(), action);
}
ClientCallback & ClientCallback &
ClientThread::GetCallback() ClientThread::GetCallback()
{ {
+21 -12
View File
@@ -88,7 +88,7 @@ struct GCC_PACKED NetPacketJoinGameAckData
u_int16_t smallBlind; u_int16_t smallBlind;
u_int16_t handsBeforeRaise; u_int16_t handsBeforeRaise;
u_int16_t proposedGuiSpeed; u_int16_t proposedGuiSpeed;
u_int32_t startCash; u_int32_t startMoney;
}; };
struct GCC_PACKED NetPacketJoinGameErrorData struct GCC_PACKED NetPacketJoinGameErrorData
@@ -140,7 +140,7 @@ struct GCC_PACKED NetPacketPlayersActionData
NetPacketHeader head; NetPacketHeader head;
u_int16_t gameState; u_int16_t gameState;
u_int16_t playerAction; u_int16_t playerAction;
u_int32_t cashValue; u_int32_t playerBet;
}; };
struct GCC_PACKED NetPacketPlayersActionDoneData struct GCC_PACKED NetPacketPlayersActionDoneData
@@ -150,7 +150,10 @@ struct GCC_PACKED NetPacketPlayersActionDoneData
u_int16_t playerId; u_int16_t playerId;
u_int16_t playerAction; u_int16_t playerAction;
u_int16_t reserved; 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 struct GCC_PACKED NetPacketPlayersActionRejectedData
@@ -158,7 +161,7 @@ struct GCC_PACKED NetPacketPlayersActionRejectedData
NetPacketHeader head; NetPacketHeader head;
u_int16_t gameState; u_int16_t gameState;
u_int16_t playerAction; u_int16_t playerAction;
u_int32_t cashValue; u_int32_t playerBet;
u_int16_t rejectionReason; u_int16_t rejectionReason;
u_int16_t reserved; u_int16_t reserved;
}; };
@@ -554,7 +557,7 @@ NetPacketJoinGameAck::SetData(const NetPacketJoinGameAck::Data &inData)
tmpData->smallBlind = htons(inData.gameData.smallBlind); tmpData->smallBlind = htons(inData.gameData.smallBlind);
tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise); tmpData->handsBeforeRaise = htons(inData.gameData.handsBeforeRaise);
tmpData->proposedGuiSpeed = htons(inData.gameData.guiSpeed); tmpData->proposedGuiSpeed = htons(inData.gameData.guiSpeed);
tmpData->startCash = htonl(inData.gameData.startCash); tmpData->startMoney = htonl(inData.gameData.startMoney);
} }
void void
@@ -570,7 +573,7 @@ NetPacketJoinGameAck::GetData(NetPacketJoinGameAck::Data &outData) const
outData.gameData.smallBlind = ntohs(tmpData->smallBlind); outData.gameData.smallBlind = ntohs(tmpData->smallBlind);
outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise); outData.gameData.handsBeforeRaise = ntohs(tmpData->handsBeforeRaise);
outData.gameData.guiSpeed = ntohs(tmpData->proposedGuiSpeed); outData.gameData.guiSpeed = ntohs(tmpData->proposedGuiSpeed);
outData.gameData.startCash = ntohl(tmpData->startCash); outData.gameData.startMoney = ntohl(tmpData->startMoney);
} }
const NetPacketJoinGameAck * const NetPacketJoinGameAck *
@@ -983,7 +986,7 @@ NetPacketPlayersAction::SetData(const NetPacketPlayersAction::Data &inData)
tmpData->gameState = htons(inData.gameState); tmpData->gameState = htons(inData.gameState);
tmpData->playerAction = htons(inData.playerAction); tmpData->playerAction = htons(inData.playerAction);
tmpData->cashValue = htonl(inData.cashValue); tmpData->playerBet = htonl(inData.playerBet);
} }
void void
@@ -994,7 +997,7 @@ NetPacketPlayersAction::GetData(NetPacketPlayersAction::Data &outData) const
outData.gameState = static_cast<GameState>(ntohs(tmpData->gameState)); outData.gameState = static_cast<GameState>(ntohs(tmpData->gameState));
outData.playerAction = static_cast<PlayerAction>(ntohs(tmpData->playerAction)); outData.playerAction = static_cast<PlayerAction>(ntohs(tmpData->playerAction));
outData.cashValue = ntohl(tmpData->cashValue); outData.playerBet = ntohl(tmpData->playerBet);
} }
const NetPacketPlayersAction * const NetPacketPlayersAction *
@@ -1061,7 +1064,10 @@ NetPacketPlayersActionDone::SetData(const NetPacketPlayersActionDone::Data &inDa
tmpData->gameState = htons(inData.gameState); tmpData->gameState = htons(inData.gameState);
tmpData->playerId = htons(inData.playerId); tmpData->playerId = htons(inData.playerId);
tmpData->playerAction = htons(inData.playerAction); 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 void
@@ -1073,7 +1079,10 @@ NetPacketPlayersActionDone::GetData(NetPacketPlayersActionDone::Data &outData) c
outData.gameState = static_cast<GameState>(ntohs(tmpData->gameState)); outData.gameState = static_cast<GameState>(ntohs(tmpData->gameState));
outData.playerId = ntohs(tmpData->playerId); outData.playerId = ntohs(tmpData->playerId);
outData.playerAction = static_cast<PlayerAction>(ntohs(tmpData->playerAction)); outData.playerAction = static_cast<PlayerAction>(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 * const NetPacketPlayersActionDone *
@@ -1135,7 +1144,7 @@ NetPacketPlayersActionRejected::SetData(const NetPacketPlayersActionRejected::Da
tmpData->gameState = htons(inData.gameState); tmpData->gameState = htons(inData.gameState);
tmpData->playerAction = htons(inData.playerAction); tmpData->playerAction = htons(inData.playerAction);
tmpData->cashValue = htonl(inData.cashValue); tmpData->playerBet = htonl(inData.playerBet);
// TODO: set rejection reason // TODO: set rejection reason
tmpData->rejectionReason = htons(0); tmpData->rejectionReason = htons(0);
@@ -1149,7 +1158,7 @@ NetPacketPlayersActionRejected::GetData(NetPacketPlayersActionRejected::Data &ou
outData.gameState = static_cast<GameState>(ntohs(tmpData->gameState)); outData.gameState = static_cast<GameState>(ntohs(tmpData->gameState));
outData.playerAction = static_cast<PlayerAction>(ntohs(tmpData->playerAction)); outData.playerAction = static_cast<PlayerAction>(ntohs(tmpData->playerAction));
outData.cashValue = ntohl(tmpData->cashValue); outData.playerBet = ntohl(tmpData->playerBet);
// TODO: set rejection reason // TODO: set rejection reason
} }
+85 -6
View File
@@ -294,6 +294,9 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards); server.GetSender().Send(playerArray[i]->getNetSessionData()->GetSocket(), notifyCards);
} }
// Start hand.
curGame.startHand();
// Auto small blind / big blind at the beginning of hand. // Auto small blind / big blind at the beginning of hand.
for (int i = 0; i < curGame.getActualQuantityPlayers(); i++) for (int i = 0; i < curGame.getActualQuantityPlayers(); i++)
{ {
@@ -304,7 +307,10 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND; actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND;
actionDoneData.playerId = playerArray[i]->getMyUniqueID(); actionDoneData.playerId = playerArray[i]->getMyUniqueID();
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction(); 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<NetPacketPlayersActionDone *>(notifySmallBlind.get())->SetData(actionDoneData); static_cast<NetPacketPlayersActionDone *>(notifySmallBlind.get())->SetData(actionDoneData);
server.SendToAllPlayers(notifySmallBlind); server.SendToAllPlayers(notifySmallBlind);
break; break;
@@ -319,16 +325,16 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND; actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND;
actionDoneData.playerId = playerArray[i]->getMyUniqueID(); actionDoneData.playerId = playerArray[i]->getMyUniqueID();
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction(); 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<NetPacketPlayersActionDone *>(notifyBigBlind.get())->SetData(actionDoneData); static_cast<NetPacketPlayersActionDone *>(notifyBigBlind.get())->SetData(actionDoneData);
server.SendToAllPlayers(notifyBigBlind); server.SendToAllPlayers(notifyBigBlind);
break; break;
} }
} }
// Start hand.
curGame.startHand();
server.SetState(ServerRecvStateStartRound::Instance()); server.SetState(ServerRecvStateStartRound::Instance());
return MSG_NET_GAME_SERVER_HAND; return MSG_NET_GAME_SERVER_HAND;
@@ -386,7 +392,7 @@ ServerRecvStateStartRound::Process(ServerRecvThread &server)
server.SendToAllPlayers(notification); server.SendToAllPlayers(notification);
server.SetState(ServerRecvStateFinal::Instance()); server.SetState(ServerRecvStateWaitPlayerAction::Instance());
return MSG_NET_GAME_SERVER_ROUND; return MSG_NET_GAME_SERVER_ROUND;
} }
@@ -444,6 +450,79 @@ ServerRecvStateStartRound::GetCurrentPlayer(Game &curGame)
return curGame.getPlayerArray()[curPlayerNum]; return curGame.getPlayerArray()[curPlayerNum];
} }
//-----------------------------------------------------------------------------
ServerRecvStateWaitPlayerAction &
ServerRecvStateWaitPlayerAction::Instance()
{
static ServerRecvStateWaitPlayerAction state;
return state;
}
ServerRecvStateWaitPlayerAction::ServerRecvStateWaitPlayerAction()
{
}
ServerRecvStateWaitPlayerAction::~ServerRecvStateWaitPlayerAction()
{
}
void
ServerRecvStateWaitPlayerAction::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> 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<NetPacket> 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<NetPacket> 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<NetPacketPlayersActionDone *>(notifyActionDone.get())->SetData(actionDoneData);
server.SendToAllPlayers(notifyActionDone);
}
}
}
return MSG_SOCK_INTERNAL_PENDING;
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
+1 -1
View File
@@ -54,7 +54,7 @@ private:
ServerRecvThread::ServerRecvThread(GuiInterface &gui, ConfigFile *playerConfig) 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_senderCallback.reset(new ServerSenderCallback(*this));
m_sender.reset(new SenderThread(GetSenderCallback())); m_sender.reset(new SenderThread(GetSenderCallback()));
+6 -3
View File
@@ -269,7 +269,7 @@ public:
{ {
GameState gameState; GameState gameState;
PlayerAction playerAction; PlayerAction playerAction;
u_int32_t cashValue; u_int32_t playerBet;
}; };
NetPacketPlayersAction(); NetPacketPlayersAction();
@@ -295,7 +295,10 @@ public:
GameState gameState; GameState gameState;
u_int16_t playerId; u_int16_t playerId;
PlayerAction playerAction; PlayerAction playerAction;
u_int32_t cashValue; u_int32_t playerBet;
u_int32_t curPlayerMoney;
u_int32_t potSize;
u_int32_t curHandBets;
}; };
NetPacketPlayersActionDone(); NetPacketPlayersActionDone();
@@ -321,7 +324,7 @@ public:
{ {
GameState gameState; GameState gameState;
PlayerAction playerAction; PlayerAction playerAction;
u_int32_t cashValue; u_int32_t playerBet;
int rejectionReason; int rejectionReason;
}; };
+22
View File
@@ -135,6 +135,28 @@ protected:
PlayerInterface *GetCurrentPlayer(Game &curGame); 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<ConnectData> data);
//
virtual int Process(ServerRecvThread &server);
protected:
// Protected constructor - this is a singleton.
ServerRecvStateWaitPlayerAction();
};
// State: Final. // State: Final.
class ServerRecvStateFinal : public ServerRecvState class ServerRecvStateFinal : public ServerRecvState
{ {
+1
View File
@@ -166,6 +166,7 @@ friend class ServerRecvStateInit;
friend class ServerRecvStateStartGame; friend class ServerRecvStateStartGame;
friend class ServerRecvStateStartHand; friend class ServerRecvStateStartHand;
friend class ServerRecvStateStartRound; friend class ServerRecvStateStartRound;
friend class ServerRecvStateWaitPlayerAction;
friend class ServerRecvStateFinal; friend class ServerRecvStateFinal;
}; };
+7
View File
@@ -182,3 +182,10 @@ void Session::terminateNetworkServer()
myNetServer = 0; myNetServer = 0;
} }
void Session::sendClientPlayerAction()
{
if (!myNetClient)
return;
myNetClient->SendPlayerAction();
}
+2
View File
@@ -53,6 +53,8 @@ public:
void initiateNetworkServerGame(); void initiateNetworkServerGame();
void terminateNetworkServer(); void terminateNetworkServer();
void sendClientPlayerAction();
void setCurrentGameID(const int& theValue) { currentGameID = theValue; } void setCurrentGameID(const int& theValue) { currentGameID = theValue; }
int getCurrentGameID() const { return currentGameID; } int getCurrentGameID() const { return currentGameID; }