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-06-13 00:48:24 +00:00
|
|
|
|
public static Action? LoadHandler;
|
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
|
|
|
|
}
|
2022-06-13 00:48:24 +00:00
|
|
|
|
SaveSettings();
|
|
|
|
|
LoadHandler?.Invoke();
|
2022-02-18 01:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
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-05-31 21:48:57 +00:00
|
|
|
|
public BannedPlayers BanList { get; set; } = new BannedPlayers();
|
2022-06-13 00:48:24 +00:00
|
|
|
|
public DiscordTable Discord { get; set; } = new DiscordTable();
|
2022-08-21 05:31:31 +00:00
|
|
|
|
public ShineTable Shines { get; set; } = new ShineTable();
|
2022-07-22 16:39:41 +00:00
|
|
|
|
public PersistShinesTable PersistShines { get; set; } = new PersistShinesTable();
|
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-05-08 22:04:57 +00:00
|
|
|
|
public ushort MaxPlayers { get; set; } = 8;
|
2022-02-18 01:56:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-03-01 21:08:53 +00:00
|
|
|
|
public class ScenarioTable {
|
|
|
|
|
public bool MergeEnabled { get; set; } = false;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-31 21:48:57 +00:00
|
|
|
|
public class BannedPlayers {
|
2022-03-15 21:02:27 +00:00
|
|
|
|
public bool Enabled { get; set; } = false;
|
2022-05-31 21:48:57 +00:00
|
|
|
|
public List<Guid> Players { get; set; } = new List<Guid>();
|
|
|
|
|
public List<string> IpAddresses { get; set; } = new List<string>();
|
2022-03-15 21:02:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-18 01:56:12 +00:00
|
|
|
|
public class FlipTable {
|
2022-03-06 23:32:49 +00:00
|
|
|
|
public bool Enabled { get; set; } = true;
|
2022-05-31 21:48:57 +00:00
|
|
|
|
public List<Guid> Players { get; set; } = new List<Guid>();
|
2022-02-18 01:56:12 +00:00
|
|
|
|
public FlipOptions Pov { get; set; } = FlipOptions.Both;
|
|
|
|
|
}
|
2022-06-13 00:48:24 +00:00
|
|
|
|
|
|
|
|
|
public class DiscordTable {
|
|
|
|
|
public string? Token { get; set; }
|
|
|
|
|
public string Prefix { get; set; } = "$";
|
2022-08-22 22:57:49 +00:00
|
|
|
|
public string? CommandChannel { get; set; }
|
2022-06-13 00:48:24 +00:00
|
|
|
|
public string? LogChannel { get; set; }
|
|
|
|
|
}
|
2022-07-22 16:39:41 +00:00
|
|
|
|
|
2022-08-21 05:31:31 +00:00
|
|
|
|
public class ShineTable {
|
|
|
|
|
public bool Enabled { get; set; } = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class PersistShinesTable
|
|
|
|
|
{
|
|
|
|
|
public bool Enabled { get; set; } = false;
|
|
|
|
|
public string Filename { get; set; } = "./moons.json";
|
2022-07-22 16:39:41 +00:00
|
|
|
|
}
|
2022-02-18 01:56:12 +00:00
|
|
|
|
}
|