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); }
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) { Log.Info("Loading plugins..."); PluginManager = new PluginManager(); PluginManager.LoadPlugins(); Log.Info("Plugins loaded!"); // Bootstrap server PluginManager.ExecuteStartup(this); GreylistManager ??= new GreylistManager(this); SessionManager ??= new SessionManager(); LevelManager ??= new LevelManager(); //LevelManager ??= new SpreadLevelManager(75); PlayerFactory ??= new PlayerFactory(); PluginManager.EnablePlugins(this, LevelManager); // Cache - remove LevelManager.GetLevel(null, Dimension.Overworld.ToString()); } GreylistManager ??= new GreylistManager(this); MotdProvider ??= new MotdProvider(); if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Proxy) { _listener = CreateListener(); new Thread(Receive) { IsBackground = true }.Start(_listener); } ServerInfo = new ServerInfo(LevelManager, _rakNetSessions) { MaxNumberOfPlayers = Config.GetProperty("MaxNumberOfPlayers", 10) }; ServerInfo.MaxNumberOfConcurrentConnects = Config.GetProperty("MaxNumberOfConcurrentConnects", ServerInfo.MaxNumberOfPlayers); _tickerHighPrecisionTimer = new HighPrecisionTimer(10, SendTick, true); Log.Info("Server open for business on port " + Endpoint?.Port + " ..."); return(true); } catch (Exception e) { Log.Error("Error during startup!", e); StopServer(); } return(false); }