From 31ee71260a0bffaf0b80cd0759e770c35f6382ec Mon Sep 17 00:00:00 2001 From: RaidMax Date: Fri, 9 Jul 2021 16:50:33 -0500 Subject: [PATCH] use default settings for maps and quick messages config (remove from IW4MAdminSettings) --- Application/ApplicationManager.cs | 16 +++++++-- Application/DefaultSettings.json | 4 +-- Application/IW4MServer.cs | 10 ++++-- Application/Main.cs | 3 ++ .../Stats/Helpers/ChatResourceQueryHelper.cs | 34 ++++++++++--------- .../Configuration/ApplicationConfiguration.cs | 4 +++ SharedLibraryCore/Server.cs | 11 ------ 7 files changed, 48 insertions(+), 34 deletions(-) diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index 1a8e23b94..d1e14029c 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -353,9 +353,7 @@ namespace IW4MAdmin.Application _appConfig.AutoMessages = defaultConfig.AutoMessages; _appConfig.GlobalRules = defaultConfig.GlobalRules; - _appConfig.Maps = defaultConfig.Maps; _appConfig.DisallowedClientNames = defaultConfig.DisallowedClientNames; - _appConfig.QuickMessages = defaultConfig.QuickMessages; //if (newConfig.Servers == null) { @@ -396,6 +394,18 @@ namespace IW4MAdmin.Application await ConfigHandler.Save(); } +#pragma warning disable 618 + if (_appConfig.Maps != null) + { + _appConfig.Maps = null; + } + + if (_appConfig.QuickMessages != null) + { + _appConfig.QuickMessages = null; + } +#pragma warning restore 618 + var validator = new ApplicationConfigurationValidator(); var validationResult = validator.Validate(_appConfig); @@ -410,7 +420,7 @@ namespace IW4MAdmin.Application foreach (var serverConfig in _appConfig.Servers) { - Migration.ConfigurationMigration.ModifyLogPath020919(serverConfig); + ConfigurationMigration.ModifyLogPath020919(serverConfig); if (serverConfig.RConParserVersion == null || serverConfig.EventParserVersion == null) { diff --git a/Application/DefaultSettings.json b/Application/DefaultSettings.json index 1678015ec..01fa47114 100644 --- a/Application/DefaultSettings.json +++ b/Application/DefaultSettings.json @@ -435,8 +435,8 @@ "Name": "oilrig" }, { - "Name": "Village", - "Alias": "co_hunted" + "Alias": "Village", + "Name": "co_hunted" } ] }, diff --git a/Application/IW4MServer.cs b/Application/IW4MServer.cs index 93d172a36..ed4a128b6 100644 --- a/Application/IW4MServer.cs +++ b/Application/IW4MServer.cs @@ -613,7 +613,7 @@ namespace IW4MAdmin { try { - message = Manager.GetApplicationSettings().Configuration() + message = _serviceProvider.GetRequiredService() .QuickMessages .First(_qm => _qm.Game == GameName) .Messages[E.Data.Substring(1)]; @@ -1138,8 +1138,14 @@ namespace IW4MAdmin { Manager.GetApplicationSettings().Configuration().ContactUri = Website; } + + var defaultConfig = _serviceProvider.GetRequiredService(); + var gameMaps = defaultConfig?.Maps?.FirstOrDefault(map => map.Game == GameName); - InitializeMaps(); + if (gameMaps != null) + { + Maps.AddRange(gameMaps.Maps); + } WorkingDirectory = basepath.Value; this.Hostname = hostname; diff --git a/Application/Main.cs b/Application/Main.cs index fdb2f502c..6f328e8da 100644 --- a/Application/Main.cs +++ b/Application/Main.cs @@ -333,6 +333,8 @@ namespace IW4MAdmin.Application // setup the static resources (config/master api/translations) var serviceCollection = new ServiceCollection(); var appConfigHandler = new BaseConfigurationHandler("IW4MAdminSettings"); + var defaultConfigHandler = new BaseConfigurationHandler("DefaultSettings"); + var defaultConfig = defaultConfigHandler.Configuration(); var appConfig = appConfigHandler.Configuration(); var masterUri = Utilities.IsDevelopment ? new Uri("http://127.0.0.1:8080") @@ -361,6 +363,7 @@ namespace IW4MAdmin.Application serviceCollection .AddBaseLogger(appConfig) + .AddSingleton(defaultConfig) .AddSingleton(_serviceProvider => serviceCollection) .AddSingleton, BaseConfigurationHandler>() .AddSingleton((IConfigurationHandler) appConfigHandler) diff --git a/Plugins/Stats/Helpers/ChatResourceQueryHelper.cs b/Plugins/Stats/Helpers/ChatResourceQueryHelper.cs index 4b871906b..a3bb26813 100644 --- a/Plugins/Stats/Helpers/ChatResourceQueryHelper.cs +++ b/Plugins/Stats/Helpers/ChatResourceQueryHelper.cs @@ -24,14 +24,14 @@ namespace Stats.Helpers { private readonly IDatabaseContextFactory _contextFactory; private readonly ILogger _logger; - private readonly ApplicationConfiguration _appConfig; + private readonly DefaultSettings _defaultSettings; private List serverCache; - public ChatResourceQueryHelper(ILogger logger, IDatabaseContextFactory contextFactory, ApplicationConfiguration appConfig) + public ChatResourceQueryHelper(ILogger logger, IDatabaseContextFactory contextFactory, DefaultSettings defaultSettings) { _contextFactory = contextFactory; _logger = logger; - _appConfig = appConfig; + _defaultSettings = defaultSettings; } /// @@ -106,20 +106,22 @@ namespace Stats.Helpers { message.IsHidden = serverCache.Any(server => server.ServerId == message.ServerId && server.IsPasswordProtected); - if (message.Message.IsQuickMessage()) + if (!message.Message.IsQuickMessage()) { - try - { - var quickMessages = _appConfig - .QuickMessages - .First(_qm => _qm.Game == message.GameName); - message.Message = quickMessages.Messages[message.Message.Substring(1)]; - message.IsQuickMessage = true; - } - catch - { - message.Message = message.Message.Substring(1); - } + continue; + } + + try + { + var quickMessages = _defaultSettings + .QuickMessages + .First(_qm => _qm.Game == message.GameName); + message.Message = quickMessages.Messages[message.Message.Substring(1)]; + message.IsQuickMessage = true; + } + catch + { + message.Message = message.Message.Substring(1); } } diff --git a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs index 0f4d667b2..450090a9e 100644 --- a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs +++ b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; +using Newtonsoft.Json; using static Data.Models.Client.EFClient; namespace SharedLibraryCore.Configuration @@ -149,10 +150,13 @@ namespace SharedLibraryCore.Configuration [ConfigurationIgnore] public int MinimumNameLength { get; set; } = 3; [ConfigurationIgnore] public string Id { get; set; } [ConfigurationIgnore] public string SubscriptionId { get; set; } + [Obsolete("Moved to DefaultSettings")] [ConfigurationIgnore] public MapConfiguration[] Maps { get; set; } + [Obsolete("Moved to DefaultSettings")] [ConfigurationIgnore] public QuickMessageConfiguration[] QuickMessages { get; set; } [ConfigurationIgnore] + [JsonIgnore] public string WebfrontUrl => string.IsNullOrEmpty(ManualWebfrontUrl) ? WebfrontBindUrl?.Replace("0.0.0.0", "127.0.0.1") : ManualWebfrontUrl; diff --git a/SharedLibraryCore/Server.cs b/SharedLibraryCore/Server.cs index a0336c318..02907d5ec 100644 --- a/SharedLibraryCore/Server.cs +++ b/SharedLibraryCore/Server.cs @@ -251,17 +251,6 @@ namespace SharedLibraryCore /// abstract public void InitializeTokens(); - /// - /// Read the map configuration - /// - protected void InitializeMaps() - { - Maps = new List(); - var gameMaps = Manager.GetApplicationSettings().Configuration().Maps.FirstOrDefault(m => m.Game == GameName); - if (gameMaps != null) - Maps.AddRange(gameMaps.Maps); - } - /// /// Initialize the messages to be broadcasted ///