/// <summary> /// Creates the server. /// </summary> public void Create(NameValueCollection variables) { if (Server != null) throw new InvalidOperationException("The server has already been created! (Is CreateOnEnable enabled?)"); if (configuration != null) { //Create spawn data from config ServerSpawnData spawnData = ServerSpawnData.CreateFromXml(XDocument.Parse(configuration.text), variables); //Inaccessible from xml, set from inspector spawnData.EventsFromDispatcher = eventsFromDispatcher; //Unity is broken, work around it... //This is an obsolete property but is still used if the user is using obsolete <server> tag properties #pragma warning disable 0618 spawnData.Server.UseFallbackNetworking = true; #pragma warning restore 0618 //Add types spawnData.PluginSearch.PluginTypes.AddRange(UnityServerHelper.SearchForPlugins()); spawnData.PluginSearch.PluginTypes.Add(typeof(UnityConsoleWriter)); //Create server Server = new DarkRiftServer(spawnData); Server.Start(); enetListener = Server.NetworkListenerManager.GetNetworkListenersByType<EnetListenerPlugin>().First(); } else Debug.LogError("No configuration file specified!"); }
/// <summary> /// Creates the server. /// </summary> public void Create(NameValueCollection variables) { if (Server != null) { throw new InvalidOperationException("The server has already been created! (Is CreateOnEnable enabled?)"); } if (configuration != null) { //Create spawn data from config ServerSpawnData spawnData = ServerSpawnData.CreateFromXml(XDocument.Parse(configuration.text), variables); //Inaccessible from xml, set from inspector spawnData.EventsFromDispatcher = eventsFromDispatcher; //Unity is broken, work around it... spawnData.Server.UseFallbackNetworking = true; //Add types spawnData.PluginSearch.PluginTypes.AddRange(UnityServerHelper.SearchForPlugins()); spawnData.PluginSearch.PluginTypes.Add(typeof(UnityConsoleWriter)); //Create server Server = new DarkRiftServer(spawnData); Server.Start(); } else { Debug.LogError("No configuration file specified!"); } }
/// <summary> /// Creates the server. /// </summary> public void Create(NameValueCollection variables) { if (Server != null) { if (Server.Disposed) { Server.StartServer(); } else { throw new InvalidOperationException("The server has already been created! (Is CreateOnEnable enabled?)"); } } if (configuration != null) { // Create spawn data from config ServerSpawnData spawnData = ServerSpawnData.CreateFromXml(XDocument.Parse(configuration.text), variables); if (spawnData == null) { throw new Exception("SpawnData not defined"); } // Allow only this thread to execute dispatcher tasks to enable deadlock protection spawnData.DispatcherExecutorThreadID = Thread.CurrentThread.ManagedThreadId; // Inaccessible from XML, set from inspector spawnData.EventsFromDispatcher = eventsFromDispatcher; // Unity is broken, work around it... // This is an obsolete property but is still used if the user is using obsolete <server> tag properties #pragma warning disable 0618 spawnData.Server.UseFallbackNetworking = true; #pragma warning restore 0618 // Add types spawnData.PluginSearch.PluginTypes.AddRange(UnityServerHelper.SearchForPlugins()); spawnData.Listeners.NetworkListeners[0].Port = port; // Create server Server = new DarkRiftServer(spawnData); Server.StartServer(); } else { throw new Exception("Configuration file not set"); } }
public void GivenIHaveARunningServer(string serverConfig) { NameValueCollection parameters = new NameValueCollection { { "port", GetFreePort().ToString() } }; DarkRiftServer server = new DarkRiftServer(ServerSpawnData.CreateFromXml("Configurations/Server/" + serverConfig, parameters)); server.StartServer(); world.AddServer(server); #if DEBUG // We've just requested a load of objects that wont be returned until we close // UDP receive TCP accept performanceSteps.ExpectedUnaccountedForSocketAsyncEventArgs += 2; #endif }
/// <summary> /// Creates the server. /// </summary> public void Create(NameValueCollection variables) { if (Server != null) { throw new InvalidOperationException("The server has already been created! (Is CreateOnEnable enabled?)"); } if (configuration != null) { // Create spawn data from config ServerSpawnData spawnData = ServerSpawnData.CreateFromXml(XDocument.Parse(configuration.text), variables); // Allow only this thread to execute dispatcher tasks to enable deadlock protection spawnData.DispatcherExecutorThreadID = Thread.CurrentThread.ManagedThreadId; // Inaccessible from XML, set from inspector spawnData.EventsFromDispatcher = eventsFromDispatcher; // Unity is broken, work around it... // This is an obsolete property but is still used if the user is using obsolete <server> tag properties #pragma warning disable 0618 spawnData.Server.UseFallbackNetworking = true; #pragma warning restore 0618 // Add types spawnData.PluginSearch.PluginTypes.AddRange(UnityServerHelper.SearchForPlugins()); spawnData.PluginSearch.PluginTypes.Add(typeof(UnityConsoleWriter)); // Create server Server = new DarkRiftServer(spawnData); Server.StartServer(); } else { Debug.LogError("No configuration file specified! Please ensure there is a configuration file set on the XmlUnityServer component before starting the server."); } }
/// <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> 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(); } }