diff --git a/src/config/configfile.cpp b/src/config/configfile.cpp index 0476f369..e3818223 100644 --- a/src/config/configfile.cpp +++ b/src/config/configfile.cpp @@ -19,6 +19,7 @@ ***************************************************************************/ #include "configfile.h" #include +#include #define MODUS 0711 @@ -325,7 +326,7 @@ void ConfigFile::fillBuffer() { } - else { cout << "Could not find the element to fill the config-buffer with!"; } + else { LOG_ERROR("Could not find the root element in the config file!"); } // cout << configBufferList[i].name << " " << configBufferList[i].defaultValue << endl; } @@ -522,7 +523,7 @@ void ConfigFile::updateConfig(ConfigState myConfigState) { } newDoc.SaveFile( configFileName ); } - else { cout << "cannot update config file. did not found it" << endl; } + else { LOG_ERROR("Cannot update config file: Unable to load configuration."); } } diff --git a/src/core/linux/convhelper.cpp b/src/core/linux/convhelper.cpp index 7a4fba6e..342156cf 100644 --- a/src/core/linux/convhelper.cpp +++ b/src/core/linux/convhelper.cpp @@ -1,95 +1,95 @@ -/*************************************************************************** - * Copyright (C) 2007 by Lothar May * - * * - * 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. * - ***************************************************************************/ - -#include "convhelper.h" - -#ifdef _WIN32 -#error This file is not for Windows. -#endif - -#include -#include - -#include -#include - -using namespace std; - -string -ConvHelper::NativeToUtf8(const std::string &inStr) -{ - string retStr(inStr); - size_t insize = inStr.length(); - char *inbuf = const_cast(inStr.data()); - - const size_t c_outsize = insize * 6; // max size of utf-8 char is 6 per input char - size_t outsize = c_outsize; - char *c_outbuf = new char[outsize]; - char *outbuf = c_outbuf; - - //nl_langinfo(CODESET) - iconv_t conversion = iconv_open("UTF-8", "ISO-8859-1"); - - if (conversion == (iconv_t)(-1)) - cout << "iconv_open() failed: " << strerror(errno) << endl; - else - { - size_t retval = iconv(conversion, &inbuf, &insize, &outbuf, &outsize); - - if (retval == -1) - cout << "iconv() failed: " << strerror(errno) << endl; - retStr = string(c_outbuf, c_outsize - outsize); - } - delete[] c_outbuf; - - iconv_close(conversion); - return retStr; -} - -string -ConvHelper::Utf8ToNative(const std::string &inStr) -{ - string retStr(inStr); - size_t insize = inStr.length(); - char *inbuf = const_cast(inStr.data()); - - const size_t c_outsize = insize; - size_t outsize = c_outsize; - char *c_outbuf = new char[outsize]; - char *outbuf = c_outbuf; - - iconv_t conversion = iconv_open("ISO-8859-1", "UTF-8"); - - if (conversion == (iconv_t)(-1)) - cout << "iconv_open() failed: " << strerror(errno) << endl; - else - { - size_t retval = iconv(conversion, &inbuf, &insize, &outbuf, &outsize); - - if (retval == -1) - cout << "iconv() failed: " << strerror(errno) << endl; - retStr = string(c_outbuf, c_outsize - outsize); - } - delete[] c_outbuf; - - iconv_close(conversion); - return retStr; -} - - +/*************************************************************************** + * Copyright (C) 2007 by Lothar May * + * * + * 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. * + ***************************************************************************/ + +#include "convhelper.h" +#include + +#ifdef _WIN32 +#error This file is not for Windows. +#endif + +#include + +#include +#include + +using namespace std; + +string +ConvHelper::NativeToUtf8(const std::string &inStr) +{ + string retStr(inStr); + size_t insize = inStr.length(); + char *inbuf = const_cast(inStr.data()); + + const size_t c_outsize = insize * 6; // max size of utf-8 char is 6 per input char + size_t outsize = c_outsize; + char *c_outbuf = new char[outsize]; + char *outbuf = c_outbuf; + + //nl_langinfo(CODESET) + iconv_t conversion = iconv_open("UTF-8", "ISO-8859-1"); + + if (conversion == (iconv_t)(-1)) + LOG_ERROR("iconv_open() failed: " << strerror(errno)); + else + { + size_t retval = iconv(conversion, &inbuf, &insize, &outbuf, &outsize); + + if (retval == -1) + LOG_ERROR("iconv() failed: " << strerror(errno)); + retStr = string(c_outbuf, c_outsize - outsize); + } + delete[] c_outbuf; + + iconv_close(conversion); + return retStr; +} + +string +ConvHelper::Utf8ToNative(const std::string &inStr) +{ + string retStr(inStr); + size_t insize = inStr.length(); + char *inbuf = const_cast(inStr.data()); + + const size_t c_outsize = insize; + size_t outsize = c_outsize; + char *c_outbuf = new char[outsize]; + char *outbuf = c_outbuf; + + iconv_t conversion = iconv_open("ISO-8859-1", "UTF-8"); + + if (conversion == (iconv_t)(-1)) + LOG_ERROR("iconv_open() failed: " << strerror(errno)); + else + { + size_t retval = iconv(conversion, &inbuf, &insize, &outbuf, &outsize); + + if (retval == -1) + LOG_ERROR("iconv() failed: " << strerror(errno)); + retStr = string(c_outbuf, c_outsize - outsize); + } + delete[] c_outbuf; + + iconv_close(conversion); + return retStr; +} + + diff --git a/src/core/loghelper.h b/src/core/loghelper.h new file mode 100644 index 00000000..a5e6dcf4 --- /dev/null +++ b/src/core/loghelper.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2007 by Lothar May * + * * + * 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. * + ***************************************************************************/ +/* Helper class for logging. */ + +#ifndef _LOGHELPER_H_ +#define _LOGHELPER_H_ + +#ifndef _WIN32 + #ifdef POKERTH_DEDICATED_SERVER + #include + #include + #include + #define LOG_ERROR(e) \ + do \ + { \ + std::ostringstream outStream; \ + outStream << e << std::endl; \ + syslog(LOG_ERR, "%s", outStream.str()); \ + } \ + while(false) + #endif +#endif + +#ifndef LOG_ERROR + #include + #define LOG_ERROR(e) \ + std::cout << e << std::endl +#endif + +#endif + diff --git a/src/engine/local_engine/localbero.cpp b/src/engine/local_engine/localbero.cpp index 8f1e77e9..c52628f8 100644 --- a/src/engine/local_engine/localbero.cpp +++ b/src/engine/local_engine/localbero.cpp @@ -21,6 +21,7 @@ #include "localexception.h" #include "engine_msg.h" +#include using namespace std; @@ -61,6 +62,12 @@ LocalBeRo::~LocalBeRo() { } +int LocalBeRo::getHighestCardsValue() const +{ + LOG_ERROR(__FILE__ << " (" << __LINE__ << "): getHighestCardsValue() in wrong BeRo"); + return 0; +} + void LocalBeRo::nextPlayer() { PlayerListConstIterator currentPlayersTurnConstIt = myHand->getRunningPlayerIt(currentPlayersTurnId); @@ -137,7 +144,7 @@ void LocalBeRo::run() { break; case GAME_STATE_RIVER: myHand->getGuiInterface()->logDealBoardCardsMsg(myBeRoID, tempBoardCardsArray[0], tempBoardCardsArray[1], tempBoardCardsArray[2], tempBoardCardsArray[3], tempBoardCardsArray[4]); break; - default: { cout << "ERROR in localbero.cpp - wrong myBeRoID" << endl;} + default: { LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR - wrong myBeRoID"); } } logBoardCardsDone = true; diff --git a/src/engine/local_engine/localbero.h b/src/engine/local_engine/localbero.h index d6e0153d..db110793 100644 --- a/src/engine/local_engine/localbero.h +++ b/src/engine/local_engine/localbero.h @@ -21,7 +21,6 @@ #define LOCALBERO_H -#include #include "game_defs.h" #include "berointerface.h" @@ -34,7 +33,7 @@ public: GameState getMyBeRoID() const { return myBeRoID; } - int getHighestCardsValue() const { std::cout << "getHighestCardsValue() in wrong BeRo" << std::endl; return 0; } + int getHighestCardsValue() const; void setHighestCardsValue(int /*theValue*/) { } void setMinimumRaise ( int theValue ) { minimumRaise = theValue; } diff --git a/src/engine/local_engine/localboard.cpp b/src/engine/local_engine/localboard.cpp index 4ef7fa5c..a5eb9b93 100755 --- a/src/engine/local_engine/localboard.cpp +++ b/src/engine/local_engine/localboard.cpp @@ -21,6 +21,7 @@ #include "handinterface.h" #include +#include #include "localexception.h" #include "engine_msg.h" @@ -214,7 +215,7 @@ void LocalBoard::distributePot() { // ERROR-Outputs - if(pot!=0) cout << "distributePot-ERROR: Pot = " << pot << endl; + if(pot!=0) LOG_ERROR(__FILE__ << " (" << __LINE__ << "): distributePot-ERROR: Pot = " << pot); int sum = 0; diff --git a/src/engine/local_engine/localhand.cpp b/src/engine/local_engine/localhand.cpp index 051e1fb6..e9a2912f 100755 --- a/src/engine/local_engine/localhand.cpp +++ b/src/engine/local_engine/localhand.cpp @@ -21,6 +21,7 @@ #include "tools.h" #include "cardsvalue.h" #include +#include #include "localexception.h" #include "engine_msg.h" @@ -79,7 +80,7 @@ LocalHand::LocalHand(boost::shared_ptr f, GuiInterface *g, BoardI // error-check for(j=0; j<5; j++) { if (bestHandPos[j] == -1) { - cout << "ERROR getMyBestHandPosition in localhand.cpp" << endl; + LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR getMyBestHandPosition"); } } @@ -336,7 +337,7 @@ void LocalHand::start() { if(it_sB != getActivePlayerList()->end() && it_bB != getActivePlayerList()->end()) { myGui->logNewBlindsSetsMsg((*it_sB)->getMySet(), (*it_bB)->getMySet(), (*it_sB)->getMyName().c_str(), (*it_bB)->getMyName().c_str()); } - else { cout << "Log Error: cannot find sBID or bBID" << "\n"; } + else { LOG_ERROR(__FILE__ << " (" << __LINE__ << "): Log Error: cannot find sBID or bBID"); } myGui->flushLogAtHand(); // deal cards diff --git a/src/engine/local_engine/localplayer.cpp b/src/engine/local_engine/localplayer.cpp index 9e4f71a0..5ce59dc0 100755 --- a/src/engine/local_engine/localplayer.cpp +++ b/src/engine/local_engine/localplayer.cpp @@ -22,8 +22,10 @@ #include "tools.h" #include "cardsvalue.h" #include +#include #include +#include using namespace std; @@ -3524,7 +3526,7 @@ void LocalPlayer::calcMyOdds() { break; } } - if(myOdds == -1) cout << "ERROR myOdds - " << handCode << endl; + if (myOdds == -1) LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR myOdds - " << handCode); } break; @@ -3559,8 +3561,10 @@ void LocalPlayer::calcMyOdds() { } } if(myOdds == -1) { - cout << "ERROR" << endl; - for(i=0; i<5; i++) cout << tempArray[i] << " "; + ostringstream logger; + logger << "ERROR myOdds is -1: "; + for(i=0; i<5; i++) logger << tempArray[i] << " "; + LOG_ERROR(__FILE__ << " (" << __LINE__ << "): " << logger.str()); // cout << "\t" << handCode << "\t" << myID << endl; } else { // cout << myHoleCardsValue << endl; @@ -3679,7 +3683,7 @@ void LocalPlayer::calcMyOdds() { } break; - default: cout <<"ERROR - wrong init of currentRound" << endl; + default: LOG_ERROR(__FILE__ << " (" << __LINE__ << "): ERROR - wrong init of currentRound"); } diff --git a/src/gui/qt/mainwindow/log/log.cpp b/src/gui/qt/mainwindow/log/log.cpp index 16037943..83ea1ca6 100644 --- a/src/gui/qt/mainwindow/log/log.cpp +++ b/src/gui/qt/mainwindow/log/log.cpp @@ -102,7 +102,7 @@ Log::Log(mainWindowImpl* w, ConfigFile *c) : myW(w), myConfig(c), myLogDir(0), m } } - else { cout << "Log directory doesn't exists. Cannot create log files"; } + else { cout << "Log directory doesn't exist. Cannot create log files"; } } } @@ -1624,9 +1624,9 @@ void Log::writeLogFileStream(QString streamString) { stream << streamString; myLogFile->close(); } - else { cout << "could not open log-file to write log-messages!" << endl; } + else { cout << "Could not open log-file to write log-messages!" << endl; } } - else { cout << "could not find log-file to write log-messages!" << endl; } + else { cout << "Could not find log-file to write log-messages!" << endl; } } void Log::flushLogAtHand() { diff --git a/src/gui/qt/mainwindow/mainwindowimpl.cpp b/src/gui/qt/mainwindow/mainwindowimpl.cpp index 98d1e0bb..05970a9a 100755 --- a/src/gui/qt/mainwindow/mainwindowimpl.cpp +++ b/src/gui/qt/mainwindow/mainwindowimpl.cpp @@ -1907,7 +1907,7 @@ void mainWindowImpl::provideMyActions() { //if text changed on checked button --> uncheck to prevent unwanted actions if((pushButtonCallCheckString != lastPushButtonCallCheckString && pushButton_CallCheck->isChecked()) || (pushButtonBetRaiseString != lastPushButtonBetRaiseString && pushButton_BetRaise->isChecked()) ) { - cout << "jo" << endl; +// cout << "jo" << endl; uncheckMyButtons(); resetMyButtonsCheckStateMemory(); } diff --git a/src/net/common/serveracceptthread.cpp b/src/net/common/serveracceptthread.cpp index ebd31bf0..1000e756 100644 --- a/src/net/common/serveracceptthread.cpp +++ b/src/net/common/serveracceptthread.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #define ACCEPT_TIMEOUT_MSEC 50 #define NET_SERVER_LISTEN_BACKLOG 5 @@ -87,6 +88,7 @@ ServerAcceptThread::Main() } catch (const PokerTHException &e) { GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode()); + LOG_ERROR(e.what()); } GetLobbyThread().SignalTermination(); GetLobbyThread().Join(LOBBY_THREAD_TERMINATE_TIMEOUT); diff --git a/src/net/common/serverlobbythread.cpp b/src/net/common/serverlobbythread.cpp index d52c0af8..433e69ab 100644 --- a/src/net/common/serverlobbythread.cpp +++ b/src/net/common/serverlobbythread.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -289,6 +290,7 @@ ServerLobbyThread::Main() } catch (const PokerTHException &e) { GetCallback().SignalNetServerError(e.GetErrorId(), e.GetOsErrorCode()); + LOG_ERROR(e.what()); } TerminateGames();