/// <summary> /// Main entry point of the server which starts a single server. /// </summary> /// <param name="args"></param> public static void Main(string[] args) { string[] rawArguments = CommandEngine.ParseArguments(string.Join(" ", args)); string[] arguments = CommandEngine.GetArguments(rawArguments); NameValueCollection variables = CommandEngine.GetFlags(rawArguments); string configFile; if (arguments.Length == 0) { configFile = "./Server.config"; } else if (arguments.Length == 1) { configFile = arguments[0]; } else { System.Console.Error.WriteLine("Invalid comand line arguments."); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } ServerSpawnData spawnData; try { spawnData = ServerSpawnData.CreateFromXml(configFile, variables); } catch (IOException e) { System.Console.Error.WriteLine("Could not load the config file needed to start (" + e.Message + "). Are you sure it's present and accessible?"); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } catch (XmlConfigurationException e) { System.Console.Error.WriteLine(e.Message); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } catch (KeyNotFoundException e) { System.Console.Error.WriteLine(e.Message); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } spawnData.PluginSearch.PluginTypes.Add(typeof(UDRMS.PluginServer.Lobby_Plugin)); //spawnData.Cache.MaxCachedMessages = 1600; //////Console.WriteLine(spawnData.Cache.MaxCachedMessages); //spawnData.Cache.MaxCachedReaders = 1600; //////Console.WriteLine(spawnData.Cache.MaxCachedReaders); //spawnData.Cache.MaxCachedWriters = 1600; //////Console.WriteLine(spawnData.Cache.MaxCachedWriters); //spawnData.Cache.MaxActionDispatcherTasks = 3200; //////Console.WriteLine(spawnData.Cache.MaxActionDispatcherTasks); //spawnData.Cache.MaxCachedSocketAsyncEventArgs = 6400; //////Console.WriteLine(spawnData.Cache.MaxCachedSocketAsyncEventArgs); server = new DarkRiftServer(spawnData); //spawnData.Server.MaxStrikes server.Start(); new Thread(new ThreadStart(ConsoleLoop)).Start(); //server.PluginManager.GetPluginByType<Lobby_Plugin>().GetLobbysPerPage(5); while (true) { server.DispatcherWaitHandle.WaitOne(); } }
/// <summary> /// Main entry point of the server which starts a single server. /// </summary> /// <param name="args"></param> public static void Main(string[] args) { string[] rawArguments = CommandEngine.ParseArguments(string.Join(" ", args)); string[] arguments = CommandEngine.GetArguments(rawArguments); NameValueCollection variables = CommandEngine.GetFlags(rawArguments); string configFile; if (arguments.Length == 0) { configFile = "Server.config"; } else if (arguments.Length == 1) { configFile = arguments[0]; } else { System.Console.Error.WriteLine("Invalid comand line arguments."); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } ServerSpawnData spawnData; try { spawnData = ServerSpawnData.CreateFromXml(configFile, variables); } catch (IOException e) { System.Console.Error.WriteLine("Could not load the config file needed to start (" + e.Message + "). Are you sure it's present and accessible?"); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } catch (XmlConfigurationException e) { System.Console.Error.WriteLine(e.Message); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } catch (KeyNotFoundException e) { System.Console.Error.WriteLine(e.Message); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } spawnData.PluginSearch.PluginTypes.Add(typeof(Login)); server = new DarkRiftServer(spawnData); server.Start(); new Thread(new ThreadStart(ConsoleLoop)).Start(); while (true) { //server.DispatcherWaitHandle.WaitOne(); Thread.Sleep(1000 / serverTickRate); server.ExecuteDispatcherTasks(); OnTick?.Invoke(null, server.ClientManager); } }
/// <summary> /// Main entry point of the server which starts a single server. /// </summary> /// <param name="args"></param> private static void Main(string[] args) { string[] rawArguments = CommandEngine.ParseArguments(string.Join(" ", args)); string[] arguments = CommandEngine.GetArguments(rawArguments); NameValueCollection variables = CommandEngine.GetFlags(rawArguments); foreach (DictionaryEntry environmentVariable in Environment.GetEnvironmentVariables()) { variables.Add((string)environmentVariable.Key, (string)environmentVariable.Value); } string serverConfigFile; string clusterConfigFile; if (arguments.Length < 1) { serverConfigFile = "Server.config"; clusterConfigFile = "Cluster.config"; } else if (arguments.Length == 1) { serverConfigFile = arguments[0]; clusterConfigFile = "Cluster.config"; } else if (arguments.Length == 2) { serverConfigFile = arguments[0]; clusterConfigFile = arguments[1]; } else { System.Console.Error.WriteLine("Unexpected number of comand line arguments passed. Expected 0-2 but found " + arguments.Length + "."); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } DarkRiftServerConfigurationBuilder serverConfigurationBuilder; try { serverConfigurationBuilder = DarkRiftServerConfigurationBuilder.CreateFromXml(serverConfigFile, variables); } catch (IOException e) { System.Console.Error.WriteLine("Could not load the server config file needed to start (" + e.Message + "). Are you sure it's present and accessible?"); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } catch (XmlConfigurationException e) { System.Console.Error.WriteLine($"Failed to load '{serverConfigFile}': {e.Message}"); System.Console.Error.WriteLine(); System.Console.Error.WriteLine(e.DocumentationLink != null ? $"See {e.DocumentationLink} for more information." : "No additional documentation available."); System.Console.Error.WriteLine(); System.Console.Error.WriteLine(e.LineInfo != null && e.LineInfo.HasLineInfo() ? $"Line {e.LineInfo.LineNumber} Col: {e.LineInfo.LinePosition}" : "(Unknown location)"); System.Console.Error.WriteLine(); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } // Set this thread as the one executing dispatcher tasks serverConfigurationBuilder.WithDispatcherExecutorThreadID(Thread.CurrentThread.ManagedThreadId); #if PRO if (File.Exists(clusterConfigFile)) { DarkRiftClusterConfigurationBuilder clusterConfigurationBuilder; try { clusterConfigurationBuilder = DarkRiftClusterConfigurationBuilder.CreateFromXml(clusterConfigFile, variables); } catch (IOException e) { System.Console.Error.WriteLine("Could not load the cluster config file needed to start (" + e.Message + "). Are you sure it's present and accessible?"); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } catch (XmlConfigurationException e) { System.Console.Error.WriteLine($"Failed to load '{clusterConfigFile}': {e.Message}"); System.Console.Error.WriteLine(); System.Console.Error.WriteLine(e.DocumentationLink != null ? $"See {e.DocumentationLink} for more information." : "No additional documentation available."); System.Console.Error.WriteLine(); System.Console.Error.WriteLine(e.LineInfo != null && e.LineInfo.HasLineInfo() ? $"Line {e.LineInfo.LineNumber} Col: {e.LineInfo.LinePosition}" : "(Unknown location)"); System.Console.Error.WriteLine(); System.Console.WriteLine("Press any key to exit..."); System.Console.ReadKey(); return; } server = new DarkRiftServer(serverConfigurationBuilder.ServerSpawnData, clusterConfigurationBuilder.ClusterSpawnData); } else { server = new DarkRiftServer(serverConfigurationBuilder.ServerSpawnData); } #else server = new DarkRiftServer(serverConfigurationBuilder.ServerSpawnData); #endif server.StartServer(); new Thread(new ThreadStart(ConsoleLoop)).Start(); while (!server.Disposed) { server.DispatcherWaitHandle.WaitOne(); server.ExecuteDispatcherTasks(); } }