diff options
Diffstat (limited to 'src/trinityrealm/Main.cpp')
-rw-r--r-- | src/trinityrealm/Main.cpp | 74 |
1 files changed, 53 insertions, 21 deletions
diff --git a/src/trinityrealm/Main.cpp b/src/trinityrealm/Main.cpp index 05fd704c10b..3d934f4ba85 100644 --- a/src/trinityrealm/Main.cpp +++ b/src/trinityrealm/Main.cpp @@ -1,7 +1,7 @@ /* - * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> + * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/> * - * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> + * Copyright (C) 2008-2009 Trinity <http://www.trinitycore.org/> * * 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 @@ -31,8 +31,9 @@ #include "sockets/ListenSocket.h" #include "AuthSocket.h" #include "SystemConfig.h" -#include "revision.h" #include "Util.h" +#include <openssl/opensslv.h> +#include <openssl/crypto.h> // Format is YYYYMMDDRR where RR is the change in the conf file // for that day. @@ -41,12 +42,12 @@ #endif #ifndef _TRINITY_REALM_CONFIG -# define _TRINITY_REALM_CONFIG "trinityrealm.conf" +# define _TRINITY_REALM_CONFIG "TrinityRealm.conf" #endif //_TRINITY_REALM_CONFIG #ifdef WIN32 #include "ServiceWin32.h" -char serviceName[] = "realmd"; +char serviceName[] = "TrinityRealm"; char serviceLongName[] = "Trinity realm service"; char serviceDescription[] = "Massive Network Game Object Server"; /* @@ -58,7 +59,7 @@ char serviceDescription[] = "Massive Network Game Object Server"; int m_ServiceStatus = -1; #endif -bool StartDB(std::string &dbstring); +bool StartDB(); void UnhookSignals(); void HookSignals(); @@ -71,7 +72,6 @@ DatabaseType LoginDatabase; ///< Accessor to the void usage(const char *prog) { sLog.outString("Usage: \n %s [<options>]\n" - " --version print version and exit\n\r" " -c config_file use config_file as configuration file\n\r" #ifdef WIN32 " Running as service functions:\n\r" @@ -85,6 +85,7 @@ void usage(const char *prog) /// Launch the realm server extern int main(int argc, char **argv) { + sLog.SetLogDB(false); ///- Command line parsing to get the configuration file name char const* cfg_file = _TRINITY_REALM_CONFIG; int c=1; @@ -102,12 +103,6 @@ extern int main(int argc, char **argv) cfg_file = argv[c]; } - if( strcmp(argv[c],"--version") == 0) - { - printf("%s\n", _FULLVERSION); - return 0; - } - #ifdef WIN32 //////////// //Services// @@ -153,6 +148,9 @@ extern int main(int argc, char **argv) sLog.outError("Could not find configuration file %s.", cfg_file); return 1; } + + sLog.outString( "%s (realm-daemon)", _FULLVERSION ); + sLog.outString( "<Ctrl-C> to stop.\n" ); sLog.outString("Using configuration file %s.", cfg_file); ///- Check the version of the configuration file @@ -169,8 +167,12 @@ extern int main(int argc, char **argv) while (pause > clock()) {} } - sLog.outString( "%s (realm-daemon)", _FULLVERSION ); - sLog.outString( "<Ctrl-C> to stop.\n" ); + sLog.outDetail("%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); + if (SSLeay() < 0x009080bfL ) + { + sLog.outDetail("WARNING: Outdated version of OpenSSL lib. Logins to server impossible!"); + sLog.outDetail("WARNING: Minimal required version [OpenSSL 0.9.8k]"); + } /// realmd PID file creation std::string pidfile = sConfig.GetStringDefault("PidFile", ""); @@ -187,10 +189,25 @@ extern int main(int argc, char **argv) } ///- Initialize the database connection - std::string dbstring; - if(!StartDB(dbstring)) + if(!StartDB()) return 1; + ///- Initialize the log database + if(sConfig.GetBoolDefault("EnableLogDB", false)) + { + // everything successful - set var to enable DB logging once startup finished. + sLog.SetLogDBLater(true); + sLog.SetLogDB(false); + // ensure we've set realm to 0 (realmd realmid) + sLog.SetRealmID(0); + } + else + { + sLog.SetLogDBLater(false); + sLog.SetLogDB(false); + sLog.SetRealmID(0); + } + ///- Get the list of realms for the server m_realmList.Initialize(sConfig.GetIntDefault("RealmsStateUpdateDelay", 20)); if (m_realmList.size() == 0) @@ -263,6 +280,20 @@ extern int main(int argc, char **argv) uint32 numLoops = (sConfig.GetIntDefault( "MaxPingTime", 30 ) * (MINUTE * 1000000 / 100000)); uint32 loopCounter = 0; + // possibly enable db logging; avoid massive startup spam by doing it here. + if (sLog.GetLogDBLater()) + { + sLog.outString("Enabling database logging..."); + sLog.SetLogDBLater(false); + // login db needs thread for logging + sLog.SetLogDB(true); + } + else + { + sLog.SetLogDB(false); + sLog.SetLogDBLater(false); + } + ///- Wait for termination signal while (!stopEvent) { @@ -282,6 +313,7 @@ extern int main(int argc, char **argv) } ///- Wait for the delay thread to exit + LoginDatabase.ThreadEnd(); LoginDatabase.HaltDelayThread(); ///- Remove signal handling before leaving @@ -312,20 +344,21 @@ void OnSignal(int s) } /// Initialize connection to the database -bool StartDB(std::string &dbstring) +bool StartDB() { - if(!sConfig.GetString("LoginDatabaseInfo", &dbstring)) + std::string dbstring = sConfig.GetStringDefault("LoginDatabaseInfo", ""); + if(dbstring.empty()) { sLog.outError("Database not specified"); return false; } - sLog.outString("Database: %s", dbstring.c_str() ); if(!LoginDatabase.Initialize(dbstring.c_str())) { sLog.outError("Cannot connect to database"); return false; } + LoginDatabase.ThreadStart(); return true; } @@ -351,4 +384,3 @@ void UnhookSignals() } /// @} - |