using System.IO;
using System.Web.Script.Serialization;
using TGServiceInterface;
namespace TGServerService
{
///
/// Configuration settings for a
///
public 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; }
///
/// Whether or not testmerge commits are published to a temporary remote branch
///
bool PushTestmergeCommits { get; set; }
///
/// Saves the to it's
///
void Save();
}
///
class InstanceConfig : IInstanceConfig
{
///
/// The name the file is saved as in the
///
[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
///
[ScriptIgnore]
public string Directory { get; private set; }
///
public ulong Version { get; protected set; } = CurrentVersion;
///
public string Name { get; set; } = "TG Station Server";
///
public bool Enabled { get; set; } = true;
///
public string ProjectName { get; set; } = "tgstation";
///
public ushort Port { get; set; } = 1337;
///
public DreamDaemonSecurity Security { get; set; } = DreamDaemonSecurity.Trusted;
///
public bool Autostart { get; set; } = false;
///
public bool Webclient { get; set; } = false;
///
public string CommitterName { get; set; } = "tgstation-server";
///
public string CommitterEmail { get; set; } = "tgstation-server@tgstation13.org";
///
public string ChatProviderData { get; set; } = ServerInstance.UninitializedString;
///
public string ChatProviderEntropy { get; set; }
///
public bool ReattachRequired { get; set; } = false;
///
public int ReattachProcessID { get; set; }
///
public ushort ReattachPort { get; set; }
///
public string ReattachCommsKey { get; set; }
///
public string ReattachAPIVersion { get; set; }
///
public string AuthorizedUserGroupSID { get; set; } = null;
///
public ulong AutoUpdateInterval { get; set; } = 0;
///
public bool PushTestmergeCommits { get; set; } = false;
///
/// Construct a for a at
///
/// The path to the
public InstanceConfig(string path)
{
Directory = path;
}
///
public void Save()
{
var data = new JavaScriptSerializer().Serialize(this);
var path = Path.Combine(Directory, JSONFilename);
File.WriteAllText(path, data);
}
///
/// Loads and migrates an from a at
///
/// The path to the directory
/// The migrated
public static IInstanceConfig Load(string path)
{
var configtext = File.ReadAllText(Path.Combine(path, JSONFilename));
var res = new JavaScriptSerializer().Deserialize(configtext);
res.Directory = path;
res.MigrateToCurrentVersion();
return res;
}
}
}