implement logOnOff, logInterval

This commit is contained in:
doitux
2007-05-15 23:34:03 +00:00
parent 151a45de33
commit d213ee3ff2
2 changed files with 85 additions and 74 deletions
+81 -72
View File
@@ -31,6 +31,9 @@ Log::Log(mainWindowImpl* w, ConfigFile *c) : myW(w), myConfig(c)
{ {
myW->setLog(this); myW->setLog(this);
logFileStreamString = "";
lastGameID = 0;
if(myConfig->readConfigInt("LogOnOff")) { if(myConfig->readConfigInt("LogOnOff")) {
//if write logfiles is enabled //if write logfiles is enabled
if(myConfig->readConfigString("LogDir") != "" && QDir::QDir(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())).exists()) { if(myConfig->readConfigString("LogDir") != "" && QDir::QDir(QString::fromUtf8(myConfig->readConfigString("LogDir").c_str())).exists()) {
@@ -56,8 +59,6 @@ Log::Log(mainWindowImpl* w, ConfigFile *c) : myW(w), myConfig(c)
// stream << "</html>\n"; // stream << "</html>\n";
myLogFile->close(); myLogFile->close();
linesInFile = 3;
//Zu alte Dateien löschen!!! //Zu alte Dateien löschen!!!
int daysUntilWaste = myConfig->readConfigInt("LogStoreDuration"); int daysUntilWaste = myConfig->readConfigInt("LogStoreDuration");
int i; int i;
@@ -100,8 +101,6 @@ Log::~Log()
void Log::logPlayerActionMsg(string playerName, int action, int setValue) { void Log::logPlayerActionMsg(string playerName, int action, int setValue) {
int i;
QString msg; QString msg;
msg = QString::fromUtf8(playerName.c_str()); msg = QString::fromUtf8(playerName.c_str());
@@ -128,15 +127,13 @@ void Log::logPlayerActionMsg(string playerName, int action, int setValue) {
if(myConfig->readConfigInt("LogOnOff")) { if(myConfig->readConfigInt("LogOnOff")) {
//if write logfiles is enabled //if write logfiles is enabled
myLogFile->open( QIODevice::ReadWrite ); logFileStreamString += msg+"</br>\n";
QTextStream stream( myLogFile );
for(i=0; i<=linesInFile; i++) { stream.readLine(); } if(myConfig->readConfigInt("LogInterval") == 0) {
stream << msg+"</br>\n"; writeLogFileStream(logFileStreamString);
// stream << "</body>\n"; logFileStreamString = "";
// stream << "</html>\n"; }
myLogFile->close();
linesInFile++;
} }
} }
@@ -148,13 +145,9 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
if(myConfig->readConfigInt("LogOnOff")) { if(myConfig->readConfigInt("LogOnOff")) {
//if write logfiles is enabled //if write logfiles is enabled
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
stream << "<p><b>####################&#160;&#160;&#160;Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+"&#160;&#160;&#160;####################</b></br>"; logFileStreamString += "<p><b>####################&#160;&#160;&#160;Game: "+QString::number(gameID,10)+" | Hand: "+QString::number(handID,10)+"&#160;&#160;&#160;####################</b></br>";
stream << "CASH: "; logFileStreamString += "CASH: ";
//Aktive Spieler zählen //Aktive Spieler zählen
int activePlayersCounter = 0; int activePlayersCounter = 0;
@@ -172,14 +165,14 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
if(currentHand->getPlayerArray()[i]->getMyButton() == 1) { if(currentHand->getPlayerArray()[i]->getMyButton() == 1) {
if(k==1) { stream << ", "; } if(k==1) { logFileStreamString += ", "; }
k=1; k=1;
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(currentHand->getPlayerArray()[i]->getMyCash(),10)+"$"; logFileStreamString += QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(currentHand->getPlayerArray()[i]->getMyCash(),10)+"$";
} }
else { else {
if(k==1) { stream << ", "; } if(k==1) { logFileStreamString += ", "; }
k=1; k=1;
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$"; logFileStreamString += QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$";
} }
} }
} }
@@ -189,19 +182,19 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
if(currentHand->getPlayerArray()[i]->getMyActiveStatus()) { if(currentHand->getPlayerArray()[i]->getMyActiveStatus()) {
//print cash only for active players //print cash only for active players
if(currentHand->getPlayerArray()[i]->getMyButton() == 3) { if(currentHand->getPlayerArray()[i]->getMyButton() == 3) {
if(k==1) { stream << ", "; } if(k==1) { logFileStreamString += ", "; }
k=1; k=1;
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$"; logFileStreamString += QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+" (Dealer): "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$";
} }
else { else {
if(k==1) { stream << ", "; } if(k==1) { logFileStreamString += ", "; }
k=1; k=1;
stream << QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$"; logFileStreamString += QString::fromUtf8(currentHand->getPlayerArray()[i]->getMyName().c_str())+": "+QString::number(currentHand->getPlayerArray()[i]->getMyCash()+currentHand->getPlayerArray()[i]->getMySet(),10)+"$";
} }
} }
} }
} }
stream << "</br>BLINDS: "; logFileStreamString += "</br>BLINDS: ";
for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) { for(i=0; i<MAX_NUMBER_OF_PLAYERS; i++) {
j = 0; j = 0;
@@ -216,53 +209,61 @@ void Log::logNewGameHandMsg(int gameID, int handID) {
// cout << (i+currentHand->getDealerPosition()+j)%5 << endl; // cout << (i+currentHand->getDealerPosition()+j)%5 << endl;
switch (currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyButton()) { switch (currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyButton()) {
case 2 : stream << QString::fromUtf8(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$), "; case 2 : logFileStreamString += QString::fromUtf8(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$), ";
break; break;
case 3 : stream << QString::fromUtf8(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$)"; case 3 : logFileStreamString += QString::fromUtf8(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMyName().c_str())+" ("+QString::number(currentHand->getPlayerArray()[(i+currentHand->getDealerPosition()+j)%MAX_NUMBER_OF_PLAYERS]->getMySet(),10)+"$)";
break; break;
default :; default :;
} }
} }
stream << "</br></br><b>PREFLOP</b>"; logFileStreamString += "</br></br><b>PREFLOP</b>";
stream << "</br>\n"; logFileStreamString += "</br>\n";
myLogFile->close(); if(myConfig->readConfigInt("LogInterval") < 2) {
// write for log after every action and after every hand
linesInFile = linesInFile++; writeLogFileStream(logFileStreamString);
logFileStreamString = "";
}
else {
// write for log after every game
if(gameID > lastGameID) {
writeLogFileStream(logFileStreamString);
logFileStreamString = "";
lastGameID = gameID;
}
}
} }
} }
void Log::logPlayerWinsMsg(int playerID, int pot) { void Log::logPlayerWinsMsg(int playerID, int pot) {
int i;
HandInterface *currentHand = myW->getSession().getCurrentGame()->getCurrentHand(); HandInterface *currentHand = myW->getSession().getCurrentGame()->getCurrentHand();
myW->textBrowser_Log->append(QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!! "); myW->textBrowser_Log->append(QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!! ");
if(myConfig->readConfigInt("LogOnOff")) { if(myConfig->readConfigInt("LogOnOff")) {
//if write logfiles is enabled //if write logfiles is enabled
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
// if (cardsValueInt != -1) { // if (cardsValueInt != -1) {
// myW->textBrowser_Log->append(QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$ with "+translateCardsValueCode(cardsValueInt).at(0)+"!!! "); // myW->textBrowser_Log->append(QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$ with "+translateCardsValueCode(cardsValueInt).at(0)+"!!! ");
// stream << "</br><i>"+QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n"; // stream << "</br><i>"+QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
// } // }
// else { // else {
stream << "</br><i>"+QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
// } logFileStreamString += "</br><i>"+QString::fromUtf8(currentHand->getPlayerArray()[playerID]->getMyName().c_str())+" wins "+QString::number(pot,10)+"$!!!</i></p>\n";
myLogFile->close();
if(myConfig->readConfigInt("LogInterval") == 0) {
linesInFile++; writeLogFileStream(logFileStreamString);
logFileStreamString = "";
}
} }
} }
void Log::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int card4, int card5) { void Log::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int card4, int card5) {
int i;
QString round; QString round;
switch (roundID) { switch (roundID) {
@@ -281,34 +282,30 @@ void Log::logDealBoardCardsMsg(int roundID, int card1, int card2, int card3, int
if(myConfig->readConfigInt("LogOnOff")) { if(myConfig->readConfigInt("LogOnOff")) {
//if write logfiles is enabled //if write logfiles is enabled
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
switch (roundID) { switch (roundID) {
case 1: round = "Flop"; case 1: round = "Flop";
stream << "</br><b>"+round.toUpper()+"</b> [board cards <b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+",<b>"+translateCardCode(card3).at(0)+"</b>"+translateCardCode(card3).at(1)+"]"+"</br>\n"; logFileStreamString += "</br><b>"+round.toUpper()+"</b> [board cards <b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+",<b>"+translateCardCode(card3).at(0)+"</b>"+translateCardCode(card3).at(1)+"]"+"</br>\n";
break; break;
case 2: round = "Turn"; case 2: round = "Turn";
stream << "</br><b>"+round.toUpper()+"</b> [board cards <b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+",<b>"+translateCardCode(card3).at(0)+"</b>"+translateCardCode(card3).at(1)+",<b>"+translateCardCode(card4).at(0)+"</b>"+translateCardCode(card4).at(1)+"]"+"</br>\n"; logFileStreamString += "</br><b>"+round.toUpper()+"</b> [board cards <b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+",<b>"+translateCardCode(card3).at(0)+"</b>"+translateCardCode(card3).at(1)+",<b>"+translateCardCode(card4).at(0)+"</b>"+translateCardCode(card4).at(1)+"]"+"</br>\n";
break; break;
case 3: round = "River"; case 3: round = "River";
stream << "</br><b>"+round.toUpper()+"</b> [board cards <b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+",<b>"+translateCardCode(card3).at(0)+"</b>"+translateCardCode(card3).at(1)+",<b>"+translateCardCode(card4).at(0)+"</b>"+translateCardCode(card4).at(1)+",<b>"+translateCardCode(card5).at(0)+"</b>"+translateCardCode(card5).at(1)+"]"+"</br>\n"; logFileStreamString += "</br><b>"+round.toUpper()+"</b> [board cards <b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+",<b>"+translateCardCode(card3).at(0)+"</b>"+translateCardCode(card3).at(1)+",<b>"+translateCardCode(card4).at(0)+"</b>"+translateCardCode(card4).at(1)+",<b>"+translateCardCode(card5).at(0)+"</b>"+translateCardCode(card5).at(1)+"]"+"</br>\n";
break; break;
default: round = "ERROR"; default: round = "ERROR";
} }
if(myConfig->readConfigInt("LogInterval") == 0) {
myLogFile->close(); writeLogFileStream(logFileStreamString);
linesInFile++; logFileStreamString = "";
}
} }
} }
void Log::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int cardsValueInt, string showHas) { void Log::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int cardsValueInt, string showHas) {
int i;
if (cardsValueInt != -1) { if (cardsValueInt != -1) {
QString tempHandName; QString tempHandName;
@@ -418,12 +415,14 @@ void Log::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int
if(myConfig->readConfigInt("LogOnOff")) { if(myConfig->readConfigInt("LogOnOff")) {
//if write logfiles is enabled //if write logfiles is enabled
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile ); logFileStreamString += QString::fromUtf8(playerName.c_str())+" "+QString::fromUtf8(showHas.c_str())+" [ <b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+"] - "+tempHandName+"</br>\n";
for(i=0; i<=linesInFile; i++) { stream.readLine(); }
stream << QString::fromUtf8(playerName.c_str())+" "+QString::fromUtf8(showHas.c_str())+" [ <b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+"] - "+tempHandName+"</br>\n"; if(myConfig->readConfigInt("LogInterval") == 0) {
myLogFile->close(); writeLogFileStream(logFileStreamString);
linesInFile++; logFileStreamString = "";
}
} }
} }
else { else {
@@ -431,12 +430,12 @@ void Log::logFlipHoleCardsMsg(std::string playerName, int card1, int card2, int
if(myConfig->readConfigInt("LogOnOff")) { if(myConfig->readConfigInt("LogOnOff")) {
//if write logfiles is enabled //if write logfiles is enabled
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile ); logFileStreamString += QString::fromUtf8(playerName.c_str())+" "+QString::fromUtf8(showHas.c_str())+" [<b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+"]"+"</br>\n";
for(i=0; i<=linesInFile; i++) { stream.readLine(); } if(myConfig->readConfigInt("LogInterval") == 0) {
stream << QString::fromUtf8(playerName.c_str())+" "+QString::fromUtf8(showHas.c_str())+" [<b>"+translateCardCode(card1).at(0)+"</b>"+translateCardCode(card1).at(1)+",<b>"+translateCardCode(card2).at(0)+"</b>"+translateCardCode(card2).at(1)+"]"+"</br>\n"; writeLogFileStream(logFileStreamString);
myLogFile->close(); logFileStreamString = "";
linesInFile++; }
} }
} }
@@ -1136,3 +1135,13 @@ QStringList Log::translateCardsValueCode(int cardsValueCode) {
return cardString; return cardString;
} }
void Log::writeLogFileStream(QString streamString) {
myLogFile->open( QIODevice::ReadWrite );
QTextStream stream( myLogFile );
stream.readAll();
stream << streamString;
myLogFile->close();
}
+4 -2
View File
@@ -47,15 +47,17 @@ public:
QStringList translateCardsValueCode(int cardsValueCode); QStringList translateCardsValueCode(int cardsValueCode);
QStringList translateCardCode(int cardCode); QStringList translateCardCode(int cardCode);
void writeLogFileStream(QString string);
private: private:
int lastGameID;
int linesInFile;
mainWindowImpl *myW; mainWindowImpl *myW;
ConfigFile *myConfig; ConfigFile *myConfig;
QTextStream stream; QTextStream stream;
QFile *myLogFile; QFile *myLogFile;
QDir *myLogDir; QDir *myLogDir;
QString logFileStreamString;
}; };