diff --git a/src/engine/enginefactory.h b/src/engine/enginefactory.h index 8d293544..9a15c99c 100644 --- a/src/engine/enginefactory.h +++ b/src/engine/enginefactory.h @@ -34,7 +34,7 @@ public: virtual boost::shared_ptr createHand(boost::shared_ptr f, GuiInterface *g, boost::shared_ptr b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC) =0; virtual boost::shared_ptr createBoard(unsigned dp) =0; virtual boost::shared_ptr createPlayer(int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB) =0; - virtual std::vector > createBeRo(HandInterface *hi, int id, unsigned dP, int sB) =0; + virtual std::vector > createBeRo(HandInterface *hi, unsigned dP, int sB) =0; }; #endif diff --git a/src/engine/local_engine/localbero.cpp b/src/engine/local_engine/localbero.cpp index 00483e0d..2ee1c5b9 100644 --- a/src/engine/local_engine/localbero.cpp +++ b/src/engine/local_engine/localbero.cpp @@ -24,8 +24,8 @@ using namespace std; -LocalBeRo::LocalBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState gS) - : BeRoInterface(), myHand(hi), myBeRoID(gS), myID(id), dealerPosition(dP), smallBlindPosition(0), dealerPositionId(dP), smallBlindPositionId(0), bigBlindPositionId(0), smallBlind(sB), highestSet(0), minimumRaise(2*sB), fullBetRule(false), firstRun(true), firstRunGui(true), firstRound(true), firstHeadsUpRound(true), currentPlayersTurnId(0), firstRoundLastPlayersTurnId(0), logBoardCardsDone(false) +LocalBeRo::LocalBeRo(HandInterface* hi, unsigned dP, int sB, GameState gS) + : BeRoInterface(), myHand(hi), myBeRoID(gS), dealerPosition(dP), smallBlindPosition(0), dealerPositionId(dP), smallBlindPositionId(0), bigBlindPositionId(0), smallBlind(sB), highestSet(0), minimumRaise(2*sB), fullBetRule(false), firstRun(true), firstRunGui(true), firstRound(true), firstHeadsUpRound(true), currentPlayersTurnId(0), firstRoundLastPlayersTurnId(0), logBoardCardsDone(false) { currentPlayersTurnIt = myHand->getRunningPlayerList()->begin(); lastPlayersTurnIt = myHand->getRunningPlayerList()->begin(); diff --git a/src/engine/local_engine/localbero.h b/src/engine/local_engine/localbero.h index 15bbfb3d..2a8c0225 100644 --- a/src/engine/local_engine/localbero.h +++ b/src/engine/local_engine/localbero.h @@ -28,7 +28,7 @@ class LocalBeRo : public BeRoInterface { public: - LocalBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState gS); + LocalBeRo(HandInterface* hi, unsigned dP, int sB, GameState gS); ~LocalBeRo(); GameState getMyBeRoID() const { @@ -169,7 +169,6 @@ private: HandInterface* myHand; const GameState myBeRoID; - int myID; int dealerPosition; int smallBlindPosition; diff --git a/src/engine/local_engine/localberoflop.cpp b/src/engine/local_engine/localberoflop.cpp index 5f81b232..ef082b68 100644 --- a/src/engine/local_engine/localberoflop.cpp +++ b/src/engine/local_engine/localberoflop.cpp @@ -23,7 +23,7 @@ using namespace std; -LocalBeRoFlop::LocalBeRoFlop(HandInterface* hi, int id, unsigned dP, int sB) : LocalBeRo(hi, id, dP, sB, GAME_STATE_FLOP) +LocalBeRoFlop::LocalBeRoFlop(HandInterface* hi, unsigned dP, int sB) : LocalBeRo(hi, dP, sB, GAME_STATE_FLOP) { } diff --git a/src/engine/local_engine/localberoflop.h b/src/engine/local_engine/localberoflop.h index df983a9d..cb2f7c10 100644 --- a/src/engine/local_engine/localberoflop.h +++ b/src/engine/local_engine/localberoflop.h @@ -28,7 +28,7 @@ class LocalBeRoFlop : public LocalBeRo { public: - LocalBeRoFlop(HandInterface*, int, unsigned, int); + LocalBeRoFlop(HandInterface*, unsigned, int); ~LocalBeRoFlop(); }; diff --git a/src/engine/local_engine/localberopostriver.cpp b/src/engine/local_engine/localberopostriver.cpp index dbb69cb9..1aa9d4a9 100644 --- a/src/engine/local_engine/localberopostriver.cpp +++ b/src/engine/local_engine/localberopostriver.cpp @@ -24,7 +24,7 @@ using namespace std; -LocalBeRoPostRiver::LocalBeRoPostRiver(HandInterface* hi, int id, int dP, int sB) : LocalBeRo(hi, id, dP, sB, GAME_STATE_POST_RIVER), highestCardsValue(0) +LocalBeRoPostRiver::LocalBeRoPostRiver(HandInterface* hi, int dP, int sB) : LocalBeRo(hi, dP, sB, GAME_STATE_POST_RIVER), highestCardsValue(0) { } @@ -83,6 +83,15 @@ void LocalBeRoPostRiver::postRiverRun() //Pot auf 0 setzen getMyHand()->getBoard()->setPot(0); + // Logging hole Cards / Hands + int myCards[2]; + for(it_c=getMyHand()->getActivePlayerList()->begin(); it_c!=getMyHand()->getActivePlayerList()->end(); ++it_c) { + if( (*it_c)->getMyAction() != PLAYER_ACTION_FOLD) { + (*it_c)->getMyCards(myCards); + getMyHand()->getLog()->logHoleCardsHandName((*it_c)->getMyID()+1,myCards,(*it_c)->getMyCardsValueInt(),getMyHand()->getActivePlayerList()); + } + } + //starte die Animaionsreihe getMyHand()->getGuiInterface()->postRiverRunAnimation1(); } diff --git a/src/engine/local_engine/localberopostriver.h b/src/engine/local_engine/localberopostriver.h index abef4ec4..964dfd87 100644 --- a/src/engine/local_engine/localberopostriver.h +++ b/src/engine/local_engine/localberopostriver.h @@ -28,7 +28,7 @@ class HandInterface; class LocalBeRoPostRiver : public LocalBeRo { public: - LocalBeRoPostRiver(HandInterface*, int, int, int); + LocalBeRoPostRiver(HandInterface*, int, int); ~LocalBeRoPostRiver(); void setHighestCardsValue(int theValue) { diff --git a/src/engine/local_engine/localberopreflop.cpp b/src/engine/local_engine/localberopreflop.cpp index fefaaac5..9486fd5d 100644 --- a/src/engine/local_engine/localberopreflop.cpp +++ b/src/engine/local_engine/localberopreflop.cpp @@ -26,7 +26,7 @@ using namespace std; -LocalBeRoPreflop::LocalBeRoPreflop(HandInterface* hi, int id, unsigned dP, int sB) : LocalBeRo(hi, id, dP, sB, GAME_STATE_PREFLOP) +LocalBeRoPreflop::LocalBeRoPreflop(HandInterface* hi, unsigned dP, int sB) : LocalBeRo(hi, dP, sB, GAME_STATE_PREFLOP) { setHighestSet(2*getSmallBlind()); } diff --git a/src/engine/local_engine/localberopreflop.h b/src/engine/local_engine/localberopreflop.h index d1ed4e41..1e5b23f9 100644 --- a/src/engine/local_engine/localberopreflop.h +++ b/src/engine/local_engine/localberopreflop.h @@ -28,7 +28,7 @@ class LocalBeRoPreflop : public LocalBeRo { public: - LocalBeRoPreflop(HandInterface*, int, unsigned, int); + LocalBeRoPreflop(HandInterface*, unsigned, int); ~LocalBeRoPreflop(); void run(); diff --git a/src/engine/local_engine/localberoriver.cpp b/src/engine/local_engine/localberoriver.cpp index b7ffe136..56c959da 100644 --- a/src/engine/local_engine/localberoriver.cpp +++ b/src/engine/local_engine/localberoriver.cpp @@ -24,7 +24,7 @@ using namespace std; -LocalBeRoRiver::LocalBeRoRiver(HandInterface* hi, int id, unsigned dP, int sB) : LocalBeRo(hi, id, dP, sB, GAME_STATE_RIVER) +LocalBeRoRiver::LocalBeRoRiver(HandInterface* hi, unsigned dP, int sB) : LocalBeRo(hi, dP, sB, GAME_STATE_RIVER) { } diff --git a/src/engine/local_engine/localberoriver.h b/src/engine/local_engine/localberoriver.h index c9357388..459f71bd 100644 --- a/src/engine/local_engine/localberoriver.h +++ b/src/engine/local_engine/localberoriver.h @@ -28,7 +28,7 @@ class HandInterface; class LocalBeRoRiver : public LocalBeRo { public: - LocalBeRoRiver(HandInterface*, int, unsigned, int); + LocalBeRoRiver(HandInterface*, unsigned, int); ~LocalBeRoRiver(); }; diff --git a/src/engine/local_engine/localberoturn.cpp b/src/engine/local_engine/localberoturn.cpp index adfd1094..3d08ea16 100644 --- a/src/engine/local_engine/localberoturn.cpp +++ b/src/engine/local_engine/localberoturn.cpp @@ -23,7 +23,7 @@ using namespace std; -LocalBeRoTurn::LocalBeRoTurn(HandInterface* hi, int id, unsigned dP, int sB) : LocalBeRo(hi, id, dP, sB, GAME_STATE_TURN) +LocalBeRoTurn::LocalBeRoTurn(HandInterface* hi, unsigned dP, int sB) : LocalBeRo(hi, dP, sB, GAME_STATE_TURN) { } diff --git a/src/engine/local_engine/localberoturn.h b/src/engine/local_engine/localberoturn.h index fad7ec5f..684bcbec 100644 --- a/src/engine/local_engine/localberoturn.h +++ b/src/engine/local_engine/localberoturn.h @@ -27,7 +27,7 @@ class HandInterface; class LocalBeRoTurn : public LocalBeRo { public: - LocalBeRoTurn(HandInterface*, int, unsigned, int); + LocalBeRoTurn(HandInterface*, unsigned, int); ~LocalBeRoTurn(); }; diff --git a/src/engine/local_engine/localenginefactory.cpp b/src/engine/local_engine/localenginefactory.cpp index c22d39e3..68350e60 100644 --- a/src/engine/local_engine/localenginefactory.cpp +++ b/src/engine/local_engine/localenginefactory.cpp @@ -60,19 +60,19 @@ LocalEngineFactory::createPlayer(int id, unsigned uniqueId, PlayerType type, std } std::vector > -LocalEngineFactory::createBeRo(HandInterface *hi, int id, unsigned dP, int sB) +LocalEngineFactory::createBeRo(HandInterface *hi, unsigned dP, int sB) { std::vector > myBeRo; - myBeRo.push_back(boost::shared_ptr(new LocalBeRoPreflop(hi, id, dP, sB))); + myBeRo.push_back(boost::shared_ptr(new LocalBeRoPreflop(hi, dP, sB))); - myBeRo.push_back(boost::shared_ptr(new LocalBeRoFlop(hi, id, dP, sB))); + myBeRo.push_back(boost::shared_ptr(new LocalBeRoFlop(hi, dP, sB))); - myBeRo.push_back(boost::shared_ptr(new LocalBeRoTurn(hi, id, dP, sB))); + myBeRo.push_back(boost::shared_ptr(new LocalBeRoTurn(hi, dP, sB))); - myBeRo.push_back(boost::shared_ptr(new LocalBeRoRiver(hi, id, dP, sB))); + myBeRo.push_back(boost::shared_ptr(new LocalBeRoRiver(hi, dP, sB))); - myBeRo.push_back(boost::shared_ptr(new LocalBeRoPostRiver(hi, id, dP, sB))); + myBeRo.push_back(boost::shared_ptr(new LocalBeRoPostRiver(hi, dP, sB))); return myBeRo; diff --git a/src/engine/local_engine/localenginefactory.h b/src/engine/local_engine/localenginefactory.h index 5f4c94f5..f1f6a1de 100644 --- a/src/engine/local_engine/localenginefactory.h +++ b/src/engine/local_engine/localenginefactory.h @@ -39,7 +39,7 @@ public: virtual boost::shared_ptr createHand(boost::shared_ptr f, GuiInterface *g, boost::shared_ptr b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); virtual boost::shared_ptr createBoard(unsigned dp); virtual boost::shared_ptr createPlayer(int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); - virtual std::vector > createBeRo(HandInterface *hi, int id, unsigned dP, int sB); + virtual std::vector > createBeRo(HandInterface *hi, unsigned dP, int sB); private: ConfigFile *myConfig; diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index bb0b9ea0..a7a44e37 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -367,7 +367,7 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, boost: setBlinds(); - myBeRo = myFactory->createBeRo(this, myID, dealerPosition, smallBlind); + myBeRo = myFactory->createBeRo(this, dealerPosition, smallBlind); } @@ -626,6 +626,14 @@ void LocalHand::switchRounds() myGui->refreshPot(); myGui->refreshSet(); myGui->flipHolecardsAllIn(); + // Logging HoleCards + int myCards[2]; + for (it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) { + if ((*it_c)->getMyAction() != PLAYER_ACTION_FOLD) { + (*it_c)->getMyCards(myCards); + myLog->logHoleCards(currentRound+1,(*it_c)->getMyID()+1,myCards); + } + } if (currentRound < 4) // do not increment past 4 currentRound++; diff --git a/src/engine/local_engine/localplayer.h b/src/engine/local_engine/localplayer.h index 1a71c1e3..682f0728 100755 --- a/src/engine/local_engine/localplayer.h +++ b/src/engine/local_engine/localplayer.h @@ -166,15 +166,15 @@ public: switch(state) { case 1: currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt); - currentHand->getLog()->logHoleCardsHandName(myID+1,myCards,myCardsValueInt,currentHand->getActivePlayerList()); +// currentHand->getLog()->logHoleCardsHandName(myID+1,myCards,myCardsValueInt,currentHand->getActivePlayerList()); break; case 2: currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1]); - currentHand->getLog()->logHoleCards(currentHand->getCurrentRound()+1,myID+1,myCards); +// currentHand->getLog()->logHoleCards(currentHand->getCurrentRound()+1,myID+1,myCards); break; case 3: currentHand->getGuiInterface()->logFlipHoleCardsMsg(myName, myCards[0], myCards[1], myCardsValueInt, "has"); - currentHand->getLog()->logHandName(myID+1,myCardsValueInt,currentHand->getActivePlayerList()); +// currentHand->getLog()->logHandName(myID+1,myCardsValueInt,currentHand->getActivePlayerList()); break; default: ; diff --git a/src/engine/log.cpp b/src/engine/log.cpp index fd58909a..dd5fba2b 100644 --- a/src/engine/log.cpp +++ b/src/engine/log.cpp @@ -23,32 +23,26 @@ #include "cardsvalue.h" #include -#include #include #include using namespace std; -Log::Log(string logDirString, int logOnOffInt) : curGameID(0), curHandID(0), logOnOff(false) +Log::Log(ConfigFile *c) : myConfig(c), curGameID(0), curHandID(0), sql(""), logHoleCardsDone(false) { if(SQLITE_LOG) { // logging activated - if(logOnOffInt) { - - logOnOff = true; + if(myConfig->readConfigInt("LogOnOff")) { DIR *logDir; - logDir = opendir(logDirString.c_str()); + logDir = opendir((myConfig->readConfigString("LogDir")).c_str()); bool dirExists = logDir != NULL; closedir(logDir); // check if logging path exist - if(logDirString != "" && dirExists) { - - string sql; - char *errmsg = NULL; + if(myConfig->readConfigString("LogDir") != "" && dirExists) { // detect current time char curDateTime[20]; @@ -60,7 +54,7 @@ Log::Log(string logDirString, int logOnOffInt) : curGameID(0), curHandID(0), log strftime(curDate,11,"%Y-%m-%d",z); strftime(curTime,9,"%H:%M:%S",z); - string mySqliteLogFileName = boost::lexical_cast(logDirString.c_str()); + string mySqliteLogFileName = boost::lexical_cast((myConfig->readConfigString("LogDir")).c_str()); mySqliteLogFileName += "pokerth-log-" + boost::lexical_cast(curDateTime) + ".pdb"; // open sqlite-db @@ -69,33 +63,23 @@ Log::Log(string logDirString, int logOnOffInt) : curGameID(0), curHandID(0), log int i; // create session table - sql = "CREATE TABLE Session ("; + sql += "CREATE TABLE Session ("; sql += "PokerTH_Version TEXT NOT NULL"; sql += ",Date TEXT NOT NULL"; sql += ",Time TEXT NOT NULL"; - sql += ", PRIMARY KEY(Date,Time))"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ", PRIMARY KEY(Date,Time));"; - sql = "INSERT INTO Session ("; + sql += "INSERT INTO Session ("; sql += "PokerTH_Version"; sql += ",Date"; sql += ",Time"; sql += ") VALUES ("; sql += "\"" + boost::lexical_cast(POKERTH_BETA_RELEASE_STRING) + "\","; sql += "\"" + boost::lexical_cast(curDate) + "\","; - sql += "\"" + boost::lexical_cast(curTime) + "\")"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += "\"" + boost::lexical_cast(curTime) + "\");"; // create game table - sql = "CREATE TABLE Game ("; + sql += "CREATE TABLE Game ("; sql += "GameID INTEGER NOT NULL PRIMARY KEY"; sql += ",Startmoney INTEGER NOT NULL"; sql += ",StartSb INTEGER NOT NULL"; @@ -104,15 +88,10 @@ Log::Log(string logDirString, int logOnOffInt) : curGameID(0), curHandID(0), log sql += ",Seat_" + boost::lexical_cast(i) + " TEXT"; } sql += ",Winner_Seat INTEGER"; - sql += ")"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ");"; // create hand table - sql = "CREATE TABLE Hand ("; + sql += "CREATE TABLE Hand ("; sql += "HandID INTEGER NOT NULL"; sql += ",GameID INTEGER NOT NULL"; sql += ",Dealer_Seat INTEGER"; @@ -130,15 +109,10 @@ Log::Log(string logDirString, int logOnOffInt) : curGameID(0), curHandID(0), log for(i=1; i<=5; i++) { sql += ",BoardCard_" + boost::lexical_cast(i) + " INTEGER"; } - sql += ",PRIMARY KEY(HandID,GameID))"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ",PRIMARY KEY(HandID,GameID));"; // create action table - sql = "CREATE TABLE Action ("; + sql += "CREATE TABLE Action ("; sql += "ActionID INTEGER PRIMARY KEY AUTOINCREMENT"; sql += ",HandID INTEGER NOT NULL"; sql += ",GameID INTEGER NOT NULL"; @@ -146,12 +120,9 @@ Log::Log(string logDirString, int logOnOffInt) : curGameID(0), curHandID(0), log sql += ",Player INTEGER NOT NULL"; sql += ",Action TEXT NOT NULL"; sql += ",Amount INTEGER"; - sql += ")"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ");"; + + exec_transaction(&sql); } } } @@ -172,18 +143,16 @@ void Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned if(SQLITE_LOG) { - if(logOnOff) { + if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled PlayerListConstIterator it_c; - string sql; - char *errmsg = NULL; if( mySqliteLogDb != 0 ) { // sqlite-db is open int i; - sql = "INSERT INTO Game ("; + sql += "INSERT INTO Game ("; sql += "GameID"; sql += ",Startmoney"; sql += ",StartSb"; @@ -203,12 +172,8 @@ void Log::logNewGameMsg(int gameID, int startCash, int startSmallBlind, unsigned sql += ",NULL"; } } - sql += ")"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ");"; + exec_transaction(&sql); } } } @@ -221,18 +186,16 @@ void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, uns if(SQLITE_LOG) { - if(logOnOff) { + if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled PlayerListConstIterator it_c; - string sql; - char *errmsg = NULL; if( mySqliteLogDb != 0 ) { // sqlite-db is open int i; - sql = "INSERT INTO Hand ("; + sql += "INSERT INTO Hand ("; sql += "HandID"; sql += ",GameID"; sql += ",Dealer_Seat"; @@ -258,12 +221,10 @@ void Log::logNewHandMsg(int handID, unsigned dealerPosition, int smallBlind, uns sql += ",NULL"; } } - sql += ")"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ");"; + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(&sql); + } logPlayerAction(0,dealerPosition,LOG_ACTION_DEALER); } @@ -276,16 +237,13 @@ void Log::logPlayerAction(int bero, int seat, PlayerActionLog action, int amount if(SQLITE_LOG) { - if(logOnOff) { + if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled - string sql; - char *errmsg = NULL; - if( mySqliteLogDb != 0 ) { // sqlite-db is open - sql = "INSERT INTO Action ("; + sql += "INSERT INTO Action ("; sql += "HandID"; sql += ",GameID"; sql += ",BeRo"; @@ -348,12 +306,10 @@ void Log::logPlayerAction(int bero, int seat, PlayerActionLog action, int amount } else { sql += ",NULL"; } - sql += ")"; - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ");"; + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(&sql); + } } } } @@ -363,28 +319,27 @@ void Log::logBoardCards(int bero, int boardCards[5]) { if(SQLITE_LOG) { - if(logOnOff) { + if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled - string sql; - char *errmsg = NULL; - if( mySqliteLogDb != 0 ) { // sqlite-db is open - sql = "UPDATE Hand SET "; switch(bero) { case 2: { + sql += "UPDATE Hand SET "; sql += "BoardCard_1=" + boost::lexical_cast(boardCards[0]) + ","; sql += "BoardCard_2=" + boost::lexical_cast(boardCards[1]) + ","; sql += "BoardCard_3=" + boost::lexical_cast(boardCards[2]); } break; case 3: { + sql += "UPDATE Hand SET "; sql += "BoardCard_4=" + boost::lexical_cast(boardCards[3]); } break; case 4: { + sql += "UPDATE Hand SET "; sql += "BoardCard_5=" + boost::lexical_cast(boardCards[4]); } break; @@ -394,11 +349,10 @@ void Log::logBoardCards(int bero, int boardCards[5]) sql += " WHERE "; sql += "GameID=" + boost::lexical_cast(curGameID) + " AND "; sql += "HandID=" + boost::lexical_cast(curHandID); - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ";"; + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(&sql); + } } } } @@ -406,28 +360,27 @@ void Log::logBoardCards(int bero, int boardCards[5]) void Log::logHoleCards(int bero, int seat, int cards[2]) { + + logHoleCardsDone = false; + if(SQLITE_LOG) { - if(logOnOff) { + if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled - string sql; - char *errmsg = NULL; - if( mySqliteLogDb != 0 ) { // sqlite-db is open - sql = "UPDATE Hand SET "; + sql += "UPDATE Hand SET "; sql += "Seat_" + boost::lexical_cast(seat) + "_Card_1=" + boost::lexical_cast(cards[0]); sql += ",Seat_" + boost::lexical_cast(seat) + "_Card_2=" + boost::lexical_cast(cards[1]); sql += " WHERE "; sql += "GameID=" + boost::lexical_cast(curGameID) + " AND "; sql += "HandID=" + boost::lexical_cast(curHandID); - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ";"; + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(&sql); + } logPlayerAction(bero,seat,LOG_ACTION_SHOW); } @@ -439,27 +392,22 @@ void Log::logHandName(int seat, int cardsValueInt, PlayerList activePlayerList) { if(SQLITE_LOG) { - if(logOnOff) { + if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled - string sql; - char *errmsg = NULL; - if( mySqliteLogDb != 0 ) { // sqlite-db is open - sql = "UPDATE Hand SET "; + sql += "UPDATE Hand SET "; sql += "Seat_" + boost::lexical_cast(seat) + "_Hand_text=\"" + CardsValue::determineHandName(cardsValueInt,activePlayerList) + "\""; sql += ",Seat_" + boost::lexical_cast(seat) + "_Hand_int=" + boost::lexical_cast(cardsValueInt); sql += " WHERE "; sql += "GameID=" + boost::lexical_cast(curGameID) + " AND "; sql += "HandID=" + boost::lexical_cast(curHandID); - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - } - - sqlite3_free(errmsg); - errmsg = NULL; + sql += ";"; + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(&sql); + } logPlayerAction(5,seat,LOG_ACTION_HAS); } @@ -471,35 +419,52 @@ void Log::logHoleCardsHandName(int seat, int cards[2], int cardsValueInt, Player { if(SQLITE_LOG) { - if(logOnOff) { + if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled - string sql; - char *errmsg = NULL; - if( mySqliteLogDb != 0 ) { // sqlite-db is open - sql = "UPDATE Hand SET "; - sql += "Seat_" + boost::lexical_cast(seat) + "_Card_1=" + boost::lexical_cast(cards[0]); - sql += ",Seat_" + boost::lexical_cast(seat) + "_Card_2=" + boost::lexical_cast(cards[1]); - sql += ",Seat_" + boost::lexical_cast(seat) + "_Hand_text=\"" + CardsValue::determineHandName(cardsValueInt,activePlayerList) + "\""; - sql += ",Seat_" + boost::lexical_cast(seat) + "_Hand_int=" + boost::lexical_cast(cardsValueInt); + sql += "UPDATE Hand SET "; + sql += "Seat_" + boost::lexical_cast(seat) + "_Hand_text=\"" + CardsValue::determineHandName(cardsValueInt,activePlayerList) + "\""; + sql += ",Seat_" + boost::lexical_cast(seat) + "_Hand_int=" + boost::lexical_cast(cardsValueInt); + if(!logHoleCardsDone) { + sql += ",Seat_" + boost::lexical_cast(seat) + "_Card_1=" + boost::lexical_cast(cards[0]); + sql += ",Seat_" + boost::lexical_cast(seat) + "_Card_2=" + boost::lexical_cast(cards[1]); + } sql += " WHERE "; sql += "GameID=" + boost::lexical_cast(curGameID) + " AND "; sql += "HandID=" + boost::lexical_cast(curHandID); - if(sqlite3_exec(mySqliteLogDb, sql.data(), 0, 0, &errmsg) != SQLITE_OK) { - cout << "Error in statement: " << sql.data() << "[" << errmsg << "]." << endl; - sqlite3_free(errmsg); - errmsg = NULL; - } + sql += ";"; + if(myConfig->readConfigInt("LogInterval") == 0) { + exec_transaction(&sql); + } logPlayerAction(5,seat,LOG_ACTION_SHOW); + if(!logHoleCardsDone) { + logPlayerAction(5,seat,LOG_ACTION_SHOW); + } else { + logPlayerAction(5,seat,LOG_ACTION_HAS); + } } } } } +void Log::exec_transaction(string *sql) +{ + char *errmsg = NULL; + + string sql_transaction = "BEGIN;" + *sql + "COMMIT;"; + *sql = ""; + + if(sqlite3_exec(mySqliteLogDb, sql_transaction.data(), 0, 0, &errmsg) != SQLITE_OK) { + cout << "Error in statement: " << sql_transaction.data() << "[" << errmsg << "]." << endl; + sqlite3_free(errmsg); + errmsg = NULL; + } +} + //void //Log::closeLogDbAtExit() //{ @@ -528,3 +493,11 @@ void Log::logHoleCardsHandName(int seat, int cards[2], int cardsValueInt, Player // 11 wins (side pot) // 11 sits out // 12 wins game + +// Bero-Code +// 0 Pre-Preflop +// 1 Preflop +// 2 Flop +// 3 Turn +// 4 River +// 5 Post-River diff --git a/src/engine/log.h b/src/engine/log.h index fe2b3259..405236f1 100644 --- a/src/engine/log.h +++ b/src/engine/log.h @@ -24,11 +24,13 @@ struct sqlite3; +class ConfigFile; + class Log { public: - Log(std::string logDirString, int logOnOffInt); + Log(ConfigFile *c); ~Log(); @@ -39,15 +41,17 @@ public: void logHoleCards(int bero, int seat, int cards[2]); void logHandName(int seat, int cardsValueInt, PlayerList activePlayerList); void logHoleCardsHandName(int seat, int cards[2], int cardsValueInt, PlayerList activePlayerList); + void exec_transaction(std::string *sql); // void closeLogDbAtExit(); private: sqlite3 *mySqliteLogDb; + ConfigFile *myConfig; int curGameID; int curHandID; - bool logOnOff; - + std::string sql; + bool logHoleCardsDone; }; #endif // LOG_H diff --git a/src/engine/network_engine/clientbero.cpp b/src/engine/network_engine/clientbero.cpp index fbf8f2de..71faede2 100644 --- a/src/engine/network_engine/clientbero.cpp +++ b/src/engine/network_engine/clientbero.cpp @@ -18,7 +18,7 @@ #include "clientbero.h" -ClientBeRo::ClientBeRo(HandInterface* hi, int /*id*/, unsigned /*dP*/, int sB, GameState gS) +ClientBeRo::ClientBeRo(HandInterface* hi, unsigned /*dP*/, int sB, GameState gS) : BeRoInterface(), myBeRoID(gS), myHand(hi), highestCardsValue(0), smallBlindPositionId(0), bigBlindPositionId(0), currentPlayersTurnId(0), firstRoundLastPlayersTurnId(0), highestSet(0), firstRound(true), smallBlindPosition(0), smallBlind(sB), minimumRaise(2*sB), fullBetRule(false), lastActionPlayer(0) diff --git a/src/engine/network_engine/clientbero.h b/src/engine/network_engine/clientbero.h index 24cf7f13..4ddec12f 100644 --- a/src/engine/network_engine/clientbero.h +++ b/src/engine/network_engine/clientbero.h @@ -30,7 +30,7 @@ class HandInterface; class ClientBeRo : public BeRoInterface { public: - ClientBeRo(HandInterface* hi, int id, unsigned dP, int sB, GameState gS); + ClientBeRo(HandInterface* hi, unsigned dP, int sB, GameState gS); ~ClientBeRo(); GameState getMyBeRoID() const; diff --git a/src/engine/network_engine/clientenginefactory.cpp b/src/engine/network_engine/clientenginefactory.cpp index 28794488..5a260cb1 100644 --- a/src/engine/network_engine/clientenginefactory.cpp +++ b/src/engine/network_engine/clientenginefactory.cpp @@ -54,15 +54,15 @@ ClientEngineFactory::createPlayer(int id, unsigned uniqueId, PlayerType type, st } std::vector > -ClientEngineFactory::createBeRo(HandInterface *hi, int id, unsigned dP, int sB) +ClientEngineFactory::createBeRo(HandInterface *hi, unsigned dP, int sB) { std::vector > myBeRo; - myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, id, dP, sB, GAME_STATE_PREFLOP))); - myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, id, dP, sB, GAME_STATE_FLOP))); - myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, id, dP, sB, GAME_STATE_TURN))); - myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, id, dP, sB, GAME_STATE_RIVER))); - myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, id, dP, sB, GAME_STATE_POST_RIVER))); + myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, dP, sB, GAME_STATE_PREFLOP))); + myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, dP, sB, GAME_STATE_FLOP))); + myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, dP, sB, GAME_STATE_TURN))); + myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, dP, sB, GAME_STATE_RIVER))); + myBeRo.push_back(boost::shared_ptr(new ClientBeRo(hi, dP, sB, GAME_STATE_POST_RIVER))); return myBeRo; diff --git a/src/engine/network_engine/clientenginefactory.h b/src/engine/network_engine/clientenginefactory.h index 9ac85d02..b1766902 100644 --- a/src/engine/network_engine/clientenginefactory.h +++ b/src/engine/network_engine/clientenginefactory.h @@ -41,7 +41,7 @@ public: virtual boost::shared_ptr createHand(boost::shared_ptr f, GuiInterface *g, boost::shared_ptr b, Log *l, PlayerList sl, PlayerList apl, PlayerList rpl, int id, int sP, int dP, int sB,int sC); virtual boost::shared_ptr createBoard(unsigned dp); virtual boost::shared_ptr createPlayer(int id, unsigned uniqueId, PlayerType type, std::string name, std::string avatar, int sC, bool aS, int mB); - virtual std::vector > createBeRo(HandInterface *hi, int id, unsigned dP, int sB); + virtual std::vector > createBeRo(HandInterface *hi, unsigned dP, int sB); }; #endif diff --git a/src/engine/network_engine/clienthand.cpp b/src/engine/network_engine/clienthand.cpp index 3345253b..9d5dd4d4 100644 --- a/src/engine/network_engine/clienthand.cpp +++ b/src/engine/network_engine/clienthand.cpp @@ -51,7 +51,7 @@ ClientHand::ClientHand(boost::shared_ptr f, GuiInterface *g, boos // the rest of the buttons are assigned later as received from the server. // Preflop, Flop, Turn und River erstellen - myBeRo = myFactory->createBeRo(this, myID, dealerPosition, smallBlind); + myBeRo = myFactory->createBeRo(this, dealerPosition, smallBlind); } diff --git a/src/gui/qt/gametable/gametableimpl.cpp b/src/gui/qt/gametable/gametableimpl.cpp index cdc1d4c2..36a921bd 100755 --- a/src/gui/qt/gametable/gametableimpl.cpp +++ b/src/gui/qt/gametable/gametableimpl.cpp @@ -2512,6 +2512,7 @@ void gameTableImpl::postRiverRunAnimation3() for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) { if((*it_c)->getMyCash() == 0) { currentHand->getGuiInterface()->logPlayerSitsOut((*it_c)->getMyName()); + currentHand->getLog()->logPlayerAction(5, (*it_c)->getMyID()+1, LOG_ACTION_SIT_OUT); } } diff --git a/src/net/common/clientthread.cpp b/src/net/common/clientthread.cpp index 5f298a5b..1517d021 100644 --- a/src/net/common/clientthread.cpp +++ b/src/net/common/clientthread.cpp @@ -55,7 +55,7 @@ ClientThread::ClientThread(GuiInterface &gui, AvatarManager &avatarManager, Conf m_curGameId(0), m_curGameNum(1), m_guiPlayerId(0), m_sessionEstablished(false), m_stateTimer(*m_ioService), m_avatarTimer(*m_ioService) { - m_clientLog.reset(new Log("", 0)); + m_clientLog.reset(new Log(config)); m_context.reset(new ClientContext); myQtToolsInterface.reset(CreateQtToolsWrapper()); m_senderHelper.reset(new SenderHelper(m_ioService)); diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index c18f0bb0..955d943a 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -214,7 +214,7 @@ ServerLobbyThread::Init(const string &logDir) m_serverConfig.readConfigString("DBServerEncryptionKey")); GetBanManager().InitGameNameBadWordList(m_serverConfig.readConfigStringList("GameNameBadWordList")); - m_serverLog.reset(new Log(logDir, 0)); + m_serverLog.reset(new Log(&m_serverConfig)); } void diff --git a/src/session.cpp b/src/session.cpp index dbcf5c25..dacd9b92 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -43,7 +43,7 @@ Session::Session(GuiInterface *g, ConfigFile *c) : currentGameNum(0), myGui(g), myConfig(c), myLog(0), myGameType(GAME_TYPE_NONE) { myQtToolsInterface = CreateQtToolsWrapper(); - myLog = new Log(myConfig->readConfigString("LogDir"),myConfig->readConfigInt("LogOnOff")); + myLog = new Log(myConfig); }