2022-02-18 01:56:12 +00:00
|
|
|
|
using System.Net;
|
2022-02-18 02:39:48 +00:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Converters;
|
|
|
|
|
using Newtonsoft.Json.Serialization;
|
2022-02-18 01:56:12 +00:00
|
|
|
|
using Shared;
|
|
|
|
|
|
2022-02-18 02:39:48 +00:00
|
|
|
|
namespace Server;
|
2022-02-18 01:56:12 +00:00
|
|
|
|
|
|
|
|
|
public class Settings {
|
|
|
|
|
public static Settings Instance = new Settings();
|
|
|
|
|
private static readonly Logger Logger = new Logger("Settings");
|
2022-02-18 02:39:48 +00:00
|
|
|
|
|
2022-02-18 01:56:12 +00:00
|
|
|
|
static Settings() {
|
|
|
|
|
LoadSettings();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void LoadSettings() {
|
2022-02-18 02:39:48 +00:00
|
|
|
|
if (File.Exists("settings.json")) {
|
|
|
|
|
string text = File.ReadAllText("settings.json");
|
|
|
|
|
try {
|
|
|
|
|
Instance = JsonConvert.DeserializeObject<Settings>(text, new StringEnumConverter(new CamelCaseNamingStrategy())) ?? Instance;
|
|
|
|
|
Logger.Info("Loaded settings from settings.json");
|
2022-03-01 21:08:53 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
2022-02-18 02:39:48 +00:00
|
|
|
|
Logger.Warn($"Failed to load settings.json: {e}");
|
|
|
|
|
}
|
2022-02-18 01:56:12 +00:00
|
|
|
|
} else {
|
|
|
|
|
SaveSettings();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-18 02:39:48 +00:00
|
|
|
|
public static void SaveSettings() {
|
2022-02-18 01:56:12 +00:00
|
|
|
|
try {
|
2022-02-18 02:39:48 +00:00
|
|
|
|
File.WriteAllText("settings.json", JsonConvert.SerializeObject(Instance, Formatting.Indented, new StringEnumConverter(new CamelCaseNamingStrategy())));
|
|
|
|
|
Logger.Info("Saved settings to settings.json");
|
2022-03-01 21:08:53 +00:00
|
|
|
|
}
|
|
|
|
|
catch (Exception e) {
|
2022-02-18 02:39:48 +00:00
|
|
|
|
Logger.Error($"Failed to save settings.json {e}");
|
2022-02-18 01:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ServerTable Server { get; set; } = new ServerTable();
|
|
|
|
|
public FlipTable Flip { get; set; } = new FlipTable();
|
2022-03-01 21:08:53 +00:00
|
|
|
|
public ScenarioTable Scenario { get; set; } = new ScenarioTable();
|
2022-02-18 01:56:12 +00:00
|
|
|
|
|
|
|
|
|
public class ServerTable {
|
|
|
|
|
public string Address { get; set; } = IPAddress.Any.ToString();
|
|
|
|
|
public ushort Port { get; set; } = 1027;
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 21:08:53 +00:00
|
|
|
|
public class ScenarioTable {
|
|
|
|
|
public bool MergeEnabled { get; set; } = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-18 01:56:12 +00:00
|
|
|
|
public class FlipTable {
|
|
|
|
|
public List<Guid> Players { get; set; } = new List<Guid>();
|
2022-03-06 23:32:49 +00:00
|
|
|
|
public bool Enabled { get; set; } = true;
|
2022-02-18 01:56:12 +00:00
|
|
|
|
public FlipOptions Pov { get; set; } = FlipOptions.Both;
|
|
|
|
|
}
|
|
|
|
|
}
|