diff --git a/src/gui/generic/genericservergui.cpp b/src/gui/generic/genericservergui.cpp index 4c95f605..beb10f64 100644 --- a/src/gui/generic/genericservergui.cpp +++ b/src/gui/generic/genericservergui.cpp @@ -19,6 +19,7 @@ #include "genericservergui.h" #include +#include using namespace std; @@ -53,3 +54,68 @@ void GenericServerGui::waitForNetworkAction(GameState state, unsigned uniquePlay getSession().waitForNetworkServerAction(state, uniquePlayerId); } + +void GenericServerGui::dealHoleCards() +{ +} + +void GenericServerGui::dealFlopCards() +{ +} + +void GenericServerGui::dealTurnCard() +{ +} + +void GenericServerGui::dealRiverCard() +{ +} + +void GenericServerGui::nextPlayerAnimation() +{ +} + +void GenericServerGui::preflopAnimation1() +{ +} + +void GenericServerGui::preflopAnimation2() +{ +} + +void GenericServerGui::flopAnimation1() +{ +} + +void GenericServerGui::flopAnimation2() +{ +} + +void GenericServerGui::turnAnimation1() +{ +} + +void GenericServerGui::turnAnimation2() +{ +} + +void GenericServerGui::riverAnimation1() +{ +} + +void GenericServerGui::riverAnimation2() +{ +} + +void GenericServerGui::postRiverAnimation1() +{ +} + +void GenericServerGui::postRiverRunAnimation1() +{ +} + +void GenericServerGui::flipHolecardsAllIn() +{ +} + diff --git a/src/gui/generic/genericservergui.h b/src/gui/generic/genericservergui.h index 29cbd6db..0d5ccd07 100644 --- a/src/gui/generic/genericservergui.h +++ b/src/gui/generic/genericservergui.h @@ -39,6 +39,30 @@ public: void waitForNetworkAction(GameState state, unsigned uniquePlayerId); + void dealHoleCards(); + void dealFlopCards(); + void dealTurnCard(); + void dealRiverCard(); + + void nextPlayerAnimation(); + + void preflopAnimation1(); + void preflopAnimation2(); + + void flopAnimation1(); + void flopAnimation2(); + + void turnAnimation1(); + void turnAnimation2(); + + void riverAnimation1(); + void riverAnimation2(); + + void postRiverAnimation1(); + void postRiverRunAnimation1(); + + void flipHolecardsAllIn(); + private: boost::shared_ptr mySession; diff --git a/src/gui/generic/serverguiwrapper.cpp b/src/gui/generic/serverguiwrapper.cpp index 78083dbd..6ee124c6 100644 --- a/src/gui/generic/serverguiwrapper.cpp +++ b/src/gui/generic/serverguiwrapper.cpp @@ -74,36 +74,36 @@ void ServerGuiWrapper::refreshPot() const {} void ServerGuiWrapper::refreshGroupbox(int playerID, int status) const {} void ServerGuiWrapper::refreshPlayerName() const {} -void ServerGuiWrapper::dealHoleCards() const {} -void ServerGuiWrapper::dealFlopCards() const {} -void ServerGuiWrapper::dealTurnCard() const {} -void ServerGuiWrapper::dealRiverCard() const {} +void ServerGuiWrapper::dealHoleCards() { myGui->dealHoleCards(); } +void ServerGuiWrapper::dealFlopCards() { myGui->dealFlopCards(); } +void ServerGuiWrapper::dealTurnCard() { myGui->dealTurnCard(); } +void ServerGuiWrapper::dealRiverCard() { myGui->dealRiverCard(); } void ServerGuiWrapper::highlightRoundLabel(string round) const {} -void ServerGuiWrapper::nextPlayerAnimation() const {} +void ServerGuiWrapper::nextPlayerAnimation() { myGui->nextPlayerAnimation(); } -void ServerGuiWrapper::preflopAnimation1() const {} -void ServerGuiWrapper::preflopAnimation2() const {} +void ServerGuiWrapper::preflopAnimation1() { myGui->preflopAnimation1(); } +void ServerGuiWrapper::preflopAnimation2() { myGui->preflopAnimation2(); } -void ServerGuiWrapper::flopAnimation1() const {} -void ServerGuiWrapper::flopAnimation2() const {} +void ServerGuiWrapper::flopAnimation1() { myGui->flopAnimation1(); } +void ServerGuiWrapper::flopAnimation2() { myGui->flopAnimation2(); } -void ServerGuiWrapper::turnAnimation1() const {} -void ServerGuiWrapper::turnAnimation2() const {} +void ServerGuiWrapper::turnAnimation1() { myGui->turnAnimation1(); } +void ServerGuiWrapper::turnAnimation2() { myGui->turnAnimation2(); } -void ServerGuiWrapper::riverAnimation1() const {} -void ServerGuiWrapper::riverAnimation2() const {} +void ServerGuiWrapper::riverAnimation1() { myGui->riverAnimation1(); } +void ServerGuiWrapper::riverAnimation2() { myGui->riverAnimation2(); } -void ServerGuiWrapper::postRiverAnimation1() const {} -void ServerGuiWrapper::postRiverRunAnimation1() const {} +void ServerGuiWrapper::postRiverAnimation1() { myGui->postRiverAnimation1(); } +void ServerGuiWrapper::postRiverRunAnimation1() { myGui->postRiverRunAnimation1(); } -void ServerGuiWrapper::flipHolecardsAllIn() const {} +void ServerGuiWrapper::flipHolecardsAllIn() { myGui->flipHolecardsAllIn(); } -void ServerGuiWrapper::nextRoundCleanGui() const {} +void ServerGuiWrapper::nextRoundCleanGui() {} -void ServerGuiWrapper::meInAction() const {} +void ServerGuiWrapper::meInAction() {} void ServerGuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) {} void ServerGuiWrapper::logNewGameHandMsg(int gameID, int handID) {} diff --git a/src/gui/generic/serverguiwrapper.h b/src/gui/generic/serverguiwrapper.h index 71050872..a5cfdef5 100644 --- a/src/gui/generic/serverguiwrapper.h +++ b/src/gui/generic/serverguiwrapper.h @@ -47,35 +47,35 @@ public: void refreshAll() const; void refreshPlayerName() const; - void dealHoleCards() const; - void dealFlopCards() const; - void dealTurnCard() const; - void dealRiverCard() const; + void dealHoleCards(); + void dealFlopCards(); + void dealTurnCard(); + void dealRiverCard(); void highlightRoundLabel(std::string round) const; - void nextPlayerAnimation() const; + void nextPlayerAnimation(); - void preflopAnimation1() const; - void preflopAnimation2() const; + void preflopAnimation1(); + void preflopAnimation2(); - void flopAnimation1() const; - void flopAnimation2() const; + void flopAnimation1(); + void flopAnimation2(); - void turnAnimation1() const; - void turnAnimation2() const; + void turnAnimation1(); + void turnAnimation2(); - void riverAnimation1() const; - void riverAnimation2() const; + void riverAnimation1(); + void riverAnimation2(); - void postRiverAnimation1() const; - void postRiverRunAnimation1() const; + void postRiverAnimation1(); + void postRiverRunAnimation1(); - void flipHolecardsAllIn() const; + void flipHolecardsAllIn(); - void nextRoundCleanGui() const; + void nextRoundCleanGui(); - void meInAction() const; + void meInAction(); void logPlayerActionMsg(std::string playerName, int action, int setValue) ; void logNewGameHandMsg(int gameID, int handID) ; diff --git a/src/gui/guiinterface.h b/src/gui/guiinterface.h index 742fd7fc..1f202e66 100644 --- a/src/gui/guiinterface.h +++ b/src/gui/guiinterface.h @@ -58,40 +58,40 @@ public: // virtual void refreshCash() const=0; // // Karten-Funktionen - virtual void dealHoleCards() const=0; - virtual void dealFlopCards() const=0; - virtual void dealTurnCard() const=0; - virtual void dealRiverCard() const=0; + virtual void dealHoleCards()=0; + virtual void dealFlopCards()=0; + virtual void dealTurnCard()=0; + virtual void dealRiverCard()=0; virtual void highlightRoundLabel(std::string) const=0; - virtual void nextPlayerAnimation() const=0; + virtual void nextPlayerAnimation()=0; - virtual void preflopAnimation1() const=0; - virtual void preflopAnimation2() const=0; + virtual void preflopAnimation1()=0; + virtual void preflopAnimation2()=0; - virtual void flopAnimation1() const=0; - virtual void flopAnimation2() const=0; + virtual void flopAnimation1()=0; + virtual void flopAnimation2()=0; - virtual void turnAnimation1() const=0; - virtual void turnAnimation2() const=0; + virtual void turnAnimation1()=0; + virtual void turnAnimation2()=0; - virtual void riverAnimation1() const=0; - virtual void riverAnimation2() const=0; + virtual void riverAnimation1()=0; + virtual void riverAnimation2()=0; - virtual void postRiverAnimation1() const=0; - virtual void postRiverRunAnimation1() const=0; -// virtual void postRiverAnimation2() const=0; - virtual void flipHolecardsAllIn() const=0; + virtual void postRiverAnimation1()=0; + virtual void postRiverRunAnimation1()=0; +// virtual void postRiverAnimation2()=0; + virtual void flipHolecardsAllIn()=0; // virtual void handSwitchRounds() const=0; // // virtual void startNewHand() const=0; - virtual void nextRoundCleanGui() const=0; + virtual void nextRoundCleanGui()=0; // // virtual void userWidgetsBackgroudColor() const=0; // virtual void timerBlockerFalse() const=0; - virtual void meInAction() const=0; + virtual void meInAction()=0; //log.cpp diff --git a/src/gui/qt/guiwrapper.cpp b/src/gui/qt/guiwrapper.cpp index 4c5bdeb6..501a6f39 100644 --- a/src/gui/qt/guiwrapper.cpp +++ b/src/gui/qt/guiwrapper.cpp @@ -59,36 +59,36 @@ void GuiWrapper::refreshPot() const { myW->refreshPot(); } void GuiWrapper::refreshGroupbox(int playerID, int status) const { myW->refreshGroupbox(playerID, status); } void GuiWrapper::refreshPlayerName() const { myW->refreshPlayerName(); } -void GuiWrapper::dealHoleCards() const { myW->dealHoleCards(); } -void GuiWrapper::dealFlopCards() const { myW->dealFlopCards0(); } -void GuiWrapper::dealTurnCard() const { myW->dealTurnCards0(); } -void GuiWrapper::dealRiverCard() const { myW->dealRiverCards0(); } +void GuiWrapper::dealHoleCards() { myW->dealHoleCards(); } +void GuiWrapper::dealFlopCards() { myW->dealFlopCards0(); } +void GuiWrapper::dealTurnCard() { myW->dealTurnCards0(); } +void GuiWrapper::dealRiverCard() { myW->dealRiverCards0(); } void GuiWrapper::highlightRoundLabel(string round) const { myW->highlightRoundLabel(round); } -void GuiWrapper::nextPlayerAnimation() const { myW->nextPlayerAnimation(); } +void GuiWrapper::nextPlayerAnimation() { myW->nextPlayerAnimation(); } -void GuiWrapper::preflopAnimation1() const { myW->preflopAnimation1(); } -void GuiWrapper::preflopAnimation2() const { myW->preflopAnimation2(); } +void GuiWrapper::preflopAnimation1() { myW->preflopAnimation1(); } +void GuiWrapper::preflopAnimation2() { myW->preflopAnimation2(); } -void GuiWrapper::flopAnimation1() const { myW->flopAnimation1(); } -void GuiWrapper::flopAnimation2() const { myW->flopAnimation2(); } +void GuiWrapper::flopAnimation1() { myW->flopAnimation1(); } +void GuiWrapper::flopAnimation2() { myW->flopAnimation2(); } -void GuiWrapper::turnAnimation1() const { myW->turnAnimation1(); } -void GuiWrapper::turnAnimation2() const { myW->turnAnimation2(); } +void GuiWrapper::turnAnimation1() { myW->turnAnimation1(); } +void GuiWrapper::turnAnimation2() { myW->turnAnimation2(); } -void GuiWrapper::riverAnimation1() const { myW->riverAnimation1(); } -void GuiWrapper::riverAnimation2() const { myW->riverAnimation2(); } +void GuiWrapper::riverAnimation1() { myW->riverAnimation1(); } +void GuiWrapper::riverAnimation2() { myW->riverAnimation2(); } -void GuiWrapper::postRiverAnimation1() const { myW->postRiverAnimation1(); } -void GuiWrapper::postRiverRunAnimation1() const { myW->postRiverRunAnimation1(); } +void GuiWrapper::postRiverAnimation1() { myW->postRiverAnimation1(); } +void GuiWrapper::postRiverRunAnimation1() { myW->postRiverRunAnimation1(); } -void GuiWrapper::flipHolecardsAllIn() const { myW->flipHolecardsAllIn(); } +void GuiWrapper::flipHolecardsAllIn() { myW->flipHolecardsAllIn(); } -void GuiWrapper::nextRoundCleanGui() const { myW->nextRoundCleanGui(); } +void GuiWrapper::nextRoundCleanGui() { myW->nextRoundCleanGui(); } -void GuiWrapper::meInAction() const { myW->meInAction(); } +void GuiWrapper::meInAction() { myW->meInAction(); } void GuiWrapper::logPlayerActionMsg(string playerName, int action, int setValue) { myLog->logPlayerActionMsg(playerName, action, setValue); } void GuiWrapper::logNewGameHandMsg(int gameID, int handID) { myLog->logNewGameHandMsg(gameID, handID); } diff --git a/src/gui/qt/guiwrapper.h b/src/gui/qt/guiwrapper.h index db559f5b..efe60381 100644 --- a/src/gui/qt/guiwrapper.h +++ b/src/gui/qt/guiwrapper.h @@ -54,35 +54,35 @@ public: void refreshAll() const; void refreshPlayerName() const; - void dealHoleCards() const; - void dealFlopCards() const; - void dealTurnCard() const; - void dealRiverCard() const; + void dealHoleCards(); + void dealFlopCards(); + void dealTurnCard(); + void dealRiverCard(); void highlightRoundLabel(std::string round) const; - void nextPlayerAnimation() const; + void nextPlayerAnimation(); - void preflopAnimation1() const; - void preflopAnimation2() const; + void preflopAnimation1(); + void preflopAnimation2(); - void flopAnimation1() const; - void flopAnimation2() const; + void flopAnimation1(); + void flopAnimation2(); - void turnAnimation1() const; - void turnAnimation2() const; + void turnAnimation1(); + void turnAnimation2(); - void riverAnimation1() const; - void riverAnimation2() const; + void riverAnimation1(); + void riverAnimation2(); - void postRiverAnimation1() const; - void postRiverRunAnimation1() const; + void postRiverAnimation1(); + void postRiverRunAnimation1(); - void flipHolecardsAllIn() const; + void flipHolecardsAllIn(); - void nextRoundCleanGui() const; + void nextRoundCleanGui(); - void meInAction() const; + void meInAction(); void logPlayerActionMsg(std::string playerName, int action, int setValue) ; void logNewGameHandMsg(int gameID, int handID) ; diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 96c67838..3bc598ad 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -40,6 +40,7 @@ #include "log.h" #include "configfile.h" +#include #include @@ -594,7 +595,8 @@ void mainWindowImpl::startNewLocalGame(newGameDialogImpl *v) { // Start new local game - terminate existing network game. mySession->terminateNetworkClient(); - mySession->terminateNetworkServer(); + if (myServerGuiInterface.get()) + myServerGuiInterface->getSession().terminateNetworkServer(); //get values from local game dialog GameData gameData; @@ -630,8 +632,19 @@ void mainWindowImpl::callCreateNetworkGameDialog() { // if (myCreateNetworkGameDialog->result() == QDialog::Accepted ) { + if (!myServerGuiInterface.get()) + { + // Create pseudo Gui Wrapper for the server. + myServerGuiInterface.reset(new ServerGuiWrapper(myConfig, mySession->getGui(), mySession->getGui())); + { + boost::shared_ptr session(new Session(myServerGuiInterface.get(), myConfig)); + myServerGuiInterface->setSession(session); + } + } + + // Terminate existing network games. mySession->terminateNetworkClient(); - mySession->terminateNetworkServer(); + myServerGuiInterface->getSession().terminateNetworkServer(); GameData gameData; gameData.numberOfPlayers = myCreateNetworkGameDialog->spinBox_quantityPlayers->value(); @@ -641,8 +654,8 @@ void mainWindowImpl::callCreateNetworkGameDialog() { gameData.guiSpeed = myCreateNetworkGameDialog->spinBox_gameSpeed->value(); myStartNetworkGameDialog->treeWidget->clear(); - - mySession->startNetworkServer(gameData); + + myServerGuiInterface->getSession().startNetworkServer(gameData); mySession->startNetworkClientForLocalServer(); myStartNetworkGameDialog->exec(); @@ -650,11 +663,11 @@ void mainWindowImpl::callCreateNetworkGameDialog() { if (myStartNetworkGameDialog->result() == QDialog::Accepted ) { - mySession->initiateNetworkServerGame(); + myServerGuiInterface->getSession().initiateNetworkServerGame(); } else { mySession->terminateNetworkClient(); - mySession->terminateNetworkServer(); + myServerGuiInterface->getSession().terminateNetworkServer(); } } @@ -667,7 +680,8 @@ void mainWindowImpl::callJoinNetworkGameDialog() { if (myJoinNetworkGameDialog->result() == QDialog::Accepted ) { mySession->terminateNetworkClient(); - mySession->terminateNetworkServer(); + if (myServerGuiInterface.get()) + myServerGuiInterface->getSession().terminateNetworkServer(); myWaitingForServerGameDialog->treeWidget->clear(); // Maybe use QUrl::toPunycode. diff --git a/src/gui/qt/mainwindow/mainwindowimpl.h b/src/gui/qt/mainwindow/mainwindowimpl.h index cc91ccc9..3e72fc65 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.h +++ b/src/gui/qt/mainwindow/mainwindowimpl.h @@ -35,6 +35,7 @@ class Log; class ConfigFile; class Session; +class GuiInterface; class BoardInterface; // class HandInterface; class PlayerInterface; @@ -199,7 +200,8 @@ public slots: void networkStart(int, int, int, int); private: - + + boost::shared_ptr myServerGuiInterface; boost::shared_ptr mySession; Log *myLog; ConfigFile *myConfig; diff --git a/src/net/common/serverrecvstate.cpp b/src/net/common/serverrecvstate.cpp index 0dac6a68..e7bbffe0 100644 --- a/src/net/common/serverrecvstate.cpp +++ b/src/net/common/serverrecvstate.cpp @@ -28,6 +28,7 @@ #include #include #include +#include using namespace std; @@ -258,10 +259,12 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server) { boost::shared_ptr answer(new NetPacketHandStart); + // Initialize hand. Game &curGame = server.GetGame(); curGame.initHand(); PlayerInterface **playerArray = curGame.getPlayerArray(); + // Send cards to all players. for (int i = 0; i < curGame.getActualQuantityPlayers(); i++) { if (playerArray[i]->getNetSessionData().get()) @@ -278,13 +281,51 @@ ServerRecvStateStartHand::Process(ServerRecvThread &server) } } - server.SetState(ServerRecvStateFinal::Instance()); + // Start hand. + curGame.startHand(); + + server.SetState(ServerRecvStateStartRound::Instance()); return MSG_NET_GAME_SERVER_HAND; } //----------------------------------------------------------------------------- +ServerRecvStateStartRound & +ServerRecvStateStartRound::Instance() +{ + static ServerRecvStateStartRound state; + return state; +} + +ServerRecvStateStartRound::ServerRecvStateStartRound() +{ +} + +ServerRecvStateStartRound::~ServerRecvStateStartRound() +{ +} + +void +ServerRecvStateStartRound::HandleNewConnection(ServerRecvThread &server, boost::shared_ptr connData) +{ + // TODO: send error msg +} + +int +ServerRecvStateStartRound::Process(ServerRecvThread &server) +{ + Game &curGame = server.GetGame(); + + curGame.getCurrentHand()->switchRounds(); + + server.SetState(ServerRecvStateFinal::Instance()); + + return MSG_NET_GAME_SERVER_ROUND; +} + +//----------------------------------------------------------------------------- + ServerRecvStateFinal & ServerRecvStateFinal::Instance() { diff --git a/src/net/serverrecvstate.h b/src/net/serverrecvstate.h index c70f754d..4b649d9c 100644 --- a/src/net/serverrecvstate.h +++ b/src/net/serverrecvstate.h @@ -109,6 +109,27 @@ protected: ServerRecvStateStartHand(); }; +// State: Start new round. +class ServerRecvStateStartRound : public ServerRecvState +{ +public: + // Access the state singleton. + static ServerRecvStateStartRound &Instance(); + + virtual ~ServerRecvStateStartRound(); + + // + virtual void HandleNewConnection(ServerRecvThread &server, boost::shared_ptr data); + + // + virtual int Process(ServerRecvThread &server); + +protected: + + // Protected constructor - this is a singleton. + ServerRecvStateStartRound(); +}; + // State: Final. class ServerRecvStateFinal : public ServerRecvState { diff --git a/src/net/serverrecvthread.h b/src/net/serverrecvthread.h index aec6ee85..1009f3ec 100644 --- a/src/net/serverrecvthread.h +++ b/src/net/serverrecvthread.h @@ -159,6 +159,7 @@ private: friend class ServerRecvStateInit; friend class ServerRecvStateStartGame; friend class ServerRecvStateStartHand; +friend class ServerRecvStateStartRound; }; #endif diff --git a/src/net/socket_msg.h b/src/net/socket_msg.h index 97a2b174..2a719028 100644 --- a/src/net/socket_msg.h +++ b/src/net/socket_msg.h @@ -65,6 +65,7 @@ #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 #endif diff --git a/src/pokerth.cpp b/src/pokerth.cpp index 54252c66..565c3def 100755 --- a/src/pokerth.cpp +++ b/src/pokerth.cpp @@ -89,9 +89,9 @@ int main( int argc, char **argv ) a.installTranslator(&translator); /////////////////////////////////////////////////// - GuiInterface *myGuiInterface = new GuiWrapper(myConfig); + boost::shared_ptr myGuiInterface(new GuiWrapper(myConfig)); { - boost::shared_ptr session(new Session(myGuiInterface, myConfig)); + boost::shared_ptr session(new Session(myGuiInterface.get(), myConfig)); myGuiInterface->setSession(session); } diff --git a/src/session.cpp b/src/session.cpp index eb7d1c7d..716de3d8 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -93,6 +93,11 @@ Game *Session::getCurrentGame() return currentGame; } +GuiInterface *Session::getGui() +{ + return myGui; +} + void Session::startNetworkClient(const string &serverAddress, unsigned serverPort, bool ipv6, const string &pwd) { if (myNetClient || !myGui) diff --git a/src/session.h b/src/session.h index 1739bb01..7d1aae55 100755 --- a/src/session.h +++ b/src/session.h @@ -41,6 +41,8 @@ public: Game *getCurrentGame(); + GuiInterface *getGui(); + void startNetworkClient(const std::string &serverAddress, unsigned serverPort, bool ipv6, const std::string &pwd); void startNetworkClientForLocalServer(); void terminateNetworkClient();