From c5bae66142210db6805bce4cdc3628c4fb4d40c1 Mon Sep 17 00:00:00 2001 From: lotodore Date: Thu, 22 Nov 2007 00:57:03 +0000 Subject: [PATCH] Move server configuration to dedicated server only. Separate error logging for client and server, in preparation of creating a log file on the dedicated server. --- pokerth_game.pro | 6 +++- pokerth_server.pro | 6 +++- src/core/common/avatarmanager.cpp | 10 ++---- src/core/common/loghelper_client.cpp | 41 +++++++++++++++++++++ src/core/common/loghelper_server.cpp | 54 ++++++++++++++++++++++++++++ src/core/loghelper.h | 51 +++++++++++--------------- src/net/common/net_helper_client.cpp | 37 +++++++++++++++++++ src/net/common/net_helper_server.cpp | 37 +++++++++++++++++++ src/net/net_helper.h | 27 ++++++++++++++ src/session.cpp | 2 -- 10 files changed, 230 insertions(+), 41 deletions(-) create mode 100644 src/core/common/loghelper_client.cpp create mode 100644 src/core/common/loghelper_server.cpp create mode 100644 src/net/common/net_helper_client.cpp create mode 100644 src/net/common/net_helper_server.cpp create mode 100644 src/net/net_helper.h diff --git a/pokerth_game.pro b/pokerth_game.pro index 4a6ab4ab..2e8730d8 100644 --- a/pokerth_game.pro +++ b/pokerth_game.pro @@ -95,6 +95,7 @@ HEADERS += \ src/gamedata.h \ src/config/configfile.h \ src/core/thread.h \ + src/core/loghelper.h \ src/engine/boardinterface.h \ src/engine/enginefactory.h \ src/engine/handinterface.h \ @@ -115,6 +116,7 @@ HEADERS += \ src/net/socket_helper.h \ src/net/socket_msg.h \ src/net/socket_startup.h \ + src/net/net_helper.h \ src/core/tinyxml/tinystr.h \ src/core/tinyxml/tinyxml.h \ src/engine/local_engine/cardsvalue.h \ @@ -221,7 +223,9 @@ SOURCES += \ src/gui/qt/mymessagedialog/mymessagedialogimpl.cpp \ src/gui/qt/gamelobbydialog/gamelobbydialogimpl.cpp \ src/gui/qt/gamelobbydialog/mygamelisttreewidget.cpp \ - src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp + src/gui/qt/gamelobbydialog/lobbychat/lobbychat.cpp \ + src/net/common/net_helper_client.cpp \ + src/core/common/loghelper_client.cpp TRANSLATIONS = \ ts/pokerth_de.ts \ diff --git a/pokerth_server.pro b/pokerth_server.pro index 890ec960..dd8e4f65 100644 --- a/pokerth_server.pro +++ b/pokerth_server.pro @@ -75,10 +75,12 @@ HEADERS += \ src/net/socket_helper.h \ src/net/socket_msg.h \ src/net/socket_startup.h \ + src/net/net_helper.h \ src/core/tinyxml/tinystr.h \ src/core/tinyxml/tinyxml.h \ src/core/pokerthexception.h \ src/core/convhelper.h \ + src/core/loghelper.h \ src/engine/local_engine/cardsvalue.h \ src/engine/local_engine/localboard.h \ src/engine/local_engine/localenginefactory.h \ @@ -104,7 +106,9 @@ HEADERS += \ SOURCES += \ src/pokerth_server.cpp \ src/gui/qt/qttools/nonqttoolswrapper.cpp \ - src/gui/qt/qttools/nonqthelper/nonqthelper.cpp + src/gui/qt/qttools/nonqthelper/nonqthelper.cpp \ + src/net/common/net_helper_server.cpp \ + src/core/common/loghelper_server.cpp win32 { DEPENDPATH += src/net/win32/ src/core/win32 diff --git a/src/core/common/avatarmanager.cpp b/src/core/common/avatarmanager.cpp index f1773a84..de7b26a0 100644 --- a/src/core/common/avatarmanager.cpp +++ b/src/core/common/avatarmanager.cpp @@ -18,6 +18,7 @@ ***************************************************************************/ #include "avatarmanager.h" +#include #include #include #include @@ -30,13 +31,8 @@ #include #include -#ifdef POKERTH_DEDICATED_SERVER - #define MAX_NUMBER_OF_FILES 1024 - #define MAX_AVATAR_CACHE_AGE 2592000 // 1 Month -#else - #define MAX_NUMBER_OF_FILES 256 - #define MAX_AVATAR_CACHE_AGE 86400 -#endif +#define MAX_NUMBER_OF_FILES GetMaxNumberOfAvatarFiles() +#define MAX_AVATAR_CACHE_AGE GetMaxAvatarCacheAgeSec() #define PNG_HEADER "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" #define PNG_HEADER_SIZE (sizeof(PNG_HEADER) - 1) diff --git a/src/core/common/loghelper_client.cpp b/src/core/common/loghelper_client.cpp new file mode 100644 index 00000000..cfbc457f --- /dev/null +++ b/src/core/common/loghelper_client.cpp @@ -0,0 +1,41 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +#ifdef POKERTH_DEDICATED_SERVER +#error This file is only for the client. +#endif + +#include +#include + + +using namespace std; + +void +internal_log_err(const string &msg) +{ + cout << msg; +} + +void +internal_log_msg(const std::string &msg) +{ + cout << msg; +} + diff --git a/src/core/common/loghelper_server.cpp b/src/core/common/loghelper_server.cpp new file mode 100644 index 00000000..822aa084 --- /dev/null +++ b/src/core/common/loghelper_server.cpp @@ -0,0 +1,54 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +#ifndef POKERTH_DEDICATED_SERVER +#error This file is only for the server. +#endif + +#include +#ifdef _WIN32 + #include +#else + #include + #include +#endif + + +using namespace std; + +void +internal_log_err(const string &msg) +{ +#ifdef _WIN32 + cout << msg; +#else + syslog(LOG_ERR, "%s", msg.c_str()); +#endif +} + +void +internal_log_msg(const std::string &msg) +{ +#ifdef _WIN32 + cout << msg; +#else + syslog(LOG_INFO, "%s", msg.c_str()); +#endif +} + diff --git a/src/core/loghelper.h b/src/core/loghelper.h index df8d35a5..e530aa9b 100644 --- a/src/core/loghelper.h +++ b/src/core/loghelper.h @@ -21,37 +21,28 @@ #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().c_str()); \ - } \ - while(false) - #define LOG_MSG(e) \ - do \ - { \ - std::ostringstream outStream; \ - outStream << e << std::endl; \ - syslog(LOG_INFO, "%s", outStream.str().c_str()); \ - } \ - while(false) - #endif -#endif +#include +#include -#ifndef LOG_ERROR - #include - #define LOG_ERROR(e) \ - std::cout << e << std::endl - #define LOG_MSG(e) \ - std::cout << e << std::endl -#endif +void internal_log_err(const std::string &msg); +void internal_log_msg(const std::string &msg); + +#define LOG_ERROR(e) \ + do \ + { \ + std::ostringstream outStream; \ + outStream << e << std::endl; \ + internal_log_err(outStream.str()); \ + } \ + while(false) +#define LOG_MSG(e) \ + do \ + { \ + std::ostringstream outStream; \ + outStream << e << std::endl; \ + internal_log_msg(outStream.str()); \ + } \ + while(false) #endif diff --git a/src/net/common/net_helper_client.cpp b/src/net/common/net_helper_client.cpp new file mode 100644 index 00000000..dab1185d --- /dev/null +++ b/src/net/common/net_helper_client.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +#ifdef POKERTH_DEDICATED_SERVER +#error This file is only for the client. +#endif + +#include + +unsigned +GetMaxNumberOfAvatarFiles() +{ + return 256; +} + +unsigned +GetMaxAvatarCacheAgeSec() +{ + return 604800; // 1 Week +} + diff --git a/src/net/common/net_helper_server.cpp b/src/net/common/net_helper_server.cpp new file mode 100644 index 00000000..d3e25726 --- /dev/null +++ b/src/net/common/net_helper_server.cpp @@ -0,0 +1,37 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ + +#ifndef POKERTH_DEDICATED_SERVER +#error This file is only for the server. +#endif + +#include + +unsigned +GetMaxNumberOfAvatarFiles() +{ + return 2048; +} + +unsigned +GetMaxAvatarCacheAgeSec() +{ + return 2592000; // 1 Month +} + diff --git a/src/net/net_helper.h b/src/net/net_helper.h new file mode 100644 index 00000000..28cd1571 --- /dev/null +++ b/src/net/net_helper.h @@ -0,0 +1,27 @@ +/*************************************************************************** + * 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. * + ***************************************************************************/ +/* Retrieve internal configuration values. */ +#ifndef _NET_HELPER_H_ +#define _NET_HELPER_H_ + +unsigned GetMaxNumberOfAvatarFiles(); +unsigned GetMaxAvatarCacheAgeSec(); + +#endif + diff --git a/src/session.cpp b/src/session.cpp index 4b346165..a7926411 100755 --- a/src/session.cpp +++ b/src/session.cpp @@ -56,9 +56,7 @@ bool Session::init() { myAvatarManager.reset(new AvatarManager); bool retVal = myAvatarManager->Init(myConfig->readConfigString("AppDataDir"), myConfig->readConfigString("CacheDir")); -#ifndef POKERTH_DEDICATED_SERVER myAvatarManager->AddSingleAvatar(myConfig->readConfigString("MyAvatar")); -#endif myAvatarManager->RemoveOldAvatarCacheEntries(); return retVal; }