diff options
author | Nay <dnpd.dd@gmail.com> | 2013-07-28 16:59:07 +0100 |
---|---|---|
committer | Nay <dnpd.dd@gmail.com> | 2013-07-28 16:59:07 +0100 |
commit | f71d894a215ed7cd9052913c9b07c8f62f0e99ca (patch) | |
tree | d1253ba869f0195c23d05630cbd7315dd07e1421 /src | |
parent | 62918e92d0493978e16f5fb1365818e9efa8461b (diff) |
Servers: Fix some code style issues in world and authserver
Diffstat (limited to 'src')
-rw-r--r-- | src/server/authserver/Main.cpp | 69 | ||||
-rw-r--r-- | src/server/worldserver/CommandLine/CliRunnable.cpp | 17 | ||||
-rw-r--r-- | src/server/worldserver/CommandLine/CliRunnable.h | 4 | ||||
-rw-r--r-- | src/server/worldserver/Main.cpp | 20 | ||||
-rw-r--r-- | src/server/worldserver/Master.cpp | 192 | ||||
-rw-r--r-- | src/server/worldserver/Master.h | 4 | ||||
-rw-r--r-- | src/server/worldserver/RemoteAccess/RARunnable.cpp | 17 | ||||
-rw-r--r-- | src/server/worldserver/RemoteAccess/RARunnable.h | 3 | ||||
-rw-r--r-- | src/server/worldserver/RemoteAccess/RASocket.cpp | 18 | ||||
-rw-r--r-- | src/server/worldserver/RemoteAccess/RASocket.h | 21 | ||||
-rw-r--r-- | src/server/worldserver/TCSoap/TCSoap.cpp | 8 | ||||
-rw-r--r-- | src/server/worldserver/TCSoap/TCSoap.h | 19 | ||||
-rw-r--r-- | src/server/worldserver/WorldThread/WorldRunnable.h | 4 |
13 files changed, 186 insertions, 210 deletions
diff --git a/src/server/authserver/Main.cpp b/src/server/authserver/Main.cpp index 9a80abe55e9..4a44dbfb1c4 100644 --- a/src/server/authserver/Main.cpp +++ b/src/server/authserver/Main.cpp @@ -22,6 +22,7 @@ * This file contains the main program for the * authentication server */ + #include <ace/Dev_Poll_Reactor.h> #include <ace/TP_Reactor.h> #include <ace/ACE.h> @@ -54,9 +55,9 @@ LoginDatabaseWorkerPool LoginDatabase; // Accessor to the a class AuthServerSignalHandler : public Trinity::SignalHandler { public: - virtual void HandleSignal(int SigNum) + virtual void HandleSignal(int sigNum) { - switch (SigNum) + switch (sigNum) { case SIGINT: case SIGTERM: @@ -67,7 +68,7 @@ public: }; /// Print out the usage string for this program on the console. -void usage(const char *prog) +void usage(const char* prog) { TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "Usage: \n %s [<options>]\n" " -c config_file use config_file as configuration file\n\r", @@ -75,37 +76,37 @@ void usage(const char *prog) } /// Launch the auth server -extern int main(int argc, char **argv) +extern int main(int argc, char** argv) { // Command line parsing to get the configuration file name - char const* cfg_file = _TRINITY_REALM_CONFIG; - int c = 1; - while (c < argc) + char const* configFile = _TRINITY_REALM_CONFIG; + int count = 1; + while (count < argc) { - if (strcmp(argv[c], "-c") == 0) + if (strcmp(argv[count], "-c") == 0) { - if (++c >= argc) + if (++count >= argc) { printf("Runtime-Error: -c option requires an input argument\n"); usage(argv[0]); return 1; } else - cfg_file = argv[c]; + configFile = argv[count]; } - ++c; + ++count; } - if (!sConfigMgr->LoadInitial(cfg_file)) + if (!sConfigMgr->LoadInitial(configFile)) { - printf("Invalid or missing configuration file : %s\n", cfg_file); + printf("Invalid or missing configuration file : %s\n", configFile); printf("Verify that the file exists and has \'[authserver]\' written in the top of the file!\n"); return 1; } TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "%s (authserver)", _FULLVERSION); TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "<Ctrl-C> to stop.\n"); - TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "Using configuration file %s.", cfg_file); + TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "Using configuration file %s.", configFile); TC_LOG_WARN(LOG_FILTER_AUTHSERVER, "%s (Library: %s)", OPENSSL_VERSION_TEXT, SSLeay_version(SSLEAY_VERSION)); @@ -118,16 +119,16 @@ extern int main(int argc, char **argv) TC_LOG_DEBUG(LOG_FILTER_AUTHSERVER, "Max allowed open files is %d", ACE::max_handles()); // authserver PID file creation - std::string pidfile = sConfigMgr->GetStringDefault("PidFile", ""); - if (!pidfile.empty()) + std::string pidFile = sConfigMgr->GetStringDefault("PidFile", ""); + if (!pidFile.empty()) { - uint32 pid = CreatePIDFile(pidfile); - if (!pid) + if (uint32 pid = CreatePIDFile(pidFile)) + TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "Daemon PID: %u\n", pid); + else { - TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Cannot create PID file %s.\n", pidfile.c_str()); + TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Cannot create PID file %s.\n", pidFile.c_str()); return 1; } - TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "Daemon PID: %u\n", pid); } // Initialize the database connection @@ -162,7 +163,7 @@ extern int main(int argc, char **argv) return 1; } - // Initialise the signal handlers + // Initialize the signal handlers AuthServerSignalHandler SignalINT, SignalTERM; // Register authservers's signal handlers @@ -175,35 +176,31 @@ extern int main(int argc, char **argv) { HANDLE hProcess = GetCurrentProcess(); - uint32 Aff = sConfigMgr->GetIntDefault("UseProcessors", 0); - if (Aff > 0) + uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0); + if (affinity > 0) { ULONG_PTR appAff; ULONG_PTR sysAff; if (GetProcessAffinityMask(hProcess, &appAff, &sysAff)) { - ULONG_PTR curAff = Aff & appAff; // remove non accessible processors + ULONG_PTR currentAffinity = affinity & appAff; // remove non accessible processors - if (!curAff) - TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Processors marked in UseProcessors bitmask (hex) %x not accessible for authserver. Accessible processors bitmask (hex): %x", Aff, appAff); - else if (SetProcessAffinityMask(hProcess, curAff)) - TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "Using processors (bitmask, hex): %x", curAff); + if (!currentAffinity) + TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the worldserver. Accessible processors bitmask (hex): %x", affinity, appAff); + else if (SetProcessAffinityMask(hProcess, currentAffinity)) + TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "Using processors (bitmask, hex): %x", currentAffinity); else - TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Can't set used processors (hex): %x", curAff); + TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Can't set used processors (hex): %x", currentAffinity); } - } - bool Prio = sConfigMgr->GetBoolDefault("ProcessPriority", false); - - if (Prio) + if (bool priority = sConfigMgr->GetBoolDefault("ProcessPriority", false)) { if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS)) - TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "The auth server process priority class has been set to HIGH"); + TC_LOG_INFO(LOG_FILTER_AUTHSERVER, "authserver process priority class set to HIGH"); else - TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Can't set auth server process priority class."); - + TC_LOG_ERROR(LOG_FILTER_AUTHSERVER, "Can't set authserver process priority class."); } } #endif diff --git a/src/server/worldserver/CommandLine/CliRunnable.cpp b/src/server/worldserver/CommandLine/CliRunnable.cpp index 361af453712..e136269e2a0 100644 --- a/src/server/worldserver/CommandLine/CliRunnable.cpp +++ b/src/server/worldserver/CommandLine/CliRunnable.cpp @@ -39,7 +39,7 @@ #include <readline/readline.h> #include <readline/history.h> -char * command_finder(const char* text, int state) +char* command_finder(const char* text, int state) { static int idx, len; const char* ret; @@ -70,19 +70,18 @@ char * command_finder(const char* text, int state) return ((char*)NULL); } -char ** cli_completion(const char * text, int start, int /*end*/) +char** cli_completion(const char* text, int start, int /*end*/) { - char ** matches; - matches = (char**)NULL; + char** matches = NULL; - if (start == 0) - matches = rl_completion_matches((char*)text, &command_finder); - else + if (start) rl_bind_key('\t', rl_abort); - return (matches); + else + matches = rl_completion_matches((char*)text, &command_finder); + return matches; } -int cli_hook_func(void) +int cli_hook_func() { if (World::IsStopped()) rl_done = 1; diff --git a/src/server/worldserver/CommandLine/CliRunnable.h b/src/server/worldserver/CommandLine/CliRunnable.h index bd14413ef2e..6e608f60881 100644 --- a/src/server/worldserver/CommandLine/CliRunnable.h +++ b/src/server/worldserver/CommandLine/CliRunnable.h @@ -27,7 +27,9 @@ class CliRunnable : public ACE_Based::Runnable { public: - void run(); + void run() OVERRIDE; }; + #endif + /// @} diff --git a/src/server/worldserver/Main.cpp b/src/server/worldserver/Main.cpp index 33ece8197f8..61aaf5f2ee9 100644 --- a/src/server/worldserver/Main.cpp +++ b/src/server/worldserver/Main.cpp @@ -33,7 +33,7 @@ #ifndef _TRINITY_CORE_CONFIG # define _TRINITY_CORE_CONFIG "worldserver.conf" -#endif //_TRINITY_CORE_CONFIG +#endif #ifdef _WIN32 #include "ServiceWin32.h" @@ -56,7 +56,7 @@ LoginDatabaseWorkerPool LoginDatabase; ///< Accessor to the uint32 realmID; ///< Id of the realm /// Print out the usage string for this program on the console. -void usage(const char *prog) +void usage(const char* prog) { printf("Usage:\n"); printf(" %s [<options>]\n", prog); @@ -70,14 +70,14 @@ void usage(const char *prog) } /// Launch the Trinity server -extern int main(int argc, char **argv) +extern int main(int argc, char** argv) { ///- Command line parsing to get the configuration file name char const* cfg_file = _TRINITY_CORE_CONFIG; int c = 1; - while ( c < argc ) + while (c < argc) { - if (strcmp(argv[c], "-c") == 0) + if (!strcmp(argv[c], "-c")) { if (++c >= argc) { @@ -90,10 +90,7 @@ extern int main(int argc, char **argv) } #ifdef _WIN32 - //////////// - //Services// - //////////// - if (strcmp(argv[c], "-s") == 0) + if (strcmp(argv[c], "-s") == 0) // Services { if (++c >= argc) { @@ -101,6 +98,7 @@ extern int main(int argc, char **argv) usage(argv[0]); return 1; } + if (strcmp(argv[c], "install") == 0) { if (WinServiceInstall()) @@ -120,11 +118,9 @@ extern int main(int argc, char **argv) return 1; } } + if (strcmp(argv[c], "--service") == 0) - { WinServiceRun(); - } - //// #endif ++c; } diff --git a/src/server/worldserver/Master.cpp b/src/server/worldserver/Master.cpp index 69b163b4a4b..c65fc903ffc 100644 --- a/src/server/worldserver/Master.cpp +++ b/src/server/worldserver/Master.cpp @@ -54,18 +54,18 @@ extern int m_ServiceStatus; class WorldServerSignalHandler : public Trinity::SignalHandler { public: - virtual void HandleSignal(int SigNum) + virtual void HandleSignal(int sigNum) { - switch (SigNum) + switch (sigNum) { case SIGINT: World::StopNow(RESTART_EXIT_CODE); break; case SIGTERM: - #ifdef _WIN32 +#ifdef _WIN32 case SIGBREAK: if (m_ServiceStatus != 1) - #endif /* _WIN32 */ +#endif World::StopNow(SHUTDOWN_EXIT_CODE); break; } @@ -74,33 +74,35 @@ class WorldServerSignalHandler : public Trinity::SignalHandler class FreezeDetectorRunnable : public ACE_Based::Runnable { +private: + uint32 _loops; + uint32 _lastChange; + uint32 _delaytime; public: FreezeDetectorRunnable() { _delaytime = 0; } - uint32 m_loops, m_lastchange; - uint32 w_loops, w_lastchange; - uint32 _delaytime; + void SetDelayTime(uint32 t) { _delaytime = t; } - void run(void) + + void run() OVERRIDE { if (!_delaytime) return; + TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "Starting up anti-freeze thread (%u seconds max stuck time)...", _delaytime/1000); - m_loops = 0; - w_loops = 0; - m_lastchange = 0; - w_lastchange = 0; + _loops = 0; + _lastChange = 0; while (!World::IsStopped()) { ACE_Based::Thread::Sleep(1000); uint32 curtime = getMSTime(); // normal work - if (w_loops != World::m_worldLoopCounter) + if (_loops != World::m_worldLoopCounter) { - w_lastchange = curtime; - w_loops = World::m_worldLoopCounter; + _lastChange = curtime; + _loops = World::m_worldLoopCounter; } // possible freeze - else if (getMSTimeDiff(w_lastchange, curtime) > _delaytime) + else if (getMSTimeDiff(_lastChange, curtime) > _delaytime) { TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "World Thread hangs, kicking out server!"); ASSERT(false); @@ -110,14 +112,6 @@ public: } }; -Master::Master() -{ -} - -Master::~Master() -{ -} - /// Main function int Master::Run() { @@ -138,17 +132,16 @@ int Master::Run() TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "http://TrinityCore.org \\/__/\n"); /// worldserver PID file creation - std::string pidfile = sConfigMgr->GetStringDefault("PidFile", ""); - if (!pidfile.empty()) + std::string pidFile = sConfigMgr->GetStringDefault("PidFile", ""); + if (!pidFile.empty()) { - uint32 pid = CreatePIDFile(pidfile); - if (!pid) + if (uint32 pid = CreatePIDFile(pidFile)) + TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "Daemon PID: %u\n", pid); + else { - TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Cannot create PID file %s.\n", pidfile.c_str()); + TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Cannot create PID file %s.\n", pidFile.c_str()); return 1; } - - TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "Daemon PID: %u\n", pid); } ///- Start the databases @@ -162,22 +155,22 @@ int Master::Run() sWorld->SetInitialWorldSettings(); ///- Initialize the signal handlers - WorldServerSignalHandler SignalINT, SignalTERM; + WorldServerSignalHandler signalINT, signalTERM; #ifdef _WIN32 - WorldServerSignalHandler SignalBREAK; + WorldServerSignalHandler signalBREAK; #endif /* _WIN32 */ ///- Register worldserver's signal handlers - ACE_Sig_Handler Handler; - Handler.register_handler(SIGINT, &SignalINT); - Handler.register_handler(SIGTERM, &SignalTERM); - #ifdef _WIN32 - Handler.register_handler(SIGBREAK, &SignalBREAK); - #endif /* _WIN32 */ + ACE_Sig_Handler handle; + handle.register_handler(SIGINT, &signalINT); + handle.register_handler(SIGTERM, &signalTERM); +#ifdef _WIN32 + handle.register_handler(SIGBREAK, &signalBREAK); +#endif ///- Launch WorldRunnable thread - ACE_Based::Thread world_thread(new WorldRunnable); - world_thread.setPriority(ACE_Based::Highest); + ACE_Based::Thread worldThread(new WorldRunnable); + worldThread.setPriority(ACE_Based::Highest); ACE_Based::Thread* cliThread = NULL; @@ -191,41 +184,33 @@ int Master::Run() cliThread = new ACE_Based::Thread(new CliRunnable); } - ACE_Based::Thread rar_thread(new RARunnable); + ACE_Based::Thread rarThread(new RARunnable); ///- Handle affinity for multiple processors and process priority on Windows - #ifdef _WIN32 +#ifdef _WIN32 { HANDLE hProcess = GetCurrentProcess(); - uint32 Aff = sConfigMgr->GetIntDefault("UseProcessors", 0); - if (Aff > 0) + uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0); + if (affinity > 0) { ULONG_PTR appAff; ULONG_PTR sysAff; if (GetProcessAffinityMask(hProcess, &appAff, &sysAff)) { - ULONG_PTR curAff = Aff & appAff; // remove non accessible processors + ULONG_PTR currentAffinity = affinity & appAff; // remove non accessible processors - if (!curAff) - { - TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the worldserver. Accessible processors bitmask (hex): %x", Aff, appAff); - } + if (!currentAffinity) + TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Processors marked in UseProcessors bitmask (hex) %x are not accessible for the worldserver. Accessible processors bitmask (hex): %x", affinity, appAff); + else if (SetProcessAffinityMask(hProcess, currentAffinity)) + TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "Using processors (bitmask, hex): %x", currentAffinity); else - { - if (SetProcessAffinityMask(hProcess, curAff)) - TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "Using processors (bitmask, hex): %x", curAff); - else - TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Can't set used processors (hex): %x", curAff); - } + TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Can't set used processors (hex): %x", currentAffinity); } } - bool Prio = sConfigMgr->GetBoolDefault("ProcessPriority", false); - - //if (Prio && (m_ServiceStatus == -1) /* need set to default process priority class in service mode*/) - if (Prio) + if (bool priority = sConfigMgr->GetBoolDefault("ProcessPriority", false)) { if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS)) TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "worldserver process priority class set to HIGH"); @@ -233,31 +218,32 @@ int Master::Run() TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Can't set worldserver process priority class."); } } - #endif +#endif + //Start soap serving thread - ACE_Based::Thread* soap_thread = NULL; + ACE_Based::Thread* soapThread = NULL; if (sConfigMgr->GetBoolDefault("SOAP.Enabled", false)) { TCSoapRunnable* runnable = new TCSoapRunnable(); - runnable->setListenArguments(sConfigMgr->GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetIntDefault("SOAP.Port", 7878))); - soap_thread = new ACE_Based::Thread(runnable); + runnable->SetListenArguments(sConfigMgr->GetStringDefault("SOAP.IP", "127.0.0.1"), uint16(sConfigMgr->GetIntDefault("SOAP.Port", 7878))); + soapThread = new ACE_Based::Thread(runnable); } ///- Start up freeze catcher thread - if (uint32 freeze_delay = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0)) + if (uint32 freezeDelay = sConfigMgr->GetIntDefault("MaxCoreStuckTime", 0)) { FreezeDetectorRunnable* fdr = new FreezeDetectorRunnable(); - fdr->SetDelayTime(freeze_delay * 1000); - ACE_Based::Thread freeze_thread(fdr); - freeze_thread.setPriority(ACE_Based::Highest); + fdr->SetDelayTime(freezeDelay * 1000); + ACE_Based::Thread freezeThread(fdr); + freezeThread.setPriority(ACE_Based::Highest); } ///- Launch the world listener socket - uint16 wsport = uint16(sWorld->getIntConfig(CONFIG_PORT_WORLD)); - std::string bind_ip = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0"); + uint16 worldPort = uint16(sWorld->getIntConfig(CONFIG_PORT_WORLD)); + std::string bindIp = sConfigMgr->GetStringDefault("BindIP", "0.0.0.0"); - if (sWorldSocketMgr->StartNetwork(wsport, bind_ip.c_str()) == -1) + if (sWorldSocketMgr->StartNetwork(worldPort, bindIp.c_str()) == -1) { TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Failed to start network"); World::StopNow(ERROR_EXIT_CODE); @@ -271,14 +257,14 @@ int Master::Run() // when the main thread closes the singletons get unloaded // since worldrunnable uses them, it will crash if unloaded after master - world_thread.wait(); - rar_thread.wait(); + worldThread.wait(); + rarThread.wait(); - if (soap_thread) + if (soapThread) { - soap_thread->wait(); - soap_thread->destroy(); - delete soap_thread; + soapThread->wait(); + soapThread->destroy(); + delete soapThread; } // set server offline @@ -298,7 +284,7 @@ int Master::Run() // this only way to terminate CLI thread exist at Win32 (alt. way exist only in Windows Vista API) //_exit(1); // send keyboard input to safely unblock the CLI thread - INPUT_RECORD b[5]; + INPUT_RECORD b[4]; HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE); b[0].EventType = KEY_EVENT; b[0].Event.KeyEvent.bKeyDown = TRUE; @@ -354,78 +340,78 @@ bool Master::_StartDB() { MySQL::Library_Init(); - std::string dbstring; - uint8 async_threads, synch_threads; + std::string dbString; + uint8 asyncThreads, synchThreads; - dbstring = sConfigMgr->GetStringDefault("WorldDatabaseInfo", ""); - if (dbstring.empty()) + dbString = sConfigMgr->GetStringDefault("WorldDatabaseInfo", ""); + if (dbString.empty()) { TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "World database not specified in configuration file"); return false; } - async_threads = uint8(sConfigMgr->GetIntDefault("WorldDatabase.WorkerThreads", 1)); - if (async_threads < 1 || async_threads > 32) + asyncThreads = uint8(sConfigMgr->GetIntDefault("WorldDatabase.WorkerThreads", 1)); + if (asyncThreads < 1 || asyncThreads > 32) { TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "World database: invalid number of worker threads specified. " "Please pick a value between 1 and 32."); return false; } - synch_threads = uint8(sConfigMgr->GetIntDefault("WorldDatabase.SynchThreads", 1)); - ///- Initialise the world database - if (!WorldDatabase.Open(dbstring, async_threads, synch_threads)) + synchThreads = uint8(sConfigMgr->GetIntDefault("WorldDatabase.SynchThreads", 1)); + ///- Initialize the world database + if (!WorldDatabase.Open(dbString, asyncThreads, synchThreads)) { - TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Cannot connect to world database %s", dbstring.c_str()); + TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Cannot connect to world database %s", dbString.c_str()); return false; } ///- Get character database info from configuration file - dbstring = sConfigMgr->GetStringDefault("CharacterDatabaseInfo", ""); - if (dbstring.empty()) + dbString = sConfigMgr->GetStringDefault("CharacterDatabaseInfo", ""); + if (dbString.empty()) { TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Character database not specified in configuration file"); return false; } - async_threads = uint8(sConfigMgr->GetIntDefault("CharacterDatabase.WorkerThreads", 1)); - if (async_threads < 1 || async_threads > 32) + asyncThreads = uint8(sConfigMgr->GetIntDefault("CharacterDatabase.WorkerThreads", 1)); + if (asyncThreads < 1 || asyncThreads > 32) { TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Character database: invalid number of worker threads specified. " "Please pick a value between 1 and 32."); return false; } - synch_threads = uint8(sConfigMgr->GetIntDefault("CharacterDatabase.SynchThreads", 2)); + synchThreads = uint8(sConfigMgr->GetIntDefault("CharacterDatabase.SynchThreads", 2)); - ///- Initialise the Character database - if (!CharacterDatabase.Open(dbstring, async_threads, synch_threads)) + ///- Initialize the Character database + if (!CharacterDatabase.Open(dbString, asyncThreads, synchThreads)) { - TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Cannot connect to Character database %s", dbstring.c_str()); + TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Cannot connect to Character database %s", dbString.c_str()); return false; } ///- Get login database info from configuration file - dbstring = sConfigMgr->GetStringDefault("LoginDatabaseInfo", ""); - if (dbstring.empty()) + dbString = sConfigMgr->GetStringDefault("LoginDatabaseInfo", ""); + if (dbString.empty()) { TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Login database not specified in configuration file"); return false; } - async_threads = uint8(sConfigMgr->GetIntDefault("LoginDatabase.WorkerThreads", 1)); - if (async_threads < 1 || async_threads > 32) + asyncThreads = uint8(sConfigMgr->GetIntDefault("LoginDatabase.WorkerThreads", 1)); + if (asyncThreads < 1 || asyncThreads > 32) { TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Login database: invalid number of worker threads specified. " "Please pick a value between 1 and 32."); return false; } - synch_threads = uint8(sConfigMgr->GetIntDefault("LoginDatabase.SynchThreads", 1)); + synchThreads = uint8(sConfigMgr->GetIntDefault("LoginDatabase.SynchThreads", 1)); ///- Initialise the login database - if (!LoginDatabase.Open(dbstring, async_threads, synch_threads)) + if (!LoginDatabase.Open(dbString, asyncThreads, synchThreads)) { - TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Cannot connect to login database %s", dbstring.c_str()); + TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Cannot connect to login database %s", dbString.c_str()); return false; } diff --git a/src/server/worldserver/Master.h b/src/server/worldserver/Master.h index 4f07c24e8f8..93b2387feec 100644 --- a/src/server/worldserver/Master.h +++ b/src/server/worldserver/Master.h @@ -29,8 +29,6 @@ class Master { public: - Master(); - ~Master(); int Run(); private: @@ -41,5 +39,7 @@ class Master }; #define sMaster ACE_Singleton<Master, ACE_Null_Mutex>::instance() + #endif + /// @} diff --git a/src/server/worldserver/RemoteAccess/RARunnable.cpp b/src/server/worldserver/RemoteAccess/RARunnable.cpp index 465e605beac..c381c65e9e2 100644 --- a/src/server/worldserver/RemoteAccess/RARunnable.cpp +++ b/src/server/worldserver/RemoteAccess/RARunnable.cpp @@ -61,24 +61,21 @@ void RARunnable::run() ACE_Acceptor<RASocket, ACE_SOCK_ACCEPTOR> acceptor; - uint16 raport = uint16(sConfigMgr->GetIntDefault("Ra.Port", 3443)); - std::string stringip = sConfigMgr->GetStringDefault("Ra.IP", "0.0.0.0"); - ACE_INET_Addr listen_addr(raport, stringip.c_str()); + uint16 raPort = uint16(sConfigMgr->GetIntDefault("Ra.Port", 3443)); + std::string stringIp = sConfigMgr->GetStringDefault("Ra.IP", "0.0.0.0"); + ACE_INET_Addr listenAddress(raPort, stringIp.c_str()); - if (acceptor.open(listen_addr, m_Reactor) == -1) + if (acceptor.open(listenAddress, m_Reactor) == -1) { - TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Trinity RA can not bind to port %d on %s", raport, stringip.c_str()); + TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "Trinity RA can not bind to port %d on %s", raPort, stringIp.c_str()); return; } - TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "Starting Trinity RA on port %d on %s", raport, stringip.c_str()); + TC_LOG_INFO(LOG_FILTER_WORLDSERVER, "Starting Trinity RA on port %d on %s", raPort, stringIp.c_str()); while (!World::IsStopped()) { - // don't be too smart to move this outside the loop - // the run_reactor_event_loop will modify interval - ACE_Time_Value interval(0, 100000); - if (m_Reactor->run_reactor_event_loop(interval) == -1) + if (m_Reactor->run_reactor_event_loop(ACE_Time_Value(0, 100000)) == -1) break; } diff --git a/src/server/worldserver/RemoteAccess/RARunnable.h b/src/server/worldserver/RemoteAccess/RARunnable.h index 6597e7c742f..a03e16e2154 100644 --- a/src/server/worldserver/RemoteAccess/RARunnable.h +++ b/src/server/worldserver/RemoteAccess/RARunnable.h @@ -31,7 +31,7 @@ class RARunnable : public ACE_Based::Runnable public: RARunnable(); virtual ~RARunnable(); - void run(); + void run() OVERRIDE; private: ACE_Reactor* m_Reactor; @@ -39,4 +39,5 @@ private: }; #endif /* _TRINITY_RARUNNABLE_H_ */ + /// @} diff --git a/src/server/worldserver/RemoteAccess/RASocket.cpp b/src/server/worldserver/RemoteAccess/RASocket.cpp index 3fd4e34e89e..a4d402286ed 100644 --- a/src/server/worldserver/RemoteAccess/RASocket.cpp +++ b/src/server/worldserver/RemoteAccess/RASocket.cpp @@ -36,26 +36,22 @@ RASocket::RASocket() _commandExecuting = false; } -RASocket::~RASocket() -{ -} - int RASocket::open(void *) { - ACE_INET_Addr remote_addr; + ACE_INET_Addr remoteAddress; - if (peer().get_remote_addr(remote_addr) == -1) + if (peer().get_remote_addr(remoteAddress) == -1) { TC_LOG_ERROR(LOG_FILTER_WORLDSERVER, "RASocket::open: peer().get_remote_addr error is %s", ACE_OS::strerror(errno)); return -1; } - TC_LOG_INFO(LOG_FILTER_REMOTECOMMAND, "Incoming connection from %s", remote_addr.get_host_addr()); + TC_LOG_INFO(LOG_FILTER_REMOTECOMMAND, "Incoming connection from %s", remoteAddress.get_host_addr()); return activate(); } -int RASocket::handle_close(ACE_HANDLE, ACE_Reactor_Mask) +int RASocket::handle_close(ACE_HANDLE /*handle*/, ACE_Reactor_Mask /*mask*/) { TC_LOG_INFO(LOG_FILTER_REMOTECOMMAND, "Closing connection"); peer().close_reader(); @@ -89,9 +85,7 @@ int RASocket::recv_line(ACE_Message_Block& buffer) ssize_t n = peer().recv(&byte, sizeof(byte)); if (n < 0) - { return -1; - } if (n == 0) { @@ -110,8 +104,8 @@ int RASocket::recv_line(ACE_Message_Block& buffer) return -1; } - const char null_term = '\0'; - if (buffer.copy(&null_term, sizeof(null_term)) == -1) + const char nullTerm = '\0'; + if (buffer.copy(&nullTerm, sizeof(nullTerm)) == -1) return -1; return 0; diff --git a/src/server/worldserver/RemoteAccess/RASocket.h b/src/server/worldserver/RemoteAccess/RASocket.h index e92cb35eaf0..add23198bde 100644 --- a/src/server/worldserver/RemoteAccess/RASocket.h +++ b/src/server/worldserver/RemoteAccess/RASocket.h @@ -31,33 +31,34 @@ #include <ace/SOCK_Acceptor.h> /// Remote Administration socket -class RASocket: public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH> +class RASocket : public ACE_Svc_Handler<ACE_SOCK_STREAM, ACE_MT_SYNCH> { public: RASocket(); - virtual ~RASocket(); + virtual ~RASocket() { } - virtual int svc(void); - virtual int open(void * = 0); - virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK); + virtual int svc() OVERRIDE; + virtual int open(void* = 0) OVERRIDE; + virtual int handle_close(ACE_HANDLE = ACE_INVALID_HANDLE, ACE_Reactor_Mask = ACE_Event_Handler::ALL_EVENTS_MASK) OVERRIDE; private: - int recv_line(std::string& out_line); + int recv_line(std::string& outLine); int recv_line(ACE_Message_Block& buffer); int process_command(const std::string& command); int authenticate(); - int subnegotiate(); //! Used by telnet protocol RFC 854 / 855 + int subnegotiate(); ///< Used by telnet protocol RFC 854 / 855 int check_access_level(const std::string& user); int check_password(const std::string& user, const std::string& pass); int send(const std::string& line); - static void zprint(void* callbackArg, const char * szText ); + static void zprint(void* callbackArg, const char* szText); static void commandFinished(void* callbackArg, bool success); private: - /// Minimum security level required to connect - uint8 _minLevel; + uint8 _minLevel; ///< Minimum security level required to connect ACE_Atomic_Op<ACE_Thread_Mutex, bool> _commandExecuting; }; + #endif + /// @} diff --git a/src/server/worldserver/TCSoap/TCSoap.cpp b/src/server/worldserver/TCSoap/TCSoap.cpp index 3ccc3bccac9..e10968bcbee 100644 --- a/src/server/worldserver/TCSoap/TCSoap.cpp +++ b/src/server/worldserver/TCSoap/TCSoap.cpp @@ -33,13 +33,13 @@ void TCSoapRunnable::run() soap.accept_timeout = 3; soap.recv_timeout = 5; soap.send_timeout = 5; - if (!soap_valid_socket(soap_bind(&soap, m_host.c_str(), m_port, 100))) + if (!soap_valid_socket(soap_bind(&soap, _host.c_str(), _port, 100))) { - TC_LOG_ERROR(LOG_FILTER_SOAP, "Couldn't bind to %s:%d", m_host.c_str(), m_port); + TC_LOG_ERROR(LOG_FILTER_SOAP, "Couldn't bind to %s:%d", _host.c_str(), _port); exit(-1); } - TC_LOG_INFO(LOG_FILTER_SOAP, "Bound to http://%s:%d", m_host.c_str(), m_port); + TC_LOG_INFO(LOG_FILTER_SOAP, "Bound to http://%s:%d", _host.c_str(), _port); while (!World::IsStopped()) { @@ -121,9 +121,7 @@ int ns1__executeCommand(soap* soap, char* command, char** result) int acc = connection.pendingCommands.acquire(); if (acc) - { TC_LOG_ERROR(LOG_FILTER_SOAP, "Error while acquiring lock, acc = %i, errno = %u", acc, errno); - } // alright, command finished diff --git a/src/server/worldserver/TCSoap/TCSoap.h b/src/server/worldserver/TCSoap/TCSoap.h index 63ccb6b304e..ff2a49a4d7e 100644 --- a/src/server/worldserver/TCSoap/TCSoap.h +++ b/src/server/worldserver/TCSoap/TCSoap.h @@ -24,21 +24,24 @@ #include <ace/Task.h> #include <Threading.h> -class TCSoapRunnable: public ACE_Based::Runnable +class TCSoapRunnable : public ACE_Based::Runnable { public: - TCSoapRunnable() : m_host(""), m_port(0) { } - void run(); - void setListenArguments(std::string host, uint16 port) + TCSoapRunnable() : _port(0) { } + + void run() OVERRIDE; + + void SetListenArguments(const std::string& host, uint16 port) { - m_host = host; - m_port = port; + _host = host; + _port = port; } + private: void process_message(ACE_Message_Block* mb); - std::string m_host; - uint16 m_port; + std::string _host; + uint16 _port; }; class SOAPCommand diff --git a/src/server/worldserver/WorldThread/WorldRunnable.h b/src/server/worldserver/WorldThread/WorldRunnable.h index 38fc96a9f9f..56a3b41eae7 100644 --- a/src/server/worldserver/WorldThread/WorldRunnable.h +++ b/src/server/worldserver/WorldThread/WorldRunnable.h @@ -27,7 +27,9 @@ class WorldRunnable : public ACE_Based::Runnable { public: - void run(); + void run() OVERRIDE; }; + #endif + /// @} |