/***************************************************************************** * PokerTH - The open source texas holdem engine * * Copyright (C) 2006-2011 Felix Hammer, Florian Thauer, Lothar May * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU Affero General Public License as * * published by the Free Software Foundation, either version 3 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 Affero General Public License for more details. * * * * You should have received a copy of the GNU Affero General Public License * * along with this program. If not, see . * *****************************************************************************/ #include "guilog.h" #include "gametableimpl.h" #include #include #include #include #include #include "gametablestylereader.h" using namespace std; guiLog::guiLog(gameTableImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir(0), myHtmlLogFile(0) { myW->setGuiLog(this); myStyle = myW->getMyGameTableStyle(); myAppDataPath = QString::fromUtf8(myConfig->readConfigString("AppDataDir").c_str()); connect(this, SIGNAL(signalLogPlayerActionMsg(QString, int, int)), this, SLOT(logPlayerActionMsg(QString, int, int))); connect(this, SIGNAL(signalLogNewGameHandMsg(int, int)), this, SLOT(logNewGameHandMsg(int, int))); connect(this, SIGNAL(signalLogNewBlindsSetsMsg(int, int, QString, QString)), this, SLOT(logNewBlindsSetsMsg(int, int, QString, QString))); connect(this, SIGNAL(signalLogPlayerWinsMsg(QString, int, bool)), this, SLOT(logPlayerWinsMsg(QString, int, bool))); connect(this, SIGNAL(signalLogPlayerSitsOut(QString)), this, SLOT(logPlayerSitsOut(QString))); connect(this, SIGNAL(signalLogDealBoardCardsMsg(int, int, int, int, int, int)), this, SLOT(logDealBoardCardsMsg(int, int, int, int, int, int))); connect(this, SIGNAL(signalLogFlipHoleCardsMsg(QString, int, int, int, QString)), this, SLOT(logFlipHoleCardsMsg(QString, int, int, int, QString))); connect(this, SIGNAL(signalLogPlayerLeftMsg(QString, int)), this, SLOT(logPlayerLeftMsg(QString, int))); connect(this, SIGNAL(signalLogPlayerJoinedMsg(QString)), this, SLOT(logPlayerJoinedMsg(QString))); connect(this, SIGNAL(signalLogNewGameAdminMsg(QString)), this, SLOT(logNewGameAdminMsg(QString))); connect(this, SIGNAL(signalLogPlayerWinGame(QString, int)), this, SLOT(logPlayerWinGame(QString, int))); connect(this, SIGNAL(signalFlushLogAtGame(int)), this, SLOT(flushLogAtGame(int))); connect(this, SIGNAL(signalFlushLogAtHand()), this, SLOT(flushLogAtHand())); logFileStreamString = ""; lastGameID = 0; if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled QDir logDir(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())); if(myConfig->readConfigString("LogDir") != "" && logDir.exists()) { int i; if(HTML_LOG) { myLogDir = new QDir(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())); QDateTime currentTime = QDateTime::currentDateTime(); myHtmlLogFile = new QFile(myLogDir->absolutePath()+"/pokerth-log-"+currentTime.toString("yyyy-MM-dd_hh.mm.ss")+".html"); //Logo-Pixmap extrahieren QPixmap logoChipPixmapFile(":/gfx/logoChip3D.png"); logoChipPixmapFile.save(myLogDir->absolutePath()+"/logo.png"); // myW->textBrowser_Log->append(myHtmlLogFile->fileName()); // erstelle html-Datei myHtmlLogFile->open( QIODevice::WriteOnly ); QTextStream stream( myHtmlLogFile ); stream << "\n"; stream << "\n"; stream << ""; stream << "\n"; stream << "\n"; stream << "\n"; stream << QString("

Log-File for PokerTH %1 Session started on ").arg(POKERTH_BETA_RELEASE_STRING)+QDate::currentDate().toString("yyyy-MM-dd")+" at "+QTime::currentTime().toString("hh:mm:ss")+"

