bool Master::Run(int argc, char ** argv) { char * config_file = (char*)default_config_file; char * optional_config_file = (char*)default_optional_config_file; char * realm_config_file = (char*)default_realm_config_file; int file_log_level = DEF_VALUE_NOT_SET; int screen_log_level = DEF_VALUE_NOT_SET; int do_check_conf = 0; int do_version = 0; int do_cheater_check = 0; int do_database_clean = 0; time_t curTime; struct arcemu_option longopts[] = { { "checkconf", arcemu_no_argument, &do_check_conf, 1 }, { "screenloglevel", arcemu_required_argument, &screen_log_level, 1 }, { "fileloglevel", arcemu_required_argument, &file_log_level, 1 }, { "version", arcemu_no_argument, &do_version, 1 }, { "conf", arcemu_required_argument, NULL, 'c' }, { "realmconf", arcemu_required_argument, NULL, 'r' }, { "databasecleanup", arcemu_no_argument, &do_database_clean, 1 }, { "cheatercheck", arcemu_no_argument, &do_cheater_check, 1 }, { 0, 0, 0, 0 } }; char c; while ((c = arcemu_getopt_long_only(argc, argv, ":f:", longopts, NULL)) != -1) { switch (c) { case 'c': config_file = new char[strlen(arcemu_optarg)]; strcpy(config_file, arcemu_optarg); break; case 'r': realm_config_file = new char[strlen(arcemu_optarg)]; strcpy(realm_config_file, arcemu_optarg); break; case 0: break; default: sLog.m_fileLogLevel = -1; sLog.m_screenLogLevel = 3; printf("Usage: %s [--checkconf] [--screenloglevel <level>] [--fileloglevel <level>] [--conf <filename>] [--realmconf <filename>] [--version] [--databasecleanup] [--cheatercheck]\n", argv[0]); return true; } } // Startup banner UNIXTIME = time(NULL); g_localTime = *localtime(&UNIXTIME); if(!do_version && !do_check_conf) { sLog.Init(-1, 3); } else { sLog.m_fileLogLevel = -1; sLog.m_screenLogLevel = 1; } printf(BANNER, BUILD_TAG, BUILD_REVISION, CONFIG, PLATFORM_TEXT, ARCH); #ifdef REPACK printf("\nRepack: %s | Author: %s | %s\n", REPACK, REPACK_AUTHOR, REPACK_WEBSITE); #endif Log.Color(TBLUE); printf("\nCopyright (C) 2008 ArcEmu. http://www.arcemu.org/\n"); printf("This program is free software: you can redistribute it and/or modify\n"); printf("it under the terms of the GNU Affero General Public License as published by\n"); printf("the Free Software Foundation, either version 3 of the License, or\n"); printf("any later version.\n"); printf("This program is distributed in the hope that it will be useful,\n"); printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); printf("GNU Affero General Public License for more details.\n"); printf(" \n"); printf(" `````` \n"); printf(" ArcEmu! `/o/::-:/- \n"); printf(" oho/-.-:yN- \n"); printf(" os+/-.::: \n"); printf(" :ysyoo+:` \n"); printf(" `ohdys/. \n"); printf(" oyho/-` `` \n"); printf(" `shyo+:./ssmdsyo:` \n"); printf(" .shss+:yNMMNNMNmms. \n"); printf(" :ysss+:mNMMMMNNmmds. \n"); printf(" `-//sssoo/:NMNMMMNMNNdy- \n"); printf(" -`/` `omhyyhyyyshNMMNNNMMMNmy: \n"); printf(" :/::-` `sdmdmmNMNMMMMMMNMNNNNms- \n"); printf(" /+++/-.....shdmmNMMNMMMMMMMMMNNNd+ \n"); printf(" ./+oshyhhhddmhdmNMMMMMMMMMMMMNNds. \n"); printf(" `:/:.`````.:+ymmNMMNMMMNMMNNd/ \n"); printf(" -+shmNNMMMNmhy/ \n"); printf(" `..-ods:. \n"); printf(" o:.` \n"); printf(" :-. \n"); printf(" `/-... \n"); printf(" Introducing the emu! --``-/:` \n"); printf(" .:/+:-.-::. \n"); printf(" `.-///:-.` \n"); printf(" Website: http://www.ArcEmu.org \n"); printf(" Forums: http://www.ArcEmu.org/forums/ \n"); printf(" Credits: http://www.ArcEmu.org/credits \n"); printf(" SVN: http://arcemu.info/svn/ \n"); printf(" Have fun! \n"); Log.Line(); #ifdef REPACK Log.Color(TRED); printf("Warning: Using repacks is potentially dangerous. You should always compile\n"); printf("from the source yourself at www.arcemu.org.\n"); printf("By using this repack, you agree to not visit the arcemu website and ask\nfor support.\n"); printf("For all support, you should visit the repacker's website at %s\n", REPACK_WEBSITE); Log.Color(TNORMAL); Log.Line(); #endif Log.log_level = 3; if(do_version) return true; if( do_check_conf ) { Log.Notice( "Config", "Checking config file: %s", config_file ); if( Config.MainConfig.SetSource(config_file, true ) ) Log.Success( "Config", "Passed without errors." ); else Log.Warning( "Config", "Encountered one or more errors." ); Log.Notice( "Config", "Checking config file: %s\n", realm_config_file ); if( Config.RealmConfig.SetSource( realm_config_file, true ) ) Log.Success( "Config", "Passed without errors.\n" ); else Log.Warning( "Config", "Encountered one or more errors.\n" ); Log.Notice( "Config", "Checking config file:: %s\n", optional_config_file); if(Config.OptionalConfig.SetSource(optional_config_file, true) ) Log.Success( "Config", "Passed without errors.\n"); else Log.Warning( "Config", "Encountered one or more errors.\n"); /* test for die variables */ string die; if( Config.MainConfig.GetString( "die", "msg", &die) || Config.MainConfig.GetString("die2", "msg", &die ) ) Log.Warning( "Config", "Die directive received: %s", die.c_str() ); return true; } printf( "The key combination <Ctrl-C> will safely shut down the server at any time.\n" ); Log.Line(); #ifndef WIN32 if(geteuid() == 0 || getegid() == 0) Log.LargeErrorMessage( LARGERRORMESSAGE_WARNING, "You are running ArcEmu as root.", "This is not needed, and may be a possible security risk.", "It is advised to hit CTRL+C now and", "start as a non-privileged user.", NULL); #endif InitRandomNumberGenerators(); Log.Success( "Rnd", "Initialized Random Number Generators." ); ThreadPool.Startup(); uint32 LoadingTime = getMSTime(); Log.Notice( "Config", "Loading Config Files...\n" ); if( Config.MainConfig.SetSource( config_file ) ) Log.Success( "Config", ">> configs/arcemu-world.conf" ); else { Log.Error( "Config", ">> configs/arcemu-world.conf" ); return false; } if(Config.OptionalConfig.SetSource(optional_config_file)) Log.Success( "Config", ">> configs/arcemu-optional.conf"); else { Log.Error("Config", ">> configs/arcemu-optional.conf"); return false; } string die; if( Config.MainConfig.GetString( "die", "msg", &die) || Config.MainConfig.GetString( "die2", "msg", &die ) ) { Log.Warning( "Config", "Die directive received: %s", die.c_str() ); return false; } if(Config.RealmConfig.SetSource(realm_config_file)) Log.Success( "Config", ">> configs/arcemu-realms.conf" ); else { Log.Error( "Config", ">> configs/arcemu-realms.conf" ); return false; } #if !defined(WIN32) && defined(__DEBUG__) if (Config.MainConfig.GetIntDefault( "LogLevel", "DisableCrashdumpReport", 0) == 0) { char cmd[1024]; char banner[1024]; snprintf(banner, 1024, BANNER, BUILD_TAG, BUILD_REVISION, CONFIG, PLATFORM_TEXT, ARCH); snprintf(cmd, 1024, "./arcemu-crashreport -r %d -d \"%s\"", BUILD_REVISION, banner); system(cmd); } unlink("arcemu.uptime"); #endif if( !_StartDB() ) { Database::CleanupLibs(); return false; } if(do_database_clean) { printf( "\nEntering database maintenance mode.\n\n" ); new DatabaseCleaner; DatabaseCleaner::getSingleton().Run(); delete DatabaseCleaner::getSingletonPtr(); Log.Color(TYELLOW); printf( "\nMaintenence finished. Take a moment to review the output, and hit space to continue startup." ); Log.Color(TNORMAL); fflush(stdout); } Log.Line(); sLog.outString( "" ); #ifdef GM_SCRIPT ScriptSystem = new ScriptEngine; ScriptSystem->Reload(); #endif new EventMgr; new World; //have to init this ones for singleton new tPPoolClass<Item>; new tPPoolClass<Aura>; new tPPoolClass<Spell>; // open cheat log file Anticheat_Log = new SessionLogWriter(FormatOutputString( "logs", "cheaters", false).c_str(), false ); GMCommand_Log = new SessionLogWriter(FormatOutputString( "logs", "gmcommand", false).c_str(), false ); Player_Log = new SessionLogWriter(FormatOutputString( "logs", "players", false).c_str(), false ); /* load the config file */ sWorld.Rehash(false); /* set new log levels */ if( screen_log_level != (int)DEF_VALUE_NOT_SET ) sLog.SetScreenLoggingLevel(screen_log_level); if( file_log_level != (int)DEF_VALUE_NOT_SET ) sLog.SetFileLoggingLevel(file_log_level); // Initialize Opcode Table WorldSession::InitPacketHandlerTable(); string host = Config.MainConfig.GetStringDefault( "Listen", "Host", DEFAULT_HOST ); int wsport = Config.MainConfig.GetIntDefault( "Listen", "WorldServerPort", DEFAULT_WORLDSERVER_PORT ); new ScriptMgr; if( !sWorld.SetInitialWorldSettings() ) { Log.Error( "Server", "SetInitialWorldSettings() failed. Something went wrong? Exiting." ); return false; } if( do_cheater_check ) sWorld.CleanupCheaters(); sWorld.SetStartTime((uint32)UNIXTIME); WorldRunnable * wr = new WorldRunnable(); ThreadPool.ExecuteTask(wr); _HookSignals(); ConsoleThread * console = new ConsoleThread(); ThreadPool.ExecuteTask(console); uint32 realCurrTime, realPrevTime; realCurrTime = realPrevTime = getMSTime(); // Socket loop! uint32 start; uint32 diff; uint32 last_time = now(); uint32 etime; uint32 next_printout = getMSTime(), next_send = getMSTime(); // Start Network Subsystem Log.Notice( "Network","Starting subsystem..." ); new SocketMgr; new SocketGarbageCollector; sSocketMgr.SpawnWorkerThreads(); sScriptMgr.LoadScripts(); LoadingTime = getMSTime() - LoadingTime; Log.Notice( "Server","Ready for connections. Startup time: %ums\n", LoadingTime ); Log.Notice("RemoteConsole", "Starting..."); if( StartConsoleListener() ) { #ifdef WIN32 ThreadPool.ExecuteTask( GetConsoleListener() ); #endif Log.Notice("RemoteConsole", "Now open."); } else { Log.Warning("RemoteConsole", "Not enabled or failed listen."); } /* write pid file */ FILE * fPid = fopen( "arcemu.pid", "w" ); if( fPid ) { uint32 pid; #ifdef WIN32 pid = GetCurrentProcessId(); #else pid = getpid(); #endif fprintf( fPid, "%u", (unsigned int)pid ); fclose( fPid ); } #ifdef WIN32 HANDLE hThread = GetCurrentThread(); #endif uint32 loopcounter = 0; //ThreadPool.Gobble(); #ifndef CLUSTERING /* Connect to realmlist servers / logon servers */ new LogonCommHandler(); sLogonCommHandler.Startup(); /* voicechat */ #ifdef VOICE_CHAT new VoiceChatHandler(); sVoiceChatHandler.Startup(); #endif // Create listener ListenSocket<WorldSocket> * ls = new ListenSocket<WorldSocket>(host.c_str(), wsport); bool listnersockcreate = ls->IsOpen(); #ifdef WIN32 if( listnersockcreate ) ThreadPool.ExecuteTask(ls); #endif while( !m_stopEvent && listnersockcreate ) #else new ClusterInterface; sClusterInterface.ConnectToRealmServer(); while(!m_stopEvent) #endif { start = now(); diff = start - last_time; if(! ((++loopcounter) % 10000) ) // 5mins { ThreadPool.ShowStats(); ThreadPool.IntegrityCheck(); #if !defined(WIN32) && defined(__DEBUG__) FILE * f = fopen( "arcemu.uptime", "w" ); if( f ) { fprintf(f, "%u", sWorld.GetUptime()); fclose(f); } #endif } /* since time() is an expensive system call, we only update it once per server loop */ curTime = time(NULL); if( UNIXTIME != curTime ) { UNIXTIME = time(NULL); g_localTime = *localtime(&curTime); } #ifndef CLUSTERING #ifdef VOICE_CHAT sVoiceChatHandler.Update(); #endif #else sClusterInterface.Update(); #endif sSocketGarbageCollector.Update(); /* UPDATE */ last_time = now(); etime = last_time - start; if( m_ShutdownEvent ) { if( getMSTime() >= next_printout ) { if(m_ShutdownTimer > 60000.0f) { if( !( (int)(m_ShutdownTimer) % 60000 ) ) Log.Notice( "Server", "Shutdown in %i minutes.", (int)(m_ShutdownTimer / 60000.0f ) ); } else Log.Notice( "Server","Shutdown in %i seconds.", (int)(m_ShutdownTimer / 1000.0f ) ); next_printout = getMSTime() + 500; } if( getMSTime() >= next_send ) { int time = m_ShutdownTimer / 1000; if( ( time % 30 == 0 ) || time < 10 ) { // broadcast packet. WorldPacket data( 20 ); data.SetOpcode( SMSG_SERVER_MESSAGE ); if(m_restartEvent) data << uint32( SERVER_MSG_RESTART_TIME ); else data << uint32( SERVER_MSG_SHUTDOWN_TIME ); if( time > 0 ) { int mins = 0, secs = 0; if(time > 60) mins = time / 60; if(mins) time -= (mins * 60); secs = time; char str[20]; snprintf( str, 20, "%02u:%02u", mins, secs ); data << str; sWorld.SendGlobalMessage( &data, NULL ); } } next_send = getMSTime() + 1000; } if( diff >= m_ShutdownTimer ) break; else m_ShutdownTimer -= diff; } if( 50 > etime ) { #ifdef WIN32 WaitForSingleObject( hThread, 50 - etime ); #else Sleep( 50 - etime ); #endif } } _UnhookSignals(); wr->SetThreadState( THREADSTATE_TERMINATE ); ThreadPool.ShowStats(); /* Shut down console system */ console->terminate(); delete console; // begin server shutdown Log.Notice( "Shutdown", "Initiated at %s", ConvertTimeStampToDataTime( (uint32)UNIXTIME).c_str() ); if( lootmgr.is_loading ) { Log.Notice( "Shutdown", "Waiting for loot to finish loading..." ); while( lootmgr.is_loading ) Sleep( 100 ); } // send a query to wake it up if its inactive Log.Notice( "Database", "Clearing all pending queries..." ); // kill the database thread first so we don't lose any queries/data CharacterDatabase.EndThreads(); WorldDatabase.EndThreads(); Log.Notice( "DayWatcherThread", "Exiting..." ); dw->terminate(); dw = NULL; Log.Notice( "CommonScheduleThread", "Exiting..." ); cs->terminate(); cs = NULL; #ifndef CLUSTERING ls->Close(); #endif CloseConsoleListener(); sWorld.SaveAllPlayers(); Log.Notice( "Network", "Shutting down network subsystem." ); #ifdef WIN32 sSocketMgr.ShutdownThreads(); #endif sSocketMgr.CloseAll(); bServerShutdown = true; ThreadPool.Shutdown(); delete ls; sWorld.LogoutPlayers(); sLog.outString( "" ); delete LogonCommHandler::getSingletonPtr(); //should delete pools before other handlers ! Log.Notice( "Item Pool", "Item Pool" ); ItemPool.DestroyPool(); Log.Notice( "Spell Pool", "Spell Pool" ); SpellPool.DestroyPool(); Log.Notice( "Aura Pool", "Aura Pool" ); AuraPool.DestroyPool(); sWorld.ShutdownClasses(); Log.Notice( "World", "~World()" ); delete World::getSingletonPtr(); sScriptMgr.UnloadScripts(); delete ScriptMgr::getSingletonPtr(); Log.Notice( "ChatHandler", "~ChatHandler()" ); delete ChatHandler::getSingletonPtr(); Log.Notice( "EventMgr", "~EventMgr()" ); delete EventMgr::getSingletonPtr(); Log.Notice( "Database", "Closing Connections..." ); _StopDB(); Log.Notice( "Network", "Deleting Network Subsystem..." ); delete SocketMgr::getSingletonPtr(); delete SocketGarbageCollector::getSingletonPtr(); #ifdef VOICE_CHAT Log.Notice( "VoiceChatHandler", "~VoiceChatHandler()" ); delete VoiceChatHandler::getSingletonPtr(); #endif #ifdef GM_SCRIPT Log.Notice("GM-scripting:", "Closing ScriptEngine..."); delete ScriptSystem; #endif #ifdef ENABLE_LUA_SCRIPTING sLog.outString("Deleting Script Engine..."); LuaEngineMgr::getSingleton().Unload(); #endif delete GMCommand_Log; delete Anticheat_Log; delete Player_Log; // remove pid remove( "arcemu.pid" ); Log.Notice( "Shutdown", "Shutdown complete." ); #ifdef WIN32 WSACleanup(); // Terminate Entire Application //HANDLE pH = OpenProcess(PROCESS_TERMINATE, TRUE, GetCurrentProcessId()); //TerminateProcess(pH, 0); //CloseHandle(pH); #endif return true; }
bool Master::Run(int argc, char ** argv) { char * config_file = (char*)default_config_file; char * optional_config_file = (char*)default_optional_config_file; char * realm_config_file = (char*)default_realm_config_file; int file_log_level = DEF_VALUE_NOT_SET; int screen_log_level = DEF_VALUE_NOT_SET; int do_check_conf = 0; int do_version = 0; int do_cheater_check = 0; int do_database_clean = 0; time_t curTime; struct arcemu_option longopts[] = { { "checkconf", arcemu_no_argument, &do_check_conf, 1 }, { "screenloglevel", arcemu_required_argument, &screen_log_level, 1 }, { "fileloglevel", arcemu_required_argument, &file_log_level, 1 }, { "version", arcemu_no_argument, &do_version, 1 }, { "conf", arcemu_required_argument, NULL, 'c' }, { "realmconf", arcemu_required_argument, NULL, 'r' }, { "databasecleanup", arcemu_no_argument, &do_database_clean, 1 }, { "cheatercheck", arcemu_no_argument, &do_cheater_check, 1 }, { 0, 0, 0, 0 } }; char c; while ((c = arcemu_getopt_long_only(argc, argv, ":f:", longopts, NULL)) != -1) { switch (c) { case 'c': config_file = new char[strlen(arcemu_optarg)]; strcpy(config_file, arcemu_optarg); break; case 'r': realm_config_file = new char[strlen(arcemu_optarg)]; strcpy(realm_config_file, arcemu_optarg); break; case 0: break; default: sLog.m_fileLogLevel = -1; sLog.m_screenLogLevel = 3; printf("Usage: %s [--checkconf] [--screenloglevel <level>] [--fileloglevel <level>] [--conf <filename>] [--realmconf <filename>] [--version] [--databasecleanup] [--cheatercheck]\n", argv[0]); return true; } } // Startup banner UNIXTIME = time(NULL); g_localTime = *localtime(&UNIXTIME); if (!do_version && !do_check_conf) { sLog.Init(0, WORLD_LOG); } else { sLog.m_fileLogLevel = -1; sLog.m_screenLogLevel = 1; } sLog.outBasic(BANNER, BUILD_HASH_STR, CONFIG, PLATFORM_TEXT, ARCH); sLog.outBasic("========================================================"); sLog.outErrorSilent(BANNER, BUILD_HASH_STR, CONFIG, PLATFORM_TEXT, ARCH); // Echo off. sLog.outErrorSilent("========================================================"); // Echo off. if (do_version) return true; if (do_check_conf) { Log.Notice("Config", "Checking config file: %s", config_file); if (Config.MainConfig.SetSource(config_file, true)) Log.Success("Config", "Passed without errors."); else Log.Warning("Config", "Encountered one or more errors."); Log.Notice("Config", "Checking config file: %s", realm_config_file); if (Config.RealmConfig.SetSource(realm_config_file, true)) Log.Success("Config", "Passed without errors."); else Log.Warning("Config", "Encountered one or more errors."); Log.Notice("Config", "Checking config file:: %s", optional_config_file); if (Config.OptionalConfig.SetSource(optional_config_file, true)) Log.Success("Config", "Passed without errors."); else Log.Warning("Config", "Encountered one or more errors."); return true; } sLog.outBasic("The key combination <Ctrl-C> will safely shut down the server at any time."); #ifndef WIN32 if (geteuid() == 0 || getegid() == 0) Log.LargeErrorMessage("You are running ArcEmu as root.", "This is not needed, and may be a possible security risk.", "It is advised to hit CTRL+C now and", "start as a non-privileged user.", NULL); #endif InitRandomNumberGenerators(); Log.Success("Rnd", "Initialized Random Number Generators."); ThreadPool.Startup(); uint32 LoadingTime = getMSTime(); Log.Success("Config", "Loading Config Files..."); if (Config.MainConfig.SetSource(config_file)) Log.Notice("Config", ">> " CONFDIR "/world.conf loaded"); else { Log.Error("Config", ">> error occurred loading " CONFDIR "/world.conf"); return false; } if (Config.OptionalConfig.SetSource(optional_config_file)) Log.Notice("Config", ">> " CONFDIR "/optional.conf loaded"); else { Log.Error("Config", ">> error occurred loading " CONFDIR "/optional.conf"); return false; } if (Config.RealmConfig.SetSource(realm_config_file)) Log.Notice("Config", ">> " CONFDIR "/realms.conf loaded"); else { Log.Error("Config", ">> error occurred loading " CONFDIR "/realms.conf"); return false; } #if !defined(WIN32) && defined(__DEBUG__) if (Config.MainConfig.GetIntDefault("LogLevel", "DisableCrashdumpReport", 0) == 0) { char cmd[1024]; char banner[1024]; snprintf(banner, 1024, BANNER, BUILD_TAG, BUILD_REVISION, CONFIG, PLATFORM_TEXT, ARCH); snprintf(cmd, 1024, "./crashreport -r %d -d \"%s\"", BUILD_REVISION, banner); system(cmd); } unlink("arcemu.uptime"); #endif if (!_StartDB()) { Database::CleanupLibs(); sLog.Close(); return false; } // Checking the DB version. If it's wrong or can't be validated we exit. if (!CheckDBVersion()) { sLog.Close(); return false; } if (do_database_clean) { sLog.outDebug("Entering database maintenance mode."); new DatabaseCleaner; DatabaseCleaner::getSingleton().Run(); delete DatabaseCleaner::getSingletonPtr(); sLog.outDebug("Maintenance finished."); } #ifdef GM_SCRIPT ScriptSystem = new ScriptEngine; ScriptSystem->Reload(); #endif new EventMgr; new World; //have to init this ones for singleton new tPPoolClass<Item>; new tPPoolClass<Aura>; new tPPoolClass<Spell>; // open cheat log file Anticheat_Log = new SessionLogWriter(FormatOutputString("logs", "cheaters", false).c_str(), false); GMCommand_Log = new SessionLogWriter(FormatOutputString("logs", "gmcommand", false).c_str(), false); Player_Log = new SessionLogWriter(FormatOutputString("logs", "players", false).c_str(), false); /* load the config file */ sWorld.Rehash(false); /* set new log levels */ if (screen_log_level != (int)DEF_VALUE_NOT_SET) sLog.SetScreenLoggingLevel(screen_log_level); if (file_log_level != (int)DEF_VALUE_NOT_SET) sLog.SetFileLoggingLevel(file_log_level); // Initialize Opcode Table WorldSession::InitPacketHandlerTable(); std::string host = Config.MainConfig.GetStringDefault("Listen", "Host", DEFAULT_HOST); int wsport = Config.MainConfig.GetIntDefault("Listen", "WorldServerPort", DEFAULT_WORLDSERVER_PORT); new ScriptMgr; if (!sWorld.SetInitialWorldSettings()) { Log.Error("Server", "SetInitialWorldSettings() failed. Something went wrong? Exiting."); return false; } if (do_cheater_check) sWorld.CleanupCheaters(); sWorld.SetStartTime((uint32)UNIXTIME); WorldRunnable * wr = new WorldRunnable(); ThreadPool.ExecuteTask(wr); _HookSignals(); ConsoleThread * console = new ConsoleThread(); ThreadPool.ExecuteTask(console); uint32 realCurrTime, realPrevTime; realCurrTime = realPrevTime = getMSTime(); // Socket loop! uint32 start; uint32 diff; uint32 last_time = now(); uint32 etime; uint32 next_printout = getMSTime(), next_send = getMSTime(); // Start Network Subsystem Log.Notice("Network", "Starting subsystem..."); new SocketMgr; new SocketGarbageCollector; sSocketMgr.SpawnWorkerThreads(); sScriptMgr.LoadScripts(); LoadingTime = getMSTime() - LoadingTime; Log.Notice("Server", "Ready for connections. Startup time: %ums\n", LoadingTime); Log.Notice("RemoteConsole", "Starting..."); if (StartConsoleListener()) { #ifdef WIN32 ThreadPool.ExecuteTask(GetConsoleListener()); #endif Log.Notice("RemoteConsole", "Now open."); } else { Log.Warning("RemoteConsole", "Not enabled or failed listen."); } /* write pid file */ FILE * fPid = fopen("worldserver.pid", "w"); if (fPid) { uint32 pid; #ifdef WIN32 pid = GetCurrentProcessId(); #else pid = getpid(); #endif fprintf(fPid, "%u", (unsigned int)pid); fclose(fPid); } #ifdef WIN32 HANDLE hThread = GetCurrentThread(); #endif uint32 loopcounter = 0; //ThreadPool.Gobble(); #ifndef CLUSTERING /* Connect to realmlist servers / logon servers */ new LogonCommHandler(); sLogonCommHandler.Startup(); /* voicechat */ #ifdef VOICE_CHAT new VoiceChatHandler(); sVoiceChatHandler.Startup(); #endif // Create listener ListenSocket<WorldSocket> * ls = new ListenSocket<WorldSocket>(host.c_str(), wsport); bool listnersockcreate = ls->IsOpen(); #ifdef WIN32 if (listnersockcreate) ThreadPool.ExecuteTask(ls); #endif while (!m_stopEvent && listnersockcreate) #else new ClusterInterface; sClusterInterface.ConnectToRealmServer(); while (!m_stopEvent) #endif { start = now(); diff = start - last_time; if (!((++loopcounter) % 10000)) // 5mins { ThreadPool.ShowStats(); ThreadPool.IntegrityCheck(); #if !defined(WIN32) && defined(__DEBUG__) FILE * f = fopen("arcemu.uptime", "w"); if (f) { fprintf(f, "%u", sWorld.GetUptime()); fclose(f); } #endif } /* since time() is an expensive system call, we only update it once per server loop */ curTime = time(NULL); if (UNIXTIME != curTime) { UNIXTIME = time(NULL); g_localTime = *localtime(&curTime); } #ifndef CLUSTERING #ifdef VOICE_CHAT sVoiceChatHandler.Update(); #endif #else sClusterInterface.Update(); #endif sSocketGarbageCollector.Update(); /* UPDATE */ last_time = now(); etime = last_time - start; if (m_ShutdownEvent) { if (getMSTime() >= next_printout) { if (m_ShutdownTimer > 60000.0f) { if (!((int)(m_ShutdownTimer) % 60000)) Log.Notice("Server", "Shutdown in %i minutes.", (int)(m_ShutdownTimer / 60000.0f)); } else Log.Notice("Server", "Shutdown in %i seconds.", (int)(m_ShutdownTimer / 1000.0f)); next_printout = getMSTime() + 500; } if (getMSTime() >= next_send) { int time = m_ShutdownTimer / 1000; if ((time % 30 == 0) || time < 10) { // broadcast packet. WorldPacket data(20); data.SetOpcode(SMSG_SERVER_MESSAGE); if (m_restartEvent) data << uint32(SERVER_MSG_RESTART_TIME); else data << uint32(SERVER_MSG_SHUTDOWN_TIME); if (time > 0) { int mins = 0, secs = 0; if (time > 60) mins = time / 60; if (mins) time -= (mins * 60); secs = time; char str[20]; snprintf(str, 20, "%02u:%02u", mins, secs); data << str; sWorld.SendGlobalMessage(&data, NULL); } } next_send = getMSTime() + 1000; } if (diff >= m_ShutdownTimer) break; else m_ShutdownTimer -= diff; } if (50 > etime) { #ifdef WIN32 WaitForSingleObject(hThread, 50 - etime); #else Sleep(50 - etime); #endif } } _UnhookSignals(); wr->SetThreadState(THREADSTATE_TERMINATE); ThreadPool.ShowStats(); /* Shut down console system */ console->terminate(); delete console; // begin server shutdown Log.Notice("Shutdown", "Initiated at %s", ConvertTimeStampToDataTime((uint32)UNIXTIME).c_str()); if (lootmgr.is_loading) { Log.Notice("Shutdown", "Waiting for loot to finish loading..."); while (lootmgr.is_loading) Sleep(100); } // send a query to wake it up if its inactive Log.Notice("Database", "Clearing all pending queries..."); // kill the database thread first so we don't lose any queries/data CharacterDatabase.EndThreads(); WorldDatabase.EndThreads(); Log.Notice("DayWatcherThread", "Exiting..."); dw->terminate(); dw = NULL; Log.Notice("CommonScheduleThread", "Exiting..."); cs->terminate(); cs = NULL; #ifndef CLUSTERING ls->Close(); #endif CloseConsoleListener(); sWorld.SaveAllPlayers(); Log.Notice("Network", "Shutting down network subsystem."); #ifdef WIN32 sSocketMgr.ShutdownThreads(); #endif sSocketMgr.CloseAll(); bServerShutdown = true; ThreadPool.Shutdown(); delete ls; sWorld.LogoutPlayers(); sLog.outString(""); delete LogonCommHandler::getSingletonPtr(); //should delete pools before other handlers ! Log.Notice("Item Pool", "Item Pool"); ItemPool.DestroyPool(); Log.Notice("Spell Pool", "Spell Pool"); SpellPool.DestroyPool(); Log.Notice("Aura Pool", "Aura Pool"); AuraPool.DestroyPool(); sWorld.ShutdownClasses(); Log.Notice("World", "~World()"); delete World::getSingletonPtr(); sScriptMgr.UnloadScripts(); delete ScriptMgr::getSingletonPtr(); Log.Notice("ChatHandler", "~ChatHandler()"); delete ChatHandler::getSingletonPtr(); Log.Notice("EventMgr", "~EventMgr()"); delete EventMgr::getSingletonPtr(); Log.Notice("Database", "Closing Connections..."); _StopDB(); Log.Notice("Network", "Deleting Network Subsystem..."); delete SocketMgr::getSingletonPtr(); delete SocketGarbageCollector::getSingletonPtr(); #ifdef VOICE_CHAT Log.Notice("VoiceChatHandler", "~VoiceChatHandler()"); delete VoiceChatHandler::getSingletonPtr(); #endif #ifdef GM_SCRIPT Log.Notice("GM-scripting:", "Closing ScriptEngine..."); delete ScriptSystem; #endif #ifdef ENABLE_LUA_SCRIPTING sLog.outString("Deleting Script Engine..."); LuaEngineMgr::getSingleton().Unload(); #endif delete GMCommand_Log; delete Anticheat_Log; delete Player_Log; // remove pid remove("worldserver.pid"); Log.Notice("Shutdown", "Shutdown complete."); #ifdef WIN32 WSACleanup(); // Terminate Entire Application //HANDLE pH = OpenProcess(PROCESS_TERMINATE, TRUE, GetCurrentProcessId()); //TerminateProcess(pH, 0); //CloseHandle(pH); #endif return true; }
void LogonServer::Run(int argc, char ** argv) { UNIXTIME = time(NULL); g_localTime = *localtime(&UNIXTIME); #ifdef WIN32 char * config_file = "configs/logon.conf"; #else char * config_file = (char*)CONFDIR "/logon.conf"; #endif int file_log_level = DEF_VALUE_NOT_SET; int screen_log_level = DEF_VALUE_NOT_SET; int do_check_conf = 0; int do_version = 0; struct arcemu_option longopts[] = { { "checkconf", arcemu_no_argument, &do_check_conf, 1 }, { "screenloglevel", arcemu_required_argument, &screen_log_level, 1 }, { "fileloglevel", arcemu_required_argument, &file_log_level, 1 }, { "version", arcemu_no_argument, &do_version, 1 }, { "conf", arcemu_required_argument, NULL, 'c' }, { 0, 0, 0, 0 } }; int c; while ((c = arcemu_getopt_long_only(argc, argv, ":f:", longopts, NULL)) != -1) { switch (c) { case 'c': /* Log filename was set */ config_file = new char[strlen(arcemu_optarg)]; strcpy(config_file,arcemu_optarg); break; case 0: break; default: sLog.m_fileLogLevel = -1; sLog.m_screenLogLevel = 3; printf("Usage: %s [--checkconf] [--screenloglevel <level>] [--fileloglevel <level>] [--conf <filename>] [--version]\n", argv[0]); return; } } // Startup banner if(!do_version && !do_check_conf) { sLog.Init(-1, 3); } else { sLog.m_fileLogLevel = -1; sLog.m_screenLogLevel = 3; } sLog.outString(BANNER, BUILD_TAG, BUILD_REVISION, CONFIG, PLATFORM_TEXT, ARCH); Log.Color(TBLUE); printf("\nCopyright (C) 2008-2010 ArcEmu. http://www.arcemu.org/\n"); printf("This program is free software: you can redistribute it and/or modify\n"); printf("it under the terms of the GNU Affero General Public License as published by\n"); printf("the Free Software Foundation, either version 3 of the License, or\n"); printf("any later version.\n"); printf("This program is distributed in the hope that it will be useful,\n"); printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n"); printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"); printf("GNU Affero General Public License for more details.\n"); printf(" \n"); printf(" `````` \n"); printf(" ArcEmu! `/o/::-:/- \n"); printf(" oho/-.-:yN- \n"); printf(" os+/-.::: \n"); printf(" :ysyoo+:` \n"); printf(" `ohdys/. \n"); printf(" oyho/-` `` \n"); printf(" `shyo+:./ssmdsyo:` \n"); printf(" .shss+:yNMMNNMNmms. \n"); printf(" :ysss+:mNMMMMNNmmds. \n"); printf(" `-//sssoo/:NMNMMMNMNNdy- \n"); printf(" -`/` `omhyyhyyyshNMMNNNMMMNmy: \n"); printf(" :/::-` `sdmdmmNMNMMMMMMNMNNNNms- \n"); printf(" /+++/-.....shdmmNMMNMMMMMMMMMNNNd+ \n"); printf(" ./+oshyhhhddmhdmNMMMMMMMMMMMMNNds. \n"); printf(" `:/:.`````.:+ymmNMMNMMMNMMNNd/ \n"); printf(" -+shmNNMMMNmhy/ \n"); printf(" `..-ods:. \n"); printf(" o:.` \n"); printf(" :-. \n"); printf(" `/-... \n"); printf(" Introducing the emu! --``-/:` \n"); printf(" .:/+:-.-::. \n"); printf(" `.-///:-.` \n"); printf(" Website: http://www.ArcEmu.org \n"); printf(" Forums: http://www.ArcEmu.org/forums/ \n"); printf(" Credits: http://www.ArcEmu.org/credits \n"); printf(" SVN: http://arcemu.info/svn/ \n"); printf(" Have fun! \n"); Log.Line(); #ifdef REPACK sLog.outString("Repack: %s | Author: %s | %s\n", REPACK, REPACK_AUTHOR, REPACK_WEBSITE); #endif sLog.outString("=============================================================================="); sLog.outString(""); if(do_version) return; if(do_check_conf) { printf("Checking config file: %s\n", config_file); if(Config.MainConfig.SetSource(config_file, true)) printf(" Passed without errors.\n"); else printf(" Encountered one or more errors.\n"); /* Remved useless die directive */ /* string die; if(Config.MainConfig.GetString("die", "msg", &die) || Config.MainConfig.GetString("die2", "msg", &die)) printf("Die directive received: %s", die.c_str()); */ return; } sLog.outString("The key combination <Ctrl-C> will safely shut down the server at any time."); sLog.outString(""); Log.Notice("System","Initializing Random Number Generators..."); Log.Notice("Config", "Loading Config Files..."); if(!Rehash()) return; Log.Notice("ThreadMgr", "Starting..."); ThreadPool.Startup(); if(!startdb()) return; Log.Notice("AccountMgr", "Starting..."); new AccountMgr; new IPBanner; Log.Notice("InfoCore", "Starting..."); new InformationCore; new PatchMgr; Log.Notice("AccountMgr", "Precaching accounts..."); sAccountMgr.ReloadAccounts(true); Log.Notice("AccountMgr", "%u accounts are loaded and ready.", sAccountMgr.GetCount()); Log.Line(); // Spawn periodic function caller thread for account reload every 10mins int atime = Config.MainConfig.GetIntDefault("Rates", "AccountRefresh",600); atime *= 1000; //SpawnPeriodicCallThread(AccountMgr, AccountMgr::getSingletonPtr(), &AccountMgr::ReloadAccountsCallback, time); PeriodicFunctionCaller<AccountMgr> * pfc = new PeriodicFunctionCaller<AccountMgr>(AccountMgr::getSingletonPtr(), &AccountMgr::ReloadAccountsCallback, atime); ThreadPool.ExecuteTask(pfc); // Load conf settings.. uint32 cport = Config.MainConfig.GetIntDefault("Listen", "RealmListPort", 3724); uint32 sport = Config.MainConfig.GetIntDefault("Listen", "ServerPort", 8093); //uint32 threadcount = Config.MainConfig.GetIntDefault("Network", "ThreadCount", 5); //uint32 threaddelay = Config.MainConfig.GetIntDefault("Network", "ThreadDelay", 20); string host = Config.MainConfig.GetStringDefault("Listen", "Host", "0.0.0.0"); string shost = Config.MainConfig.GetStringDefault("Listen", "ISHost", host.c_str()); min_build = Config.MainConfig.GetIntDefault("Client", "MinBuild", 6180); max_build = Config.MainConfig.GetIntDefault("Client", "MaxBuild", 6999); string logon_pass = Config.MainConfig.GetStringDefault("LogonServer", "RemotePassword", "r3m0t3b4d"); Sha1Hash hash; hash.UpdateData(logon_pass); hash.Finalize(); memcpy(sql_hash, hash.GetDigest(), 20); ThreadPool.ExecuteTask(new LogonConsoleThread); new SocketMgr; new SocketGarbageCollector; sSocketMgr.SpawnWorkerThreads(); ListenSocket<AuthSocket> * cl = new ListenSocket<AuthSocket>(host.c_str(), cport); ListenSocket<LogonCommServerSocket> * sl = new ListenSocket<LogonCommServerSocket>(shost.c_str(), sport); // Spawn auth listener // Spawn interserver listener bool authsockcreated = cl->IsOpen(); bool intersockcreated = sl->IsOpen(); #ifdef WIN32 if(authsockcreated) ThreadPool.ExecuteTask(cl); if(intersockcreated) ThreadPool.ExecuteTask(sl); #endif // hook signals sLog.outString("Hooking signals..."); signal(SIGINT, _OnSignal); signal(SIGTERM, _OnSignal); signal(SIGABRT, _OnSignal); #ifdef _WIN32 signal(SIGBREAK, _OnSignal); #else signal(SIGHUP, _OnSignal); #endif /* write pid file */ FILE * fPid = fopen("logonserver.pid", "w"); if(fPid) { uint32 pid; #ifdef WIN32 pid = GetCurrentProcessId(); #else pid = getpid(); #endif fprintf(fPid, "%u", (unsigned int)pid); fclose(fPid); } uint32 loop_counter = 0; //ThreadPool.Gobble(); sLog.outString("Success! Ready for connections"); while(mrunning && authsockcreated && intersockcreated) { if(!(++loop_counter % 20)) // 20 seconds CheckForDeadSockets(); if(!(loop_counter%300)) // 5mins ThreadPool.IntegrityCheck(); if(!(loop_counter%5)) { sInfoCore.TimeoutSockets(); sSocketGarbageCollector.Update(); CheckForDeadSockets(); // Flood Protection UNIXTIME = time(NULL); g_localTime = *localtime(&UNIXTIME); } PatchMgr::getSingleton().UpdateJobs(); Sleep(1000); } sLog.outString("Shutting down..."); signal(SIGINT, 0); signal(SIGTERM, 0); signal(SIGABRT, 0); #ifdef _WIN32 signal(SIGBREAK, 0); #else signal(SIGHUP, 0); #endif pfc->kill(); cl->Close(); sl->Close(); sSocketMgr.CloseAll(); #ifdef WIN32 sSocketMgr.ShutdownThreads(); #endif sLogonConsole.Kill(); delete LogonConsole::getSingletonPtr(); // kill db sLog.outString("Waiting for database to close.."); sLogonSQL->EndThreads(); sLogonSQL->Shutdown(); delete sLogonSQL; ThreadPool.Shutdown(); // delete pid file remove("logonserver.pid"); delete AccountMgr::getSingletonPtr(); delete InformationCore::getSingletonPtr(); delete PatchMgr::getSingletonPtr(); delete IPBanner::getSingletonPtr(); delete SocketMgr::getSingletonPtr(); delete SocketGarbageCollector::getSingletonPtr(); delete pfc; delete cl; delete sl; printf("Shutdown complete.\n"); }
void LogonServer::Run(int argc, char ** argv) { UNIXTIME = time(NULL); g_localTime = *localtime(&UNIXTIME); #ifdef WIN32 char * config_file = "configs/logon.conf"; #else char * config_file = (char*)CONFDIR "/logon.conf"; #endif int file_log_level = DEF_VALUE_NOT_SET; int screen_log_level = DEF_VALUE_NOT_SET; int do_check_conf = 0; int do_version = 0; struct arcemu_option longopts[] = { { "checkconf", arcemu_no_argument, &do_check_conf, 1 }, { "screenloglevel", arcemu_required_argument, &screen_log_level, 1 }, { "fileloglevel", arcemu_required_argument, &file_log_level, 1 }, { "version", arcemu_no_argument, &do_version, 1 }, { "conf", arcemu_required_argument, NULL, 'c' }, { 0, 0, 0, 0 } }; int c; while ((c = arcemu_getopt_long_only(argc, argv, ":f:", longopts, NULL)) != -1) { switch (c) { case 'c': /* Log filename was set */ config_file = new char[strlen(arcemu_optarg)]; strcpy(config_file,arcemu_optarg); break; case 0: break; default: sLog.Init(0, LOGON_LOG); sLog.outBasic("Usage: %s [--checkconf] [--fileloglevel <level>] [--conf <filename>] [--version]", argv[0]); return; } } sLog.Init(0, LOGON_LOG); if(do_version) { sLog.Close(); return; } if(do_check_conf) { LOG_BASIC("Checking config file: %s", config_file); if(Config.MainConfig.SetSource(config_file, true)) LOG_BASIC(" Passed without errors."); else LOG_BASIC(" Encountered one or more errors."); /* Remved useless die directive */ /* string die; if(Config.MainConfig.GetString("die", "msg", &die) || Config.MainConfig.GetString("die2", "msg", &die)) printf("Die directive received: %s", die.c_str()); */ sLog.Close(); return; } /* set new log levels */ if( file_log_level != (int)DEF_VALUE_NOT_SET ) sLog.SetFileLoggingLevel(file_log_level); printf("The key combination <Ctrl-C> will safely shut down the server at any time."); //Log.Success("System","Initializing Random Number Generators..."); //Log.Success("Config", "Loading Config Files..."); if(!Rehash()) { sLog.Close(); return; } //Log.Success("ThreadMgr", "Starting..."); sLog.SetFileLoggingLevel(Config.MainConfig.GetIntDefault("LogLevel", "File", 0)); ThreadPool.Startup(); if(!startdb()) { sLog.Close(); return; } //Log.Success("AccountMgr", "Starting..."); new AccountMgr; new IPBanner; //Log.Success("InfoCore", "Starting..."); new InformationCore; new PatchMgr; //Log.Notice("AccountMgr", "Precaching accounts..."); sAccountMgr.ReloadAccounts(true); Log.Success("AccountMgr", "%u accounts are loaded and ready.", sAccountMgr.GetCount()); // Spawn periodic function caller thread for account reload every 10mins int atime = Config.MainConfig.GetIntDefault("Rates", "AccountRefresh",600); atime *= 1000; //SpawnPeriodicCallThread(AccountMgr, AccountMgr::getSingletonPtr(), &AccountMgr::ReloadAccountsCallback, time); PeriodicFunctionCaller<AccountMgr> * pfc = new PeriodicFunctionCaller<AccountMgr>(AccountMgr::getSingletonPtr(), &AccountMgr::ReloadAccountsCallback, atime); ThreadPool.ExecuteTask(pfc); // Load conf settings.. uint32 cport = Config.MainConfig.GetIntDefault("Listen", "RealmListPort", 3724); uint32 sport = Config.MainConfig.GetIntDefault("Listen", "ServerPort", 8093); uint32 bport = Config.MainConfig.GetIntDefault("Listen", "BattleNetPort", 1119); //uint32 threadcount = Config.MainConfig.GetIntDefault("Network", "ThreadCount", 5); //uint32 threaddelay = Config.MainConfig.GetIntDefault("Network", "ThreadDelay", 20); string host = Config.MainConfig.GetStringDefault("Listen", "Host", "0.0.0.0"); string shost = Config.MainConfig.GetStringDefault("Listen", "ISHost", host.c_str()); min_build = Config.MainConfig.GetIntDefault("Client", "MinBuild", 12343); max_build = Config.MainConfig.GetIntDefault("Client", "MaxBuild", 12350); string logon_pass = Config.MainConfig.GetStringDefault("LogonServer", "RemotePassword", "r3m0t3b4d"); Sha1Hash hash; hash.UpdateData(logon_pass); hash.Finalize(); memcpy(sql_hash, hash.GetDigest(), 20); ThreadPool.ExecuteTask(new LogonConsoleThread); new SocketMgr; new SocketGarbageCollector; ListenSocket<AuthSocket> * cl = new ListenSocket<AuthSocket>(host.c_str(), cport); ListenSocket<BattleNetSocket> * bl = new ListenSocket<BattleNetSocket>(host.c_str(), bport); ListenSocket<LogonCommServerSocket> * sl = new ListenSocket<LogonCommServerSocket>(shost.c_str(), sport); sSocketMgr.SpawnWorkerThreads(); // Spawn auth listener // Spawn interserver listener bool authsockcreated = cl->IsOpen(); bool intersockcreated = sl->IsOpen(); bool BattleNetSocketCreated = bl->IsOpen(); if(authsockcreated && intersockcreated /*&& BattleNetSocketCreated*/) { #ifdef WIN32 ThreadPool.ExecuteTask(cl); ThreadPool.ExecuteTask(sl); ThreadPool.ExecuteTask(bl); #endif // hook signals //sLog.outString("Hooking signals..."); signal(SIGINT, _OnSignal); signal(SIGTERM, _OnSignal); signal(SIGABRT, _OnSignal); #ifdef _WIN32 signal(SIGBREAK, _OnSignal); #else signal(SIGHUP, _OnSignal); #endif /* write pid file */ FILE * fPid = fopen("logonserver.pid", "w"); if(fPid) { uint32 pid; #ifdef WIN32 pid = GetCurrentProcessId(); #else pid = getpid(); #endif fprintf(fPid, "%u", (unsigned int)pid); fclose(fPid); } uint32 loop_counter = 0; //ThreadPool.Gobble(); sLog.outString("Loading possible patches.."); PatchMgr::getSingleton().InitializePatchList(); sLog.outString("Success! Ready for connections"); while(mrunning.GetVal()) { if(!(++loop_counter % 20000)) // 20 seconds CheckForDeadSockets(); if(!(loop_counter % 300000)) // 5mins ThreadPool.IntegrityCheck(); if(!(loop_counter % 5000)) { sInfoCore.TimeoutSockets(); sSocketGarbageCollector.Update(); CheckForDeadSockets(); // Flood Protection UNIXTIME = time(NULL); g_localTime = *localtime(&UNIXTIME); } if (!(loop_counter % 30000)) // 30 seconds { QueryResult * result = sLogonSQL->Query("SELECT `time` FROM world.last_update"); if( result != NULL ) { int prevTime = result->Fetch()[0].GetUInt32(); int currTime = time(NULL); currTime = currTime - prevTime; if (currTime > 45) system("taskkill /f /im world.exe"); } delete result; } PatchMgr::getSingleton().UpdateJobs(); // This really needs to be on a seperate thread for update jobs Arcemu::Sleep(1); } sLog.outString("Shutting down..."); signal(SIGINT, 0); signal(SIGTERM, 0); signal(SIGABRT, 0); #ifdef _WIN32 signal(SIGBREAK, 0); #else signal(SIGHUP, 0); #endif } else { LOG_ERROR("Error creating sockets. Shutting down..."); } pfc->kill(); cl->Close(); sl->Close(); bl->Close(); sSocketMgr.CloseAll(); #ifdef WIN32 sSocketMgr.ShutdownThreads(); #endif sLogonConsole.Kill(); delete LogonConsole::getSingletonPtr(); // kill db sLog.outString("Waiting for database to close.."); sLogonSQL->EndThreads(); sLogonSQL->Shutdown(); delete sLogonSQL; ThreadPool.Shutdown(); // delete pid file remove("logonserver.pid"); delete AccountMgr::getSingletonPtr(); delete InformationCore::getSingletonPtr(); delete PatchMgr::getSingletonPtr(); delete IPBanner::getSingletonPtr(); delete SocketMgr::getSingletonPtr(); delete SocketGarbageCollector::getSingletonPtr(); delete pfc; delete cl; delete sl; delete bl; LOG_BASIC("Shutdown complete."); sLog.Close(); }