public new bool StartServer() { var type = typeof(MiNetServer); RakConnection c = ReflectionHelper.GetPrivateFieldValue <RakConnection>(type, this, "_listener"); if (c != null) { return(false); } try { Log.Info("Initializing..."); if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Proxy) { if (Endpoint == null) { var ip = IPAddress.Parse(Config.GetProperty("ip", "0.0.0.0")); int port = Config.GetProperty("port", 19132); ReflectionHelper.SetPrivatePropertyValue(type, this, "Endpoint", new IPEndPoint(ip, port)); } } ServerManager = ServerManager ?? new DefaultServerManager(this); OpenServerInfo openInfo = null; if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Node) { PluginManager = new PluginManager(); global::MiNET.Items.ItemFactory.CustomItemFactory = OpenApi.ItemFactory; GreyListManager = GreyListManager ?? new GreyListManager(ConnectionInfo); SessionManager = SessionManager ?? new SessionManager(); LevelManager = OpenApi.LevelManager; PlayerFactory = OpenApi.PlayerManager; } MotdProvider = OpenApi.MotdProvider; OpenApi.OnEnable(this); if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Proxy) { RakConnection listener = new RakConnection(Endpoint, GreyListManager, MotdProvider); listener.CustomMessageHandlerFactory = session => new BedrockMessageHandler(session, ServerManager, PluginManager); /* listener.DontFragment = false; * listener.EnableBroadcast = true; * * if (!System.Runtime.InteropServices.RuntimeInformation * .IsOSPlatform(OSPlatform.Windows)) * { * listener.Client.ReceiveBufferSize = 1024 * 1024 * 3; * listener.Client.SendBufferSize = 4096; * } * else * { * listener.Client.ReceiveBufferSize = int.MaxValue; * listener.Client.SendBufferSize = int.MaxValue; * listener.DontFragment = false; * listener.EnableBroadcast = false; * * uint IOC_IN = 0x80000000; * uint IOC_VENDOR = 0x18000000; * uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12; * listener.Client.IOControl((int) SIO_UDP_CONNRESET, new byte[] {Convert.ToByte(false)}, null); * }*/ openInfo = new OpenServerInfo(listener.ConnectionInfo, OpenApi, listener.ConnectionInfo.RakSessions, OpenApi.LevelManager); ConnectionInfo = openInfo; openInfo.Init(); OpenApi.ServerInfo = openInfo; if (!Config.GetProperty("EnableThroughput", true)) { listener.ConnectionInfo.ThroughPut.Change(Timeout.Infinite, Timeout.Infinite); } ReflectionHelper.SetPrivateFieldValue(type, this, "_listener", listener); listener.Start(); /*var processData = type.GetMethod("ProcessDatagrams", * BindingFlags.NonPublic | BindingFlags.Instance); * * * ProcessingThread = new Thread((l) => * { * processData?.Invoke(this, new object[] {(UdpClient) l}); * }) {IsBackground = true}; * * ProcessingThread.Start(listener);*/ } openInfo?.OnEnable(); /* ReflectionHelper.SetPrivateFieldValue(type, this, "_tickerHighPrecisionTimer", * new HighPrecisionTimer(10, async (o) => { * ReflectionHelper.InvokePrivateMethod(type, this, "SendTick", new object[] {null}); * /* var sessions = * ReflectionHelper * .GetPrivateFieldValue<ConcurrentDictionary<IPEndPoint, PlayerNetworkSession>>( * type, this, "_playerSessions"); * * var tasks = sessions.Values.Select(session => session.SendTickAsync()); * await Task.WhenAll(tasks);* * }, true, true));*/ Log.Info("Server open for business on port " + Endpoint?.Port + " ..."); OpenApi.EventDispatcher.DispatchEvent(new ServerReadyEvent()); return(true); } catch (Exception e) { Log.Error("Error during startup!", e); StopServer(); } 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) { // 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); }
/// <summary> /// Starts the server /// </summary> /// <returns></returns> public new bool StartServer() { var type = typeof(MiNetServer); RakConnection c = ReflectionHelper.GetPrivateFieldValue <RakConnection>(type, this, "_listener"); if (c != null) { return(false); } try { Log.Info("Initializing..."); if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Proxy) { if (Endpoint == null) { var ip = IPAddress.Parse(Config.GetProperty("ip", "0.0.0.0")); int port = Config.GetProperty("port", 19132); ReflectionHelper.SetPrivatePropertyValue(type, this, "Endpoint", new IPEndPoint(ip, port)); } } ServerManager = ServerManager ?? new DefaultServerManager(this); OpenServerInfo openInfo = null; if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Node) { PluginManager = new PluginManager(); global::MiNET.Items.ItemFactory.CustomItemFactory = OpenApi.ItemFactory; GreyListManager = GreyListManager ?? new GreyListManager(ConnectionInfo); SessionManager = SessionManager ?? new SessionManager(); LevelManager = OpenApi.LevelManager; PlayerFactory = OpenApi.PlayerManager; } MotdProvider = OpenApi.MotdProvider; OpenApi.OnEnable(this); if (ServerRole == ServerRole.Full || ServerRole == ServerRole.Proxy) { RakConnection listener = new RakConnection(Endpoint, GreyListManager, MotdProvider); listener.CustomMessageHandlerFactory = session => new BedrockMessageHandler(session, ServerManager, PluginManager); openInfo = new OpenServerInfo(listener, OpenApi, listener.ConnectionInfo.RakSessions, OpenApi.LevelManager); ConnectionInfo = openInfo; openInfo.Init(); OpenApi.ServerInfo = openInfo; if (!Config.GetProperty("EnableThroughput", true)) { listener.ConnectionInfo.ThroughPut.Change(Timeout.Infinite, Timeout.Infinite); } ReflectionHelper.SetPrivateFieldValue(type, this, "_listener", listener); listener.Start(); _rakListener = listener; } openInfo?.OnEnable(); Log.Info("Server open for business on port " + Endpoint?.Port + " ..."); OpenApi.EventDispatcher.DispatchEvent(new ServerReadyEvent(this)); return(true); } catch (Exception e) { Log.Error("Error during startup!", e); StopServer(); } return(false); }