From 1a1f62e3a985d3acfe25ac7fc3befd31e1e920eb Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 6 Nov 2017 15:52:56 -0500 Subject: [PATCH] Adds IInstanceConfig --- TGServerService/DeprecatedInstanceConfig.cs | 4 +- TGServerService/InstanceConfig.cs | 206 ++++++++++++------ .../ServerInstance/ServerInstance.cs | 4 +- TGServerService/Service.cs | 22 +- TGServiceTests/Service/TestInstanceConfig.cs | 2 +- 5 files changed, 154 insertions(+), 84 deletions(-) diff --git a/TGServerService/DeprecatedInstanceConfig.cs b/TGServerService/DeprecatedInstanceConfig.cs index 152962fdfa..0c201ae057 100644 --- a/TGServerService/DeprecatedInstanceConfig.cs +++ b/TGServerService/DeprecatedInstanceConfig.cs @@ -16,8 +16,8 @@ namespace TGServerService /// /// Convert the settings version 6 .NET settings file to a config json /// - /// An based off the old .NET setting file - public static InstanceConfig CreateFromNETSettings() + /// An based off the old .NET setting file + public static IInstanceConfig CreateFromNETSettings() { var Config = Properties.Settings.Default; var result = new DeprecatedInstanceConfig(LoadPreviousNetPropertyOrDefault("ServerDirectory", "C:\\tgstation-server-3")); diff --git a/TGServerService/InstanceConfig.cs b/TGServerService/InstanceConfig.cs index 3e2a075a16..7a4892e687 100644 --- a/TGServerService/InstanceConfig.cs +++ b/TGServerService/InstanceConfig.cs @@ -4,117 +4,189 @@ using TGServiceInterface; namespace TGServerService { - class InstanceConfig + /// + /// Configuration settings for a + /// + interface IInstanceConfig + { + /// + /// The directory this is for + /// + string Directory { get; } + + /// + /// Actual version of the . Migrated up via + /// + ulong Version { get; } + + /// + /// The name of the + /// + string Name { get; set; } + + /// + /// If the is active + /// + bool Enabled { get; set; } + + /// + /// The name of the .dme/.dmb the uses + /// + string ProjectName { get; set; } + + /// + /// The port the runs on + /// + ushort Port { get; set; } + + /// + /// The level for the + /// + DreamDaemonSecurity Security { get; set; } + + /// + /// Whether or not the should immediately start DreamDaemon when activated + /// + bool Autostart { get; set; } + + /// + /// Whether or not DreamDaemon allows connections from webclients + /// + bool Webclient { get; set; } + + /// + /// Author and committer name for synchronize commits + /// + string CommitterName { get; set; } + /// + /// Author and committer e-mail for synchronize commits + /// + string CommitterEmail { get; set; } + + /// + /// Encrypted serialized s + /// + string ChatProviderData { get; set; } + + /// + /// Entropy for + /// + string ChatProviderEntropy { get; set; } + + /// + /// If the should reattach to a running DreamDaemon + /// + bool ReattachRequired { get; set; } + + /// + /// The of the runnning DreamDaemon + /// + int ReattachProcessID { get; set; } + + /// + /// The port the runnning DreamDaemon was launched on + /// + ushort ReattachPort { get; set; } + + /// + /// The serviceCommsKey the runnning DreamDaemon was launched on + /// + string ReattachCommsKey { get; set; } + + /// + /// The API version of the runnning DreamDaemon + /// + string ReattachAPIVersion { get; set; } + + /// + /// The user group allowed to use the + /// + string AuthorizedUserGroupSID { get; set; } + + /// + /// The auto update interval for the + /// + ulong AutoUpdateInterval { get; set; } + /// + /// Saves the to it's + /// + void Save(); + } + + /// + class InstanceConfig : IInstanceConfig { /// /// The name the file is saved as in the /// - //tell javascriptserializer to ignore these fields [ScriptIgnore] public const string JSONFilename = "Instance.json"; + /// /// The current version of the config /// [ScriptIgnore] protected const ulong CurrentVersion = 0; //Literally any time you add/deprecated a field, this number needs to be bumped - /// - /// The directory this is for - /// + + /// [ScriptIgnore] public string Directory { get; private set; } - /// - /// Actual version of the . Migrated up via - /// + /// public ulong Version { get; protected set; } = CurrentVersion; - /// - /// The name of the - /// + /// public string Name { get; set; } = "TG Station Server"; - /// - /// If the is active - /// + /// public bool Enabled { get; set; } = true; - /// - /// The name of the .dme/.dmb the uses - /// + /// public string ProjectName { get; set; } = "tgstation"; - /// - /// The port the runs on - /// + /// public ushort Port { get; set; } = 1337; - /// - /// The level for the - /// + /// public DreamDaemonSecurity Security { get; set; } = DreamDaemonSecurity.Trusted; - /// - /// Whether or not the should immediately start DreamDaemon when activated - /// + /// public bool Autostart { get; set; } = false; - /// - /// Whether or not DreamDaemon allows connections from webclients - /// + /// public bool Webclient { get; set; } = false; - /// - /// Author and committer name for synchronize commits - /// + /// public string CommitterName { get; set; } = "tgstation-server"; - /// - /// Author and committer e-mail for synchronize commits - /// + + /// public string CommitterEmail { get; set; } = "tgstation-server@tgstation13.org"; - /// - /// Encrypted serialized s - /// + /// public string ChatProviderData { get; set; } = ServerInstance.UninitializedString; - /// - /// Entropy for - /// + /// public string ChatProviderEntropy { get; set; } - /// - /// If the should reattach to a running DreamDaemon - /// + /// public bool ReattachRequired { get; set; } = false; - /// - /// The of the runnning DreamDaemon - /// + /// public int ReattachProcessID { get; set; } - /// - /// The port the runnning DreamDaemon was launched on - /// + /// public ushort ReattachPort { get; set; } - /// - /// The serviceCommsKey the runnning DreamDaemon was launched on - /// + /// public string ReattachCommsKey { get; set; } - /// - /// The API version of the runnning DreamDaemon - /// + /// public string ReattachAPIVersion { get; set; } - /// - /// The user group allowed to use the - /// + /// public string AuthorizedUserGroupSID { get; set; } = null; - /// - /// The auto update interval for the - /// + /// public ulong AutoUpdateInterval { get; set; } = 0; /// @@ -126,9 +198,7 @@ namespace TGServerService Directory = path; } - /// - /// Saves the to it's - /// + /// public void Save() { var data = new JavaScriptSerializer().Serialize(this); @@ -137,11 +207,11 @@ namespace TGServerService } /// - /// Loads and migrates an from a at + /// Loads and migrates an from a at /// /// The path to the directory - /// The migrated - public static InstanceConfig Load(string path) + /// The migrated + public static IInstanceConfig Load(string path) { var configtext = File.ReadAllText(Path.Combine(path, JSONFilename)); var res = new JavaScriptSerializer().Deserialize(configtext); diff --git a/TGServerService/ServerInstance/ServerInstance.cs b/TGServerService/ServerInstance/ServerInstance.cs index e11f6b8459..ec239dcb80 100644 --- a/TGServerService/ServerInstance/ServerInstance.cs +++ b/TGServerService/ServerInstance/ServerInstance.cs @@ -24,11 +24,11 @@ namespace TGServerService /// /// The configuration settings for the instance /// - readonly InstanceConfig Config; + readonly IInstanceConfig Config; /// /// Constructs and a /// - public ServerInstance(InstanceConfig config, byte logID) + public ServerInstance(IInstanceConfig config, byte logID) { LoggingID = logID; Config = config; diff --git a/TGServerService/Service.cs b/TGServerService/Service.cs index 13b1605af9..c4835b0a66 100644 --- a/TGServerService/Service.cs +++ b/TGServerService/Service.cs @@ -118,10 +118,10 @@ namespace TGServerService } /// - /// Enumerates configured s. Detaches those that fail to load + /// Enumerates configured s. Detaches those that fail to load /// - /// Each configured - IEnumerable GetInstanceConfigs() + /// Each configured + IEnumerable GetInstanceConfigs() { var pathsToRemove = new List(); lock (this) @@ -129,7 +129,7 @@ namespace TGServerService var IPS = Properties.Settings.Default.InstancePaths; foreach (var I in IPS) { - InstanceConfig ic; + IInstanceConfig ic; try { ic = InstanceConfig.Load(I); @@ -319,9 +319,9 @@ namespace TGServerService /// /// Creates and starts a for a at /// - /// The for the + /// The for the /// The inactive on success, on failure - ServiceHost SetupInstance(InstanceConfig config) + ServiceHost SetupInstance(IInstanceConfig config) { ServerInstance instance; string instanceName; @@ -484,7 +484,7 @@ namespace TGServerService foreach (var oic in GetInstanceConfigs()) if (Name == oic.Name) return String.Format("Instance named {0} already exists!", oic.Name); - InstanceConfig ic; + IInstanceConfig ic; try { ic = new InstanceConfig(path) @@ -506,9 +506,9 @@ namespace TGServerService /// /// Starts and onlines an instance located at /// - /// The for the + /// The for the /// on success, error message on failure - string SetupOneInstance(InstanceConfig config) + string SetupOneInstance(IInstanceConfig config) { try { @@ -536,7 +536,7 @@ namespace TGServerService return String.Format("Instance at {0} already exists!", path); if(!Directory.Exists(path)) return String.Format("There is no instance located at {0}!", path); - InstanceConfig ic; + IInstanceConfig ic; try { ic = InstanceConfig.Load(path); @@ -635,7 +635,7 @@ namespace TGServerService lock (this) { //we have to check em all anyway - InstanceConfig the_droid_were_looking_for = null; + IInstanceConfig the_droid_were_looking_for = null; foreach (var ic in GetInstanceConfigs()) if (ic.Name == name) { diff --git a/TGServiceTests/Service/TestInstanceConfig.cs b/TGServiceTests/Service/TestInstanceConfig.cs index 3d49c9a24e..586ccd4990 100644 --- a/TGServiceTests/Service/TestInstanceConfig.cs +++ b/TGServiceTests/Service/TestInstanceConfig.cs @@ -19,7 +19,7 @@ namespace TGServerService.Tests /// Creates a default at /// /// - InstanceConfig CreateTempConfig() + IInstanceConfig CreateTempConfig() { return new InstanceConfig(TempPath); }