Include a version number in config, to track if it needs automatic migrations.

This commit is contained in:
zontreck 2025-03-07 01:22:25 -07:00
parent 2efa532059
commit a3eee94f7e
3 changed files with 15 additions and 13 deletions

View file

@ -361,8 +361,8 @@ namespace AriasServerUtils
config = API.LoadModConfig<ASUModConfig>(GetConfigurationFile("global", ModConfigType.Global)); config = API.LoadModConfig<ASUModConfig>(GetConfigurationFile("global", ModConfigType.Global));
if (config == null) config = new ASUModConfig(); if (config == null) config = new ASUModConfig();
// Step 2. Check if there are new or missing cooldowns // Step 2. Check if config needs Migrations
config.SanityCheckCooldowns(); config.SanityCheck();
// -> Step 3. Load Mod Warps <- // -> Step 3. Load Mod Warps <-
serverWarps = API.LoadModConfig<Warps>(GetConfigurationFile("warps", ModConfigType.Global)); serverWarps = API.LoadModConfig<Warps>(GetConfigurationFile("warps", ModConfigType.Global));

View file

@ -22,28 +22,24 @@ namespace AriasServerUtils
{ CooldownType.RTP, "30s" }, { CooldownType.RTP, "30s" },
{ CooldownType.Back, "5s" } { CooldownType.Back, "5s" }
}; };
private static readonly int CURRENT_VERSION = 3;
public int Version { get; set; } = 0;
public int MaxHomes { get; set; } = 20; public int MaxHomes { get; set; } = 20;
public bool AdminsBypassMaxHomes { get; set; } = true; public bool AdminsBypassMaxHomes { get; set; } = true;
public bool onlyAdminsCreateWarps { get; set; } = true; public bool onlyAdminsCreateWarps { get; set; } = true;
public int MaxBackCache { get; set; } = 10; public int MaxBackCache { get; set; } = 10;
public int PlayerSleepingPercentage { get; set; } = 50; public int PlayerSleepingPercentage { get; set; } = 50;
public int MaxRTPBlockDistance { get; set; } = 5000; public int MaxRTPBlockDistance { get; set; } = 5000;
public Dictionary<CooldownType, string> Cooldowns { get; set; } = new Dictionary<CooldownType, string> public Dictionary<CooldownType, string> Cooldowns { get; set; } = new Dictionary<CooldownType, string>();
{
{ CooldownType.Home, "5s" },
{ CooldownType.Warp, "10s" },
{ CooldownType.Spawn, "5s" },
{ CooldownType.RTP, "30s" },
{ CooldownType.Back, "5s" }
};
public Dictionary<CooldownType, string> GetDefaultCooldowns() public Dictionary<CooldownType, string> GetDefaultCooldowns()
{ {
return m_defaultCD; return m_defaultCD;
} }
public void SanityCheckCooldowns() public void SanityCheck()
{ {
foreach (var cd in GetDefaultCooldowns()) foreach (var cd in GetDefaultCooldowns())
{ {
@ -53,6 +49,12 @@ namespace AriasServerUtils
ServerUtilities.MarkDirty(); ServerUtilities.MarkDirty();
} }
} }
if (Version < CURRENT_VERSION)
{
Version = CURRENT_VERSION;
ServerUtilities.MarkDirty(); // This is here to ensure that the config gets saved when there is a update. Whenever a new field is added to config, the CURRENT_VERSION should get bumped so that this SanityCheck can properly work
}
} }

View file

@ -3,8 +3,8 @@
"modid": "ariasserverutils", "modid": "ariasserverutils",
"name": "Aria's Server Utilities", "name": "Aria's Server Utilities",
"authors": ["zontreck"], "authors": ["zontreck"],
"description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:17 AM MST", "description": "A collection of server utilities\n\nBuild Date: 03-07-2025 @ 1:21 AM MST",
"version": "1.0.5-dev.3", "version": "1.0.5-dev.4",
"dependencies": { "dependencies": {
"game": "" "game": ""
} }