/// <summary> /// Stops the server gracefully /// </summary> /// <returns></returns> public new bool StopServer() { OpenApi.EventDispatcher.DispatchEvent(new ServerClosingEvent(this)); Log.Info($"Stopping server..."); _rakListener.Stop(); var task = Task.Run( () => { try { OpenApi?.OnDisable(); } finally { _rakListener?.Stop(); OnServerShutdown?.Invoke(this, EventArgs.Empty); } }); if (!task.Wait(Config.GetProperty("ForcedShutdownDelay", 10) * 1000)) { Log.Warn($"Server took too long to shutdown, force exiting..."); Environment.Exit(1); return(false); } Log.Info($"Server shutdown gracefully... Exiting..."); Environment.Exit(0); return(true); }
public void StopServer() { foreach (Level level in LevelManager.Levels) { try { level.Close(); } catch (Exception e) { Log.Warn($"Error while stopping server", e); } } Log.Info("Disabling plugins..."); PluginManager?.DisablePlugins(); _listener?.Stop(); }
public void StopServer() { Log.Info($"Stopping..."); LevelManager.Close(); Log.Info("Disabling plugins..."); PluginManager?.DisablePlugins(); _listener?.Stop(); ConnectionInfo?.Stop(); var fastThreadPool = FastThreadPool; fastThreadPool?.Dispose(); Log.Info($"Waiting for threads to exit..."); fastThreadPool?.WaitForThreadsExit(); }
public bool StartServer() { DisplayTimerProperties(); if (_listener != null) { return(false); // Already started } try { Log.Info("Initializing..."); if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Proxy) { if (IsEdu) { EduTokenManager = new EduTokenManager(); } if (Endpoint == null) { var ip = IPAddress.Parse(Config.GetProperty("ip", "0.0.0.0")); int port = Config.GetProperty("port", DefaultPort); Endpoint = new IPEndPoint(ip, port); } } ServerManager ??= new DefaultServerManager(this); if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Node) { // This stuff needs to be in an extension to connection // somehow ... Log.Info("Loading plugins..."); PluginManager = new PluginManager(); PluginManager.LoadPlugins(); Log.Info("Plugins loaded!"); // Bootstrap server PluginManager.ExecuteStartup(this); SessionManager ??= new SessionManager(); LevelManager ??= new LevelManager(); //LevelManager ??= new SpreadLevelManager(50); PlayerFactory ??= new PlayerFactory(); PluginManager.EnablePlugins(this, LevelManager); // Cache - remove LevelManager.GetLevel(null, Dimension.Overworld.ToString()); } GreyListManager ??= new GreyListManager(); MotdProvider ??= new MotdProvider(); if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Proxy) { _listener = new RakConnection(Endpoint, GreyListManager, MotdProvider); //_listener.ServerInfo.DisableAck = true; _listener.CustomMessageHandlerFactory = session => new BedrockMessageHandler(session, ServerManager, PluginManager); //TODO: This is bad design, need to refactor this later. GreyListManager.ConnectionInfo = _listener.ConnectionInfo; ConnectionInfo = _listener.ConnectionInfo; ConnectionInfo.MaxNumberOfPlayers = Config.GetProperty("MaxNumberOfPlayers", 10); ConnectionInfo.MaxNumberOfConcurrentConnects = Config.GetProperty("MaxNumberOfConcurrentConnects", ConnectionInfo.MaxNumberOfPlayers); _listener.Start(); } Log.Info("Server open for business on port " + Endpoint?.Port + " ..."); return(true); } catch (Exception e) { Log.Error("Error during startup!", e); _listener.Stop(); } return(false); }