Files
pokerth/src/gui/qt/log.cpp
T

260 lines
9.1 KiB
C++
Raw Normal View History

2007-01-13 02:40:33 +00:00
/***************************************************************************
* Copyright (C) 2006 by FThauer FHammer *
* f.thauer@web.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 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 General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
2007-01-31 22:48:44 +00:00
#include "log.h"
2007-01-13 02:40:33 +00:00
#include "mainwindowimpl.h"
using namespace std;
2007-01-31 22:48:44 +00:00
Log::Log(mainWindowImpl* w) : myW(w)
2007-01-13 02:40:33 +00:00
{
2007-01-31 22:48:44 +00:00
myW->setLog(this);
2007-02-03 22:47:16 +00:00
myConfig = new ConfigFile;
if(myConfig->readConfigString("LogDir") != "" && QDir::QDir(QString::fromStdString(myConfig->readConfigString("LogDir"))).exists()) {
2007-02-05 22:33:52 +00:00
#ifdef _WIN32
2007-02-09 22:56:03 +00:00
myLogDir = new QDir(QString::fromStdString(myConfig->readConfigString("LogDir")));
2007-02-06 01:14:00 +00:00
#else
myLogDir = new QDir(QString::fromStdString(myConfig->readConfigString("LogDir")));
2007-02-05 22:33:52 +00:00
#endif
2007-02-09 22:56:03 +00:00
myLogFile = new QFile(myLogDir->absolutePath()+"/pokerth-log-"+QDateTime::currentDateTime().toString("yyyy-MM-dd_hh.mm.ss")+".html");
2007-02-06 01:14:00 +00:00
2007-02-04 00:34:44 +00:00
//Logo-Pixmap extrahieren
2007-02-05 22:33:52 +00:00
QPixmap::QPixmap(":graphics/graphics/logo-140-100.png").save(myLogDir->absolutePath()+"/logo.png");
2007-02-03 22:47:16 +00:00
2007-02-09 22:56:03 +00:00
// myW->textBrowser_Log->append(myLogFile->fileName());
2007-02-03 22:47:16 +00:00
myLogFile->open( QIODevice::WriteOnly );
QTextStream stream( myLogFile );
2007-02-04 13:46:27 +00:00
stream << "<html>\n";
stream << "<body>\n";
stream << "<img src='logo.png'>\n";
stream << "<h3><b>Log-File for PokerTH Session started on "+QDate::currentDate().toString("yyyy-MM-dd")+" at "+QTime::currentTime().toString("hh:mm:ss")+"</b></h3>\n";
2007-02-04 23:58:50 +00:00
// stream << "</body>\n";
// stream << "</html>\n";
2007-02-03 22:47:16 +00:00
myLogFile->close();
2007-02-04 13:46:27 +00:00
2007-02-04 23:58:50 +00:00
linesInFile = 3;
2007-02-03 22:47:16 +00:00
}
2007-02-08 18:49:36 +00:00
//Zu alte Dateien löschen!!!
int daysUntilWaste = myConfig->readConfigInt("LogStoreDuration");
int i;
2007-02-09 22:56:03 +00:00
QStringList filters("pokerth-log*");
QStringList logFileList = myLogDir->entryList(filters, QDir::Files);
2007-02-08 18:49:36 +00:00
for(i=0; i<logFileList.count(); i++) {
// cout << logFileList.at(i).toStdString() << endl;
QString dateString = logFileList.at(i);
dateString.remove("pokerth-log-");
dateString.remove(10,14);
QDate dateOfFile(QDate::fromString(dateString, Qt::ISODate));
QDate today(QDate::currentDate());
// cout << dateOfFile.daysTo(today) << endl;
if (dateOfFile.daysTo(today) > daysUntilWaste) {
// cout << QString::QString(myLogDir->absolutePath()+"/"+logFileList.at(i)).toStdString() << endl;
QFile fileToDelete(myLogDir->absolutePath()+"/"+logFileList.at(i));
fileToDelete.remove();
}
}
2007-01-13 02:40:33 +00:00
}
2007-01-31 22:48:44 +00:00
Log::~Log()
2007-01-13 02:40:33 +00:00
{
}
2007-02-04 13:46:27 +00:00
void Log::logPlayerActionMsg(string playerName, int action, int setValue) {
int i;
2007-01-13 02:40:33 +00:00
QString msg;
msg = QString::fromStdString(playerName);
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 += " sets ";
break;
case 6: msg += " is all in with ";
break;
default: msg += "ERROR";
}
if (action >= 3) { msg += QString::number(setValue,10)+"$."; }
myW->textBrowser_Log->append(msg);
2007-02-04 13:46:27 +00:00
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
2007-02-04 23:58:50 +00:00
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
2007-02-04 13:46:27 +00:00
stream << msg+"</br>\n";
2007-02-04 23:58:50 +00:00
// stream << "</body>\n";
// stream << "</html>\n";
2007-02-04 13:46:27 +00:00
myLogFile->close();
linesInFile++;
2007-01-13 02:40:33 +00:00
}
2007-02-04 13:46:27 +00:00
void Log::logNewGameHandMsg(int gameID, int handID) {
2007-01-13 02:40:33 +00:00
2007-02-04 13:46:27 +00:00
int i;
2007-01-13 02:40:33 +00:00
2007-02-08 01:28:58 +00:00
myW->textBrowser_Log->append("<b>## Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+" ##</b>");
2007-02-04 13:46:27 +00:00
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
2007-02-04 23:58:50 +00:00
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
2007-02-04 13:46:27 +00:00
2007-02-11 17:33:43 +00:00
stream << "<p><b>##### Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+" #####</b></br>";
2007-02-10 20:00:33 +00:00
stream << "CASH: ";
2007-02-10 21:52:05 +00:00
int k = 0;
//Aktive Spieler zählen
int activePlayersCounter = 0;
for (k=0; k<myW->getMaxQuantityPlayers(); k++) {
if (myW->getActualHand()->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
}
if(activePlayersCounter > 2) {
for(i=0; i<myW->getActualHand()->getActualQuantityPlayers(); i++) {
if(myW->getActualHand()->getPlayerArray()[i]->getMyButton() == 1) {
if(i == myW->getActualHand()->getActualQuantityPlayers()-1) {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+" (Dealer): "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$";
}
else {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+" (Dealer): "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$, ";
}
2007-02-10 21:52:05 +00:00
}
else {
if(i == myW->getActualHand()->getActualQuantityPlayers()-1) {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+": "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$";
}
else {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+": "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$, ";
}
}
2007-02-10 21:52:05 +00:00
}
}
else {
for(i=0; i<myW->getActualHand()->getActualQuantityPlayers(); i++) {
if(myW->getActualHand()->getPlayerArray()[i]->getMyButton() == 3) {
if(i == myW->getActualHand()->getActualQuantityPlayers()-1) {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+" (Dealer): "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$";
}
else {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+" (Dealer): "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$, ";
}
2007-02-10 21:52:05 +00:00
}
else {
if(i == myW->getActualHand()->getActualQuantityPlayers()-1) {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+": "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$";
}
else {
stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[i]->getMyName())+": "+QString::number(myW->getActualHand()->getPlayerArray()[i]->getMyCash(),10)+"$, ";
}
2007-02-10 21:52:05 +00:00
}
2007-02-04 23:58:50 +00:00
}
}
2007-02-10 20:00:33 +00:00
stream << "</br>BLINDS: ";
for(i=0; i<myW->getMaxQuantityPlayers(); i++) {
int j,k = 0;
//Aktive Spieler zählen
int activePlayersCounter = 0;
for (k=0; k<myW->getMaxQuantityPlayers(); k++) {
if (myW->getActualHand()->getPlayerArray()[k]->getMyAction() != 1 && myW->getActualHand()->getPlayerArray()[k]->getMyActiveStatus() == 1) activePlayersCounter++;
}
if(activePlayersCounter < 3) { j=1; }
2007-02-10 21:52:05 +00:00
// cout << activePlayersCounter << endl;
// cout << (i+myW->getActualHand()->getDealerPosition()+j)%5 << endl;
2007-02-10 20:00:33 +00:00
switch (myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%5]->getMyButton()) {
case 2 : stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%5]->getMyName())+" ("+QString::number(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%5]->getMySet(),10)+"$), ";
break;
case 3 : stream << QString::fromStdString(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%5]->getMyName())+" ("+QString::number(myW->getActualHand()->getPlayerArray()[(i+myW->getActualHand()->getDealerPosition()+j)%5]->getMySet(),10)+"$)";
break;
default :;
}
}
stream << "</br></br><b>PREFLOP</b>";
stream << "</br>\n";
2007-02-10 20:00:33 +00:00
2007-02-04 13:46:27 +00:00
myLogFile->close();
2007-02-11 17:33:43 +00:00
linesInFile = linesInFile++;
2007-02-04 23:58:50 +00:00
}
void Log::logPlayerWinsMsg(int playerID) {
int i;
myW->textBrowser_Log->append(QString::fromStdString(myW->getActualHand()->getPlayerArray()[playerID]->getMyName())+" wins!!! ");
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
QString msg("</br><i>"+QString::fromStdString(myW->getActualHand()->getPlayerArray()[playerID]->getMyName())+" wins!!!</i></p>\n");
2007-02-04 23:58:50 +00:00
stream << msg;
myLogFile->close();
linesInFile++;
2007-02-04 13:46:27 +00:00
}
2007-02-11 17:33:43 +00:00
void Log::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3) {
QString round;
switch (roundID) {
case 1: round = "Flop";
break;
case 2: round = "Turn";
break;
case 3: round = "River";
break;
default: round = "ERROR";
}
}