diff --git a/src/game_defs.h b/src/game_defs.h index 2e71a0ef..06523e9c 100644 --- a/src/game_defs.h +++ b/src/game_defs.h @@ -25,8 +25,8 @@ #define MAX_GUI_SPEED 11 #define DEBUG_MODE 0 -#define SQLITE_LOG 0 -#define HTML_LOG 1 +#define SQLITE_LOG 1 +#define HTML_LOG 0 #define POKERTH_VERSION_MAJOR 0 #define POKERTH_VERSION_MINOR 90 diff --git a/src/gui/qt/gametable/log/guilog.cpp b/src/gui/qt/gametable/log/guilog.cpp index ccf31055..430b29b7 100644 --- a/src/gui/qt/gametable/log/guilog.cpp +++ b/src/gui/qt/gametable/log/guilog.cpp @@ -62,9 +62,10 @@ guiLog::guiLog(gameTableImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir( int i; + myLogDir = new QDir(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())); + if(HTML_LOG) { - myLogDir = new QDir(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())); QDateTime currentTime = QDateTime::currentDateTime(); if(SQLITE_LOG) { myHtmlLogFile_old = new QFile(myLogDir->absolutePath()+"/pokerth-log-"+currentTime.toString("yyyy-MM-dd_hh.mm.ss")+"_old.html"); @@ -167,10 +168,10 @@ void guiLog::logPlayerActionMsg(QString msg, int action, int setValue) myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+msg+""); - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + if(HTML_LOG) { - if(HTML_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled logFileStreamString += msg+"
\n"; @@ -194,10 +195,10 @@ void guiLog::logNewGameHandMsg(int gameID, int handID) myW->textBrowser_Log->append("getChatLogTextColor()+"; font-size:large; font-weight:bold\">## Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+" ##"); - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + if(HTML_LOG) { - if(HTML_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled logFileStreamString += "

Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+"
"; logFileStreamString += "BLIND LEVEL: $"+QString::number(currentHand->getSmallBlind())+" / $"+QString::number(currentHand->getSmallBlind()*2)+"
"; @@ -222,10 +223,10 @@ void guiLog::logNewBlindsSetsMsg(int sbSet, int bbSet, QString sbName, QString b myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+sbName+" posts small blind ($"+QString::number(sbSet,10)+")"); myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+bbName+" posts big blind ($"+QString::number(bbSet,10)+")"); - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + if(HTML_LOG) { - if(HTML_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled logFileStreamString += "BLINDS: "; @@ -271,19 +272,23 @@ void guiLog::logPlayerWinsMsg(QString playerName, int pot, bool main) myW->textBrowser_Log->append("getLogWinnerSidePotColor()+";\">"+playerName+" wins $"+QString::number(pot,10)+" (side pot)"); } - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + if(HTML_LOG) { - logFileStreamString += "
"+playerName+" wins $"+QString::number(pot,10); - if(!main) { - logFileStreamString += " (side pot)"; - } - logFileStreamString += "\n"; + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; + logFileStreamString += "
"+playerName+" wins $"+QString::number(pot,10); + if(!main) { + logFileStreamString += " (side pot)"; + } + logFileStreamString += "\n"; + + if(myConfig->readConfigInt("LogInterval") == 0) { + writeLogFileStream(logFileStreamString); + logFileStreamString = ""; + } } + } } @@ -292,14 +297,18 @@ void guiLog::logPlayerSitsOut(QString playerName) myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">"+playerName+" sits out"); - if(myConfig->readConfigInt("LogOnOff")) { + if(HTML_LOG) { - logFileStreamString += "
"+playerName+" sits out\n"; + if(myConfig->readConfigInt("LogOnOff")) { - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; + logFileStreamString += "
"+playerName+" sits out\n"; + + if(myConfig->readConfigInt("LogInterval") == 0) { + writeLogFileStream(logFileStreamString); + logFileStreamString = ""; + } } + } } @@ -326,10 +335,10 @@ void guiLog::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, round = "ERROR"; } - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + if(HTML_LOG) { - if(HTML_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled switch (roundID) { @@ -376,10 +385,10 @@ void guiLog::logFlipHoleCardsMsg(QString playerName, int card1, int card2, int c } - if(myConfig->readConfigInt("LogOnOff")) { - //if write logfiles is enabled + if(HTML_LOG) { - if(HTML_LOG) { + if(myConfig->readConfigInt("LogOnOff")) { + //if write logfiles is enabled if (cardsValueInt != -1) { @@ -415,14 +424,18 @@ void guiLog::logPlayerLeftMsg(QString playerName, int wasKicked) myW->textBrowser_Log->append( "getChatLogTextColor()+";\">"+playerName+" "+action+" the game!"); - if(myConfig->readConfigInt("LogOnOff")) { + if(HTML_LOG) { - logFileStreamString += ""+playerName+" "+action+" the game!
\n"; + if(myConfig->readConfigInt("LogOnOff")) { - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; + logFileStreamString += ""+playerName+" "+action+" the game!
\n"; + + if(myConfig->readConfigInt("LogInterval") == 0) { + writeLogFileStream(logFileStreamString); + logFileStreamString = ""; + } } + } } @@ -431,14 +444,18 @@ void guiLog::logNewGameAdminMsg(QString playerName) myW->textBrowser_Log->append( "getLogNewGameAdminColor()+";\">"+playerName+" is game admin now!"); - if(myConfig->readConfigInt("LogOnOff")) { + if(HTML_LOG) { - logFileStreamString += ""+playerName+" is game admin now!
\n"; + if(myConfig->readConfigInt("LogOnOff")) { - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; + logFileStreamString += ""+playerName+" is game admin now!
\n"; + + if(myConfig->readConfigInt("LogInterval") == 0) { + writeLogFileStream(logFileStreamString); + logFileStreamString = ""; + } } + } } @@ -453,14 +470,18 @@ void guiLog::logPlayerWinGame(QString playerName, int gameID) myW->textBrowser_Log->append( ""+playerName+" wins game " + QString::number(gameID,10) +"!
"); - if(myConfig->readConfigInt("LogOnOff")) { + if(HTML_LOG) { - logFileStreamString += "

"+playerName+" wins game " + QString::number(gameID,10) +"!
\n"; + if(myConfig->readConfigInt("LogOnOff")) { - if(myConfig->readConfigInt("LogInterval") == 0) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; + logFileStreamString += "

"+playerName+" wins game " + QString::number(gameID,10) +"!
\n"; + + if(myConfig->readConfigInt("LogInterval") == 0) { + writeLogFileStream(logFileStreamString); + logFileStreamString = ""; + } } + } } @@ -587,25 +608,33 @@ void guiLog::writeLog(string log_string, int modus) void guiLog::flushLogAtHand() { - if(myConfig->readConfigInt("LogOnOff")) { - if(myConfig->readConfigInt("LogInterval") < 2) { - // write for log after every action and after every hand - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; + if(HTML_LOG) { + + if(myConfig->readConfigInt("LogOnOff")) { + if(myConfig->readConfigInt("LogInterval") < 2) { + // write for log after every action and after every hand + writeLogFileStream(logFileStreamString); + logFileStreamString = ""; + } } + } } void guiLog::flushLogAtGame(int gameID) { - if(myConfig->readConfigInt("LogOnOff")) { - // write for log after every game - if(gameID > lastGameID) { - writeLogFileStream(logFileStreamString); - logFileStreamString = ""; - lastGameID = gameID; + if(HTML_LOG) { + + if(myConfig->readConfigInt("LogOnOff")) { + // write for log after every game + if(gameID > lastGameID) { + writeLogFileStream(logFileStreamString); + logFileStreamString = ""; + lastGameID = gameID; + } } + } } @@ -657,6 +686,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) string sql = ""; string log_string = ""; + string round_string = ""; + string action_string = ""; bool data_found = false; char **result_Session = 0, **result_Game = 0, **result_Hand = 0, **result_Hand_ID = 0, **result_Action = 0; int nRow_Session=0, nRow_Game=0, nRow_Hand=0, nRow_Hand_ID=0, nRow_Action=0; @@ -741,8 +772,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) switch(modus) { case 1: - log_string = "

" + log_string + "

"; - if(!neu) log_string = "" + log_string; + log_string = "

" + log_string + "

\n"; + if(!neu) log_string = "\n" + log_string; break; case 2: log_string += "\n"; @@ -815,7 +846,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } // run through all hands - for(hand_ctr=1; hand_ctr<=nRow_Hand_ID-1; hand_ctr++) { + for(hand_ctr=1; hand_ctr<=nRow_Hand_ID; hand_ctr++) { // log game and hand id log_string += "Game: "; @@ -826,7 +857,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) switch(modus) { case 1: log_string = "

" + log_string; - log_string += "
"; + if(!neu) log_string += ""; + else log_string += ""; break; case 2: log_string += "\n"; @@ -886,7 +918,8 @@ int guiLog::exportLog(QString fileStringPdb,int modus) switch(modus) { case 1: - log_string += "
"; + if(!neu) log_string += "
"; + else log_string += "
"; break; case 2: log_string += "\n"; @@ -918,12 +951,13 @@ int guiLog::exportLog(QString fileStringPdb,int modus) if(modus == 1 || modus == 3) { log_string += ""; } - log_string += "($"; + log_string += " ($"; log_string += boost::lexical_cast(result_Hand[j+nCol_Hand]); log_string += ")"; switch(modus) { case 1: - log_string += "
"; + if(!neu) log_string += "
"; + else log_string += "
"; break; case 2: log_string += "\n"; @@ -947,7 +981,7 @@ int guiLog::exportLog(QString fileStringPdb,int modus) if(neu) { - if(modus == 1) log_string += "
"; + if(modus == 1) log_string += "
"; // read dealer and blinds sql = "SELECT Player,Action,Amount FROM Action WHERE GameID="; @@ -1069,7 +1103,17 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } if(nRow_Action == 1) { - if(modus == 1 || modus == 3) log_string += "
"; + switch(modus) { + case 1: + if(!neu) log_string += "
"; + else log_string += "
"; + break; + case 3: + log_string += "
"; + break; + default: + ; + } log_string += player[boost::lexical_cast(result_Action[2])-1]; log_string += " starts as dealer."; } @@ -1078,64 +1122,81 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } + if(!neu && modus==1) log_string += "
"; + writeLog(log_string,modus); log_string = ""; for(round_ctr=GAME_STATE_PREFLOP; round_ctr<=GAME_STATE_POST_RIVER; round_ctr++) { + round_string = ""; // write round name and board cards if(round_ctr<=GAME_STATE_RIVER) { switch(round_ctr) { case GAME_STATE_PREFLOP: - log_string += "PREFLOP"; + round_string += "PREFLOP"; break; case GAME_STATE_FLOP: - log_string += "FLOP"; + round_string += "FLOP"; break; case GAME_STATE_TURN: - log_string += "TURN"; + round_string += "TURN"; break; case GAME_STATE_RIVER: - log_string += "RIVER"; + round_string += "RIVER"; break; default: ; } switch(modus) { case 1: - log_string = "
" + log_string + ""; + if(!neu) round_string = "
" + round_string + ""; + else round_string = "
" + round_string + ""; + if(round_ctr >= GAME_STATE_FLOP) { + if(!neu) round_string = "
\n" + round_string; + else round_string = "
\n" + round_string; + } break; case 3: - log_string = "" + log_string + ""; + round_string = "" + round_string + ""; + if(round_ctr >= GAME_STATE_FLOP) { + round_string = "

" + round_string; + } break; default: ; } - log_string += " [board cards "; - for(i=1; i<=round_ctr+2; i++) { - data_found = false; - for(j=0; j(result_Hand[j]) == "BoardCard_"+boost::lexical_cast(i)) { - if(result_Hand[j+nCol_Hand]) { - if(modus == 1 || modus == 3) log_string += ""; - string_tmp = convertCardIntToString(boost::lexical_cast(result_Hand[j+nCol_Hand])); - if(string_tmp == "") { - cout << "Implausible board card in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; - sqlite3_close(mySqliteLogDb); - return 1; - } - log_string += boost::lexical_cast(string_tmp.at(0)); - if(modus==1 || modus == 3) log_string += ""; - log_string += boost::lexical_cast(string_tmp.at(1)); - if(round_ctr+2-i > 0) log_string += ","; + if(round_ctr >= GAME_STATE_FLOP) { + round_string += " [board cards "; + for(i=1; i<=round_ctr+2; i++) { + data_found = false; + for(j=0; j(result_Hand[j]) == "BoardCard_"+boost::lexical_cast(i)) { + if(result_Hand[j+nCol_Hand]) { + if(modus == 1 || modus == 3) round_string += ""; + string_tmp = convertCardIntToString(boost::lexical_cast(result_Hand[j+nCol_Hand])); + if(string_tmp == "") { + cout << "Implausible board card in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + sqlite3_close(mySqliteLogDb); + return 1; + } + round_string += boost::lexical_cast(string_tmp.at(0)); + if(modus==1 || modus == 3) round_string += ""; + round_string += boost::lexical_cast(string_tmp.at(1)); + if(round_ctr+2-i > 0) round_string += ","; - data_found = true; + data_found = true; + } } } } + round_string += "]"; + } + if(data_found) { + log_string += round_string; + } else { + continue; } - log_string += "]"; - if(modus == 1 || modus == 3) log_string += "
"; } // read round action @@ -1154,19 +1215,92 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } for(action_ctr=1; action_ctr<=nRow_Action; action_ctr++) { - log_string += player[boost::lexical_cast(result_Action[3*action_ctr])-1]; - log_string += " "; - log_string += boost::lexical_cast(result_Action[3*action_ctr+1]); - if(result_Action[3*action_ctr+2]) { - // with amount - log_string += " $"; - log_string += boost::lexical_cast(result_Action[3*action_ctr+2]); + switch(modus) { + case 1: + if(!neu) { + if(action_ctr>1 && (boost::lexical_cast(result_Action[3*(action_ctr-1)+1]) == "wins" || boost::lexical_cast(result_Action[3*(action_ctr-1)+1]) == "sits out" || boost::lexical_cast(result_Action[3*(action_ctr-1)+1]) == "wins (side pot)")) + log_string += "\n"; + else + log_string += "
\n"; + } else { + log_string += "
\n"; + } + break; + case 3: + log_string += "
"; + break; + default: + ; + } + if(!neu && boost::lexical_cast(result_Action[3*action_ctr+1]) == "wins (side pot)") { + action_string += player[boost::lexical_cast(result_Action[3*action_ctr])-1]; + action_string += " wins $"; + action_string += boost::lexical_cast(result_Action[3*action_ctr+2]); + action_string += " (side pot)"; + } else { + action_string += player[boost::lexical_cast(result_Action[3*action_ctr])-1]; + action_string += " "; + action_string += boost::lexical_cast(result_Action[3*action_ctr+1]); + if(result_Action[3*action_ctr+2]) { + // with amount + action_string += " $"; + action_string += boost::lexical_cast(result_Action[3*action_ctr+2]); + } } - // show - if(boost::lexical_cast(result_Action[3*action_ctr+1]) == "shows") { + // wins game + if(boost::lexical_cast(result_Action[3*action_ctr+1]) == "wins game") { + switch(modus) { + case 1: + if(!neu) action_string = "

" + action_string + " " + boost::lexical_cast(gameID) + "!
"; + else action_string = "
" + action_string + " " + boost::lexical_cast(gameID) + "!"; + break; + case 3: + action_string = "" + action_string + " " + boost::lexical_cast(gameID) + "!"; + break; + default: + ; + } + } + + // wins + if(boost::lexical_cast(result_Action[3*action_ctr+1]) == "wins" || boost::lexical_cast(result_Action[3*action_ctr+1]) == "wins (side pot)") { + switch(modus) { + case 1: + if(!neu) action_string = "
" + action_string + ""; + else action_string = "" + action_string + ""; + break; + case 3: + action_string = "" + action_string + ""; + break; + default: + ; + } + } + + // sits out + if(boost::lexical_cast(result_Action[3*action_ctr+1]) == "sits out") { + switch(modus) { + case 1: + if(!neu) action_string = "
" + action_string + ""; + else action_string = "" + action_string + ""; + break; + case 3: + action_string = "" + action_string + ""; + break; + default: + ; + } + } + + log_string += action_string; + action_string = ""; + + // show cards + if(boost::lexical_cast(result_Action[3*action_ctr+1]) == "shows" || boost::lexical_cast(result_Action[3*action_ctr+1]) == "has") { // log cards - log_string += " ["; + if(!neu && round_ctr == GAME_STATE_POST_RIVER) log_string += " [ "; + else log_string += " ["; if(modus == 1 || modus == 3) log_string += ""; // find hole card 1 @@ -1221,26 +1355,42 @@ int guiLog::exportLog(QString fileStringPdb,int modus) return 1; } + if(round_ctr == GAME_STATE_POST_RIVER) { + // find hand name + data_found = false; + for(i=0; i(result_Action[3*action_ctr]); + cmpString += "_Hand_text"; + if(boost::lexical_cast(result_Hand[i]) == cmpString) { + log_string += " - " + boost::lexical_cast(result_Hand[i+nCol_Hand]); + data_found = true; + } + } + if(!data_found) { + cout << "Missing hand name information in game " << gameID << " hand " << result_Hand_ID[hand_ctr] << "!" << endl; + sqlite3_close(mySqliteLogDb); + return 1; + } + } + } - log_string += "."; - if(action_ctr(result_Action[3*action_ctr+1]) != "wins" && boost::lexical_cast(result_Action[3*action_ctr+1]) != "shows" && boost::lexical_cast(result_Action[3*action_ctr+1]) != "has" && boost::lexical_cast(result_Action[3*action_ctr+1]) != "sits out" && boost::lexical_cast(result_Action[3*action_ctr+1]) != "wins (side pot)" && boost::lexical_cast(result_Action[3*action_ctr+1]) != "wins game") { + log_string += "."; } + if(neu && boost::lexical_cast(result_Action[3*action_ctr+1]) != "wins game") log_string += "."; + } - if(modus == 1) log_string += "
"; sqlite3_free_table(result_Action); - // log river actions together with post river actions - if(round_ctr!=GAME_STATE_RIVER) { - writeLog(log_string,modus); - log_string = ""; - } - - } + if(modus == 1) log_string += "\n"; + writeLog(log_string,modus); + log_string = ""; + } @@ -1249,17 +1399,6 @@ int guiLog::exportLog(QString fileStringPdb,int modus) } - /*switch(modus) { - case 1: - break; - case 2: - break; - case 3: - break; - default: - ; - }*/ - return 0; } diff --git a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp index e7471c6f..3e869a89 100644 --- a/src/gui/qt/settingsdialog/settingsdialogimpl.cpp +++ b/src/gui/qt/settingsdialog/settingsdialogimpl.cpp @@ -1361,4 +1361,8 @@ void settingsDialogImpl::showLogFilePreview() if(selectedItem) { myGuiLog->showLog(selectedItem->data(0, Qt::UserRole).toString(), textBrowser_logPreview); } + + QTextCursor cursor(textBrowser_logPreview->textCursor()); + cursor.movePosition(QTextCursor::Start); + textBrowser_logPreview->setTextCursor(cursor); }