Network: First round seems to work fine now. Pot/sets not yet displayed correctly.
This commit is contained in:
@@ -28,7 +28,7 @@
|
||||
using namespace std;
|
||||
|
||||
LocalPlayer::LocalPlayer(ConfigFile *c, BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
|
||||
: PlayerInterface(), myConfig(c), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0)
|
||||
: PlayerInterface(), myConfig(c), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0)
|
||||
{
|
||||
|
||||
// for statistic development
|
||||
|
||||
@@ -43,10 +43,10 @@ public:
|
||||
unsigned getMyUniqueID() const { return myUniqueID; }
|
||||
PlayerType getMyType() const { return myType; }
|
||||
|
||||
void setMyDude(const int& theValue) { myDude = theValue; }
|
||||
void setMyDude(int theValue) { myDude = theValue; }
|
||||
int getMyDude() const { return myDude; }
|
||||
|
||||
void setMyDude4(const int& theValue) { myDude4 = theValue; }
|
||||
void setMyDude4(int theValue) { myDude4 = theValue; }
|
||||
int getMyDude4() const { return myDude4; }
|
||||
|
||||
void setMyName(const std::string& theValue) { myName = theValue; }
|
||||
@@ -55,17 +55,19 @@ public:
|
||||
void setMyAvatar(const std::string& theValue) { myAvatar = theValue; }
|
||||
std::string getMyAvatar() const { return myAvatar; }
|
||||
|
||||
void setMyCash(const int& theValue) { myCash = theValue; }
|
||||
void setMyCash(int theValue) { myCash = theValue; }
|
||||
int getMyCash() const { return myCash; }
|
||||
|
||||
void setMySet(const int& theValue) { mySet += theValue; myCash -= theValue; }
|
||||
void setMySet(int theValue) { myLastRelativeSet = theValue; mySet += theValue; myCash -= theValue; }
|
||||
void setMySetAbsolute(int theValue) { mySet = theValue; }
|
||||
void setMySetNull() { mySet = 0; }
|
||||
int getMySet() const { return mySet;}
|
||||
int getMyLastRelativeSet() const { return myLastRelativeSet; }
|
||||
|
||||
void setMyAction(const int& theValue) { myAction = theValue; }
|
||||
void setMyAction(int theValue) { myAction = theValue; }
|
||||
int getMyAction() const { return myAction; }
|
||||
|
||||
void setMyButton(const int& theValue) { myButton = theValue; }
|
||||
void setMyButton(int theValue) { myButton = theValue; }
|
||||
int getMyButton() const { return myButton; }
|
||||
|
||||
void setMyActiveStatus(bool theValue) { myActiveStatus = theValue; }
|
||||
@@ -80,18 +82,18 @@ public:
|
||||
void setMyCardsFlip(bool theValue){ myCardsFlip = theValue;}
|
||||
bool getMyCardsFlip() const{ return myCardsFlip;}
|
||||
|
||||
void setMyCardsValueInt(const int& theValue) { myCardsValueInt = theValue;}
|
||||
void setMyCardsValueInt(int theValue) { myCardsValueInt = theValue;}
|
||||
int getMyCardsValueInt() const { return myCardsValueInt; }
|
||||
|
||||
int* getMyBestHandPosition() { return myBestHandPosition; }
|
||||
|
||||
void setMyRoundStartCash(const int& theValue) { myRoundStartCash = theValue;}
|
||||
void setMyRoundStartCash(int theValue) { myRoundStartCash = theValue;}
|
||||
int getMyRoundStartCash() const { return myRoundStartCash; }
|
||||
|
||||
void setMyAverageSets(const int& theValue) { myAverageSets[0] = myAverageSets[1]; myAverageSets[1] = myAverageSets[2]; myAverageSets[2] = myAverageSets[3]; myAverageSets[3] = theValue; }
|
||||
void setMyAverageSets(int theValue) { myAverageSets[0] = myAverageSets[1]; myAverageSets[1] = myAverageSets[2]; myAverageSets[2] = myAverageSets[3]; myAverageSets[3] = theValue; }
|
||||
int getMyAverageSets() const { return (myAverageSets[0]+myAverageSets[1]+myAverageSets[2]+myAverageSets[3])/4; }
|
||||
|
||||
void setMyAggressive(const bool& theValue) {
|
||||
void setMyAggressive(bool theValue) {
|
||||
int i;
|
||||
for(i=0; i<6; i++) {
|
||||
myAggressive[i] = myAggressive[i+1];
|
||||
@@ -162,6 +164,7 @@ private:
|
||||
int myCards[2];
|
||||
int myCash;
|
||||
int mySet;
|
||||
int myLastRelativeSet;
|
||||
int myAction; // 0 = none, 1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
|
||||
int myButton; // 0 = none, 1 = dealer, 2 =small, 3 = big
|
||||
bool myActiveStatus; // 0 = inactive, 1 = active
|
||||
|
||||
@@ -51,11 +51,11 @@ ClientHand::ClientHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, Boar
|
||||
|
||||
// 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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ using namespace std;
|
||||
|
||||
|
||||
ClientPlayer::ClientPlayer(ConfigFile *c, BoardInterface *b, int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB)
|
||||
: PlayerInterface(), myConfig(c), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0)
|
||||
: PlayerInterface(), myConfig(c), actualHand(0), actualBoard(b), myCardsValue(0), myID(id), myUniqueID(uniqueId), myType(type), myName(name), myAvatar(avatar), myDude(0), myDude4(0), myCardsValueInt(0), myOdds(-1.0), myCash(sC), mySet(0), myLastRelativeSet(0), myAction(0), myButton(mB), myActiveStatus(aS), myTurn(0), myRoundStartCash(0), sBluff(0), sBluffStatus(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -41,10 +41,10 @@ public:
|
||||
unsigned getMyUniqueID() const { return myUniqueID; }
|
||||
PlayerType getMyType() const { return myType; }
|
||||
|
||||
void setMyDude(const int& theValue) { myDude = theValue; }
|
||||
void setMyDude(int theValue) { myDude = theValue; }
|
||||
int getMyDude() const { return myDude; }
|
||||
|
||||
void setMyDude4(const int& theValue) { myDude4 = theValue; }
|
||||
void setMyDude4(int theValue) { myDude4 = theValue; }
|
||||
int getMyDude4() const { return myDude4; }
|
||||
|
||||
void setMyName(const std::string& theValue) { myName = theValue; }
|
||||
@@ -53,17 +53,19 @@ public:
|
||||
void setMyAvatar(const std::string& theValue) { myAvatar = theValue; }
|
||||
std::string getMyAvatar() const { return myAvatar; }
|
||||
|
||||
void setMyCash(const int& theValue) { myCash = theValue; }
|
||||
void setMyCash(int theValue) { myCash = theValue; }
|
||||
int getMyCash() const { return myCash; }
|
||||
|
||||
void setMySet(const int& theValue) { mySet += theValue; myCash -= theValue; }
|
||||
void setMySetNull() { mySet = 0; }
|
||||
int getMySet() const { return mySet;}
|
||||
void setMySet(int theValue) { myLastRelativeSet = theValue; mySet += theValue; myCash -= theValue; }
|
||||
void setMySetAbsolute(int theValue) { mySet = theValue; }
|
||||
void setMySetNull() { mySet = 0; }
|
||||
int getMySet() const { return mySet;}
|
||||
int getMyLastRelativeSet() const { return myLastRelativeSet; }
|
||||
|
||||
void setMyAction(const int& theValue) { myAction = theValue; }
|
||||
void setMyAction(int theValue) { myAction = theValue; }
|
||||
int getMyAction() const { return myAction; }
|
||||
|
||||
void setMyButton(const int& theValue) { myButton = theValue; }
|
||||
void setMyButton(int theValue) { myButton = theValue; }
|
||||
int getMyButton() const { return myButton; }
|
||||
|
||||
void setMyActiveStatus(bool theValue) { myActiveStatus = theValue; }
|
||||
@@ -78,18 +80,18 @@ public:
|
||||
void setMyCardsFlip(bool theValue){ myCardsFlip = theValue;}
|
||||
bool getMyCardsFlip() const{ return myCardsFlip;}
|
||||
|
||||
void setMyCardsValueInt(const int& theValue) { myCardsValueInt = theValue;}
|
||||
void setMyCardsValueInt(int theValue) { myCardsValueInt = theValue;}
|
||||
int getMyCardsValueInt() const { return myCardsValueInt; }
|
||||
|
||||
int* getMyBestHandPosition() { return myBestHandPosition; }
|
||||
|
||||
void setMyRoundStartCash(const int& theValue) { myRoundStartCash = theValue;}
|
||||
void setMyRoundStartCash(int theValue) { myRoundStartCash = theValue;}
|
||||
int getMyRoundStartCash() const { return myRoundStartCash; }
|
||||
|
||||
void setMyAverageSets(const int& theValue) { myAverageSets[0] = myAverageSets[1]; myAverageSets[1] = myAverageSets[2]; myAverageSets[2] = myAverageSets[3]; myAverageSets[3] = theValue; }
|
||||
void setMyAverageSets(int theValue) { myAverageSets[0] = myAverageSets[1]; myAverageSets[1] = myAverageSets[2]; myAverageSets[2] = myAverageSets[3]; myAverageSets[3] = theValue; }
|
||||
int getMyAverageSets() const { return (myAverageSets[0]+myAverageSets[1]+myAverageSets[2]+myAverageSets[3])/4; }
|
||||
|
||||
void setMyAggressive(const bool& theValue) {
|
||||
void setMyAggressive(bool theValue) {
|
||||
int i;
|
||||
for(i=0; i<6; i++) {
|
||||
myAggressive[i] = myAggressive[i+1];
|
||||
@@ -160,6 +162,7 @@ private:
|
||||
int myCards[2];
|
||||
int myCash;
|
||||
int mySet;
|
||||
int myLastRelativeSet;
|
||||
int myAction; // 0 = none, 1 = fold, 2 = check, 3 = call, 4 = bet, 5 = raise, 6 = allin
|
||||
int myButton; // 0 = none, 1 = dealer, 2 =small, 3 = big
|
||||
bool myActiveStatus; // 0 = inactive, 1 = active
|
||||
|
||||
@@ -38,10 +38,10 @@ public:
|
||||
virtual unsigned getMyUniqueID() const =0;
|
||||
virtual PlayerType getMyType() const =0;
|
||||
|
||||
virtual void setMyDude(const int& theValue) =0;
|
||||
virtual void setMyDude(int theValue) =0;
|
||||
virtual int getMyDude() const =0;
|
||||
|
||||
virtual void setMyDude4(const int& theValue) =0;
|
||||
virtual void setMyDude4(int theValue) =0;
|
||||
virtual int getMyDude4() const =0;
|
||||
|
||||
virtual void setMyName(const std::string& theValue) =0;
|
||||
@@ -50,17 +50,19 @@ public:
|
||||
virtual void setMyAvatar(const std::string& theValue) =0;
|
||||
virtual std::string getMyAvatar() const =0;
|
||||
|
||||
virtual void setMyCash(const int& theValue) =0;
|
||||
virtual void setMyCash(int theValue) =0;
|
||||
virtual int getMyCash() const =0;
|
||||
|
||||
virtual void setMySet(const int& theValue) =0;
|
||||
virtual void setMySet(int theValue) =0;
|
||||
virtual void setMySetAbsolute(int theValue) =0;
|
||||
virtual void setMySetNull() =0;
|
||||
virtual int getMySet() const =0;
|
||||
virtual int getMyLastRelativeSet() const =0;
|
||||
|
||||
virtual void setMyAction(const int& theValue) =0;
|
||||
virtual void setMyAction(int theValue) =0;
|
||||
virtual int getMyAction() const =0;
|
||||
|
||||
virtual void setMyButton(const int& theValue) =0;
|
||||
virtual void setMyButton(int theValue) =0;
|
||||
virtual int getMyButton() const =0;
|
||||
|
||||
virtual void setMyActiveStatus(bool theValue) =0;
|
||||
@@ -75,18 +77,18 @@ public:
|
||||
virtual void setMyCardsFlip(bool theValue) =0;
|
||||
virtual bool getMyCardsFlip() const =0;
|
||||
|
||||
virtual void setMyCardsValueInt(const int& theValue) =0;
|
||||
virtual void setMyCardsValueInt(int theValue) =0;
|
||||
virtual int getMyCardsValueInt() const =0;
|
||||
|
||||
virtual int* getMyBestHandPosition() =0;
|
||||
|
||||
virtual void setMyRoundStartCash(const int& theValue) =0;
|
||||
virtual void setMyRoundStartCash(int theValue) =0;
|
||||
virtual int getMyRoundStartCash() const =0;
|
||||
|
||||
virtual void setMyAverageSets(const int& theValue) =0;
|
||||
virtual void setMyAverageSets(int theValue) =0;
|
||||
virtual int getMyAverageSets() const =0;
|
||||
|
||||
virtual void setMyAggressive(const bool& theValue) =0;
|
||||
virtual void setMyAggressive(bool theValue) =0;
|
||||
virtual int getMyAggressive() const =0;
|
||||
|
||||
virtual void setSBluff ( int theValue ) =0;
|
||||
|
||||
@@ -1485,7 +1485,7 @@ void mainWindowImpl::myFold(){
|
||||
statusBar()->clearMessage();
|
||||
|
||||
//Spiel läuft weiter
|
||||
nextPlayerAnimation();
|
||||
myActionDone();
|
||||
}
|
||||
|
||||
void mainWindowImpl::myCheck() {
|
||||
@@ -1504,7 +1504,7 @@ void mainWindowImpl::myCheck() {
|
||||
statusBar()->clearMessage();
|
||||
|
||||
//Spiel läuft weiter
|
||||
nextPlayerAnimation();
|
||||
myActionDone();
|
||||
}
|
||||
|
||||
void mainWindowImpl::myCall(){
|
||||
@@ -1550,7 +1550,7 @@ void mainWindowImpl::myCall(){
|
||||
statusBar()->clearMessage();
|
||||
|
||||
//Spiel läuft weiter
|
||||
nextPlayerAnimation();
|
||||
myActionDone();
|
||||
}
|
||||
|
||||
void mainWindowImpl::myBet(){
|
||||
@@ -1648,7 +1648,7 @@ void mainWindowImpl::mySet(){
|
||||
currentHand->setLastPlayersTurn(0);
|
||||
|
||||
//Spiel läuft weiter
|
||||
nextPlayerAnimation();
|
||||
myActionDone();
|
||||
}
|
||||
|
||||
void mainWindowImpl::myAllIn(){
|
||||
@@ -1686,14 +1686,20 @@ void mainWindowImpl::myAllIn(){
|
||||
currentHand->setLastPlayersTurn(0);
|
||||
|
||||
//Spiel läuft weiter
|
||||
myActionDone();
|
||||
}
|
||||
|
||||
void mainWindowImpl::myActionDone() {
|
||||
|
||||
// If a network client is running, we need
|
||||
// to transfer the action to the server.
|
||||
mySession->sendClientPlayerAction();
|
||||
|
||||
nextPlayerAnimation();
|
||||
}
|
||||
|
||||
void mainWindowImpl::nextPlayerAnimation() {
|
||||
|
||||
// TODO ugliest hack ever
|
||||
mySession->sendClientPlayerAction();
|
||||
|
||||
HandInterface *currentHand = mySession->getCurrentGame()->getCurrentHand();
|
||||
|
||||
//refresh Change Player
|
||||
|
||||
@@ -159,6 +159,8 @@ public slots:
|
||||
void myRaise();
|
||||
void myAllIn();
|
||||
|
||||
void myActionDone();
|
||||
|
||||
void dealFlopCards0();
|
||||
void dealFlopCards1();
|
||||
void dealFlopCards2();
|
||||
|
||||
@@ -219,6 +219,24 @@ protected:
|
||||
ClientStateWaitHand();
|
||||
};
|
||||
|
||||
// State: Hand Loop.
|
||||
class ClientStateRunHand : public ClientState
|
||||
{
|
||||
public:
|
||||
// Access the state singleton.
|
||||
static ClientStateRunHand &Instance();
|
||||
|
||||
virtual ~ClientStateRunHand();
|
||||
|
||||
// select on socket.
|
||||
virtual int Process(ClientThread &client);
|
||||
|
||||
protected:
|
||||
|
||||
// Protected constructor - this is a singleton.
|
||||
ClientStateRunHand();
|
||||
};
|
||||
|
||||
// State: Final (TODO).
|
||||
class ClientStateFinal : public ClientState
|
||||
{
|
||||
|
||||
@@ -114,6 +114,7 @@ friend class ClientStateStartSession;
|
||||
friend class ClientStateWaitSession;
|
||||
friend class ClientStateWaitGame;
|
||||
friend class ClientStateWaitHand;
|
||||
friend class ClientStateRunHand;
|
||||
friend class ClientStateFinal;
|
||||
};
|
||||
|
||||
|
||||
@@ -498,16 +498,18 @@ ClientStateWaitHand::~ClientStateWaitHand()
|
||||
int
|
||||
ClientStateWaitHand::Process(ClientThread &client)
|
||||
{
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
ClientContext &context = client.GetContext();
|
||||
|
||||
// delegate to receiver helper class
|
||||
// Delegate to receiver helper class.
|
||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
||||
|
||||
if (tmpPacket.get())
|
||||
{
|
||||
// TODO: Hack
|
||||
if (tmpPacket->ToNetPacketHandStart())
|
||||
{
|
||||
// Hand was started.
|
||||
// These are the cards. Good luck.
|
||||
NetPacketHandStart::Data tmpData;
|
||||
tmpPacket->ToNetPacketHandStart()->GetData(tmpData);
|
||||
int myCards[2];
|
||||
@@ -517,12 +519,48 @@ ClientStateWaitHand::Process(ClientThread &client)
|
||||
client.GetGame()->initHand();
|
||||
client.GetGame()->startHand();
|
||||
client.GetGui().dealHoleCards();
|
||||
client.SetState(ClientStateRunHand::Instance());
|
||||
|
||||
retVal = MSG_NET_GAME_CLIENT_HAND;
|
||||
}
|
||||
else if (tmpPacket->ToNetPacketPlayersActionDone())
|
||||
}
|
||||
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ClientStateRunHand &
|
||||
ClientStateRunHand::Instance()
|
||||
{
|
||||
static ClientStateRunHand state;
|
||||
return state;
|
||||
}
|
||||
|
||||
ClientStateRunHand::ClientStateRunHand()
|
||||
{
|
||||
}
|
||||
|
||||
ClientStateRunHand::~ClientStateRunHand()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
ClientStateRunHand::Process(ClientThread &client)
|
||||
{
|
||||
ClientContext &context = client.GetContext();
|
||||
|
||||
// Delegate to receiver helper class.
|
||||
boost::shared_ptr<NetPacket> tmpPacket = client.GetReceiver().Recv(context.GetSocket());
|
||||
|
||||
if (tmpPacket.get())
|
||||
{
|
||||
boost::shared_ptr<Game> curGame = client.GetGame();
|
||||
if (tmpPacket->ToNetPacketPlayersActionDone())
|
||||
{
|
||||
NetPacketPlayersActionDone::Data actionDoneData;
|
||||
tmpPacket->ToNetPacketPlayersActionDone()->GetData(actionDoneData);
|
||||
PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(actionDoneData.playerId);
|
||||
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(actionDoneData.playerId);
|
||||
assert(tmpPlayer); // TODO: throw exception
|
||||
|
||||
if (actionDoneData.gameState == GAME_STATE_PREFLOP_SMALL_BLIND)
|
||||
@@ -531,10 +569,10 @@ ClientStateWaitHand::Process(ClientThread &client)
|
||||
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);
|
||||
tmpPlayer->setMySetAbsolute(actionDoneData.totalPlayerBet);
|
||||
tmpPlayer->setMyCash(actionDoneData.playerMoney);
|
||||
curGame->getCurrentHand()->getBoard()->setPot(actionDoneData.potSize);
|
||||
curGame->getCurrentHand()->getBoard()->setSets(actionDoneData.curHandBets);
|
||||
client.GetGui().refreshSet();
|
||||
client.GetGui().refreshPot();
|
||||
client.GetGui().refreshAction();
|
||||
@@ -543,13 +581,36 @@ ClientStateWaitHand::Process(ClientThread &client)
|
||||
{
|
||||
NetPacketPlayersTurn::Data turnData;
|
||||
tmpPacket->ToNetPacketPlayersTurn()->GetData(turnData);
|
||||
PlayerInterface *tmpPlayer = client.GetGame()->getPlayerByUniqueId(turnData.playerId);
|
||||
PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(turnData.playerId);
|
||||
assert(tmpPlayer); // TODO: throw exception
|
||||
|
||||
if (tmpPlayer->getMyID() == 0) // Is this the GUI player?
|
||||
{
|
||||
client.GetGui().meInAction();
|
||||
// Set round.
|
||||
curGame->getCurrentHand()->setActualRound(turnData.gameState);
|
||||
|
||||
// Next player's turn.
|
||||
// TODO: no switch needed here if game states are polymorphic
|
||||
switch(turnData.gameState) {
|
||||
case GAME_STATE_PREFLOP: {
|
||||
curGame->getCurrentHand()->getPreflop()->setPlayersTurn(tmpPlayer->getMyID());
|
||||
} break;
|
||||
case GAME_STATE_FLOP: {
|
||||
curGame->getCurrentHand()->getFlop()->setPlayersTurn(tmpPlayer->getMyID());
|
||||
} break;
|
||||
case GAME_STATE_TURN: {
|
||||
curGame->getCurrentHand()->getTurn()->setPlayersTurn(tmpPlayer->getMyID());
|
||||
} break;
|
||||
case GAME_STATE_RIVER: {
|
||||
curGame->getCurrentHand()->getRiver()->setPlayersTurn(tmpPlayer->getMyID());
|
||||
} break;
|
||||
default: {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
client.GetGui().nextPlayerAnimation();
|
||||
|
||||
if (tmpPlayer->getMyID() == 0) // Is this the GUI player?
|
||||
client.GetGui().meInAction();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,14 +84,15 @@ ClientThread::Init(
|
||||
void
|
||||
ClientThread::SendPlayerAction()
|
||||
{
|
||||
// TODO: ugly hack
|
||||
|
||||
// Warning: This function is called in the context of the GUI thread.
|
||||
// Create a network packet containing the current player action.
|
||||
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();
|
||||
actionData.gameState = static_cast<GameState>(GetGame()->getCurrentHand()->getActualRound());
|
||||
actionData.playerAction = static_cast<PlayerAction>(GetGame()->getPlayerArray()[0]->getMyAction());
|
||||
actionData.playerBet = GetGame()->getPlayerArray()[0]->getMyLastRelativeSet();
|
||||
static_cast<NetPacketPlayersAction *>(action.get())->SetData(actionData);
|
||||
// The sender is thread-safe, so just dump the packet.
|
||||
GetSender().Send(GetContext().GetSocket(), action);
|
||||
}
|
||||
|
||||
|
||||
@@ -150,8 +150,8 @@ struct GCC_PACKED NetPacketPlayersActionDoneData
|
||||
u_int16_t playerId;
|
||||
u_int16_t playerAction;
|
||||
u_int16_t reserved;
|
||||
u_int32_t playerBet;
|
||||
u_int32_t curPlayerMoney;
|
||||
u_int32_t totalPlayerBet;
|
||||
u_int32_t playerMoney;
|
||||
u_int32_t potSize;
|
||||
u_int32_t curHandBets;
|
||||
};
|
||||
@@ -1064,8 +1064,8 @@ NetPacketPlayersActionDone::SetData(const NetPacketPlayersActionDone::Data &inDa
|
||||
tmpData->gameState = htons(inData.gameState);
|
||||
tmpData->playerId = htons(inData.playerId);
|
||||
tmpData->playerAction = htons(inData.playerAction);
|
||||
tmpData->playerBet = htonl(inData.playerBet);
|
||||
tmpData->curPlayerMoney = htonl(inData.curPlayerMoney);
|
||||
tmpData->totalPlayerBet = htonl(inData.totalPlayerBet);
|
||||
tmpData->playerMoney = htonl(inData.playerMoney);
|
||||
tmpData->potSize = htonl(inData.potSize);
|
||||
tmpData->curHandBets = htonl(inData.curHandBets);
|
||||
}
|
||||
@@ -1079,8 +1079,8 @@ 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.playerBet = ntohl(tmpData->playerBet);
|
||||
outData.curPlayerMoney = ntohl(tmpData->curPlayerMoney);
|
||||
outData.totalPlayerBet = ntohl(tmpData->totalPlayerBet);
|
||||
outData.playerMoney = ntohl(tmpData->playerMoney);
|
||||
outData.potSize = ntohl(tmpData->potSize);
|
||||
outData.curHandBets = ntohl(tmpData->curHandBets);
|
||||
}
|
||||
|
||||
@@ -207,6 +207,23 @@ ServerRecvStateInit::Process(ServerRecvThread &server)
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateRunning::ServerRecvStateRunning()
|
||||
{
|
||||
}
|
||||
|
||||
ServerRecvStateRunning::~ServerRecvStateRunning()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateRunning::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
ServerRecvStateStartGame &
|
||||
ServerRecvStateStartGame::Instance()
|
||||
{
|
||||
@@ -222,13 +239,6 @@ ServerRecvStateStartGame::~ServerRecvStateStartGame()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateStartGame::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateStartGame::Process(ServerRecvThread &server)
|
||||
{
|
||||
@@ -261,13 +271,6 @@ ServerRecvStateStartHand::~ServerRecvStateStartHand()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateStartHand::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
||||
{
|
||||
@@ -307,8 +310,8 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
||||
actionDoneData.gameState = GAME_STATE_PREFLOP_SMALL_BLIND;
|
||||
actionDoneData.playerId = playerArray[i]->getMyUniqueID();
|
||||
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction();
|
||||
actionDoneData.playerBet = playerArray[i]->getMySet();
|
||||
actionDoneData.curPlayerMoney = playerArray[i]->getMyCash();
|
||||
actionDoneData.totalPlayerBet = playerArray[i]->getMySet();
|
||||
actionDoneData.playerMoney = playerArray[i]->getMyCash();
|
||||
actionDoneData.potSize = curGame.getCurrentHand()->getBoard()->getPot();
|
||||
actionDoneData.curHandBets = playerArray[i]->getMySet(); // first bet only
|
||||
static_cast<NetPacketPlayersActionDone *>(notifySmallBlind.get())->SetData(actionDoneData);
|
||||
@@ -325,8 +328,8 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server)
|
||||
actionDoneData.gameState = GAME_STATE_PREFLOP_BIG_BLIND;
|
||||
actionDoneData.playerId = playerArray[i]->getMyUniqueID();
|
||||
actionDoneData.playerAction = (PlayerAction)playerArray[i]->getMyAction();
|
||||
actionDoneData.playerBet = playerArray[i]->getMySet();
|
||||
actionDoneData.curPlayerMoney = playerArray[i]->getMyCash();
|
||||
actionDoneData.totalPlayerBet = playerArray[i]->getMySet();
|
||||
actionDoneData.playerMoney = playerArray[i]->getMyCash();
|
||||
actionDoneData.potSize = curGame.getCurrentHand()->getBoard()->getPot();
|
||||
actionDoneData.curHandBets = curGame.getCurrentHand()->getBoard()->getSets();
|
||||
static_cast<NetPacketPlayersActionDone *>(notifyBigBlind.get())->SetData(actionDoneData);
|
||||
@@ -357,13 +360,6 @@ ServerRecvStateStartRound::~ServerRecvStateStartRound()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateStartRound::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateStartRound::Process(ServerRecvThread &server)
|
||||
{
|
||||
@@ -402,19 +398,19 @@ ServerRecvStateStartRound::GameRun(Game &curGame, int state)
|
||||
{
|
||||
// TODO: no switch needed here if game states are polymorphic
|
||||
switch(state) {
|
||||
case 0: {
|
||||
case GAME_STATE_PREFLOP: {
|
||||
// Preflop starten
|
||||
curGame.getCurrentHand()->getPreflop()->preflopRun();
|
||||
} break;
|
||||
case 1: {
|
||||
case GAME_STATE_FLOP: {
|
||||
// Flop starten
|
||||
curGame.getCurrentHand()->getFlop()->flopRun();
|
||||
} break;
|
||||
case 2: {
|
||||
case GAME_STATE_TURN: {
|
||||
// Turn starten
|
||||
curGame.getCurrentHand()->getTurn()->turnRun();
|
||||
} break;
|
||||
case 3: {
|
||||
case GAME_STATE_RIVER: {
|
||||
// River starten
|
||||
curGame.getCurrentHand()->getRiver()->riverRun();
|
||||
} break;
|
||||
@@ -430,16 +426,16 @@ ServerRecvStateStartRound::GetCurrentPlayer(Game &curGame)
|
||||
int curPlayerNum = 0;
|
||||
// TODO: no switch needed here if game states are polymorphic
|
||||
switch(curGame.getCurrentHand()->getActualRound()) {
|
||||
case 0: {
|
||||
case GAME_STATE_PREFLOP: {
|
||||
curPlayerNum = curGame.getCurrentHand()->getPreflop()->getPlayersTurn();
|
||||
} break;
|
||||
case 1: {
|
||||
case GAME_STATE_FLOP: {
|
||||
curPlayerNum = curGame.getCurrentHand()->getFlop()->getPlayersTurn();
|
||||
} break;
|
||||
case 2: {
|
||||
case GAME_STATE_TURN: {
|
||||
curPlayerNum = curGame.getCurrentHand()->getTurn()->getPlayersTurn();
|
||||
} break;
|
||||
case 3: {
|
||||
case GAME_STATE_RIVER: {
|
||||
curPlayerNum = curGame.getCurrentHand()->getRiver()->getPlayersTurn();
|
||||
} break;
|
||||
default: {
|
||||
@@ -467,17 +463,10 @@ 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;
|
||||
int retVal = MSG_SOCK_INTERNAL_PENDING;
|
||||
SOCKET recvSock = server.Select();
|
||||
|
||||
if (recvSock != INVALID_SOCKET)
|
||||
@@ -505,23 +494,31 @@ ServerRecvStateWaitPlayerAction::Process(ServerRecvThread &server)
|
||||
packet->ToNetPacketPlayersAction()->GetData(actionData);
|
||||
|
||||
Game &curGame = server.GetGame();
|
||||
PlayerInterface *tmpPlayer = curGame.getPlayerByUniqueId(session.playerData->GetUniqueId());
|
||||
assert(tmpPlayer); // TODO throw exception
|
||||
|
||||
tmpPlayer->setMyAction(actionData.playerAction);
|
||||
tmpPlayer->setMySet(actionData.playerBet);
|
||||
|
||||
boost::shared_ptr<NetPacket> notifyActionDone(new NetPacketPlayersActionDone);
|
||||
NetPacketPlayersActionDone::Data actionDoneData;
|
||||
actionDoneData.gameState = GAME_STATE_PREFLOP; // TODO
|
||||
actionDoneData.gameState = static_cast<GameState>(curGame.getCurrentHand()->getActualRound());
|
||||
actionDoneData.playerId = session.playerData->GetUniqueId();
|
||||
actionDoneData.playerAction = actionData.playerAction;
|
||||
actionDoneData.playerBet = actionData.playerBet;
|
||||
actionDoneData.curPlayerMoney = 0;
|
||||
actionDoneData.totalPlayerBet = tmpPlayer->getMySet();
|
||||
actionDoneData.playerMoney = tmpPlayer->getMyCash();
|
||||
actionDoneData.potSize = curGame.getCurrentHand()->getBoard()->getPot();
|
||||
actionDoneData.curHandBets = curGame.getCurrentHand()->getBoard()->getSets();
|
||||
static_cast<NetPacketPlayersActionDone *>(notifyActionDone.get())->SetData(actionDoneData);
|
||||
server.SendToAllPlayers(notifyActionDone);
|
||||
|
||||
server.SetState(ServerRecvStateStartRound::Instance());
|
||||
retVal = MSG_NET_GAME_SERVER_ACTION;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return MSG_SOCK_INTERNAL_PENDING;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -541,13 +538,6 @@ ServerRecvStateFinal::~ServerRecvStateFinal()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
ServerRecvStateFinal::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> connData)
|
||||
{
|
||||
// Do not accept new connections in this state.
|
||||
server.RejectNewConnection(connData);
|
||||
}
|
||||
|
||||
int
|
||||
ServerRecvStateFinal::Process(ServerRecvThread &server)
|
||||
{
|
||||
|
||||
+2
-2
@@ -295,8 +295,8 @@ public:
|
||||
GameState gameState;
|
||||
u_int16_t playerId;
|
||||
PlayerAction playerAction;
|
||||
u_int32_t playerBet;
|
||||
u_int32_t curPlayerMoney;
|
||||
u_int32_t totalPlayerBet;
|
||||
u_int32_t playerMoney;
|
||||
u_int32_t potSize;
|
||||
u_int32_t curHandBets;
|
||||
};
|
||||
|
||||
+18
-20
@@ -69,8 +69,21 @@ private:
|
||||
unsigned m_curUniquePlayerId;
|
||||
};
|
||||
|
||||
// Abstract State: Game is running.
|
||||
class ServerRecvStateRunning : public ServerRecvState
|
||||
{
|
||||
public:
|
||||
virtual ~ServerRecvStateRunning();
|
||||
|
||||
//
|
||||
virtual void HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> data);
|
||||
|
||||
protected:
|
||||
ServerRecvStateRunning();
|
||||
};
|
||||
|
||||
// State: Start server game.
|
||||
class ServerRecvStateStartGame : public ServerRecvState
|
||||
class ServerRecvStateStartGame : public ServerRecvStateRunning
|
||||
{
|
||||
public:
|
||||
// Access the state singleton.
|
||||
@@ -78,9 +91,6 @@ public:
|
||||
|
||||
virtual ~ServerRecvStateStartGame();
|
||||
|
||||
//
|
||||
virtual void HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> data);
|
||||
|
||||
//
|
||||
virtual int Process(ServerRecvThread &server);
|
||||
|
||||
@@ -91,7 +101,7 @@ protected:
|
||||
};
|
||||
|
||||
// State: Start new hand.
|
||||
class ServerRecvStateStartHand : public ServerRecvState
|
||||
class ServerRecvStateStartHand : public ServerRecvStateRunning
|
||||
{
|
||||
public:
|
||||
// Access the state singleton.
|
||||
@@ -99,9 +109,6 @@ public:
|
||||
|
||||
virtual ~ServerRecvStateStartHand();
|
||||
|
||||
//
|
||||
virtual void HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> data);
|
||||
|
||||
//
|
||||
virtual int Process(ServerRecvThread &server);
|
||||
|
||||
@@ -112,7 +119,7 @@ protected:
|
||||
};
|
||||
|
||||
// State: Start new round.
|
||||
class ServerRecvStateStartRound : public ServerRecvState
|
||||
class ServerRecvStateStartRound : public ServerRecvStateRunning
|
||||
{
|
||||
public:
|
||||
// Access the state singleton.
|
||||
@@ -120,9 +127,6 @@ public:
|
||||
|
||||
virtual ~ServerRecvStateStartRound();
|
||||
|
||||
//
|
||||
virtual void HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> data);
|
||||
|
||||
//
|
||||
virtual int Process(ServerRecvThread &server);
|
||||
|
||||
@@ -136,7 +140,7 @@ protected:
|
||||
};
|
||||
|
||||
// State: Wait for a player action.
|
||||
class ServerRecvStateWaitPlayerAction : public ServerRecvState
|
||||
class ServerRecvStateWaitPlayerAction : public ServerRecvStateRunning
|
||||
{
|
||||
public:
|
||||
// Access the state singleton.
|
||||
@@ -144,9 +148,6 @@ public:
|
||||
|
||||
virtual ~ServerRecvStateWaitPlayerAction();
|
||||
|
||||
//
|
||||
virtual void HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> data);
|
||||
|
||||
//
|
||||
virtual int Process(ServerRecvThread &server);
|
||||
|
||||
@@ -158,7 +159,7 @@ protected:
|
||||
|
||||
|
||||
// State: Final.
|
||||
class ServerRecvStateFinal : public ServerRecvState
|
||||
class ServerRecvStateFinal : public ServerRecvStateRunning
|
||||
{
|
||||
public:
|
||||
// Access the state singleton.
|
||||
@@ -166,9 +167,6 @@ public:
|
||||
|
||||
virtual ~ServerRecvStateFinal();
|
||||
|
||||
//
|
||||
virtual void HandleNewConnection(ServerRecvThread &server, boost::shared_ptr<ConnectData> data);
|
||||
|
||||
//
|
||||
virtual int Process(ServerRecvThread &server);
|
||||
|
||||
|
||||
@@ -163,11 +163,11 @@ private:
|
||||
ConfigFile *m_playerConfig;
|
||||
|
||||
friend class ServerRecvStateInit;
|
||||
friend class ServerRecvStateRunning;
|
||||
friend class ServerRecvStateStartGame;
|
||||
friend class ServerRecvStateStartHand;
|
||||
friend class ServerRecvStateStartRound;
|
||||
friend class ServerRecvStateWaitPlayerAction;
|
||||
friend class ServerRecvStateFinal;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -67,6 +67,7 @@
|
||||
#define MSG_NET_GAME_CLIENT_HAND 7
|
||||
#define MSG_NET_GAME_SERVER_HAND 8
|
||||
#define MSG_NET_GAME_SERVER_ROUND 10
|
||||
#define MSG_NET_GAME_SERVER_ACTION 12
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user