\n"; myHtmlLogFile->close(); } // delete old log files int daysUntilWaste = myConfig->readConfigInt("LogStoreDuration"); QStringList filters("pokerth-log*"); QStringList logFileList = myLogDir->entryList(filters, QDir::Files); for(i=0; i daysUntilWaste) { // cout << QString::QString(myLogDir->absolutePath()+"/"+logFileList.at(i)).toStdString() << endl; QFile fileToDelete(myLogDir->absolutePath()+"/"+logFileList.at(i)); fileToDelete.remove(); } } } else { cout << "Log directory doesn't exist. Cannot create log files"; } } } guiLog::~guiLog() { delete myLogDir; delete myHtmlLogFile; } void guiLog::logPlayerActionMsg(QString msg, int action, int setValue) { switch (action) { case 1: msg += " folds."; break; case 2: msg += " checks."; break; case 3: msg += " calls "; break; case 4: msg += " bets "; break; case 5: msg += " bets "; break; case 6: msg += " is all in with "; break; default: msg += "ERROR"; } if (action >= 3) { msg += "$"+QString::number(setValue,10)+"."; } myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+msg+""); if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled if(HTML_LOG) { logFileStreamString += msg+"
\n"; if(myConfig->readConfigInt("LogInterval") == 0) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; } } } } void guiLog::logNewGameHandMsg(int gameID, int handID) { PlayerListConstIterator it_c; boost::shared_ptr currentHand = myW->getSession()->getCurrentGame()->getCurrentHand(); PlayerList activePlayerList = currentHand->getActivePlayerList(); 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) { logFileStreamString += "

Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+"
"; logFileStreamString += "BLIND LEVEL: $"+QString::number(currentHand->getSmallBlind())+" / $"+QString::number(currentHand->getSmallBlind()*2)+"
"; //print cash only for active players for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) { logFileStreamString += "Seat " + QString::number((*it_c)->getMyID()+1,10) + ": " + QString::fromUtf8((*it_c)->getMyName().c_str()) + " ($" + QString::number((*it_c)->getMyCash()+(*it_c)->getMySet(),10)+")
"; } } } } void guiLog::logNewBlindsSetsMsg(int sbSet, int bbSet, QString sbName, QString bbName) { // log blinds 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) { logFileStreamString += "BLINDS: "; logFileStreamString += sbName+" ($"+QString::number(sbSet,10)+"), "; logFileStreamString += bbName+" ($"+QString::number(bbSet,10)+")"; PlayerListConstIterator it_c; boost::shared_ptr currentGame = myW->getSession()->getCurrentGame(); PlayerList activePlayerList = currentGame->getActivePlayerList(); for(it_c=activePlayerList->begin(); it_c!=activePlayerList->end(); ++it_c) { if(activePlayerList->size() > 2) { if((*it_c)->getMyButton() == BUTTON_DEALER) { logFileStreamString += "
" + QString::fromUtf8((*it_c)->getMyName().c_str()) + " starts as dealer."; break; } } else { if((*it_c)->getMyButton() == BUTTON_SMALL_BLIND) { logFileStreamString += "
" + QString::fromUtf8((*it_c)->getMyName().c_str()) + " starts as dealer."; break; } } } logFileStreamString += "

