diff --git a/pokerth_db.pro b/pokerth_db.pro index 84a02187..b99f576b 100644 --- a/pokerth_db.pro +++ b/pokerth_db.pro @@ -1,60 +1,62 @@ -# QMake pro-file for PokerTH common library - -TEMPLATE = lib -CODECFORSRC = UTF-8 - -CONFIG += staticlib thread exceptions rtti stl warn_on -UI_DIR = uics -TARGET = lib/pokerth_db -MOC_DIR = mocs -OBJECTS_DIR = obj -DEFINES += ENABLE_IPV6 -QT -= core gui -#PRECOMPILED_HEADER = src/pch_lib.h - -INCLUDEPATH += . \ - src - -DEPENDPATH += . \ - src - -# Input -HEADERS += \ - src/db/serverdbcallback.h \ - src/db/serverdbfactory.h \ - src/db/serverdbinterface.h \ - src/db/serverdbgeneric.h \ - src/db/serverdbfactorygeneric.h - -SOURCES += \ - src/db/common/serverdbcallback.cpp \ - src/db/common/serverdbfactory.cpp \ - src/db/common/serverdbinterface.cpp \ - src/db/common/serverdbgeneric.cpp \ - src/db/common/serverdbfactorygeneric.cpp - -win32{ - DEFINES += CURL_STATICLIB - DEFINES += _WIN32_WINNT=0x0501 - DEPENDPATH += src/net/win32/ src/core/win32 - INCLUDEPATH += ../boost/ ../GnuTLS/include ../curl/include ../zlib -} -!win32{ - ##### My release static build options - #QMAKE_CXXFLAGS += -ffunction-sections -fdata-sections -} - -mac{ - # make it universal - CONFIG += x86 - CONFIG -= ppc - QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 - - # for universal-compilation on PPC-Mac uncomment the following line - # on Intel-Mac you have to comment this line out or build will fail. - # QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk/ - - INCLUDEPATH += /Developer/SDKs/MacOSX10.5.sdk/usr/include/ - INCLUDEPATH += /Library/Frameworks/SDL.framework/Headers - INCLUDEPATH += /Library/Frameworks/SDL_mixer.framework/Headers -} +# QMake pro-file for PokerTH common library + +TEMPLATE = lib +CODECFORSRC = UTF-8 + +CONFIG += staticlib thread exceptions rtti stl warn_on +UI_DIR = uics +TARGET = lib/pokerth_db +MOC_DIR = mocs +OBJECTS_DIR = obj +DEFINES += ENABLE_IPV6 +QT -= core gui +#PRECOMPILED_HEADER = src/pch_lib.h + +INCLUDEPATH += . \ + src + +DEPENDPATH += . \ + src + +# Input +HEADERS += \ + src/db/serverdbcallback.h \ + src/db/serverdbfactory.h \ + src/db/serverdbinterface.h \ + src/db/serverdbgeneric.h \ + src/db/serverdbfactorygeneric.h \ + src/db/serverdbnoaction.h + +SOURCES += \ + src/db/common/serverdbcallback.cpp \ + src/db/common/serverdbfactory.cpp \ + src/db/common/serverdbinterface.cpp \ + src/db/common/serverdbgeneric.cpp \ + src/db/common/serverdbfactorygeneric.cpp \ + src/db/common/serverdbnoaction.cpp + +win32{ + DEFINES += CURL_STATICLIB + DEFINES += _WIN32_WINNT=0x0501 + DEPENDPATH += src/net/win32/ src/core/win32 + INCLUDEPATH += ../boost/ ../GnuTLS/include ../curl/include ../zlib +} +!win32{ + ##### My release static build options + #QMAKE_CXXFLAGS += -ffunction-sections -fdata-sections +} + +mac{ + # make it universal + CONFIG += x86 + CONFIG -= ppc + QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.4 + + # for universal-compilation on PPC-Mac uncomment the following line + # on Intel-Mac you have to comment this line out or build will fail. + # QMAKE_MAC_SDK=/Developer/SDKs/MacOSX10.4u.sdk/ + + INCLUDEPATH += /Developer/SDKs/MacOSX10.5.sdk/usr/include/ + INCLUDEPATH += /Library/Frameworks/SDL.framework/Headers + INCLUDEPATH += /Library/Frameworks/SDL_mixer.framework/Headers +} diff --git a/src/db/common/serverdbnoaction.cpp b/src/db/common/serverdbnoaction.cpp new file mode 100644 index 00000000..8a85ce0e --- /dev/null +++ b/src/db/common/serverdbnoaction.cpp @@ -0,0 +1,29 @@ +/*************************************************************************** + * Copyright (C) 2010 by Lothar May * + * * + * 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 + + +ServerDBNoAction::ServerDBNoAction() +{ +} + +ServerDBNoAction::~ServerDBNoAction() +{ +} diff --git a/src/db/serverdbnoaction.h b/src/db/serverdbnoaction.h new file mode 100644 index 00000000..c6c86128 --- /dev/null +++ b/src/db/serverdbnoaction.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2010 by Lothar May * + * * + * 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. * + ***************************************************************************/ +/* Generic server database implementation. Basically does nothing. */ + +#ifndef _SERVERDBNOACTION_H_ +#define _SERVERDBNOACTION_H_ + +#include + + +class ServerDBNoAction : public ServerDBInterface +{ +public: + ServerDBNoAction(); + virtual ~ServerDBNoAction(); + + virtual void Init(const std::string &host, const std::string &user, const std::string &pwd, + const std::string &database, const std::string &encryptionKey) {} + + virtual void Start() {} + virtual void Stop() {} + + virtual void AsyncPlayerLogin(unsigned requestId, const std::string &playerName) {} + virtual void PlayerLogout(DB_id playerId) {} + + virtual void AsyncCreateGame(unsigned requestId, const std::string &gameName) {} + virtual void SetGamePlayerPlace(DB_id gameId, DB_id playerId, unsigned place) {} + virtual void EndGame(DB_id gameId) {} +}; + +#endif // _SERVERDBNOACTION_H_ diff --git a/src/net/common/servergame.cpp b/src/net/common/servergame.cpp index f61a8a0d..f60e3077 100644 --- a/src/net/common/servergame.cpp +++ b/src/net/common/servergame.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -231,6 +232,12 @@ ServerGame::TimerVoteKick(const boost::system::error_code &ec) void ServerGame::InternalStartGame() { + // Set DB Backend. + if (GetGameData().gameType == GAME_TYPE_RANKING) + m_database = GetLobbyThread().GetDatabase(); + else + m_database.reset(new ServerDBNoAction); + // Set order of players. AssignPlayerNumbers(); @@ -751,6 +758,13 @@ ServerGame::GetSessionManager() const return m_sessionManager; } +ServerDBInterface & +ServerGame::GetDatabase() +{ + assert(m_database); + return *m_database; +} + ServerLobbyThread & ServerGame::GetLobbyThread() { diff --git a/src/net/common/servergamestate.cpp b/src/net/common/servergamestate.cpp index d97304e1..671e677b 100644 --- a/src/net/common/servergamestate.cpp +++ b/src/net/common/servergamestate.cpp @@ -655,8 +655,7 @@ ServerGameStateStartGame::DoStart(boost::shared_ptr server) else { server->InternalStartGame(); - if (server->GetGameData().gameType == GAME_TYPE_RANKING) - server->GetLobbyThread().GetDatabase().AsyncCreateGame(server->GetId(), server->GetName()); + server->GetDatabase().AsyncCreateGame(server->GetId(), server->GetName()); boost::shared_ptr packet(new NetPacket(NetPacket::Alloc)); packet->GetMsg()->present = PokerTHMessage_PR_gameStartMessage; @@ -848,7 +847,7 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) &ServerGameStateHand::TimerComputerAction, this, boost::asio::placeholders::error, server)); } // If the player we are waiting for left, continue without him. - else if (!server->GetSessionManager().IsPlayerConnected(curPlayer->getMyName())) + else if (!server->GetSessionManager().IsPlayerConnected(curPlayer->getMyUniqueID())) { PerformPlayerAction(*server, curPlayer, PLAYER_ACTION_FOLD, 0); @@ -935,11 +934,11 @@ ServerGameStateHand::EngineLoop(boost::shared_ptr server) // Store winner in database. boost::shared_ptr winnerPlayer = *(playersWithCash.begin()); boost::shared_ptr tmpPlayer = server->GetPlayerDataByUniqueId(winnerPlayer->getMyUniqueID()); - if (server->GetGameData().gameType == GAME_TYPE_RANKING && tmpPlayer && server->GetDBId()) + if (tmpPlayer && server->GetDBId()) { cerr << "Setting winner for game " << server->GetDBId() << " player id " << tmpPlayer->GetDBId() << endl; - server->GetLobbyThread().GetDatabase().SetGamePlayerPlace(server->GetDBId(), tmpPlayer->GetDBId(), 1); - server->GetLobbyThread().GetDatabase().EndGame(server->GetDBId()); + server->GetDatabase().SetGamePlayerPlace(server->GetDBId(), tmpPlayer->GetDBId(), 1); + server->GetDatabase().EndGame(server->GetDBId()); } // View a dialog for a new game - delayed. diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index 1d3ba654..4855441b 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -646,11 +646,10 @@ ServerLobbyThread::GetIOService() return *m_ioService; } -ServerDBInterface & +boost::shared_ptr ServerLobbyThread::GetDatabase() { - assert(m_database); - return *m_database; + return m_database; } ServerBanManager & diff --git a/src/net/servergame.h b/src/net/servergame.h index b1469512..474cb824 100644 --- a/src/net/servergame.h +++ b/src/net/servergame.h @@ -34,6 +34,7 @@ class ReceiverHelper; class ServerLobbyThread; class ServerGameState; +class ServerDBInterface; class ConfigFile; struct GameData; class Game; @@ -140,6 +141,7 @@ protected: const SessionManager &GetSessionManager() const; SessionManager &GetSessionManager(); + ServerDBInterface &GetDatabase(); private: ServerGame(const ServerGame &other); @@ -157,6 +159,7 @@ private: boost::shared_ptr m_lobbyThread; boost::shared_ptr m_receiver; + boost::shared_ptr m_database; GuiInterface &m_gui; const GameData m_gameData; diff --git a/src/net/serverlobbythread.h b/src/net/serverlobbythread.h index b418bf18..b34d516a 100644 --- a/src/net/serverlobbythread.h +++ b/src/net/serverlobbythread.h @@ -107,7 +107,7 @@ public: SenderHelper &GetSender(); boost::asio::io_service &GetIOService(); - ServerDBInterface &GetDatabase(); + boost::shared_ptr GetDatabase(); ServerBanManager &GetBanManager(); protected: