From d2aeabb47a76ffe9b146eb71634d1399da1e9211 Mon Sep 17 00:00:00 2001 From: floty Date: Mon, 2 Jan 2012 22:07:25 +0000 Subject: [PATCH] creating log-object in main-function and commiting it to session --- src/engine/game.cpp | 2 +- src/engine/local_engine/localbero.cpp | 2 +- .../local_engine/localberopostriver.cpp | 12 +++++----- src/engine/local_engine/localhand.cpp | 8 +++---- src/engine/log.cpp | 22 ++++++++++++------- src/engine/log.h | 5 ++++- src/gui/qt/startwindow/startwindowimpl.cpp | 12 +++++----- src/gui/qt/startwindow/startwindowimpl.h | 4 +++- src/pokerth.cpp | 4 +++- src/pokerth_server.cpp | 2 +- src/session.cpp | 5 ++--- src/session.h | 2 +- 12 files changed, 48 insertions(+), 32 deletions(-) diff --git a/src/engine/game.cpp b/src/engine/game.cpp index 559a8538..ee835f55 100755 --- a/src/engine/game.cpp +++ b/src/engine/game.cpp @@ -113,7 +113,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr factory, currentBoard->setPlayerLists(seatsList, activePlayerList, runningPlayerList); // log game data - myLog->logNewGameMsg(myGameID, startCash, startSmallBlind, getPlayerByUniqueId(dealerPosition)->getMyID()+1, seatsList); + if(myLog) myLog->logNewGameMsg(myGameID, startCash, startSmallBlind, getPlayerByUniqueId(dealerPosition)->getMyID()+1, seatsList); //start timer blindsTimer.reset(); diff --git a/src/engine/local_engine/localbero.cpp b/src/engine/local_engine/localbero.cpp index 63a22f7d..94c43d53 100644 --- a/src/engine/local_engine/localbero.cpp +++ b/src/engine/local_engine/localbero.cpp @@ -152,7 +152,7 @@ void LocalBeRo::run() LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR - wrong myBeRoID"); } } - myHand->getLog()->logBoardCards(myBeRoID, tempBoardCardsArray); + if(myHand->getLog()) myHand->getLog()->logBoardCards(myBeRoID, tempBoardCardsArray); logBoardCardsDone = true; } diff --git a/src/engine/local_engine/localberopostriver.cpp b/src/engine/local_engine/localberopostriver.cpp index e118f05b..582739da 100644 --- a/src/engine/local_engine/localberopostriver.cpp +++ b/src/engine/local_engine/localberopostriver.cpp @@ -89,12 +89,14 @@ void LocalBeRoPostRiver::postRiverRun() if ((*it_c)->getMyAction() != PLAYER_ACTION_FOLD) nonfoldPlayersCounter++; } if(nonfoldPlayersCounter>1) { - getMyHand()->getLog()->logHoleCardsHandName(GAME_STATE_POST_RIVER,getMyHand()->getActivePlayerList()); + if(getMyHand()->getLog()) getMyHand()->getLog()->logHoleCardsHandName(GAME_STATE_POST_RIVER,getMyHand()->getActivePlayerList()); + } + if(getMyHand()->getLog()) { + getMyHand()->getLog()->logHandWinner(getMyHand()->getActivePlayerList(), highestCardsValue, getMyHand()->getBoard()->getWinners()); + getMyHand()->getLog()->logPlayerSitsOut(getMyHand()->getActivePlayerList()); + getMyHand()->getLog()->logGameWinner(getMyHand()->getActivePlayerList()); + getMyHand()->getLog()->logAfterHand(); } - getMyHand()->getLog()->logHandWinner(getMyHand()->getActivePlayerList(), highestCardsValue, getMyHand()->getBoard()->getWinners()); - getMyHand()->getLog()->logPlayerSitsOut(getMyHand()->getActivePlayerList()); - getMyHand()->getLog()->logGameWinner(getMyHand()->getActivePlayerList()); - getMyHand()->getLog()->logAfterHand(); //starte die Animaionsreihe getMyHand()->getGuiInterface()->postRiverRunAnimation1(); diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index ce3915b0..1898eea9 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -365,7 +365,7 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, boost: setBlinds(); - myLog->logNewHandMsg(myID, dealerPosition+1, smallBlind, smallBlindPosition+1, 2*smallBlind, bigBlindPosition+1, seatsList); + if(myLog) myLog->logNewHandMsg(myID, dealerPosition+1, smallBlind, smallBlindPosition+1, 2*smallBlind, bigBlindPosition+1, seatsList); myBeRo = myFactory->createBeRo(this, dealerPosition, smallBlind); } @@ -527,7 +527,7 @@ void LocalHand::switchRounds() // logging last player action PlayerListConstIterator previousPlayerIt = getRunningPlayerIt(previousPlayerID); if(previousPlayerIt != runningPlayerList->end()) { - myLog->logPlayerAction(currentRound,(*previousPlayerIt)->getMyID()+1,myLog->transformPlayerActionLog((*previousPlayerIt)->getMyAction()),(*previousPlayerIt)->getMySet()); + if(myLog) myLog->logPlayerAction(currentRound,(*previousPlayerIt)->getMyID()+1,myLog->transformPlayerActionLog((*previousPlayerIt)->getMyAction()),(*previousPlayerIt)->getMySet()); } PlayerListIterator it, it_1; @@ -630,7 +630,7 @@ void LocalHand::switchRounds() myGui->flipHolecardsAllIn(); // Logging HoleCards if(currentRoundlogHoleCardsHandName(currentRound,activePlayerList); + if(myLog) myLog->logHoleCardsHandName(currentRound,activePlayerList); } if (currentRound < GAME_STATE_POST_RIVER) // do not increment past 4 @@ -642,7 +642,7 @@ void LocalHand::switchRounds() myBoard->getMyCards(tempBoardCardsArray); myGui->logDealBoardCardsMsg(currentRound, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]); - myLog->logBoardCards(currentRound, tempBoardCardsArray); + if(myLog) myLog->logBoardCards(currentRound, tempBoardCardsArray); } } diff --git a/src/engine/log.cpp b/src/engine/log.cpp index d53abec3..a7b6b90f 100644 --- a/src/engine/log.cpp +++ b/src/engine/log.cpp @@ -29,6 +29,18 @@ using namespace std; Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), curGameID(0), curHandID(0), sql("") +{ +} + +Log::~Log() +{ + if(SQLITE_LOG) { + sqlite3_close(mySqliteLogDb); + } +} + +void +Log::init() { if(SQLITE_LOG) { @@ -80,7 +92,8 @@ Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), curGameID(0), curHandID // create game table sql += "CREATE TABLE Game ("; - sql += "GameID INTEGER NOT NULL PRIMARY KEY"; + sql += "UniqueGameID INTEGER PRIMARY KEY AUTOINCREMENT"; + sql += ",GameID INTEGER NOT NULL"; sql += ",Startmoney INTEGER NOT NULL"; sql += ",StartSb INTEGER NOT NULL"; sql += ",DealerPos INTEGER NOT NULL"; @@ -129,13 +142,6 @@ Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), curGameID(0), curHandID } } -Log::~Log() -{ - if(SQLITE_LOG) { - sqlite3_close(mySqliteLogDb); - } -} - void Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList) { diff --git a/src/engine/log.h b/src/engine/log.h index 08dbb030..238790e4 100644 --- a/src/engine/log.h +++ b/src/engine/log.h @@ -34,6 +34,7 @@ public: ~Log(); + void init(); void logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList); void logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, unsigned smallBlindPosition, int bigBlind, unsigned bigBlindPosition, PlayerList seatsList); void logPlayerAction(GameState bero, int seat, PlayerActionLog action, int amount = 0); @@ -46,11 +47,13 @@ public: void logPlayerSitsOut(PlayerList activePlayerList); void logAfterHand(); void logAfterGame(); - void exec_transaction(); // void closeLogDbAtExit(); private: + + void exec_transaction(); + sqlite3 *mySqliteLogDb; ConfigFile *myConfig; int curGameID; diff --git a/src/gui/qt/startwindow/startwindowimpl.cpp b/src/gui/qt/startwindow/startwindowimpl.cpp index 3d20e82b..69e3a089 100644 --- a/src/gui/qt/startwindow/startwindowimpl.cpp +++ b/src/gui/qt/startwindow/startwindowimpl.cpp @@ -46,14 +46,15 @@ using namespace std; -startWindowImpl::startWindowImpl(ConfigFile *c) - : myConfig(c), msgBoxOutdatedVersionActive(false) +startWindowImpl::startWindowImpl(ConfigFile *c, Log *l) + : myConfig(c), myLog(l), msgBoxOutdatedVersionActive(false) { myGuiInterface.reset(new GuiWrapper(myConfig, this)); { - mySession.reset(new Session(myGuiInterface.get(), myConfig)); + mySession.reset(new Session(myGuiInterface.get(), myConfig, myLog)); mySession->init(); // TODO handle error + myLog->init(); // myGuiInterface->setSession(session); } @@ -399,7 +400,8 @@ void startWindowImpl::callRejoinPossibleDialog(unsigned gameId) case QMessageBox::Yes: mySession->clientRejoinGame(gameId); break; - case QMessageBox::No:; + case QMessageBox::No: + ; break; } } @@ -419,7 +421,7 @@ void startWindowImpl::callCreateNetworkGameDialog() // Create pseudo Gui Wrapper for the server. myServerGuiInterface.reset(new ServerGuiWrapper(myConfig, mySession->getGui(), mySession->getGui(), mySession->getGui())); { - boost::shared_ptr session(new Session(myServerGuiInterface.get(), myConfig)); + boost::shared_ptr session(new Session(myServerGuiInterface.get(), myConfig, 0)); session->init(mySession->getAvatarManager()); myServerGuiInterface->setSession(session); } diff --git a/src/gui/qt/startwindow/startwindowimpl.h b/src/gui/qt/startwindow/startwindowimpl.h index 7711ea66..3cf6732e 100644 --- a/src/gui/qt/startwindow/startwindowimpl.h +++ b/src/gui/qt/startwindow/startwindowimpl.h @@ -51,12 +51,13 @@ class timeoutMsgBoxImpl; class serverListDialogImpl; class internetGameLoginDialogImpl; class guiLog; +class Log; class startWindowImpl: public QMainWindow, public Ui::startWindow { Q_OBJECT public: - startWindowImpl(ConfigFile *c =0); + startWindowImpl(ConfigFile *c, Log *l); ~startWindowImpl(); void setSession(boost::shared_ptr session) { @@ -155,6 +156,7 @@ public slots: private: ConfigFile *myConfig; guiLog *myGuiLog; + Log *myLog; boost::shared_ptr myGuiInterface; boost::shared_ptr mySession; diff --git a/src/pokerth.cpp b/src/pokerth.cpp index 945d8685..ac868240 100755 --- a/src/pokerth.cpp +++ b/src/pokerth.cpp @@ -32,6 +32,7 @@ #include "session.h" #include "startwindowimpl.h" #include "configfile.h" +#include "log.h" #include "startsplash.h" #include "game_defs.h" #include @@ -86,6 +87,7 @@ int main( int argc, char **argv ) //create defaultconfig ConfigFile *myConfig = new ConfigFile(argv[0], false); + Log *myLog = new Log(myConfig); // set PlastiqueStyle even for mac-version to prevent artefacts on styled widgets a.setStyle(new QPlastiqueStyle); @@ -131,7 +133,7 @@ int main( int argc, char **argv ) qRegisterMetaType("DenyGameInvitationReason"); /////////////////////////////////////////////////// - startWindowImpl mainWin(myConfig); + startWindowImpl mainWin(myConfig,myLog); a.setActivationWindow(&mainWin, true); int retVal = a.exec(); diff --git a/src/pokerth_server.cpp b/src/pokerth_server.cpp index 5715d9f7..b27a6993 100644 --- a/src/pokerth_server.cpp +++ b/src/pokerth_server.cpp @@ -157,7 +157,7 @@ main(int argc, char *argv[]) // Create pseudo Gui Wrapper for the server. boost::shared_ptr myServerGuiInterface(new ServerGuiWrapper(myConfig.get(), NULL, NULL, NULL)); - boost::shared_ptr session(new Session(myServerGuiInterface.get(), myConfig.get())); + boost::shared_ptr session(new Session(myServerGuiInterface.get(), myConfig.get(), NULL)); if (!session->init()) LOG_ERROR("Missing files - please check your directory settings!"); myServerGuiInterface->setSession(session); diff --git a/src/session.cpp b/src/session.cpp index 30c811b6..01a7f5e8 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -39,11 +39,10 @@ using namespace std; -Session::Session(GuiInterface *g, ConfigFile *c) - : currentGameNum(0), myGui(g), myConfig(c), myLog(0), myGameType(GAME_TYPE_NONE) +Session::Session(GuiInterface *g, ConfigFile *c, Log *l) + : currentGameNum(0), myGui(g), myConfig(c), myLog(l), myGameType(GAME_TYPE_NONE) { myQtToolsInterface = CreateQtToolsWrapper(); - myLog = new Log(myConfig); } diff --git a/src/session.h b/src/session.h index 73e519ba..c223a557 100755 --- a/src/session.h +++ b/src/session.h @@ -42,7 +42,7 @@ class Session { public: - Session(GuiInterface*, ConfigFile*); + Session(GuiInterface*, ConfigFile*, Log*); ~Session();