From 015d6b7c72769b0cfe1c5da02064b0755da6ee70 Mon Sep 17 00:00:00 2001 From: floty Date: Sun, 27 Jul 2014 18:09:19 +0200 Subject: [PATCH] create additional class for server time delay; remove define NEW_LOCAL_GAME --- pokerth_lib.pro | 1 + pokerth_server.pro | 1 + src/game_defs.h | 2 - src/gui/qt/startwindow/startwindowimpl.cpp | 2 - src/gui/qt/startwindow/startwindowimpl.h | 2 +- src/net/common/serverdelaytime.cpp | 87 +++++++++++++++++ src/net/common/servergame.cpp | 10 +- src/net/common/servergamestate.cpp | 105 +++------------------ src/net/common/serverlobbythread.cpp | 7 +- src/net/serverdelaytime.h | 33 +++++++ src/net/servergame.h | 19 +--- 11 files changed, 152 insertions(+), 117 deletions(-) create mode 100644 src/net/common/serverdelaytime.cpp create mode 100644 src/net/serverdelaytime.h diff --git a/pokerth_lib.pro b/pokerth_lib.pro index 6db489d8..225a135b 100644 --- a/pokerth_lib.pro +++ b/pokerth_lib.pro @@ -192,6 +192,7 @@ SOURCES += \ src/net/common/servergame.cpp \ src/net/common/servergamestate.cpp \ src/net/common/serverlobbythread.cpp \ + src/net/common/serverdelaytime.cpp \ src/net/common/serverbanmanager.cpp \ src/net/common/servercallback.cpp \ src/net/common/serveradminbot.cpp \ diff --git a/pokerth_server.pro b/pokerth_server.pro index f36031c7..1051b646 100644 --- a/pokerth_server.pro +++ b/pokerth_server.pro @@ -70,6 +70,7 @@ HEADERS += \ src/net/senderhelper.h \ src/net/serveraccepthelper.h \ src/net/serverlobbythread.h \ + src/net/serverdelaytime.h \ src/net/socket_helper.h \ src/net/socket_msg.h \ src/net/socket_startup.h \ diff --git a/src/game_defs.h b/src/game_defs.h index 8917a253..e5bc3fde 100644 --- a/src/game_defs.h +++ b/src/game_defs.h @@ -46,8 +46,6 @@ #define SQLITE_LOG_VERSION 1 -//#define NEW_LOCAL_GAME - #define RANKING_GAME_START_CASH 10000 #define RANKING_GAME_NUMBER_OF_PLAYERS 10 #define RANKING_GAME_START_SBLIND 50 diff --git a/src/gui/qt/startwindow/startwindowimpl.cpp b/src/gui/qt/startwindow/startwindowimpl.cpp index 414dc183..a5794b40 100644 --- a/src/gui/qt/startwindow/startwindowimpl.cpp +++ b/src/gui/qt/startwindow/startwindowimpl.cpp @@ -256,11 +256,9 @@ startWindowImpl::startWindowImpl(ConfigFile *c, Log *l) connect(this, SIGNAL(signalPlayerGameInvitation(unsigned, unsigned, unsigned)), myGameLobbyDialog, SLOT(chatInfoPlayerInvitation(unsigned, unsigned, unsigned))); connect(this, SIGNAL(signalRejectedGameInvitation(unsigned, unsigned, DenyGameInvitationReason)), myGameLobbyDialog, SLOT(chatInfoPlayerRejectedInvitation(unsigned, unsigned, DenyGameInvitationReason))); -#ifdef NEW_LOCAL_GAME QAction *actionStart_Local_Game_new = new QAction("Start (new) local game ...",this); menuPokerTH->addAction(actionStart_Local_Game_new); connect( actionStart_Local_Game_new, SIGNAL( triggered() ), this, SLOT( callNewGameDialogNew() ) ); -#endif this->show(); diff --git a/src/gui/qt/startwindow/startwindowimpl.h b/src/gui/qt/startwindow/startwindowimpl.h index 7693270d..64025a46 100644 --- a/src/gui/qt/startwindow/startwindowimpl.h +++ b/src/gui/qt/startwindow/startwindowimpl.h @@ -162,7 +162,7 @@ public slots: void callLogFileDialog(); void startNewLocalGame(newGameDialogImpl* =0); - void startNewLocalGameNew(newGameDialogImpl* =0); + void startNewLocalGameNew(newGameDialogImpl* =0); void showTimeoutDialog(int msgID, unsigned duration); void hideTimeoutDialog(); diff --git a/src/net/common/serverdelaytime.cpp b/src/net/common/serverdelaytime.cpp new file mode 100644 index 00000000..ac39cab4 --- /dev/null +++ b/src/net/common/serverdelaytime.cpp @@ -0,0 +1,87 @@ +#include "serverdelaytime.h" + +//#define POKERTH_SERVER_TEST + +#ifdef POKERTH_SERVER_TEST +#define SERVER_DELAY_NEXT_GAME_SEC 0 +#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 0 +#define SERVER_DEAL_TURN_CARD_DELAY_SEC 0 +#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 0 +#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 0 +#define SERVER_SHOW_CARDS_DELAY_SEC 0 +#define SERVER_COMPUTER_ACTION_DELAY_SEC 0 +#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 1 +#else +#define SERVER_DELAY_NEXT_GAME_SEC 10 +#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5 +#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2 +#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 2 +#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 2 +#define SERVER_SHOW_CARDS_DELAY_SEC 2 +#define SERVER_COMPUTER_ACTION_DELAY_SEC 2 +#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 2 +#endif + +ServerDelayTime::ServerDelayTime(const ServerMode mode) +{ + if(mode == SERVER_MODE_LAN_LOCAL) { + nextGameDelay = 0; + dealFlopCardsDelay = 0; + dealTurnCardsDelay = 0; + dealRiverCardsDelay = 0; + dealAddAllInDelay = 0; + showCardsDelay = 0; + computerActionDelay = 0; + playerTimeoutAddDelay = 0; + } else { + nextGameDelay = SERVER_DELAY_NEXT_GAME_SEC; + dealFlopCardsDelay = SERVER_DEAL_FLOP_CARDS_DELAY_SEC; + dealTurnCardsDelay = SERVER_DEAL_TURN_CARD_DELAY_SEC; + dealRiverCardsDelay = SERVER_DEAL_RIVER_CARD_DELAY_SEC; + dealAddAllInDelay = SERVER_DEAL_ADD_ALL_IN_DELAY_SEC; + showCardsDelay = SERVER_SHOW_CARDS_DELAY_SEC; + computerActionDelay = SERVER_COMPUTER_ACTION_DELAY_SEC; + playerTimeoutAddDelay = SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC; + } + +} + +int ServerDelayTime::getNextGameDelay() const +{ + return nextGameDelay; +} + +int ServerDelayTime::getDealFlopCardsDelay() const +{ + return dealFlopCardsDelay; +} + +int ServerDelayTime::getDealTurnCardsDelay() const +{ + return dealTurnCardsDelay; +} + +int ServerDelayTime::getDealRiverCardsDelay() const +{ + return dealRiverCardsDelay; +} + +int ServerDelayTime::getDealAddAllInDelay() const +{ + return dealAddAllInDelay; +} + +int ServerDelayTime::getShowCardsDelay() const +{ + return showCardsDelay; +} + +int ServerDelayTime::getComputerActionDelay() const +{ + return computerActionDelay; +} + +int ServerDelayTime::getPlayerTimeoutAddDelay() const +{ + return playerTimeoutAddDelay; +} diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index c6aa182f..41884d0e 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -66,13 +66,13 @@ static bool LessThanPlayerHandStartMoney(const boost::shared_ptr lobbyThread, u_int32_t id, const string &name, const string &pwd, const GameData &gameData, - unsigned adminPlayerId, unsigned creatorPlayerDBId, GuiInterface &gui, ConfigFile &playerConfig) + unsigned adminPlayerId, unsigned creatorPlayerDBId, GuiInterface &gui, ConfigFile &playerConfig, const ServerMode mode) : m_adminPlayerId(adminPlayerId), m_lobbyThread(lobbyThread), m_gui(gui), m_gameData(gameData), m_curState(NULL), m_id(id), m_name(name), m_password(pwd), m_creatorPlayerDBId(creatorPlayerDBId), m_playerConfig(playerConfig), m_gameNum(1), m_curPetitionId(1), m_voteKickTimer(lobbyThread->GetIOService()), m_stateTimer1(lobbyThread->GetIOService()), m_stateTimer2(lobbyThread->GetIOService()), - m_isNameReported(false) + m_isNameReported(false), m_serverDelayTime(mode) { LOG_VERBOSE("Game object " << GetId() << " created."); } @@ -1042,6 +1042,12 @@ ServerGame::GetSessionManager() const return m_sessionManager; } +const ServerDelayTime +ServerGame::GetServerDelayTime() const +{ + return m_serverDelayTime; +} + ServerDBInterface & ServerGame::GetDatabase() { diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index 50e56b48..380ba94a 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -58,39 +58,6 @@ using namespace std::chrono; using namespace boost::chrono; #endif -//#define POKERTH_SERVER_TEST - -#ifdef POKERTH_SERVER_TEST -#define SERVER_DELAY_NEXT_GAME_SEC 0 -#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 0 -#define SERVER_DEAL_TURN_CARD_DELAY_SEC 0 -#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 0 -#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 0 -#define SERVER_SHOW_CARDS_DELAY_SEC 0 -#define SERVER_COMPUTER_ACTION_DELAY_SEC 0 -#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 1 -#else -#define SERVER_DELAY_NEXT_GAME_SEC 10 -#define SERVER_DEAL_FLOP_CARDS_DELAY_SEC 5 -#define SERVER_DEAL_TURN_CARD_DELAY_SEC 2 -#define SERVER_DEAL_RIVER_CARD_DELAY_SEC 2 -#define SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 2 -#define SERVER_SHOW_CARDS_DELAY_SEC 2 -#define SERVER_COMPUTER_ACTION_DELAY_SEC 2 -#define SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 2 -#endif - -#ifdef NEW_LOCAL_GAME -#define LAN_LOCAL_SERVER_DELAY_NEXT_GAME_SEC 0 -#define LAN_LOCAL_SERVER_DEAL_FLOP_CARDS_DELAY_SEC 0 -#define LAN_LOCAL_SERVER_DEAL_TURN_CARD_DELAY_SEC 0 -#define LAN_LOCAL_SERVER_DEAL_RIVER_CARD_DELAY_SEC 0 -#define LAN_LOCAL_SERVER_DEAL_ADD_ALL_IN_DELAY_SEC 0 -#define LAN_LOCAL_SERVER_SHOW_CARDS_DELAY_SEC 0 -#define LAN_LOCAL_SERVER_COMPUTER_ACTION_DELAY_SEC 0 -#define LAN_LOCAL_SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC 0 -#endif - #define SERVER_START_GAME_TIMEOUT_SEC 10 #define SERVER_AUTOSTART_GAME_DELAY_SEC 6 #define SERVER_GAME_ADMIN_WARNING_REMAINING_SEC 60 @@ -1018,12 +985,9 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) server->SendToAllPlayers(allIn, SessionData::Game | SessionData::Spectating); curGame.getCurrentHand()->setCardsShown(true); -#ifdef NEW_LOCAL_GAME - if(server->getLanLocal()) server->GetStateTimer1().expires_from_now(seconds(LAN_LOCAL_SERVER_SHOW_CARDS_DELAY_SEC)); - else server->GetStateTimer1().expires_from_now(seconds(SERVER_SHOW_CARDS_DELAY_SEC)); -#else - server->GetStateTimer1().expires_from_now(seconds(SERVER_SHOW_CARDS_DELAY_SEC)); -#endif + server->GetStateTimer1().expires_from_now( + seconds(server->GetServerDelayTime().getShowCardsDelay())); + server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateHand::TimerShowCards, this, boost::asio::placeholders::error, server)); @@ -1058,12 +1022,9 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) // If the player is computer controlled, let the engine act. if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) { -#ifdef NEW_LOCAL_GAME - if(server->getLanLocal()) server->GetStateTimer1().expires_from_now(seconds(LAN_LOCAL_SERVER_COMPUTER_ACTION_DELAY_SEC)); - else server->GetStateTimer1().expires_from_now(seconds(SERVER_COMPUTER_ACTION_DELAY_SEC)); -#else - server->GetStateTimer1().expires_from_now(seconds(SERVER_COMPUTER_ACTION_DELAY_SEC)); -#endif + server->GetStateTimer1().expires_from_now( + seconds(server->GetServerDelayTime().getComputerActionDelay())); + server->GetStateTimer1().async_wait( boost::bind( &ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server)); @@ -1141,18 +1102,8 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) server->InternalEndGame(); // View a dialog for a new game - delayed. -#ifdef NEW_LOCAL_GAME - if(server->getLanLocal()) { - server->GetStateTimer1().expires_from_now( - seconds(LAN_LOCAL_SERVER_DELAY_NEXT_GAME_SEC)); - } else { - server->GetStateTimer1().expires_from_now( - seconds(SERVER_DELAY_NEXT_GAME_SEC)); - } -#else server->GetStateTimer1().expires_from_now( - seconds(SERVER_DELAY_NEXT_GAME_SEC)); -#endif + seconds(server->GetServerDelayTime().getNextGameDelay())); server->GetStateTimer1().async_wait( boost::bind( @@ -1230,42 +1181,18 @@ int ServerGameStateHand::GetDealCardsDelaySec(ServerGame &server) { Game &curGame = server.GetGame(); -#ifdef NEW_LOCAL_GAME - int allInDelay; - if(server.getLanLocal()) { - allInDelay = curGame.getCurrentHand()->getAllInCondition() ? LAN_LOCAL_SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0; - } else { - allInDelay = curGame.getCurrentHand()->getAllInCondition() ? SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0; - } -#else - int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? SERVER_DEAL_ADD_ALL_IN_DELAY_SEC : 0; -#endif + int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? server.GetServerDelayTime().getDealAddAllInDelay() : 0; int delay = 0; switch(curGame.getCurrentHand()->getCurrentRound()) { case GAME_STATE_FLOP: -#ifdef NEW_LOCAL_GAME - if(server.getLanLocal()) delay = LAN_LOCAL_SERVER_DEAL_FLOP_CARDS_DELAY_SEC; - else delay = SERVER_DEAL_FLOP_CARDS_DELAY_SEC; -#else - delay = SERVER_DEAL_FLOP_CARDS_DELAY_SEC; -#endif + delay = server.GetServerDelayTime().getDealFlopCardsDelay(); break; case GAME_STATE_TURN: -#ifdef NEW_LOCAL_GAME - if(server.getLanLocal()) delay = LAN_LOCAL_SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay; - else delay = SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay; -#else - delay = SERVER_DEAL_TURN_CARD_DELAY_SEC + allInDelay; -#endif + delay = server.GetServerDelayTime().getDealTurnCardsDelay() + allInDelay; break; case GAME_STATE_RIVER: -#ifdef NEW_LOCAL_GAME - if(server.getLanLocal()) delay = LAN_LOCAL_SERVER_DEAL_RIVER_CARD_DELAY_SEC; - else delay = SERVER_DEAL_RIVER_CARD_DELAY_SEC; -#else - delay = SERVER_DEAL_RIVER_CARD_DELAY_SEC; -#endif + delay = server.GetServerDelayTime().getDealRiverCardsDelay(); break; default: break; @@ -1562,15 +1489,9 @@ ServerGameStateWaitPlayerAction::Enter(boost::shared_ptr server) { if (server->GetGameData().playerActionTimeoutSec > 0) { // zero means unlimited thinking time #ifdef POKERTH_SERVER_TEST - int timeoutSec = SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC; + int timeoutSec = server->GetServerDelayTime().getPlayerTimeoutAddDelay(); #else -#ifdef NEW_LOCAL_GAME - int timeoutSec; - if(server->getLanLocal()) timeoutSec = server->GetGameData().playerActionTimeoutSec + LAN_LOCAL_SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC; - else timeoutSec = server->GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC; -#else - int timeoutSec = server->GetGameData().playerActionTimeoutSec + SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC; -#endif + int timeoutSec = server->GetServerDelayTime().getPlayerTimeoutAddDelay() + server->GetGameData().playerActionTimeoutSec; #endif server->GetStateTimer1().expires_from_now(seconds(timeoutSec)); diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 20bdb141..31840135 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -1353,10 +1353,9 @@ ServerLobbyThread::HandleNetPacketCreateGame(boost::shared_ptr sess session->GetPlayerData()->GetUniqueId(), session->GetPlayerData()->GetDBId(), GetGui(), - m_serverConfig)); -#ifdef NEW_LOCAL_GAME - if(m_mode == SERVER_MODE_LAN_LOCAL) game->setLanLocal(true); -#endif + m_serverConfig, + m_mode)); + game->Init(); // Add game to list of games. diff --git a/src/net/serverdelaytime.h b/src/net/serverdelaytime.h new file mode 100644 index 00000000..7a18d426 --- /dev/null +++ b/src/net/serverdelaytime.h @@ -0,0 +1,33 @@ +#ifndef SERVERDELAYTIME_H +#define SERVERDELAYTIME_H + +#include + +class ServerDelayTime +{ +public: + ServerDelayTime(const ServerMode mode); + + int getNextGameDelay() const; + int getDealFlopCardsDelay() const; + int getDealTurnCardsDelay() const; + int getDealRiverCardsDelay() const; + int getDealAddAllInDelay() const; + int getShowCardsDelay() const; + int getComputerActionDelay() const; + int getPlayerTimeoutAddDelay() const; + +private: + + int nextGameDelay; + int dealFlopCardsDelay; + int dealTurnCardsDelay; + int dealRiverCardsDelay; + int dealAddAllInDelay; + int showCardsDelay; + int computerActionDelay; + int playerTimeoutAddDelay; + +}; + +#endif // SERVERDELAYTIME_H diff --git a/src/net/servergame.h b/src/net/servergame.h index fbac9b85..08ceab35 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -57,7 +58,7 @@ class ServerGame : public boost::enable_shared_from_this public: ServerGame( boost::shared_ptr lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, const GameData &gameData, - unsigned adminPlayerId, unsigned creatorPlayerDBId, GuiInterface &gui, ConfigFile &playerConfig); + unsigned adminPlayerId, unsigned creatorPlayerDBId, GuiInterface &gui, ConfigFile &playerConfig, const ServerMode mode); virtual ~ServerGame(); void Init(); @@ -126,15 +127,6 @@ public: void KickPlayer(unsigned playerId); -#ifdef NEW_LOCAL_GAME - bool getLanLocal() { - return lan_local; - } - void setLanLocal(bool theValue) { - lan_local = theValue; - } -#endif - protected: struct RankingData { @@ -200,6 +192,7 @@ protected: const SessionManager &GetSessionManager() const; SessionManager &GetSessionManager(); ServerDBInterface &GetDatabase(); + const ServerDelayTime GetServerDelayTime() const; private: ServerGame(const ServerGame &other); @@ -235,6 +228,8 @@ private: boost::shared_ptr m_database; GuiInterface &m_gui; + ServerDelayTime m_serverDelayTime; + const GameData m_gameData; StartData m_startData; boost::shared_ptr m_game; @@ -262,10 +257,6 @@ private: friend class ServerGameStateWaitPlayerAction; friend class ServerGameStateWaitNextHand; -#ifdef NEW_LOCAL_GAME - bool lan_local; -#endif - }; #endif