static void Main() { Console.CancelKeyPress += (o, e) => Global.WorldMgr.StopNow(ShutdownExitCode.Shutdown); if (!ConfigMgr.Load(System.Diagnostics.Process.GetCurrentProcess().ProcessName + ".conf")) { ExitNow(); } var WorldSocketMgr = new WorldSocketManager(); if (!StartDB()) { ExitNow(); } // set server offline (not connectable) DB.Login.Execute("UPDATE realmlist SET flag = (flag & ~{0}) | {1} WHERE id = '{2}'", (uint)RealmFlags.VersionMismatch, (uint)RealmFlags.Offline, Global.WorldMgr.GetRealm().Id.Realm); Global.RealmMgr.Initialize(ConfigMgr.GetDefaultValue("RealmsStateUpdateDelay", 10)); Global.WorldMgr.SetInitialWorldSettings(); // Launch the worldserver listener socket int worldPort = WorldConfig.GetIntValue(WorldCfg.PortWorld); string worldListener = ConfigMgr.GetDefaultValue("BindIP", "0.0.0.0"); int networkThreads = ConfigMgr.GetDefaultValue("Network.Threads", 1); if (networkThreads <= 0) { Log.outError(LogFilter.Server, "Network.Threads must be greater than 0"); ExitNow(); return; } if (!WorldSocketMgr.StartNetwork(worldListener, worldPort, networkThreads)) { Log.outError(LogFilter.Network, "Failed to start Realm Network"); ExitNow(); } // set server online (allow connecting now) DB.Login.Execute("UPDATE realmlist SET flag = flag & ~{0}, population = 0 WHERE id = '{1}'", (uint)RealmFlags.Offline, Global.WorldMgr.GetRealm().Id.Realm); Global.WorldMgr.GetRealm().PopulationLevel = 0.0f; Global.WorldMgr.GetRealm().Flags = Global.WorldMgr.GetRealm().Flags & ~RealmFlags.VersionMismatch; //Set Culture CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; //- Launch CliRunnable thread if (ConfigMgr.GetDefaultValue("Console.Enable", true)) { Thread commandThread = new Thread(CommandManager.InitConsole); commandThread.Start(); } WorldUpdateLoop(); try { // Shutdown starts here Global.WorldMgr.KickAll(); // save and kick all players Global.WorldMgr.UpdateSessions(1); // real players unload required UpdateSessions call // unload Battlegroundtemplates before different singletons destroyed Global.BattlegroundMgr.DeleteAllBattlegrounds(); WorldSocketMgr.StopNetwork(); Global.MapMgr.UnloadAll(); // unload all grids (including locked in memory) Global.ScriptMgr.Unload(); // set server offline DB.Login.Execute("UPDATE realmlist SET flag = flag | {0} WHERE id = '{1}'", (uint)RealmFlags.Offline, Global.WorldMgr.GetRealm().Id.Realm); Global.RealmMgr.Close(); ClearOnlineAccounts(); ExitNow(); } catch (Exception ex) { Log.outException(ex); } }
static void Main() { //Set Culture CultureInfo.DefaultThreadCurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Console.CancelKeyPress += (o, e) => Global.WorldMgr.StopNow(ShutdownExitCode.Shutdown); AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; if (!ConfigMgr.Load(Process.GetCurrentProcess().ProcessName + ".conf")) { ExitNow(); } if (!StartDB()) { ExitNow(); } // Server startup begin uint startupBegin = Time.GetMSTime(); // set server offline (not connectable) DB.Login.DirectExecute("UPDATE realmlist SET flag = (flag & ~{0}) | {1} WHERE id = '{2}'", (uint)RealmFlags.VersionMismatch, (uint)RealmFlags.Offline, Global.WorldMgr.GetRealm().Id.Index); Global.RealmMgr.Initialize(ConfigMgr.GetDefaultValue("RealmsStateUpdateDelay", 10)); Global.WorldMgr.SetInitialWorldSettings(); // Start the Remote Access port (acceptor) if enabled if (ConfigMgr.GetDefaultValue("Ra.Enable", false)) { int raPort = ConfigMgr.GetDefaultValue("Ra.Port", 3443); string raListener = ConfigMgr.GetDefaultValue("Ra.IP", "0.0.0.0"); AsyncAcceptor raAcceptor = new(); if (!raAcceptor.Start(raListener, raPort)) { Log.outError(LogFilter.Server, "Failed to initialize RemoteAccess Socket Server"); } else { raAcceptor.AsyncAccept <RASocket>(); } } // Launch the worldserver listener socket int worldPort = WorldConfig.GetIntValue(WorldCfg.PortWorld); string worldListener = ConfigMgr.GetDefaultValue("BindIP", "0.0.0.0"); int networkThreads = ConfigMgr.GetDefaultValue("Network.Threads", 1); if (networkThreads <= 0) { Log.outError(LogFilter.Server, "Network.Threads must be greater than 0"); ExitNow(); return; } var WorldSocketMgr = new WorldSocketManager(); if (!WorldSocketMgr.StartNetwork(worldListener, worldPort, networkThreads)) { Log.outError(LogFilter.Network, "Failed to start Realm Network"); ExitNow(); } // set server online (allow connecting now) DB.Login.DirectExecute("UPDATE realmlist SET flag = flag & ~{0}, population = 0 WHERE id = '{1}'", (uint)RealmFlags.Offline, Global.WorldMgr.GetRealm().Id.Index); Global.WorldMgr.GetRealm().PopulationLevel = 0.0f; Global.WorldMgr.GetRealm().Flags = Global.WorldMgr.GetRealm().Flags & ~RealmFlags.VersionMismatch; //- Launch CliRunnable thread if (ConfigMgr.GetDefaultValue("Console.Enable", true)) { Thread commandThread = new(CommandManager.InitConsole); commandThread.Start(); } GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); uint startupDuration = Time.GetMSTimeDiffToNow(startupBegin); Log.outInfo(LogFilter.Server, "World initialized in {0} minutes {1} seconds", (startupDuration / 60000), ((startupDuration % 60000) / 1000)); WorldUpdateLoop(); try { // Shutdown starts here Global.WorldMgr.KickAll(); // save and kick all players Global.WorldMgr.UpdateSessions(1); // real players unload required UpdateSessions call // unload Battlegroundtemplates before different singletons destroyed Global.BattlegroundMgr.DeleteAllBattlegrounds(); WorldSocketMgr.StopNetwork(); Global.MapMgr.UnloadAll(); // unload all grids (including locked in memory) Global.ScriptMgr.Unload(); // set server offline DB.Login.DirectExecute("UPDATE realmlist SET flag = flag | {0} WHERE id = '{1}'", (uint)RealmFlags.Offline, Global.WorldMgr.GetRealm().Id.Index); Global.RealmMgr.Close(); ClearOnlineAccounts(); ExitNow(); } catch (Exception ex) { Log.outException(ex); ExitNow(); } }