From 18fb3b5b16a2db2929e785c4352ded8f70265342 Mon Sep 17 00:00:00 2001 From: CWX Date: Fri, 25 Apr 2025 13:49:41 +0100 Subject: [PATCH] Make Loaded configs static --- .../Servers/ConfigServer.cs | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Libraries/SPTarkov.Server.Core/Servers/ConfigServer.cs b/Libraries/SPTarkov.Server.Core/Servers/ConfigServer.cs index 888c5b38..106513ed 100644 --- a/Libraries/SPTarkov.Server.Core/Servers/ConfigServer.cs +++ b/Libraries/SPTarkov.Server.Core/Servers/ConfigServer.cs @@ -1,4 +1,5 @@ using SPTarkov.Common.Annotations; +using SPTarkov.Server.Core.Models.Eft.Common; using SPTarkov.Server.Core.Models.Enums; using SPTarkov.Server.Core.Models.Spt.Config; using SPTarkov.Server.Core.Models.Utils; @@ -10,11 +11,11 @@ namespace SPTarkov.Server.Core.Servers; [Injectable(InjectionType.Singleton)] public class ConfigServer { - protected static readonly string[] acceptableFileExtensions = ["json", "jsonc"]; + protected readonly string[] acceptableFileExtensions = ["json", "jsonc"]; protected FileUtil _fileUtil; protected JsonUtil _jsonUtil; protected ISptLogger _logger; - protected Dictionary configs = new(); + private static Dictionary _configs = new(); public ConfigServer( ISptLogger logger, @@ -25,18 +26,22 @@ public class ConfigServer _logger = logger; _jsonUtil = jsonUtil; _fileUtil = fileUtil; - Initialize(); + + if (_configs.Count == 0) + { + Initialize(); + } } public T GetConfig() where T : BaseConfig { var configKey = GetConfigKey(typeof(T)); - if (!configs.ContainsKey(configKey.GetValue())) + if (!_configs.ContainsKey(configKey.GetValue())) { throw new Exception($"Config: {configKey} is undefined. Ensure you have not broken it via editing"); } - return configs[configKey.GetValue()] as T; + return _configs[configKey.GetValue()] as T; } private ConfigTypes GetConfigKey(Type type) @@ -52,7 +57,7 @@ public class ConfigServer public T GetConfigByString(string configType) where T : BaseConfig { - return configs[configType] as T; + return _configs[configType] as T; } public void Initialize() @@ -80,18 +85,9 @@ public class ConfigServer throw new Exception($"Server will not run until the: {file} config error mentioned above is fixed"); } - configs[$"spt-{_fileUtil.StripExtension(file)}"] = deserializedContent; + _configs[$"spt-{_fileUtil.StripExtension(file)}"] = deserializedContent; } } - - /** TODO: deal with this: - this.logger.info(`Commit hash: { - globalThis.G_COMMIT || "DEBUG" - }`); - this.logger.info(`Build date: { - globalThis.G_BUILDTIME || "DEBUG" - }`); - **/ } private Type GetConfigTypeByFilename(string filename)