PREFLOP"; logFileStreamString += "
\n"; } } } void guiLog::logPlayerWinsMsg(QString playerName, int pot, bool main) { if(main) { myW->textBrowser_Log->append("getLogWinnerMainPotColor()+";\">"+playerName+" wins $"+QString::number(pot,10)+""); } else { myW->textBrowser_Log->append("getLogWinnerSidePotColor()+";\">"+playerName+" wins $"+QString::number(pot,10)+" (side pot)"); } if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled logFileStreamString += "
"+playerName+" wins $"+QString::number(pot,10); if(!main) { logFileStreamString += " (side pot)"; } logFileStreamString += "\n"; if(myConfig->readConfigInt("LogInterval") == 0) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; } } } void guiLog::logPlayerSitsOut(QString playerName) { myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">"+playerName+" sits out"); if(myConfig->readConfigInt("LogOnOff")) { logFileStreamString += "
"+playerName+" sits out\n"; if(myConfig->readConfigInt("LogInterval") == 0) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; } } } void guiLog::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int card4, int card5) { QString round; switch (roundID) { case 1: round = "Flop"; myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- "+round+" --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+"]"); break; case 2: round = "Turn"; myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- "+round+" --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+"]"); break; case 3: round = "River"; myW->textBrowser_Log->append("getLogPlayerSitsOutColor()+";\">--- "+round+" --- "+"["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+translateCardCode(card4).at(1)+","+translateCardCode(card5).at(0)+translateCardCode(card5).at(1)+"]"); break; default: round = "ERROR"; } if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled if(HTML_LOG) { switch (roundID) { case 1: round = "Flop"; logFileStreamString += "
"+round.toUpper()+" [board cards "+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+""+translateCardCode(card3).at(1)+"]"+"
\n"; break; case 2: round = "Turn"; logFileStreamString += "
"+round.toUpper()+" [board cards "+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+""+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+""+translateCardCode(card4).at(1)+"]"+"
\n"; break; case 3: round = "River"; logFileStreamString += "
"+round.toUpper()+" [board cards "+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+","+translateCardCode(card3).at(0)+""+translateCardCode(card3).at(1)+","+translateCardCode(card4).at(0)+""+translateCardCode(card4).at(1)+","+translateCardCode(card5).at(0)+""+translateCardCode(card5).at(1)+"]"+"
\n"; break; default: round = "ERROR"; } if(myConfig->readConfigInt("LogInterval") == 0) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; } } } } void guiLog::logFlipHoleCardsMsg(QString playerName, int card1, int card2, int cardsValueInt, QString showHas) { QString tempHandName; if (cardsValueInt != -1) { tempHandName = CardsValue::determineHandName(cardsValueInt,myW->getSession()->getCurrentGame()->getActivePlayerList()).c_str(); myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+playerName+" "+showHas+" ["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+"] - \""+tempHandName+"\""); } else { myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+playerName+" "+showHas+" ["+translateCardCode(card1).at(0)+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+translateCardCode(card2).at(1)+"]"); } if(myConfig->readConfigInt("LogOnOff")) { //if write logfiles is enabled if(HTML_LOG) { if (cardsValueInt != -1) { tempHandName.fromStdString(CardsValue::determineHandName(cardsValueInt,myW->getSession()->getCurrentGame()->getActivePlayerList())); logFileStreamString += playerName+" "+showHas+" [ "+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+"] - "+tempHandName+"
\n"; if(myConfig->readConfigInt("LogInterval") == 0) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; } } else { logFileStreamString += playerName+" "+showHas+" ["+translateCardCode(card1).at(0)+""+translateCardCode(card1).at(1)+","+translateCardCode(card2).at(0)+""+translateCardCode(card2).at(1)+"]"+"
\n"; if(myConfig->readConfigInt("LogInterval") == 0) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; } } } } } void guiLog::logPlayerLeftMsg(QString playerName, int wasKicked) { QString action; if(wasKicked) action = "was kicked from"; else action = "has left"; myW->textBrowser_Log->append( "getChatLogTextColor()+";\">"+playerName+" "+action+" the game!"); if(myConfig->readConfigInt("LogOnOff")) { logFileStreamString += ""+playerName+" "+action+" the game!
\n"; if(myConfig->readConfigInt("LogInterval") == 0) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; } } } void guiLog::logNewGameAdminMsg(QString playerName) { myW->textBrowser_Log->append( "getLogNewGameAdminColor()+";\">"+playerName+" is game admin now!"); if(myConfig->readConfigInt("LogOnOff")) { logFileStreamString += ""+playerName+" is game admin now!
\n"; if(myConfig->readConfigInt("LogInterval") == 0) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; } } } void guiLog::logPlayerJoinedMsg(QString playerName) { myW->textBrowser_Log->append("getChatLogTextColor()+";\">"+playerName+" has joined the game!"); } void guiLog::logPlayerWinGame(QString playerName, int gameID) { myW->textBrowser_Log->append( ""+playerName+" wins game " + QString::number(gameID,10) +"!
"); if(myConfig->readConfigInt("LogOnOff")) { logFileStreamString += "

"+playerName+" wins game " + QString::number(gameID,10) +"!
\n"; if(myConfig->readConfigInt("LogInterval") == 0) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; } } } QStringList guiLog::translateCardCode(int cardCode) { int value = cardCode%13; int color = cardCode/13; QStringList cardString; switch (value) { case 0: cardString << "2"; break; case 1: cardString << "3"; break; case 2: cardString << "4"; break; case 3: cardString << "5"; break; case 4: cardString << "6"; break; case 5: cardString << "7"; break; case 6: cardString << "8"; break; case 7: cardString << "9"; break; case 8: cardString << "T"; break; case 9: cardString << "J"; break; case 10: cardString << "Q"; break; case 11: cardString << "K"; break; case 12: cardString << "A"; break; default: cardString << "ERROR"; } switch (color) { case 0: cardString << "d"; break; case 1: cardString << "h"; break; case 2: cardString << "s"; break; case 3: cardString << "c"; break; default: cardString << "ERROR"; } return cardString; } void guiLog::writeLogFileStream(QString streamString) { if(myHtmlLogFile) { if(myHtmlLogFile->open( QIODevice::ReadWrite )) { QTextStream stream( myHtmlLogFile ); stream.readAll(); stream << streamString; myHtmlLogFile->close(); } else { cout << "Could not open log-file to write log-messages!" << endl; } } else { cout << "Could not find log-file to write log-messages!" << endl; } } 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 = ""; } } } void guiLog::flushLogAtGame(int gameID) { if(myConfig->readConfigInt("LogOnOff")) { // write for log after every game if(gameID > lastGameID) { writeLogFileStream(logFileStreamString); logFileStreamString = ""; lastGameID = gameID; } } }