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
+1
View File
@@ -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;
-2
View File
@@ -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;
+1
View File
@@ -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() ;
+1
View File
@@ -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();
+13 -42
View File
@@ -43,7 +43,19 @@ ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, Boar
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
ClientHand::switchRounds()
{
+3 -4
View File
@@ -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 <riverinterface.h>
class ClientHand : public HandInterface{
class ClientHand : public HandInterface
{
public:
ClientHand(boost::shared_ptr<EngineFactory> 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();
+1 -1
View File
@@ -33,7 +33,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> 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)
+2 -2
View File
@@ -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;
+17 -13
View File
@@ -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);
}
+2
View File
@@ -51,6 +51,8 @@ public:
const std::string &pwd,
const std::string &playerName);
void SendPlayerAction();
ClientCallback &GetCallback();
GuiInterface &GetGui();
+28 -20
View File
@@ -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();
}
}
}
+14
View File
@@ -81,6 +81,20 @@ ClientThread::Init(
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 &
ClientThread::GetCallback()
{
+21 -12
View File
@@ -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<GameState>(ntohs(tmpData->gameState));
outData.playerAction = static_cast<PlayerAction>(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<GameState>(ntohs(tmpData->gameState));
outData.playerId = ntohs(tmpData->playerId);
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 *
@@ -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<GameState>(ntohs(tmpData->gameState));
outData.playerAction = static_cast<PlayerAction>(ntohs(tmpData->playerAction));
outData.cashValue = ntohl(tmpData->cashValue);
outData.playerBet = ntohl(tmpData->playerBet);
// TODO: set rejection reason
}
+85 -6
View File
@@ -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<NetPacketPlayersActionDone *>(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<NetPacketPlayersActionDone *>(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<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)
: 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()));
+6 -3
View File
@@ -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;
};
+22
View File
@@ -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<ConnectData> data);
//
virtual int Process(ServerRecvThread &server);
protected:
// Protected constructor - this is a singleton.
ServerRecvStateWaitPlayerAction();
};
// State: Final.
class ServerRecvStateFinal : public ServerRecvState
{
+1
View File
@@ -166,6 +166,7 @@ friend class ServerRecvStateInit;
friend class ServerRecvStateStartGame;
friend class ServerRecvStateStartHand;
friend class ServerRecvStateStartRound;
friend class ServerRecvStateWaitPlayerAction;
friend class ServerRecvStateFinal;
};
+7
View File
@@ -182,3 +182,10 @@ void Session::terminateNetworkServer()
myNetServer = 0;
}
void Session::sendClientPlayerAction()
{
if (!myNetClient)
return;
myNetClient->SendPlayerAction();
}
+2
View File
@@ -53,6 +53,8 @@ public:
void initiateNetworkServerGame();
void terminateNetworkServer();
void sendClientPlayerAction();
void setCurrentGameID(const int& theValue) { currentGameID = theValue; }
int getCurrentGameID() const { return currentGameID; }