creating log-object in main-function and commiting it to session

This commit is contained in:
floty
2012-01-02 22:07:25 +00:00
parent df35ea550f
commit d2aeabb47a
12 changed files with 48 additions and 32 deletions
+1 -1
View File
@@ -113,7 +113,7 @@ Game::Game(GuiInterface* gui, boost::shared_ptr<EngineFactory> factory,
currentBoard->setPlayerLists(seatsList, activePlayerList, runningPlayerList); currentBoard->setPlayerLists(seatsList, activePlayerList, runningPlayerList);
// log game data // 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 //start timer
blindsTimer.reset(); blindsTimer.reset();
+1 -1
View File
@@ -152,7 +152,7 @@ void LocalBeRo::run()
LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR - wrong myBeRoID"); LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR - wrong myBeRoID");
} }
} }
myHand->getLog()->logBoardCards(myBeRoID, tempBoardCardsArray); if(myHand->getLog()) myHand->getLog()->logBoardCards(myBeRoID, tempBoardCardsArray);
logBoardCardsDone = true; logBoardCardsDone = true;
} }
@@ -89,12 +89,14 @@ void LocalBeRoPostRiver::postRiverRun()
if ((*it_c)->getMyAction() != PLAYER_ACTION_FOLD) nonfoldPlayersCounter++; if ((*it_c)->getMyAction() != PLAYER_ACTION_FOLD) nonfoldPlayersCounter++;
} }
if(nonfoldPlayersCounter>1) { 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()->logHandWinner(getMyHand()->getActivePlayerList(), highestCardsValue, getMyHand()->getBoard()->getWinners());
getMyHand()->getLog()->logPlayerSitsOut(getMyHand()->getActivePlayerList()); getMyHand()->getLog()->logPlayerSitsOut(getMyHand()->getActivePlayerList());
getMyHand()->getLog()->logGameWinner(getMyHand()->getActivePlayerList()); getMyHand()->getLog()->logGameWinner(getMyHand()->getActivePlayerList());
getMyHand()->getLog()->logAfterHand(); getMyHand()->getLog()->logAfterHand();
}
//starte die Animaionsreihe //starte die Animaionsreihe
getMyHand()->getGuiInterface()->postRiverRunAnimation1(); getMyHand()->getGuiInterface()->postRiverRunAnimation1();
+4 -4
View File
@@ -365,7 +365,7 @@ LocalHand::LocalHand(boost::shared_ptr<EngineFactory> f, GuiInterface *g, boost:
setBlinds(); 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); myBeRo = myFactory->createBeRo(this, dealerPosition, smallBlind);
} }
@@ -527,7 +527,7 @@ void LocalHand::switchRounds()
// logging last player action // logging last player action
PlayerListConstIterator previousPlayerIt = getRunningPlayerIt(previousPlayerID); PlayerListConstIterator previousPlayerIt = getRunningPlayerIt(previousPlayerID);
if(previousPlayerIt != runningPlayerList->end()) { 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; PlayerListIterator it, it_1;
@@ -630,7 +630,7 @@ void LocalHand::switchRounds()
myGui->flipHolecardsAllIn(); myGui->flipHolecardsAllIn();
// Logging HoleCards // Logging HoleCards
if(currentRound<GAME_STATE_RIVER) { if(currentRound<GAME_STATE_RIVER) {
myLog->logHoleCardsHandName(currentRound,activePlayerList); if(myLog) myLog->logHoleCardsHandName(currentRound,activePlayerList);
} }
if (currentRound < GAME_STATE_POST_RIVER) // do not increment past 4 if (currentRound < GAME_STATE_POST_RIVER) // do not increment past 4
@@ -642,7 +642,7 @@ void LocalHand::switchRounds()
myBoard->getMyCards(tempBoardCardsArray); myBoard->getMyCards(tempBoardCardsArray);
myGui->logDealBoardCardsMsg(currentRound, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]); myGui->logDealBoardCardsMsg(currentRound, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]);
myLog->logBoardCards(currentRound, tempBoardCardsArray); if(myLog) myLog->logBoardCards(currentRound, tempBoardCardsArray);
} }
} }
+14 -8
View File
@@ -29,6 +29,18 @@
using namespace std; using namespace std;
Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), curGameID(0), curHandID(0), sql("") 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) { if(SQLITE_LOG) {
@@ -80,7 +92,8 @@ Log::Log(ConfigFile *c) : mySqliteLogDb(0), myConfig(c), curGameID(0), curHandID
// create game table // create game table
sql += "CREATE TABLE Game ("; 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 += ",Startmoney INTEGER NOT NULL";
sql += ",StartSb INTEGER NOT NULL"; sql += ",StartSb INTEGER NOT NULL";
sql += ",DealerPos 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 void
Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList) Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList)
{ {
+4 -1
View File
@@ -34,6 +34,7 @@ public:
~Log(); ~Log();
void init();
void logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned dealerPosition, PlayerList seatsList); 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 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); void logPlayerAction(GameState bero, int seat, PlayerActionLog action, int amount = 0);
@@ -46,11 +47,13 @@ public:
void logPlayerSitsOut(PlayerList activePlayerList); void logPlayerSitsOut(PlayerList activePlayerList);
void logAfterHand(); void logAfterHand();
void logAfterGame(); void logAfterGame();
void exec_transaction();
// void closeLogDbAtExit(); // void closeLogDbAtExit();
private: private:
void exec_transaction();
sqlite3 *mySqliteLogDb; sqlite3 *mySqliteLogDb;
ConfigFile *myConfig; ConfigFile *myConfig;
int curGameID; int curGameID;
+7 -5
View File
@@ -46,14 +46,15 @@
using namespace std; using namespace std;
startWindowImpl::startWindowImpl(ConfigFile *c) startWindowImpl::startWindowImpl(ConfigFile *c, Log *l)
: myConfig(c), msgBoxOutdatedVersionActive(false) : myConfig(c), myLog(l), msgBoxOutdatedVersionActive(false)
{ {
myGuiInterface.reset(new GuiWrapper(myConfig, this)); 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 mySession->init(); // TODO handle error
myLog->init();
// myGuiInterface->setSession(session); // myGuiInterface->setSession(session);
} }
@@ -399,7 +400,8 @@ void startWindowImpl::callRejoinPossibleDialog(unsigned gameId)
case QMessageBox::Yes: case QMessageBox::Yes:
mySession->clientRejoinGame(gameId); mySession->clientRejoinGame(gameId);
break; break;
case QMessageBox::No:; case QMessageBox::No:
;
break; break;
} }
} }
@@ -419,7 +421,7 @@ void startWindowImpl::callCreateNetworkGameDialog()
// Create pseudo Gui Wrapper for the server. // Create pseudo Gui Wrapper for the server.
myServerGuiInterface.reset(new ServerGuiWrapper(myConfig, mySession->getGui(), mySession->getGui(), mySession->getGui())); myServerGuiInterface.reset(new ServerGuiWrapper(myConfig, mySession->getGui(), mySession->getGui(), mySession->getGui()));
{ {
boost::shared_ptr<Session> session(new Session(myServerGuiInterface.get(), myConfig)); boost::shared_ptr<Session> session(new Session(myServerGuiInterface.get(), myConfig, 0));
session->init(mySession->getAvatarManager()); session->init(mySession->getAvatarManager());
myServerGuiInterface->setSession(session); myServerGuiInterface->setSession(session);
} }
+3 -1
View File
@@ -51,12 +51,13 @@ class timeoutMsgBoxImpl;
class serverListDialogImpl; class serverListDialogImpl;
class internetGameLoginDialogImpl; class internetGameLoginDialogImpl;
class guiLog; class guiLog;
class Log;
class startWindowImpl: public QMainWindow, public Ui::startWindow class startWindowImpl: public QMainWindow, public Ui::startWindow
{ {
Q_OBJECT Q_OBJECT
public: public:
startWindowImpl(ConfigFile *c =0); startWindowImpl(ConfigFile *c, Log *l);
~startWindowImpl(); ~startWindowImpl();
void setSession(boost::shared_ptr<Session> session) { void setSession(boost::shared_ptr<Session> session) {
@@ -155,6 +156,7 @@ public slots:
private: private:
ConfigFile *myConfig; ConfigFile *myConfig;
guiLog *myGuiLog; guiLog *myGuiLog;
Log *myLog;
boost::shared_ptr<GuiInterface> myGuiInterface; boost::shared_ptr<GuiInterface> myGuiInterface;
boost::shared_ptr<Session> mySession; boost::shared_ptr<Session> mySession;
+3 -1
View File
@@ -32,6 +32,7 @@
#include "session.h" #include "session.h"
#include "startwindowimpl.h" #include "startwindowimpl.h"
#include "configfile.h" #include "configfile.h"
#include "log.h"
#include "startsplash.h" #include "startsplash.h"
#include "game_defs.h" #include "game_defs.h"
#include <net/socket_startup.h> #include <net/socket_startup.h>
@@ -86,6 +87,7 @@ int main( int argc, char **argv )
//create defaultconfig //create defaultconfig
ConfigFile *myConfig = new ConfigFile(argv[0], false); ConfigFile *myConfig = new ConfigFile(argv[0], false);
Log *myLog = new Log(myConfig);
// set PlastiqueStyle even for mac-version to prevent artefacts on styled widgets // set PlastiqueStyle even for mac-version to prevent artefacts on styled widgets
a.setStyle(new QPlastiqueStyle); a.setStyle(new QPlastiqueStyle);
@@ -131,7 +133,7 @@ int main( int argc, char **argv )
qRegisterMetaType<DenyGameInvitationReason>("DenyGameInvitationReason"); qRegisterMetaType<DenyGameInvitationReason>("DenyGameInvitationReason");
/////////////////////////////////////////////////// ///////////////////////////////////////////////////
startWindowImpl mainWin(myConfig); startWindowImpl mainWin(myConfig,myLog);
a.setActivationWindow(&mainWin, true); a.setActivationWindow(&mainWin, true);
int retVal = a.exec(); int retVal = a.exec();
+1 -1
View File
@@ -157,7 +157,7 @@ main(int argc, char *argv[])
// Create pseudo Gui Wrapper for the server. // Create pseudo Gui Wrapper for the server.
boost::shared_ptr<GuiInterface> myServerGuiInterface(new ServerGuiWrapper(myConfig.get(), NULL, NULL, NULL)); boost::shared_ptr<GuiInterface> myServerGuiInterface(new ServerGuiWrapper(myConfig.get(), NULL, NULL, NULL));
boost::shared_ptr<Session> session(new Session(myServerGuiInterface.get(), myConfig.get())); boost::shared_ptr<Session> session(new Session(myServerGuiInterface.get(), myConfig.get(), NULL));
if (!session->init()) if (!session->init())
LOG_ERROR("Missing files - please check your directory settings!"); LOG_ERROR("Missing files - please check your directory settings!");
myServerGuiInterface->setSession(session); myServerGuiInterface->setSession(session);
+2 -3
View File
@@ -39,11 +39,10 @@
using namespace std; using namespace std;
Session::Session(GuiInterface *g, ConfigFile *c) Session::Session(GuiInterface *g, ConfigFile *c, Log *l)
: currentGameNum(0), myGui(g), myConfig(c), myLog(0), myGameType(GAME_TYPE_NONE) : currentGameNum(0), myGui(g), myConfig(c), myLog(l), myGameType(GAME_TYPE_NONE)
{ {
myQtToolsInterface = CreateQtToolsWrapper(); myQtToolsInterface = CreateQtToolsWrapper();
myLog = new Log(myConfig);
} }
+1 -1
View File
@@ -42,7 +42,7 @@ class Session
{ {
public: public:
Session(GuiInterface*, ConfigFile*); Session(GuiInterface*, ConfigFile*, Log*);
~Session(); ~Session();