Servers: Fix some code style issues in world and authserver

This commit is contained in:
Nay
2013-07-28 16:59:07 +01:00
parent 62918e92d0
commit f71d894a21
13 changed files with 186 additions and 210 deletions

View File

@@ -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