public static void Run <T>(string[] args) where T : MyObjectBuilder_SessionSettings, new() { if (DedicatedServer.ProcessArgs(args)) { return; } if (Environment.UserInteractive) { MyPlugins.RegisterGameAssemblyFile(MyPerGameSettings.GameModAssembly); MyPlugins.RegisterGameObjectBuildersAssemblyFile(MyPerGameSettings.GameModObjBuildersAssembly); MyPlugins.RegisterSandboxAssemblyFile(MyPerGameSettings.SandboxAssembly); MyPlugins.RegisterSandboxGameAssemblyFile(MyPerGameSettings.SandboxGameAssembly); MyPlugins.RegisterFromArgs(args); MyPlugins.Load(); bool resultRegisterAssemblies = MyObjectBuilderType.RegisterAssemblies(); Debug.Assert(resultRegisterAssemblies, "Registering object builders types from assemblies failed."); resultRegisterAssemblies = MyObjectBuilderSerializer.RegisterAssembliesAndLoadSerializers(); Debug.Assert(resultRegisterAssemblies, "Registering object builders serializers from assemblies failed."); ShowWindow(GetConsoleWindow(), SW_HIDE); MyConfigurator.Start <T>(); MyPlugins.Unload(); return; } else { MyServiceBase.Run(new WindowsService()); return; } }
private static void RegisterPlugins() { MyPlugins.RegisterGameAssemblyFile("SpaceEngineers.Game.dll"); MyPlugins.RegisterGameObjectBuildersAssemblyFile("SpaceEngineers.ObjectBuilders.dll"); MyPlugins.RegisterSandboxAssemblyFile("Sandbox.Common.dll"); MyPlugins.RegisterSandboxGameAssemblyFile("Sandbox.Game.dll"); MyPlugins.Load(); MyObjectBuilderType.RegisterAssemblies(); MyObjectBuilderSerializer.RegisterAssembliesAndLoadSerializers(); }
public SpaceEngineersCore() { //SpaceEngineersGame.SetupPerGameSettings(); // not required currently. var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); //MyPlugins.RegisterGameAssemblyFile(Path.Combine(path, "SpaceEngineers.Game.dll")); // not required currently. MyPlugins.RegisterGameObjectBuildersAssemblyFile(Path.Combine(path, "SpaceEngineers.ObjectBuilders.dll")); MyPlugins.RegisterSandboxAssemblyFile(Path.Combine(path, "Sandbox.Common.dll")); //MyPlugins.RegisterSandboxGameAssemblyFile(Path.Combine(path, "Sandbox.Game.dll")); // not required currently. MyObjectBuilderType.RegisterAssemblies(); MyObjectBuilderSerializer.RegisterAssembliesAndLoadSerializers(); SpaceEngineersApi.LoadLocalization(); _stockDefinitions = new SpaceEngineersResources(); _stockDefinitions.LoadDefinitions(); _manageDeleteVoxelList = new List <string>(); }
private static void Start(string[] args) { //register object builder assembly string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SpaceEngineers.ObjectBuilders.DLL"); VRage.Plugins.MyPlugins.RegisterGameObjectBuildersAssemblyFile(path); MyObjectBuilderType.RegisterAssemblies( ); //Setup error handling for unmanaged exceptions AppDomain.CurrentDomain.UnhandledException += AppDomain_UnhandledException; Application.ThreadException += Application_ThreadException; Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); //AppDomain.CurrentDomain.ClearEventInvocations("_unhandledException"); BaseLog.Info("Starting SEServerExtender with {0} arguments: {1}", args.Length, string.Join("\r\n\t", args)); CommandLineArgs extenderArgs = CommandLineArgs = new CommandLineArgs { ConsoleTitle = string.Empty, AutoStart = false, WorldName = string.Empty, InstanceName = string.Empty, NoGui = false, NoConsole = false, Debug = false, GamePath = new DirectoryInfo(PathManager.BasePath).Parent.FullName, NoWcf = false, Autosave = 0, InstancePath = string.Empty, CloseOnCrash = false, RestartOnCrash = false, Args = string.Join(" ", args.Select(x => string.Format("\"{0}\"", x))) }; if (ConfigurationManager.AppSettings["WCFChatMaxMessageHistoryAge"] != null) { if (!int.TryParse(ConfigurationManager.AppSettings["WCFChatMaxMessageHistoryAge"], out _maxChatHistoryMessageAge)) { ConfigurationManager.AppSettings.Add("WCFChatMaxMessageHistoryAge", "3600"); } } if (ConfigurationManager.AppSettings["WCFChatMaxMessageHistoryCount"] != null) { if (!int.TryParse(ConfigurationManager.AppSettings["WCFChatMaxMessageHistoryCount"], out _maxChatHistoryMessageCount)) { ConfigurationManager.AppSettings.Add("WCFChatMaxMessageHistoryCount", "100"); } } bool logPathSet = false; //Process the args foreach (string arg in args) { string[] splitAtEquals = arg.Split('='); if (splitAtEquals.Length > 1) { string argName = splitAtEquals[0]; string argValue = splitAtEquals[1]; string lowerCaseArgument = argName.ToLower( ); if (lowerCaseArgument.Equals("instance")) { if (argValue[argValue.Length - 1] == '"') { argValue = argValue.Substring(1, argValue.Length - 2); } extenderArgs.InstanceName = argValue; //Only let this override log path if the log path wasn't already explicitly set if (!logPathSet) { FileTarget baseLogTarget = LogManager.Configuration.FindTargetByName("BaseLog") as FileTarget; if (baseLogTarget != null) { baseLogTarget.FileName = baseLogTarget.FileName.Render(new LogEventInfo { TimeStamp = DateTime.Now }).Replace("NoInstance", argValue); } FileTarget chatLogTarget = LogManager.Configuration.FindTargetByName("ChatLog") as FileTarget; if (chatLogTarget != null) { chatLogTarget.FileName = chatLogTarget.FileName.Render(new LogEventInfo { TimeStamp = DateTime.Now }).Replace("NoInstance", argValue); } FileTarget pluginLogTarget = LogManager.Configuration.FindTargetByName("PluginLog") as FileTarget; if (pluginLogTarget != null) { pluginLogTarget.FileName = pluginLogTarget.FileName.Render(new LogEventInfo { TimeStamp = DateTime.Now }).Replace("NoInstance", argValue); } } } else if (lowerCaseArgument.Equals("gamepath")) { if (argValue[argValue.Length - 1] == '"') { argValue = argValue.Substring(1, argValue.Length - 2); } extenderArgs.GamePath = argValue; } else if (lowerCaseArgument.Equals("autosave")) { if (!int.TryParse(argValue, out extenderArgs.Autosave)) { BaseLog.Warn("Autosave parameter was not a valid integer."); } } else if (lowerCaseArgument.Equals("path")) { if (argValue[argValue.Length - 1] == '"') { argValue = argValue.Substring(1, argValue.Length - 2); } extenderArgs.InstancePath = argValue; } else if (lowerCaseArgument.Equals("instancepath")) { if (argValue[argValue.Length - 1] == '"') { argValue = argValue.Substring(1, argValue.Length - 2); } extenderArgs.InstancePath = argValue; } else if (lowerCaseArgument.Equals("title")) { if (argValue[argValue.Length - 1] == '"') { argValue = argValue.Substring(1, argValue.Length - 2); } extenderArgs.ConsoleTitle = argValue; } else if (lowerCaseArgument == "logpath") { if (argValue[argValue.Length - 1] == '"') { argValue = argValue.Substring(1, argValue.Length - 2); } //This argument always prevails. FileTarget baseLogTarget = LogManager.Configuration.FindTargetByName("BaseLog") as FileTarget; if (baseLogTarget != null) { Layout l = new SimpleLayout(Path.Combine(argValue, "SEServerExtenderLog-${shortdate}.log")); baseLogTarget.FileName = l.Render(new LogEventInfo { TimeStamp = DateTime.Now }); ApplicationLog.BaseLog = BaseLog; } FileTarget chatLogTarget = LogManager.Configuration.FindTargetByName("ChatLog") as FileTarget; if (chatLogTarget != null) { Layout l = new SimpleLayout(Path.Combine(argValue, "ChatLog-${shortdate}.log")); chatLogTarget.FileName = l.Render(new LogEventInfo { TimeStamp = DateTime.Now }); ApplicationLog.ChatLog = ChatLog; } FileTarget pluginLogTarget = LogManager.Configuration.FindTargetByName("PluginLog") as FileTarget; if (pluginLogTarget != null) { Layout l = new SimpleLayout(Path.Combine(argValue, "PluginLog-${shortdate}.log")); pluginLogTarget.FileName = l.Render(new LogEventInfo { TimeStamp = DateTime.Now }); logPathSet = true; ApplicationLog.PluginLog = PluginLog; } } } else { string lowerCaseArgument = arg.ToLower( ); if (lowerCaseArgument.Equals("autostart")) { extenderArgs.AutoStart = true; } else if (lowerCaseArgument.Equals("nogui")) { extenderArgs.NoGui = true; //Implies autostart //extenderArgs.AutoStart = true; } else if (lowerCaseArgument.Equals("noconsole")) { extenderArgs.NoConsole = true; //Implies nogui and autostart extenderArgs.NoGui = true; extenderArgs.AutoStart = true; } else if (lowerCaseArgument.Equals("debug")) { extenderArgs.Debug = true; } else if (lowerCaseArgument.Equals("nowcf")) { extenderArgs.NoWcf = true; } else if (lowerCaseArgument.Equals("closeoncrash")) { extenderArgs.CloseOnCrash = true; } else if (lowerCaseArgument.Equals("autosaveasync")) { extenderArgs.AutoSaveSync = false; } else if (lowerCaseArgument.Equals("autosavesync")) { extenderArgs.AutoSaveSync = true; } else if (lowerCaseArgument.Equals("restartoncrash")) { extenderArgs.RestartOnCrash = true; } else if (lowerCaseArgument.Equals("wrr")) { extenderArgs.WorldRequestReplace = true; } else if (lowerCaseArgument.Equals("wrm")) { extenderArgs.WorldDataModify = true; } else if (lowerCaseArgument.Equals("wvm")) { extenderArgs.WorldVoxelModify = true; } } } if (!Environment.UserInteractive) { extenderArgs.NoConsole = true; extenderArgs.NoGui = true; extenderArgs.AutoStart = true; } if (extenderArgs.Debug) { ExtenderOptions.IsDebugging = true; } try { bool unitTestResult = BasicUnitTestManager.Instance.Run( ); if (!unitTestResult) { ExtenderOptions.IsInSafeMode = true; } Server = Server.Instance; Server.CommandLineArgs = extenderArgs; Server.IsWCFEnabled = !extenderArgs.NoWcf; Server.Init( ); ChatManager.ChatCommand guiCommand = new ChatManager.ChatCommand("gui", ChatCommand_GUI, false); ChatManager.Instance.RegisterChatCommand(guiCommand); if (string.IsNullOrEmpty(extenderArgs.ConsoleTitle) || string.IsNullOrWhiteSpace(extenderArgs.ConsoleTitle)) { Console.Title = "SESE"; } else { Console.Title = extenderArgs.ConsoleTitle; } if (extenderArgs.AutoStart) { Server.StartServer( ); } if (!extenderArgs.NoWcf) { string uriString = string.Format("{0}{1}", ConfigurationManager.AppSettings["WCFServerServiceBaseAddress"], CommandLineArgs.InstanceName); BaseLog.Info("Opening up WCF service listener at {0}", uriString); ServerServiceHost = new ServiceHost(typeof(ServerService.ServerService), new Uri(uriString, UriKind.Absolute)); ServerServiceHost.Open( ); ChatManager.Instance.ChatMessage += ChatManager_ChatMessage; } if (!extenderArgs.NoGui) { Thread uiThread = new Thread(StartGui); uiThread.SetApartmentState(ApartmentState.STA); uiThread.Start( ); } else if (Environment.UserInteractive) { Console.ReadLine( ); } } catch (AutoException eEx) { if (!extenderArgs.NoConsole) { BaseLog.Info("AutoException - {0}\n\r{1}", eEx.AdditionnalInfo, eEx.GetDebugString( )); } if (!extenderArgs.NoGui) { MessageBox.Show(string.Format("{0}\n\r{1}", eEx.AdditionnalInfo, eEx.GetDebugString( )), @"SEServerExtender", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (extenderArgs.NoConsole && extenderArgs.NoGui) { throw eEx.GetBaseException( ); } } catch (TargetInvocationException ex) { if (!extenderArgs.NoConsole) { BaseLog.Info("TargetInvocationException - {0}\n\r{1}", ex, ex.InnerException); } if (!extenderArgs.NoGui) { MessageBox.Show(string.Format("{0}\n\r{1}", ex, ex.InnerException), @"SEServerExtender", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (extenderArgs.NoConsole && extenderArgs.NoGui) { throw; } } catch (Exception ex) { if (!extenderArgs.NoConsole) { BaseLog.Info(ex, "Exception - {0}", ex); } if (!extenderArgs.NoGui) { MessageBox.Show(ex.ToString( ), @"SEServerExtender", MessageBoxButtons.OK, MessageBoxIcon.Error); } if (extenderArgs.NoConsole && extenderArgs.NoGui) { throw; } } }