Merge branch 'new_local_game' of github.com:/pokerth/pokerth into gocode

This commit is contained in:
lotodore
2014-08-19 18:18:32 +02:00
11 changed files with 152 additions and 117 deletions
+1
View File
@@ -192,6 +192,7 @@ SOURCES += \
src/net/common/servergame.cpp \ src/net/common/servergame.cpp \
src/net/common/servergamestate.cpp \ src/net/common/servergamestate.cpp \
src/net/common/serverlobbythread.cpp \ src/net/common/serverlobbythread.cpp \
src/net/common/serverdelaytime.cpp \
src/net/common/serverbanmanager.cpp \ src/net/common/serverbanmanager.cpp \
src/net/common/servercallback.cpp \ src/net/common/servercallback.cpp \
src/net/common/serveradminbot.cpp \ src/net/common/serveradminbot.cpp \
+1
View File
@@ -70,6 +70,7 @@ HEADERS += \
src/net/senderhelper.h \ src/net/senderhelper.h \
src/net/serveraccepthelper.h \ src/net/serveraccepthelper.h \
src/net/serverlobbythread.h \ src/net/serverlobbythread.h \
src/net/serverdelaytime.h \
src/net/socket_helper.h \ src/net/socket_helper.h \
src/net/socket_msg.h \ src/net/socket_msg.h \
src/net/socket_startup.h \ src/net/socket_startup.h \
-2
View File
@@ -46,8 +46,6 @@
#define SQLITE_LOG_VERSION 1 #define SQLITE_LOG_VERSION 1
//#define NEW_LOCAL_GAME
#define RANKING_GAME_START_CASH 10000 #define RANKING_GAME_START_CASH 10000
#define RANKING_GAME_NUMBER_OF_PLAYERS 10 #define RANKING_GAME_NUMBER_OF_PLAYERS 10
#define RANKING_GAME_START_SBLIND 50 #define RANKING_GAME_START_SBLIND 50
@@ -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(signalPlayerGameInvitation(unsigned, unsigned, unsigned)), myGameLobbyDialog, SLOT(chatInfoPlayerInvitation(unsigned, unsigned, unsigned)));
connect(this, SIGNAL(signalRejectedGameInvitation(unsigned, unsigned, DenyGameInvitationReason)), myGameLobbyDialog, SLOT(chatInfoPlayerRejectedInvitation(unsigned, unsigned, DenyGameInvitationReason))); 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); QAction *actionStart_Local_Game_new = new QAction("Start (new) local game ...",this);
menuPokerTH->addAction(actionStart_Local_Game_new); menuPokerTH->addAction(actionStart_Local_Game_new);
connect( actionStart_Local_Game_new, SIGNAL( triggered() ), this, SLOT( callNewGameDialogNew() ) ); connect( actionStart_Local_Game_new, SIGNAL( triggered() ), this, SLOT( callNewGameDialogNew() ) );
#endif
this->show(); this->show();
+1 -1
View File
@@ -162,7 +162,7 @@ public slots:
void callLogFileDialog(); void callLogFileDialog();
void startNewLocalGame(newGameDialogImpl* =0); void startNewLocalGame(newGameDialogImpl* =0);
void startNewLocalGameNew(newGameDialogImpl* =0); void startNewLocalGameNew(newGameDialogImpl* =0);
void showTimeoutDialog(int msgID, unsigned duration); void showTimeoutDialog(int msgID, unsigned duration);
void hideTimeoutDialog(); void hideTimeoutDialog();
+87
View File
@@ -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;
}
+8 -2
View File
@@ -66,13 +66,13 @@ static bool LessThanPlayerHandStartMoney(const boost::shared_ptr<PlayerInterface
ServerGame::ServerGame(boost::shared_ptr<ServerLobbyThread> lobbyThread, u_int32_t id, const string &name, const string &pwd, const GameData &gameData, ServerGame::ServerGame(boost::shared_ptr<ServerLobbyThread> 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_adminPlayerId(adminPlayerId), m_lobbyThread(lobbyThread), m_gui(gui),
m_gameData(gameData), m_curState(NULL), m_id(id), m_name(name), m_gameData(gameData), m_curState(NULL), m_id(id), m_name(name),
m_password(pwd), m_creatorPlayerDBId(creatorPlayerDBId), m_playerConfig(playerConfig), m_password(pwd), m_creatorPlayerDBId(creatorPlayerDBId), m_playerConfig(playerConfig),
m_gameNum(1), m_curPetitionId(1), m_voteKickTimer(lobbyThread->GetIOService()), m_gameNum(1), m_curPetitionId(1), m_voteKickTimer(lobbyThread->GetIOService()),
m_stateTimer1(lobbyThread->GetIOService()), m_stateTimer2(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."); LOG_VERBOSE("Game object " << GetId() << " created.");
} }
@@ -1042,6 +1042,12 @@ ServerGame::GetSessionManager() const
return m_sessionManager; return m_sessionManager;
} }
const ServerDelayTime
ServerGame::GetServerDelayTime() const
{
return m_serverDelayTime;
}
ServerDBInterface & ServerDBInterface &
ServerGame::GetDatabase() ServerGame::GetDatabase()
{ {
+13 -92
View File
@@ -58,39 +58,6 @@ using namespace std::chrono;
using namespace boost::chrono; using namespace boost::chrono;
#endif #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_START_GAME_TIMEOUT_SEC 10
#define SERVER_AUTOSTART_GAME_DELAY_SEC 6 #define SERVER_AUTOSTART_GAME_DELAY_SEC 6
#define SERVER_GAME_ADMIN_WARNING_REMAINING_SEC 60 #define SERVER_GAME_ADMIN_WARNING_REMAINING_SEC 60
@@ -1018,12 +985,9 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
server->SendToAllPlayers(allIn, SessionData::Game | SessionData::Spectating); server->SendToAllPlayers(allIn, SessionData::Game | SessionData::Spectating);
curGame.getCurrentHand()->setCardsShown(true); curGame.getCurrentHand()->setCardsShown(true);
#ifdef NEW_LOCAL_GAME server->GetStateTimer1().expires_from_now(
if(server->getLanLocal()) server->GetStateTimer1().expires_from_now(seconds(LAN_LOCAL_SERVER_SHOW_CARDS_DELAY_SEC)); seconds(server->GetServerDelayTime().getShowCardsDelay()));
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().async_wait( server->GetStateTimer1().async_wait(
boost::bind( boost::bind(
&ServerGameStateHand::TimerShowCards, this, boost::asio::placeholders::error, server)); &ServerGameStateHand::TimerShowCards, this, boost::asio::placeholders::error, server));
@@ -1058,12 +1022,9 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
// If the player is computer controlled, let the engine act. // If the player is computer controlled, let the engine act.
if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) { if (curPlayer->getMyType() == PLAYER_TYPE_COMPUTER) {
#ifdef NEW_LOCAL_GAME server->GetStateTimer1().expires_from_now(
if(server->getLanLocal()) server->GetStateTimer1().expires_from_now(seconds(LAN_LOCAL_SERVER_COMPUTER_ACTION_DELAY_SEC)); seconds(server->GetServerDelayTime().getComputerActionDelay()));
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().async_wait( server->GetStateTimer1().async_wait(
boost::bind( boost::bind(
&ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server)); &ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server));
@@ -1141,18 +1102,8 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr<ServerGame> server)
server->InternalEndGame(); server->InternalEndGame();
// View a dialog for a new game - delayed. // 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( server->GetStateTimer1().expires_from_now(
seconds(SERVER_DELAY_NEXT_GAME_SEC)); seconds(server->GetServerDelayTime().getNextGameDelay()));
#endif
server->GetStateTimer1().async_wait( server->GetStateTimer1().async_wait(
boost::bind( boost::bind(
@@ -1230,42 +1181,18 @@ int
ServerGameStateHand::GetDealCardsDelaySec(ServerGame &server) ServerGameStateHand::GetDealCardsDelaySec(ServerGame &server)
{ {
Game &curGame = server.GetGame(); Game &curGame = server.GetGame();
#ifdef NEW_LOCAL_GAME int allInDelay = curGame.getCurrentHand()->getAllInCondition() ? server.GetServerDelayTime().getDealAddAllInDelay() : 0;
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 delay = 0; int delay = 0;
switch(curGame.getCurrentHand()->getCurrentRound()) { switch(curGame.getCurrentHand()->getCurrentRound()) {
case GAME_STATE_FLOP: case GAME_STATE_FLOP:
#ifdef NEW_LOCAL_GAME delay = server.GetServerDelayTime().getDealFlopCardsDelay();
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
break; break;
case GAME_STATE_TURN: case GAME_STATE_TURN:
#ifdef NEW_LOCAL_GAME delay = server.GetServerDelayTime().getDealTurnCardsDelay() + allInDelay;
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
break; break;
case GAME_STATE_RIVER: case GAME_STATE_RIVER:
#ifdef NEW_LOCAL_GAME delay = server.GetServerDelayTime().getDealRiverCardsDelay();
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
break; break;
default: default:
break; break;
@@ -1562,15 +1489,9 @@ ServerGameStateWaitPlayerAction::Enter(boost::shared_ptr<ServerGame> server)
{ {
if (server->GetGameData().playerActionTimeoutSec > 0) { // zero means unlimited thinking time if (server->GetGameData().playerActionTimeoutSec > 0) { // zero means unlimited thinking time
#ifdef POKERTH_SERVER_TEST #ifdef POKERTH_SERVER_TEST
int timeoutSec = SERVER_PLAYER_TIMEOUT_ADD_DELAY_SEC; int timeoutSec = server->GetServerDelayTime().getPlayerTimeoutAddDelay();
#else #else
#ifdef NEW_LOCAL_GAME int timeoutSec = server->GetServerDelayTime().getPlayerTimeoutAddDelay() + server->GetGameData().playerActionTimeoutSec;
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
#endif #endif
server->GetStateTimer1().expires_from_now(seconds(timeoutSec)); server->GetStateTimer1().expires_from_now(seconds(timeoutSec));
+3 -4
View File
@@ -1353,10 +1353,9 @@ ServerLobbyThread::HandleNetPacketCreateGame(boost::shared_ptr<SessionData> sess
session->GetPlayerData()->GetUniqueId(), session->GetPlayerData()->GetUniqueId(),
session->GetPlayerData()->GetDBId(), session->GetPlayerData()->GetDBId(),
GetGui(), GetGui(),
m_serverConfig)); m_serverConfig,
#ifdef NEW_LOCAL_GAME m_mode));
if(m_mode == SERVER_MODE_LAN_LOCAL) game->setLanLocal(true);
#endif
game->Init(); game->Init();
// Add game to list of games. // Add game to list of games.
+33
View File
@@ -0,0 +1,33 @@
#ifndef SERVERDELAYTIME_H
#define SERVERDELAYTIME_H
#include <game_defs.h>
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
+5 -14
View File
@@ -39,6 +39,7 @@
#include <map> #include <map>
#include <net/sessionmanager.h> #include <net/sessionmanager.h>
#include <net/serverdelaytime.h>
#include <db/serverdbcallback.h> #include <db/serverdbcallback.h>
#include <gui/guiinterface.h> #include <gui/guiinterface.h>
#include <gamedata.h> #include <gamedata.h>
@@ -57,7 +58,7 @@ class ServerGame : public boost::enable_shared_from_this<ServerGame>
public: public:
ServerGame( ServerGame(
boost::shared_ptr<ServerLobbyThread> lobbyThread, u_int32_t id, const std::string &name, const std::string &pwd, const GameData &gameData, boost::shared_ptr<ServerLobbyThread> 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(); virtual ~ServerGame();
void Init(); void Init();
@@ -126,15 +127,6 @@ public:
void KickPlayer(unsigned playerId); void KickPlayer(unsigned playerId);
#ifdef NEW_LOCAL_GAME
bool getLanLocal() {
return lan_local;
}
void setLanLocal(bool theValue) {
lan_local = theValue;
}
#endif
protected: protected:
struct RankingData { struct RankingData {
@@ -200,6 +192,7 @@ protected:
const SessionManager &GetSessionManager() const; const SessionManager &GetSessionManager() const;
SessionManager &GetSessionManager(); SessionManager &GetSessionManager();
ServerDBInterface &GetDatabase(); ServerDBInterface &GetDatabase();
const ServerDelayTime GetServerDelayTime() const;
private: private:
ServerGame(const ServerGame &other); ServerGame(const ServerGame &other);
@@ -235,6 +228,8 @@ private:
boost::shared_ptr<ServerDBInterface> m_database; boost::shared_ptr<ServerDBInterface> m_database;
GuiInterface &m_gui; GuiInterface &m_gui;
ServerDelayTime m_serverDelayTime;
const GameData m_gameData; const GameData m_gameData;
StartData m_startData; StartData m_startData;
boost::shared_ptr<Game> m_game; boost::shared_ptr<Game> m_game;
@@ -262,10 +257,6 @@ private:
friend class ServerGameStateWaitPlayerAction; friend class ServerGameStateWaitPlayerAction;
friend class ServerGameStateWaitNextHand; friend class ServerGameStateWaitNextHand;
#ifdef NEW_LOCAL_GAME
bool lan_local;
#endif
}; };
#endif #endif