diff --git a/docs/net_protocol.txt b/docs/net_protocol.txt index e291b8a9..f7602e86 100644 --- a/docs/net_protocol.txt +++ b/docs/net_protocol.txt @@ -10,6 +10,7 @@ PokerTH general message format: | +-------------------------------+ / | padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +Minimum length is 8. Maximum length is 256. Client Request: Join Game @@ -239,7 +240,7 @@ Server Notification: Deal Flop Cards +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Flop 1st Card | Flop 2nd Card | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Flop 3rd Card | Reserved | + | Flop 3rd Card | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -250,7 +251,7 @@ Server Notification: Deal Turn Card +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Message Type = 12 | Message Length = 8 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Turn Card | Reserved | + | Turn Card | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -261,10 +262,58 @@ Server Notification: Deal River Card +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Message Type = 13 | Message Length = 8 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | River Card | Reserved | + | River Card | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +Server Notification: End Of Hand Show Cards + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Message Type = 14 | Message Length | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + |Number Of PlayerResult Records | Reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | \ + \ PlayerResult Records / + / | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + +PlayerResult Record + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Player Id | 1st Card | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | 2nd Card | Best Hand Position 1 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Best Hand Position 2 | Best Hand Position 3 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Best Hand Position 4 | Best Hand Position 5 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Value Of Cards | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Money Won | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Player Money | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + +Server Notification: End Of Hand Hide Cards + + 0 1 2 3 + 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Message Type = 15 | Message Length = 16 | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Player Id | Reserved | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Money Won | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + | Player Money | + +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + + + Client Request: Send Chat Text 0 1 2 3 diff --git a/src/engine/flopinterface.h b/src/engine/flopinterface.h index 14c65f81..0a22c87d 100644 --- a/src/engine/flopinterface.h +++ b/src/engine/flopinterface.h @@ -24,7 +24,7 @@ class FlopInterface{ public: - virtual ~FlopInterface(); + virtual ~FlopInterface(); virtual void setPlayersTurn(const int& theValue) =0; virtual int getPlayersTurn() const =0; @@ -41,6 +41,8 @@ public: virtual void setSmallBlind(const int& theValue) =0; virtual int getSmallBlind() const =0; + virtual void resetFirstRun() =0; + virtual void flopRun() =0; virtual void nextPlayer2() =0; diff --git a/src/engine/local_engine/localflop.h b/src/engine/local_engine/localflop.h index 6ba1168b..f6f2faac 100755 --- a/src/engine/local_engine/localflop.h +++ b/src/engine/local_engine/localflop.h @@ -46,6 +46,8 @@ public: void setSmallBlind(const int& theValue) { smallBlind = theValue; } int getSmallBlind() const { return smallBlind; } + void resetFirstRun() { firstFlopRun = false; } + void flopRun(); void nextPlayer2(); diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 174d4766..faf550a1 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -347,7 +347,8 @@ void LocalHand::switchRounds() { myGui->refreshPot(); myGui->refreshSet(); myGui->flipHolecardsAllIn(); - actualRound++; + if (actualRound < 4) // do not increment past 4 + actualRound++; } //unhighlight actual players groupbox diff --git a/src/engine/local_engine/localriver.h b/src/engine/local_engine/localriver.h index d76d11e1..f5fcdaa7 100755 --- a/src/engine/local_engine/localriver.h +++ b/src/engine/local_engine/localriver.h @@ -48,6 +48,8 @@ public: void setHighestCardsValue(const int& theValue) { highestCardsValue = theValue;} int getHighestCardsValue() const { return highestCardsValue;} + void resetFirstRun() { firstRiverRun = false; } + void riverRun(); void postRiverRun(); void nextPlayer2(); diff --git a/src/engine/local_engine/localturn.h b/src/engine/local_engine/localturn.h index 9f6fdc56..8c674a3f 100755 --- a/src/engine/local_engine/localturn.h +++ b/src/engine/local_engine/localturn.h @@ -44,6 +44,8 @@ public: void setSmallBlind(const int& theValue) { smallBlind = theValue; } int getSmallBlind() const { return smallBlind; } + void resetFirstRun() { firstTurnRun = false; } + void turnRun(); void nextPlayer2(); diff --git a/src/engine/network_engine/clientboard.cpp b/src/engine/network_engine/clientboard.cpp index 035c68e8..729c9c92 100644 --- a/src/engine/network_engine/clientboard.cpp +++ b/src/engine/network_engine/clientboard.cpp @@ -47,20 +47,20 @@ ClientBoard::setHand(HandInterface* br) void ClientBoard::collectSets() -{ - sets = 0; - int i; - for(i=0; igetMySet(); - -} - +{ + sets = 0; + int i; + for(i=0; igetMySet(); + +} + void ClientBoard::collectPot() { - int i; - pot += sets; - sets = 0; - for(i=0; isetMySetNull(); } -} + int i; + pot += sets; + sets = 0; + for(i=0; isetMySetNull(); } +} diff --git a/src/engine/network_engine/clientflop.h b/src/engine/network_engine/clientflop.h index 93310e7b..4de42096 100644 --- a/src/engine/network_engine/clientflop.h +++ b/src/engine/network_engine/clientflop.h @@ -44,6 +44,8 @@ public: void setSmallBlind(const int& theValue) { smallBlind = theValue; } int getSmallBlind() const { return smallBlind; } + void resetFirstRun() { firstFlopRun = false; } + void flopRun(); void nextPlayer2(); diff --git a/src/engine/network_engine/clientriver.h b/src/engine/network_engine/clientriver.h index 2dfc097b..7ea22d42 100644 --- a/src/engine/network_engine/clientriver.h +++ b/src/engine/network_engine/clientriver.h @@ -47,6 +47,8 @@ public: void setHighestCardsValue(const int& theValue) { highestCardsValue = theValue;} int getHighestCardsValue() const { return highestCardsValue;} + void resetFirstRun() { firstRiverRun = false; } + void riverRun(); void postRiverRun(); void nextPlayer2(); diff --git a/src/engine/network_engine/clientturn.h b/src/engine/network_engine/clientturn.h index 6f8478c2..d8ae48cd 100644 --- a/src/engine/network_engine/clientturn.h +++ b/src/engine/network_engine/clientturn.h @@ -43,6 +43,8 @@ public: void setSmallBlind(const int& theValue) { smallBlind = theValue; } int getSmallBlind() const { return smallBlind; } + void resetFirstRun() { firstTurnRun = false; } + void turnRun(); void nextPlayer2(); diff --git a/src/engine/riverinterface.h b/src/engine/riverinterface.h index eecaea8b..bd033edc 100644 --- a/src/engine/riverinterface.h +++ b/src/engine/riverinterface.h @@ -43,6 +43,8 @@ public: virtual void setHighestCardsValue(const int& theValue) =0; virtual int getHighestCardsValue() const =0; + virtual void resetFirstRun() =0; + virtual void riverRun() =0; virtual void postRiverRun() =0; virtual void nextPlayer2() =0; diff --git a/src/engine/turninterface.h b/src/engine/turninterface.h index 1b275efa..52477f34 100644 --- a/src/engine/turninterface.h +++ b/src/engine/turninterface.h @@ -40,6 +40,8 @@ public: virtual void setSmallBlind(const int& theValue) =0; virtual int getSmallBlind() const =0; + virtual void resetFirstRun() =0; + virtual void turnRun() =0; virtual void nextPlayer2() =0; diff --git a/src/game_defs.h b/src/game_defs.h index 125e16b6..fa058145 100644 --- a/src/game_defs.h +++ b/src/game_defs.h @@ -27,6 +27,7 @@ enum GameState { GAME_STATE_FLOP, GAME_STATE_TURN, GAME_STATE_RIVER, + GAME_STATE_POST_RIVER, GAME_STATE_PREFLOP_SMALL_BLIND = 0xF0, GAME_STATE_PREFLOP_BIG_BLIND = 0xF1 }; diff --git a/src/gui/generic/serverguiwrapper.cpp b/src/gui/generic/serverguiwrapper.cpp index a06a2043..d654d847 100644 --- a/src/gui/generic/serverguiwrapper.cpp +++ b/src/gui/generic/serverguiwrapper.cpp @@ -59,6 +59,7 @@ void ServerGuiWrapper::refreshAll() const {} void ServerGuiWrapper::refreshPot() const {} void ServerGuiWrapper::refreshGroupbox(int playerID, int status) const {} void ServerGuiWrapper::refreshPlayerName() const {} +void ServerGuiWrapper::refreshButton() const {} void ServerGuiWrapper::dealHoleCards() {} void ServerGuiWrapper::dealFlopCards() {} diff --git a/src/gui/generic/serverguiwrapper.h b/src/gui/generic/serverguiwrapper.h index 01f8ab52..64fc944f 100644 --- a/src/gui/generic/serverguiwrapper.h +++ b/src/gui/generic/serverguiwrapper.h @@ -43,6 +43,7 @@ public: void refreshGroupbox(int =-1, int =-1) const; void refreshAll() const; void refreshPlayerName() const; + void refreshButton() const; void dealHoleCards(); void dealFlopCards(); diff --git a/src/gui/guiinterface.h b/src/gui/guiinterface.h index b97653f0..7e8bc59d 100644 --- a/src/gui/guiinterface.h +++ b/src/gui/guiinterface.h @@ -48,11 +48,7 @@ public: virtual void refreshGroupbox(int =-1, int =-1) const=0; virtual void refreshAll() const=0; virtual void refreshPlayerName() const=0; - -// virtual void refreshButton() const=0; - -// virtual void refreshAction() const=0; -// virtual void refreshCash() const=0; + virtual void refreshButton() const =0; // // Karten-Funktionen virtual void dealHoleCards()=0; diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index 6b0980a5..dcafa352 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -1,108 +1,109 @@ -/*************************************************************************** - * Copyright (C) 2006 by FThauer FHammer * - * f.thauer@web.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (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 * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ - -#include "guiwrapper.h" -#include "session.h" -#include "log.h" -#include "chat.h" -#include "mainwindowimpl.h" -#include "configfile.h" - -using namespace std; - - -GuiWrapper::GuiWrapper(ConfigFile *c) : myLog(0), myW(0), myConfig(c) -{ - - - myW = new mainWindowImpl(myConfig); - myW->show(); - myLog = new Log(myW, myConfig); - myChat = new Chat(myW, myConfig); - -} - - -GuiWrapper::~GuiWrapper() -{ -} - -void GuiWrapper::initGui(int speed) { myW->initGui(speed); } - -Session &GuiWrapper::getSession() { return myW->getSession(); } -void GuiWrapper::setSession(boost::shared_ptr session) { myW->setSession(session); } - -void GuiWrapper::refreshSet() const { myW->signalRefreshSet(); } -void GuiWrapper::refreshCash() const { myW->signalRefreshCash(); } -void GuiWrapper::refreshAction(int playerID, int playerAction) const { myW->signalRefreshAction(playerID, playerAction); } -void GuiWrapper::refreshChangePlayer() const { myW->signalRefreshChangePlayer(); } -void GuiWrapper::refreshAll() const { myW->signalRefreshAll(); } -void GuiWrapper::refreshPot() const { myW->signalRefreshPot(); } -void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->signalRefreshGroupbox(playerID, status); } -void GuiWrapper::refreshPlayerName() const { myW->signalRefreshPlayerName(); } - -void GuiWrapper::dealHoleCards() { myW->signalDealHoleCards(); } -void GuiWrapper::dealFlopCards() { myW->signalDealFlopCards0(); } -void GuiWrapper::dealTurnCard() { myW->signalDealTurnCards0(); } -void GuiWrapper::dealRiverCard() { myW->signalDealRiverCards0(); } - -void GuiWrapper::highlightRoundLabel(string round) const { myW->signalHighlightRoundLabel(QString::fromUtf8(round.c_str())); } - - -void GuiWrapper::nextPlayerAnimation() { myW->signalNextPlayerAnimation(); } - -void GuiWrapper::preflopAnimation1() { myW->signalPreflopAnimation1(); } -void GuiWrapper::preflopAnimation2() { myW->signalPreflopAnimation2(); } - -void GuiWrapper::flopAnimation1() { myW->signalFlopAnimation1(); } -void GuiWrapper::flopAnimation2() { myW->signalFlopAnimation2(); } - -void GuiWrapper::turnAnimation1() { myW->signalTurnAnimation1(); } -void GuiWrapper::turnAnimation2() { myW->signalTurnAnimation2(); } - -void GuiWrapper::riverAnimation1() { myW->signalRiverAnimation1(); } -void GuiWrapper::riverAnimation2() { myW->signalRiverAnimation2(); } - -void GuiWrapper::postRiverAnimation1() { myW->signalPostRiverAnimation1(); } -void GuiWrapper::postRiverRunAnimation1() { myW->signalPostRiverRunAnimation1(); } - -void GuiWrapper::flipHolecardsAllIn() { myW->signalFlipHolecardsAllIn(); } - -void GuiWrapper::nextRoundCleanGui() { myW->signalNextRoundCleanGui(); } - -void GuiWrapper::meInAction() { myW->signalMeInAction(); } - -void GuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) { myLog->signalLogPlayerActionMsg(QString::fromUtf8(playerName.c_str()), action, setValue); } -void GuiWrapper::logNewGameHandMsg(int gameID, int handID) { myLog->signalLogNewGameHandMsg(gameID, handID); } - -void GuiWrapper::SignalNetClientConnect(int actionID) { myW->signalNetClientConnect(actionID); } -void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->signalNetClientGameInfo(actionID); } -void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->signalNetClientError(errorID, osErrorID); } -void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { myW->signalNetClientPlayerJoined(QString::fromUtf8(playerName.c_str())); } -void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { myW->signalNetClientPlayerLeft(QString::fromUtf8(playerName.c_str())); } -void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr game) { myW->signalNetClientGameStart(game); } -void GuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { myChat->signalChatMessage(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); } - -void GuiWrapper::SignalNetServerSuccess(int actionID) { } -void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { } -void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { myW->signalNetServerPlayerJoined(QString::fromUtf8(playerName.c_str())); } -void GuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { myW->signalNetServerPlayerLeft(QString::fromUtf8(playerName.c_str())); } - - +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (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 * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include "guiwrapper.h" +#include "session.h" +#include "log.h" +#include "chat.h" +#include "mainwindowimpl.h" +#include "configfile.h" + +using namespace std; + + +GuiWrapper::GuiWrapper(ConfigFile *c) : myLog(0), myW(0), myConfig(c) +{ + + + myW = new mainWindowImpl(myConfig); + myW->show(); + myLog = new Log(myW, myConfig); + myChat = new Chat(myW, myConfig); + +} + + +GuiWrapper::~GuiWrapper() +{ +} + +void GuiWrapper::initGui(int speed) { myW->initGui(speed); } + +Session &GuiWrapper::getSession() { return myW->getSession(); } +void GuiWrapper::setSession(boost::shared_ptr session) { myW->setSession(session); } + +void GuiWrapper::refreshSet() const { myW->signalRefreshSet(); } +void GuiWrapper::refreshCash() const { myW->signalRefreshCash(); } +void GuiWrapper::refreshAction(int playerID, int playerAction) const { myW->signalRefreshAction(playerID, playerAction); } +void GuiWrapper::refreshChangePlayer() const { myW->signalRefreshChangePlayer(); } +void GuiWrapper::refreshAll() const { myW->signalRefreshAll(); } +void GuiWrapper::refreshPot() const { myW->signalRefreshPot(); } +void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->signalRefreshGroupbox(playerID, status); } +void GuiWrapper::refreshPlayerName() const { myW->signalRefreshPlayerName(); } +void GuiWrapper::refreshButton() const { myW->signalRefreshButton(); } + +void GuiWrapper::dealHoleCards() { myW->signalDealHoleCards(); } +void GuiWrapper::dealFlopCards() { myW->signalDealFlopCards0(); } +void GuiWrapper::dealTurnCard() { myW->signalDealTurnCards0(); } +void GuiWrapper::dealRiverCard() { myW->signalDealRiverCards0(); } + +void GuiWrapper::highlightRoundLabel(string round) const { myW->signalHighlightRoundLabel(QString::fromUtf8(round.c_str())); } + + +void GuiWrapper::nextPlayerAnimation() { myW->signalNextPlayerAnimation(); } + +void GuiWrapper::preflopAnimation1() { myW->signalPreflopAnimation1(); } +void GuiWrapper::preflopAnimation2() { myW->signalPreflopAnimation2(); } + +void GuiWrapper::flopAnimation1() { myW->signalFlopAnimation1(); } +void GuiWrapper::flopAnimation2() { myW->signalFlopAnimation2(); } + +void GuiWrapper::turnAnimation1() { myW->signalTurnAnimation1(); } +void GuiWrapper::turnAnimation2() { myW->signalTurnAnimation2(); } + +void GuiWrapper::riverAnimation1() { myW->signalRiverAnimation1(); } +void GuiWrapper::riverAnimation2() { myW->signalRiverAnimation2(); } + +void GuiWrapper::postRiverAnimation1() { myW->signalPostRiverAnimation1(); } +void GuiWrapper::postRiverRunAnimation1() { myW->signalPostRiverRunAnimation1(); } + +void GuiWrapper::flipHolecardsAllIn() { myW->signalFlipHolecardsAllIn(); } + +void GuiWrapper::nextRoundCleanGui() { myW->signalNextRoundCleanGui(); } + +void GuiWrapper::meInAction() { myW->signalMeInAction(); } + +void GuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) { myLog->signalLogPlayerActionMsg(QString::fromUtf8(playerName.c_str()), action, setValue); } +void GuiWrapper::logNewGameHandMsg(int gameID, int handID) { myLog->signalLogNewGameHandMsg(gameID, handID); } + +void GuiWrapper::SignalNetClientConnect(int actionID) { myW->signalNetClientConnect(actionID); } +void GuiWrapper::SignalNetClientGameInfo(int actionID) { myW->signalNetClientGameInfo(actionID); } +void GuiWrapper::SignalNetClientError(int errorID, int osErrorID) { myW->signalNetClientError(errorID, osErrorID); } +void GuiWrapper::SignalNetClientPlayerJoined(const string &playerName) { myW->signalNetClientPlayerJoined(QString::fromUtf8(playerName.c_str())); } +void GuiWrapper::SignalNetClientPlayerLeft(const string &playerName) { myW->signalNetClientPlayerLeft(QString::fromUtf8(playerName.c_str())); } +void GuiWrapper::SignalNetClientGameStart(boost::shared_ptr game) { myW->signalNetClientGameStart(game); } +void GuiWrapper::SignalNetClientChatMsg(const string &playerName, const string &msg) { myChat->signalChatMessage(QString::fromUtf8(playerName.c_str()), QString::fromUtf8(msg.c_str())); } + +void GuiWrapper::SignalNetServerSuccess(int actionID) { } +void GuiWrapper::SignalNetServerError(int errorID, int osErrorID) { } +void GuiWrapper::SignalNetServerPlayerJoined(const string &playerName) { myW->signalNetServerPlayerJoined(QString::fromUtf8(playerName.c_str())); } +void GuiWrapper::SignalNetServerPlayerLeft(const string &playerName) { myW->signalNetServerPlayerLeft(QString::fromUtf8(playerName.c_str())); } + + diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index 148ac6a2..d3e2cf0b 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -1,111 +1,112 @@ -/*************************************************************************** - * Copyright (C) 2006 by FThauer FHammer * - * f.thauer@web.de * - * * - * This program is free software; you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation; either version 2 of the License, or * - * (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 * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program; if not, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * - ***************************************************************************/ -#ifndef GUIWRAPPER_H -#define GUIWRAPPER_H - -#include - -#include -#include - -class Session; -class mainWindowImpl; -class Log; -class Chat; -class ConfigFile; - -class GuiWrapper : public GuiInterface -{ -public: - GuiWrapper(ConfigFile*); - - ~GuiWrapper(); - - void initGui(int speed); - - Session &getSession(); - void setSession(boost::shared_ptr session); - - void refreshSet() const; - void refreshCash() const; - void refreshAction(int =-1, int =-1) const; - void refreshChangePlayer() const; - void refreshPot() const; - void refreshGroupbox(int =-1, int =-1) const; - void refreshAll() const; - void refreshPlayerName() const; - - void dealHoleCards(); - void dealFlopCards(); - void dealTurnCard(); - void dealRiverCard(); - - void highlightRoundLabel(std::string round) const; - - void nextPlayerAnimation(); - - void preflopAnimation1(); - void preflopAnimation2(); - - void flopAnimation1(); - void flopAnimation2(); - - void turnAnimation1(); - void turnAnimation2(); - - void riverAnimation1(); - void riverAnimation2(); - - void postRiverAnimation1(); - void postRiverRunAnimation1(); - - void flipHolecardsAllIn(); - - void nextRoundCleanGui(); - - void meInAction(); - - void logPlayerActionMsg(std::string playerName, int action, int setValue) ; - void logNewGameHandMsg(int gameID, int handID) ; - - void SignalNetClientConnect(int actionID); - void SignalNetClientGameInfo(int actionID); - void SignalNetClientError(int errorID, int osErrorID); - void SignalNetClientPlayerJoined(const std::string &playerName); - void SignalNetClientPlayerLeft(const std::string &playerName); - void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg); - - void SignalNetClientGameStart(boost::shared_ptr game); - - void SignalNetServerSuccess(int actionID); - void SignalNetServerError(int errorID, int osErrorID); - void SignalNetServerPlayerJoined(const std::string &playerName); - void SignalNetServerPlayerLeft(const std::string &playerName); - -private: - - Log *myLog; - Chat *myChat; - mainWindowImpl *myW; - ConfigFile *myConfig; - -}; - -#endif +/*************************************************************************** + * Copyright (C) 2006 by FThauer FHammer * + * f.thauer@web.de * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (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 * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef GUIWRAPPER_H +#define GUIWRAPPER_H + +#include + +#include +#include + +class Session; +class mainWindowImpl; +class Log; +class Chat; +class ConfigFile; + +class GuiWrapper : public GuiInterface +{ +public: + GuiWrapper(ConfigFile*); + + ~GuiWrapper(); + + void initGui(int speed); + + Session &getSession(); + void setSession(boost::shared_ptr session); + + void refreshSet() const; + void refreshCash() const; + void refreshAction(int =-1, int =-1) const; + void refreshChangePlayer() const; + void refreshPot() const; + void refreshGroupbox(int =-1, int =-1) const; + void refreshAll() const; + void refreshPlayerName() const; + void refreshButton() const; + + void dealHoleCards(); + void dealFlopCards(); + void dealTurnCard(); + void dealRiverCard(); + + void highlightRoundLabel(std::string round) const; + + void nextPlayerAnimation(); + + void preflopAnimation1(); + void preflopAnimation2(); + + void flopAnimation1(); + void flopAnimation2(); + + void turnAnimation1(); + void turnAnimation2(); + + void riverAnimation1(); + void riverAnimation2(); + + void postRiverAnimation1(); + void postRiverRunAnimation1(); + + void flipHolecardsAllIn(); + + void nextRoundCleanGui(); + + void meInAction(); + + void logPlayerActionMsg(std::string playerName, int action, int setValue) ; + void logNewGameHandMsg(int gameID, int handID) ; + + void SignalNetClientConnect(int actionID); + void SignalNetClientGameInfo(int actionID); + void SignalNetClientError(int errorID, int osErrorID); + void SignalNetClientPlayerJoined(const std::string &playerName); + void SignalNetClientPlayerLeft(const std::string &playerName); + void SignalNetClientChatMsg(const std::string &playerName, const std::string &msg); + + void SignalNetClientGameStart(boost::shared_ptr game); + + void SignalNetServerSuccess(int actionID); + void SignalNetServerError(int errorID, int osErrorID); + void SignalNetServerPlayerJoined(const std::string &playerName); + void SignalNetServerPlayerLeft(const std::string &playerName); + +private: + + Log *myLog; + Chat *myChat; + mainWindowImpl *myW; + ConfigFile *myConfig; + +}; + +#endif diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 19464d51..221ca0ff 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -571,6 +571,7 @@ mainWindowImpl::mainWindowImpl(ConfigFile *c, QMainWindow *parent) connect(this, SIGNAL(signalRefreshGroupbox(int, int)), this, SLOT(refreshGroupbox(int, int))); connect(this, SIGNAL(signalRefreshAll()), this, SLOT(refreshAll())); connect(this, SIGNAL(signalRefreshPlayerName()), this, SLOT(refreshPlayerName())); + connect(this, SIGNAL(signalRefreshButton()), this, SLOT(refreshButton())); connect(this, SIGNAL(signalMeInAction()), this, SLOT(meInAction())); @@ -1799,7 +1800,7 @@ void mainWindowImpl::postRiverRunAnimation2() { //Aktive Spieler zählen --> wenn nur noch einer nicht-folded dann keine Karten umdrehen int activePlayersCounter = 0; for (i=0; igetPlayerArray()[i]->getMyAction() != 1 && currentHand->getPlayerArray()[i]->getMyActiveStatus() == 1) activePlayersCounter++; + if (currentHand->getPlayerArray()[i]->getMyAction() != 1 && currentHand->getPlayerArray()[i]->getMyActiveStatus()) activePlayersCounter++; } if(activePlayersCounter!=1) { @@ -2021,6 +2022,11 @@ void mainWindowImpl::postRiverRunAnimation6() { refreshCash(); refreshPot(); + // TODO HACK + // Check for network client, do not start new hand if client is running. + if (mySession->isNetworkClientRunning()) + return; + // wenn nur noch ein Spieler aktive "neues Spiel"-Dialog anzeigen int playersPositiveCashCounter = 0; for (i=0; igetCurrentGame()->getStartQuantityPlayers(); i++) { diff --git a/src/gui/qt/mainwindow/mainwindowimpl.h b/src/gui/qt/mainwindow/mainwindowimpl.h index 2546d49d..0c17d372 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.h +++ b/src/gui/qt/mainwindow/mainwindowimpl.h @@ -81,6 +81,7 @@ signals: void signalRefreshGroupbox(int =-1, int =-1); void signalRefreshAll(); void signalRefreshPlayerName(); + void signalRefreshButton(); void signalMeInAction(); diff --git a/src/net/common/clientstate.cpp b/src/net/common/clientstate.cpp index 66da903d..28c2e998 100644 --- a/src/net/common/clientstate.cpp +++ b/src/net/common/clientstate.cpp @@ -540,7 +540,7 @@ ClientStateWaitHand::InternalProcess(ClientThread &client, boost::shared_ptr packet) { + int retVal = MSG_SOCK_INTERNAL_PENDING; ClientContext &context = client.GetContext(); if (packet.get()) @@ -601,6 +602,7 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrToNetPacketPlayersTurn()) { @@ -612,21 +614,21 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetCurrentHand()->getActualRound() != turnData.gameState) { - // Reset player actions - for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) - { - int action = curGame->getPlayerArray()[i]->getMyAction(); - if (action != 1 && action != 6) - curGame->getPlayerArray()[i]->setMyAction(0); - } - // Move sets to pot - curGame->getCurrentHand()->getBoard()->collectSets(); - curGame->getCurrentHand()->getBoard()->collectPot(); - - client.GetGui().refreshPot(); - client.GetGui().refreshSet(); - client.GetGui().refreshAction(); - client.GetGui().refreshCash(); + // Reset player actions + for (int i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) + { + int action = curGame->getPlayerArray()[i]->getMyAction(); + if (action != 1 && action != 6) + curGame->getPlayerArray()[i]->setMyAction(0); + } + // Move sets to pot + curGame->getCurrentHand()->getBoard()->collectSets(); + curGame->getCurrentHand()->getBoard()->collectPot(); + + client.GetGui().refreshPot(); + client.GetGui().refreshSet(); + client.GetGui().refreshAction(); + client.GetGui().refreshCash(); curGame->getCurrentHand()->setActualRound(turnData.gameState); } @@ -650,9 +652,8 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrToNetPacketDealFlopCards()->GetData(cardsData); int tmpCards[5]; - tmpCards[0] = static_cast(cardsData.flopCards[0]); - tmpCards[1] = static_cast(cardsData.flopCards[1]); - tmpCards[2] = static_cast(cardsData.flopCards[2]); + for (int num = 0; num < 3; num++) + tmpCards[num] = static_cast(cardsData.flopCards[num]); tmpCards[3] = tmpCards[4] = 0; curGame->getCurrentHand()->getBoard()->setMyCards(tmpCards); client.GetGui().dealFlopCards(); @@ -677,9 +678,63 @@ ClientStateRunHand::InternalProcess(ClientThread &client, boost::shared_ptrgetCurrentHand()->getBoard()->setMyCards(tmpCards); client.GetGui().dealRiverCard(); } + else if (packet->ToNetPacketEndOfHandHideCards()) + { + // End of Hand, but keep cards hidden. + NetPacketEndOfHandHideCards::Data endHandData; + packet->ToNetPacketEndOfHandHideCards()->GetData(endHandData); + + PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId(endHandData.playerId); + assert(tmpPlayer); // TODO: throw exception + + tmpPlayer->setMyCash(endHandData.playerMoney); + // TODO use moneyWon + client.GetGui().postRiverRunAnimation1(); + + // Wait for next Hand. + client.SetState(ClientStateWaitHand::Instance()); + retVal = MSG_NET_GAME_SERVER_HAND_END; + } + else if (packet->ToNetPacketEndOfHandShowCards()) + { + // End of Hand, show cards. + NetPacketEndOfHandShowCards::Data endHandData; + packet->ToNetPacketEndOfHandShowCards()->GetData(endHandData); + + NetPacketEndOfHandShowCards::PlayerResultList::const_iterator i + = endHandData.playerResults.begin(); + NetPacketEndOfHandShowCards::PlayerResultList::const_iterator end + = endHandData.playerResults.end(); + + int highestValueOfCards = 0; + while (i != end) + { + PlayerInterface *tmpPlayer = curGame->getPlayerByUniqueId((*i).playerId); + assert(tmpPlayer); // TODO: throw exception + + int tmpCards[2]; + tmpCards[0] = static_cast((*i).cards[0]); + tmpCards[1] = static_cast((*i).cards[1]); + tmpPlayer->setMyCards(tmpCards); + for (int num = 0; num < 5; num++) + tmpPlayer->getMyBestHandPosition()[num] = (*i).bestHandPos[num]; + tmpPlayer->setMyCardsValueInt((*i).valueOfCards); + if (tmpPlayer->getMyCardsValueInt() > highestValueOfCards) + highestValueOfCards = tmpPlayer->getMyCardsValueInt(); + tmpPlayer->setMyCash((*i).playerMoney); + // TODO use moneyWon + ++i; + } + client.GetGame()->getCurrentHand()->getRiver()->setHighestCardsValue(highestValueOfCards); + client.GetGui().postRiverRunAnimation1(); + + // Wait for next Hand. + client.SetState(ClientStateWaitHand::Instance()); + retVal = MSG_NET_GAME_SERVER_HAND_END; + } } - return MSG_SOCK_INTERNAL_PENDING; + return retVal; } diff --git a/src/net/common/netpacket.cpp b/src/net/common/netpacket.cpp index f8b056dc..747ad331 100644 --- a/src/net/common/netpacket.cpp +++ b/src/net/common/netpacket.cpp @@ -40,6 +40,8 @@ using namespace std; #define NET_TYPE_DEAL_FLOP_CARDS 0x000B #define NET_TYPE_DEAL_TURN_CARD 0x000C #define NET_TYPE_DEAL_RIVER_CARD 0x000D +#define NET_TYPE_END_OF_HAND_SHOW_CARDS 0x000E +#define NET_TYPE_END_OF_HAND_HIDE_CARDS 0x000F #define NET_TYPE_SEND_CHAT_TEXT 0x0200 #define NET_TYPE_CHAT_TEXT 0x0201 @@ -194,6 +196,37 @@ struct GCC_PACKED NetPacketDealRiverCardData u_int16_t reserved; }; +struct GCC_PACKED NetPacketEndOfHandShowCardsData +{ + NetPacketHeader head; + u_int16_t numberOfPlayerResults; + u_int16_t reserved; +}; + +struct GCC_PACKED PlayerResultData +{ + u_int16_t playerId; + u_int16_t card1; + u_int16_t card2; + u_int16_t bestHandPos1; + u_int16_t bestHandPos2; + u_int16_t bestHandPos3; + u_int16_t bestHandPos4; + u_int16_t bestHandPos5; + u_int32_t valueOfCards; + u_int32_t moneyWon; + u_int32_t playerMoney; +}; + +struct GCC_PACKED NetPacketEndOfHandHideCardsData +{ + NetPacketHeader head; + u_int16_t playerId; + u_int16_t reserved; + u_int32_t moneyWon; + u_int32_t playerMoney; +}; + struct GCC_PACKED NetPacketSendChatTextData { NetPacketHeader head; @@ -281,6 +314,12 @@ NetPacket::Create(char *data, unsigned &dataSize) case NET_TYPE_DEAL_RIVER_CARD: tmpPacket = boost::shared_ptr(new NetPacketDealRiverCard); break; + case NET_TYPE_END_OF_HAND_SHOW_CARDS: + tmpPacket = boost::shared_ptr(new NetPacketEndOfHandShowCards); + break; + case NET_TYPE_END_OF_HAND_HIDE_CARDS: + tmpPacket = boost::shared_ptr(new NetPacketEndOfHandHideCards); + break; case NET_TYPE_SEND_CHAT_TEXT: tmpPacket = boost::shared_ptr(new NetPacketSendChatText); break; @@ -449,6 +488,18 @@ NetPacket::ToNetPacketDealRiverCard() const return NULL; } +const NetPacketEndOfHandShowCards * +NetPacket::ToNetPacketEndOfHandShowCards() const +{ + return NULL; +} + +const NetPacketEndOfHandHideCards * +NetPacket::ToNetPacketEndOfHandHideCards() const +{ + return NULL; +} + const NetPacketSendChatText * NetPacket::ToNetPacketSendChatText() const { @@ -1493,6 +1544,199 @@ NetPacketDealRiverCard::Check(const NetPacketHeader* data) const //----------------------------------------------------------------------------- +NetPacketEndOfHandShowCards::NetPacketEndOfHandShowCards() +: NetPacket(NET_TYPE_END_OF_HAND_SHOW_CARDS, sizeof(NetPacketEndOfHandShowCardsData)) +{ +} + +NetPacketEndOfHandShowCards::~NetPacketEndOfHandShowCards() +{ +} + +boost::shared_ptr +NetPacketEndOfHandShowCards::Clone() const +{ + boost::shared_ptr newPacket(new NetPacketEndOfHandShowCards); + try + { + newPacket->SetRawData(GetRawData()); + } catch (const NetException &) + { + // Need to return the new packet anyway. + } + return newPacket; +} + +void +NetPacketEndOfHandShowCards::SetData(const NetPacketEndOfHandShowCards::Data &inData) +{ + u_int16_t numPlayerResults = (u_int16_t)inData.playerResults.size(); + + if (!numPlayerResults || numPlayerResults > MAX_NUM_PLAYER_RESULTS) + throw NetException(ERR_NET_INVALID_PLAYER_RESULTS, 0); + + // Resize the packet so that the data fits in. + Resize((u_int16_t) + (sizeof(NetPacketEndOfHandShowCardsData) + numPlayerResults * sizeof(PlayerResultData))); + + NetPacketEndOfHandShowCardsData *tmpData = (NetPacketEndOfHandShowCardsData *)GetRawData(); + assert(tmpData); + + tmpData->numberOfPlayerResults = htons(numPlayerResults); + + PlayerResultList::const_iterator i = inData.playerResults.begin(); + PlayerResultList::const_iterator end = inData.playerResults.end(); + + // Copy the player result data to continous memory + PlayerResultData *curPlayerResultData = + (PlayerResultData *)((char *)tmpData + sizeof(NetPacketEndOfHandShowCardsData)); + while (i != end) + { + curPlayerResultData->playerId = htons((*i).playerId); + curPlayerResultData->card1 = htons((*i).cards[0]); + curPlayerResultData->card2 = htons((*i).cards[1]); + curPlayerResultData->bestHandPos1 = htons((*i).bestHandPos[0]); + curPlayerResultData->bestHandPos2 = htons((*i).bestHandPos[1]); + curPlayerResultData->bestHandPos3 = htons((*i).bestHandPos[2]); + curPlayerResultData->bestHandPos4 = htons((*i).bestHandPos[3]); + curPlayerResultData->bestHandPos5 = htons((*i).bestHandPos[4]); + curPlayerResultData->valueOfCards = htonl((*i).valueOfCards); + curPlayerResultData->moneyWon = htonl((*i).moneyWon); + curPlayerResultData->playerMoney = htonl((*i).playerMoney); + ++curPlayerResultData; + ++i; + } +} + +void +NetPacketEndOfHandShowCards::GetData(NetPacketEndOfHandShowCards::Data &outData) const +{ + NetPacketEndOfHandShowCardsData *tmpData = (NetPacketEndOfHandShowCardsData *)GetRawData(); + assert(tmpData); + + outData.playerResults.clear(); + + u_int16_t numPlayerResults = ntohs(tmpData->numberOfPlayerResults); + PlayerResultData *curPlayerResultData = + (PlayerResultData *)((char *)tmpData + sizeof(NetPacketEndOfHandShowCardsData)); + + // Store all available player results. + for (int i = 0; i < numPlayerResults; i++) + { + PlayerResult tmpPlayerResult; + tmpPlayerResult.playerId = ntohs(curPlayerResultData->playerId); + tmpPlayerResult.cards[0] = ntohs(curPlayerResultData->card1); + tmpPlayerResult.cards[1] = ntohs(curPlayerResultData->card2); + tmpPlayerResult.bestHandPos[0] = ntohs(curPlayerResultData->bestHandPos1); + tmpPlayerResult.bestHandPos[1] = ntohs(curPlayerResultData->bestHandPos2); + tmpPlayerResult.bestHandPos[2] = ntohs(curPlayerResultData->bestHandPos3); + tmpPlayerResult.bestHandPos[3] = ntohs(curPlayerResultData->bestHandPos4); + tmpPlayerResult.bestHandPos[4] = ntohs(curPlayerResultData->bestHandPos5); + tmpPlayerResult.valueOfCards = ntohl(curPlayerResultData->valueOfCards); + tmpPlayerResult.moneyWon = ntohl(curPlayerResultData->moneyWon); + tmpPlayerResult.playerMoney = ntohl(curPlayerResultData->playerMoney); + + outData.playerResults.push_back(tmpPlayerResult); + ++curPlayerResultData; + } +} + +const NetPacketEndOfHandShowCards * +NetPacketEndOfHandShowCards::ToNetPacketEndOfHandShowCards() const +{ + return this; +} + +void +NetPacketEndOfHandShowCards::Check(const NetPacketHeader* data) const +{ + assert(data); + + u_int16_t dataLen = ntohs(data->length); + if (dataLen < sizeof(NetPacketEndOfHandShowCardsData)) + { + throw NetException(ERR_SOCK_INVALID_PACKET, 0); + } + + NetPacketEndOfHandShowCardsData *tmpData = (NetPacketEndOfHandShowCardsData *)data; + int numPlayerResults = ntohs(tmpData->numberOfPlayerResults); + + if (dataLen != + sizeof(NetPacketEndOfHandShowCardsData) + + numPlayerResults * sizeof(PlayerResultData)) + { + throw NetException(ERR_SOCK_INVALID_PACKET, 0); + } + // TODO: semantic checks within PlayerResultData +} + +//----------------------------------------------------------------------------- + +NetPacketEndOfHandHideCards::NetPacketEndOfHandHideCards() +: NetPacket(NET_TYPE_END_OF_HAND_HIDE_CARDS, sizeof(NetPacketEndOfHandHideCardsData)) +{ +} + +NetPacketEndOfHandHideCards::~NetPacketEndOfHandHideCards() +{ +} + +boost::shared_ptr +NetPacketEndOfHandHideCards::Clone() const +{ + boost::shared_ptr newPacket(new NetPacketEndOfHandHideCards); + try + { + newPacket->SetRawData(GetRawData()); + } catch (const NetException &) + { + // Need to return the new packet anyway. + } + return newPacket; +} + +void +NetPacketEndOfHandHideCards::SetData(const NetPacketEndOfHandHideCards::Data &inData) +{ + NetPacketEndOfHandHideCardsData *tmpData = (NetPacketEndOfHandHideCardsData *)GetRawData(); + assert(tmpData); + + tmpData->playerId = htons(inData.playerId); + tmpData->moneyWon = htonl(inData.moneyWon); + tmpData->playerMoney = htonl(inData.playerMoney); +} + +void +NetPacketEndOfHandHideCards::GetData(NetPacketEndOfHandHideCards::Data &outData) const +{ + NetPacketEndOfHandHideCardsData *tmpData = (NetPacketEndOfHandHideCardsData *)GetRawData(); + assert(tmpData); + + outData.playerId = ntohs(tmpData->playerId); + outData.moneyWon = ntohl(tmpData->moneyWon); + outData.playerMoney = ntohl(tmpData->playerMoney); +} + +const NetPacketEndOfHandHideCards * +NetPacketEndOfHandHideCards::ToNetPacketEndOfHandHideCards() const +{ + return this; +} + +void +NetPacketEndOfHandHideCards::Check(const NetPacketHeader* data) const +{ + assert(data); + + u_int16_t dataLen = ntohs(data->length); + if (dataLen != sizeof(NetPacketEndOfHandHideCardsData)) + { + throw NetException(ERR_SOCK_INVALID_PACKET, 0); + } +} + +//----------------------------------------------------------------------------- + NetPacketSendChatText::NetPacketSendChatText() : NetPacket(NET_TYPE_SEND_CHAT_TEXT, sizeof(NetPacketSendChatTextData)) { diff --git a/src/net/common/serverrecvstate.cpp b/src/net/common/serverrecvstate.cpp index 9593df12..01427869 100644 --- a/src/net/common/serverrecvstate.cpp +++ b/src/net/common/serverrecvstate.cpp @@ -33,6 +33,7 @@ using namespace std; #define SERVER_WAIT_TIMEOUT_MSEC 50 +#define SERVER_NEXT_HAND_DELAY_SEC 5 ServerRecvState::~ServerRecvState() @@ -319,6 +320,11 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server) Game &curGame = server.GetGame(); curGame.initHand(); + // HACK: Skip GUI notification run + curGame.getCurrentHand()->getFlop()->resetFirstRun(); + curGame.getCurrentHand()->getTurn()->resetFirstRun(); + curGame.getCurrentHand()->getRiver()->resetFirstRun(); + PlayerInterface **playerArray = curGame.getPlayerArray(); // Send cards to all players. @@ -380,7 +386,7 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server) server.SetState(ServerRecvStateStartRound::Instance()); - return MSG_NET_GAME_SERVER_HAND; + return MSG_NET_GAME_SERVER_HAND_START; } //----------------------------------------------------------------------------- @@ -403,51 +409,142 @@ ServerRecvStateStartRound::~ServerRecvStateStartRound() int ServerRecvStateStartRound::Process(ServerRecvThread &server) { + int retVal = MSG_SOCK_INTERNAL_PENDING; Game &curGame = server.GetGame(); - curGame.getCurrentHand()->switchRounds(); - // Call main loop - if state changes, call again. int newRound = curGame.getCurrentHand()->getActualRound(); int curRound; do { curRound = newRound; - GameRun(curGame, curRound); + curGame.getCurrentHand()->switchRounds(); + if (!curGame.getCurrentHand()->getAllInCondition()) + GameRun(curGame); newRound = curGame.getCurrentHand()->getActualRound(); // If round changes, deal cards if needed. if (newRound != curRound) { - // HACK: Skip GUI notification run - GameRun(curGame, newRound); - SendNewRoundCards(server, curGame); + assert(newRound > curRound); + SendNewRoundCards(server, curGame, newRound); } } while (newRound != curRound); - // Retrieve current player. - PlayerInterface *curPlayer = GetCurrentPlayer(curGame); - assert(curPlayer); // TODO throw exception - assert(curPlayer->getMyActiveStatus()); // TODO throw exception + if (newRound != GAME_STATE_POST_RIVER) // continue hand + { + if (!curGame.getCurrentHand()->getAllInCondition()) + { + // Retrieve current player. + PlayerInterface *curPlayer = GetCurrentPlayer(curGame); + assert(curPlayer); // TODO throw exception + assert(curPlayer->getMyActiveStatus()); // TODO throw exception - boost::shared_ptr notification(new NetPacketPlayersTurn); - NetPacketPlayersTurn::Data playersTurnData; - playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getActualRound(); - playersTurnData.playerId = curPlayer->getMyUniqueID(); - static_cast(notification.get())->SetData(playersTurnData); + boost::shared_ptr notification(new NetPacketPlayersTurn); + NetPacketPlayersTurn::Data playersTurnData; + playersTurnData.gameState = (GameState)curGame.getCurrentHand()->getActualRound(); + playersTurnData.playerId = curPlayer->getMyUniqueID(); + static_cast(notification.get())->SetData(playersTurnData); - server.SendToAllPlayers(notification); + server.SendToAllPlayers(notification); - server.SetState(ServerRecvStateWaitPlayerAction::Instance()); + server.SetState(ServerRecvStateWaitPlayerAction::Instance()); - return MSG_NET_GAME_SERVER_ROUND; + retVal = MSG_NET_GAME_SERVER_ROUND; + } + } + else // hand is over + { + // Let the engine find out the winner(s). + curGame.getCurrentHand()->getRiver()->postRiverRun(); + + // Count active players. If only one player is left, no cards are shown. + int activePlayersCounter = 0; + std::list activePlayers; + for (int i = 0; i < curGame.getActualQuantityPlayers() ; i++) + { + if (curGame.getPlayerArray()[i]->getMyActiveStatus() + && curGame.getPlayerArray()[i]->getMyAction() != PLAYER_ACTION_FOLD) + { + activePlayersCounter++; + activePlayers.push_back(curGame.getPlayerArray()[i]); + } + } + assert(activePlayersCounter); + assert(!activePlayers.empty()); + + if (activePlayersCounter == 1) + { + // End of Hand, but keep cards hidden. + PlayerInterface *player = activePlayers.front(); + boost::shared_ptr endHand(new NetPacketEndOfHandHideCards); + NetPacketEndOfHandHideCards::Data endHandData; + endHandData.playerId = player->getMyUniqueID(); + endHandData.moneyWon = 0; // TODO + endHandData.playerMoney = player->getMyCash(); + static_cast(endHand.get())->SetData(endHandData); + + server.SendToAllPlayers(endHand); + } + else + { + // End of Hand - show cards of active players. + boost::shared_ptr endHand(new NetPacketEndOfHandShowCards); + NetPacketEndOfHandShowCards::Data endHandData; + + std::list::iterator i = activePlayers.begin(); + std::list::iterator end = activePlayers.end(); + + while (i != end) + { + NetPacketEndOfHandShowCards::PlayerResult tmpPlayerResult; + tmpPlayerResult.playerId = (*i)->getMyUniqueID(); + + int tmpCards[2]; + (*i)->getMyCards(tmpCards); + tmpPlayerResult.cards[0] = static_cast(tmpCards[0]); + tmpPlayerResult.cards[1] = static_cast(tmpCards[1]); + + for (int num = 0; num < 5; num++) + tmpPlayerResult.bestHandPos[num] = (*i)->getMyBestHandPosition()[num]; + + tmpPlayerResult.valueOfCards = (*i)->getMyCardsValueInt(); + tmpPlayerResult.moneyWon = 0; // TODO + tmpPlayerResult.playerMoney = (*i)->getMyCash(); + + endHandData.playerResults.push_back(tmpPlayerResult); + ++i; + } + static_cast(endHand.get())->SetData(endHandData); + + server.SendToAllPlayers(endHand); + } + // Start next hand - if enough players are left. + int playersPositiveCashCounter = 0; + for (int i = 0; i < curGame.getStartQuantityPlayers(); i++) + { + if (curGame.getCurrentHand()->getPlayerArray()[i]->getMyCash() > 0) + playersPositiveCashCounter++; + } + if (playersPositiveCashCounter == 1) + server.SetState(ServerRecvStateFinal::Instance()); // TODO + else + { + boost::microsec_timer delayTimer; + delayTimer.start(); + ServerRecvStateNextHand::Instance().SetTimer(delayTimer); + server.SetState(ServerRecvStateNextHand::Instance()); + retVal = MSG_NET_GAME_SERVER_HAND_END; + } + } + return retVal; } void -ServerRecvStateStartRound::GameRun(Game &curGame, int state) +ServerRecvStateStartRound::GameRun(Game &curGame) { // TODO: no switch needed here if game states are polymorphic - switch(state) { + switch(curGame.getCurrentHand()->getActualRound()) { case GAME_STATE_PREFLOP: { // Preflop starten curGame.getCurrentHand()->getPreflop()->preflopRun(); @@ -497,10 +594,10 @@ ServerRecvStateStartRound::GetCurrentPlayer(Game &curGame) } void -ServerRecvStateStartRound::SendNewRoundCards(ServerRecvThread &server, Game &curGame) +ServerRecvStateStartRound::SendNewRoundCards(ServerRecvThread &server, Game &curGame, int state) { // TODO: no switch needed here if game states are polymorphic - switch(curGame.getCurrentHand()->getActualRound()) { + switch(state) { case GAME_STATE_PREFLOP: { // nothing to do } break; @@ -510,9 +607,8 @@ ServerRecvStateStartRound::SendNewRoundCards(ServerRecvThread &server, Game &cur curGame.getCurrentHand()->getBoard()->getMyCards(cards); boost::shared_ptr notifyCards(new NetPacketDealFlopCards); NetPacketDealFlopCards::Data notifyCardsData; - notifyCardsData.flopCards[0] = static_cast(cards[0]); - notifyCardsData.flopCards[1] = static_cast(cards[1]); - notifyCardsData.flopCards[2] = static_cast(cards[2]); + for (int num = 0; num < 3; num++) + notifyCardsData.flopCards[num] = static_cast(cards[num]); static_cast(notifyCards.get())->SetData(notifyCardsData); server.SendToAllPlayers(notifyCards); } break; @@ -658,6 +754,39 @@ ServerRecvStateWaitPlayerAction::SetHighestSet(Game &curGame, int highestSet) //----------------------------------------------------------------------------- +ServerRecvStateNextHand & +ServerRecvStateNextHand::Instance() +{ + static ServerRecvStateNextHand state; + return state; +} + +ServerRecvStateNextHand::ServerRecvStateNextHand() +{ +} + +ServerRecvStateNextHand::~ServerRecvStateNextHand() +{ +} + +void +ServerRecvStateNextHand::SetTimer(const boost::microsec_timer &timer) +{ + m_delayTimer = timer; +} + +int +ServerRecvStateNextHand::Process(ServerRecvThread &server) +{ + if (m_delayTimer.elapsed().seconds() >= SERVER_NEXT_HAND_DELAY_SEC) + server.SetState(ServerRecvStateStartHand::Instance()); + Thread::Msleep(10); + + return MSG_SOCK_INTERNAL_PENDING; +} + +//----------------------------------------------------------------------------- + ServerRecvStateFinal & ServerRecvStateFinal::Instance() { diff --git a/src/net/netpacket.h b/src/net/netpacket.h index 2e3ea59a..de41cca1 100644 --- a/src/net/netpacket.h +++ b/src/net/netpacket.h @@ -34,6 +34,7 @@ #define MAX_NAME_SIZE 64 #define MAX_PASSWORD_SIZE 64 #define MAX_CHAT_TEXT_SIZE 128 +#define MAX_NUM_PLAYER_RESULTS MAX_NUMBER_OF_PLAYERS struct NetPacketHeader; @@ -51,6 +52,8 @@ class NetPacketPlayersActionRejected; class NetPacketDealFlopCards; class NetPacketDealTurnCard; class NetPacketDealRiverCard; +class NetPacketEndOfHandShowCards; +class NetPacketEndOfHandHideCards; class NetPacketSendChatText; class NetPacketChatText; class NetPacketError; @@ -85,6 +88,8 @@ public: virtual const NetPacketDealFlopCards *ToNetPacketDealFlopCards() const; virtual const NetPacketDealTurnCard *ToNetPacketDealTurnCard() const; virtual const NetPacketDealRiverCard *ToNetPacketDealRiverCard() const; + virtual const NetPacketEndOfHandShowCards *ToNetPacketEndOfHandShowCards() const; + virtual const NetPacketEndOfHandHideCards *ToNetPacketEndOfHandHideCards() const; virtual const NetPacketSendChatText *ToNetPacketSendChatText() const; virtual const NetPacketChatText *ToNetPacketChatText() const; virtual const NetPacketError *ToNetPacketError() const; @@ -423,6 +428,66 @@ protected: virtual void Check(const NetPacketHeader* data) const; }; +class NetPacketEndOfHandShowCards : public NetPacket +{ +public: + struct PlayerResult + { + u_int16_t playerId; + u_int16_t cards[2]; + u_int16_t bestHandPos[5]; + u_int32_t valueOfCards; + u_int32_t moneyWon; + u_int32_t playerMoney; + }; + + typedef std::list PlayerResultList; + + struct Data + { + PlayerResultList playerResults; + }; + + NetPacketEndOfHandShowCards(); + virtual ~NetPacketEndOfHandShowCards(); + + virtual boost::shared_ptr Clone() const; + + void SetData(const Data &inData); + void GetData(Data &outData) const; + + virtual const NetPacketEndOfHandShowCards *ToNetPacketEndOfHandShowCards() const; + +protected: + + virtual void Check(const NetPacketHeader* data) const; +}; + +class NetPacketEndOfHandHideCards : public NetPacket +{ +public: + struct Data + { + u_int16_t playerId; + u_int32_t moneyWon; + u_int32_t playerMoney; + }; + + NetPacketEndOfHandHideCards(); + virtual ~NetPacketEndOfHandHideCards(); + + virtual boost::shared_ptr Clone() const; + + void SetData(const Data &inData); + void GetData(Data &outData) const; + + virtual const NetPacketEndOfHandHideCards *ToNetPacketEndOfHandHideCards() const; + +protected: + + virtual void Check(const NetPacketHeader* data) const; +}; + class NetPacketSendChatText : public NetPacket { public: diff --git a/src/net/serverrecvstate.h b/src/net/serverrecvstate.h index 8d7b525f..3e10cea1 100644 --- a/src/net/serverrecvstate.h +++ b/src/net/serverrecvstate.h @@ -81,7 +81,7 @@ protected: private: - unsigned m_curUniquePlayerId; + u_int16_t m_curUniquePlayerId; }; // Abstract State: Game is running. @@ -151,9 +151,9 @@ protected: // Protected constructor - this is a singleton. ServerRecvStateStartRound(); - static void GameRun(Game &curGame, int state); + static void GameRun(Game &curGame); static PlayerInterface *GetCurrentPlayer(Game &curGame); - static void SendNewRoundCards(ServerRecvThread &server, Game &curGame); + static void SendNewRoundCards(ServerRecvThread &server, Game &curGame, int state); }; // State: Wait for a player action. @@ -178,6 +178,30 @@ protected: static void SetHighestSet(Game &curGame, int highestSet); }; +// State: Final. +class ServerRecvStateNextHand : public ServerRecvStateRunning +{ +public: + // Access the state singleton. + static ServerRecvStateNextHand &Instance(); + + virtual ~ServerRecvStateNextHand(); + + void SetTimer(const boost::microsec_timer &timer); + + // + virtual int Process(ServerRecvThread &server); + +protected: + + // Protected constructor - this is a singleton. + ServerRecvStateNextHand(); + +private: + + boost::microsec_timer m_delayTimer; +}; + // State: Final. class ServerRecvStateFinal : public ServerRecvStateRunning diff --git a/src/net/serverrecvthread.h b/src/net/serverrecvthread.h index c34cb3fc..abfdbbfc 100644 --- a/src/net/serverrecvthread.h +++ b/src/net/serverrecvthread.h @@ -169,6 +169,7 @@ friend class ServerRecvStateStartGame; friend class ServerRecvStateStartHand; friend class ServerRecvStateStartRound; friend class ServerRecvStateWaitPlayerAction; +friend class ServerRecvStateNextHand; }; #endif diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index 261dc567..bce75293 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -48,7 +48,8 @@ #define ERR_NET_INVALID_PASSWORD_STR 105 #define ERR_NET_PLAYER_NAME_IN_USE 106 #define ERR_NET_INVALID_PLAYER_NAME 107 -#define ERR_NET_INVALID_CHAT_TEXT 108 +#define ERR_NET_INVALID_PLAYER_RESULTS 108 +#define ERR_NET_INVALID_CHAT_TEXT 109 // This is an internal message which is not reported. #define MSG_SOCK_INTERNAL_PENDING 0 @@ -65,9 +66,11 @@ // The following messages are game messages. #define MSG_NET_GAME_CLIENT_START 5 #define MSG_NET_GAME_SERVER_START 6 -#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_CLIENT_HAND_START 7 +#define MSG_NET_GAME_CLIENT_HAND_END 8 +#define MSG_NET_GAME_SERVER_HAND_START 9 +#define MSG_NET_GAME_SERVER_HAND_END 10 +#define MSG_NET_GAME_SERVER_ROUND 11 #define MSG_NET_GAME_SERVER_ACTION 12 #endif diff --git a/src/session.cpp b/src/session.cpp index 7be8a4fc..e86d6730 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -194,3 +194,10 @@ void Session::sendChatMessage(const std::string &message) { return; // only act if client is running. myNetClient->SendChatMessage(message); } + +bool Session::isNetworkClientRunning() const +{ + // This, and every place which calls this, is a HACK. + // TODO + return myNetClient != NULL; +} diff --git a/src/session.h b/src/session.h index 049c3d31..f6945640 100755 --- a/src/session.h +++ b/src/session.h @@ -61,6 +61,8 @@ public: void sendChatMessage(const std::string &message); + bool isNetworkClientRunning() const; // TODO hack + private: int currentGameID;