From 07f675eadc315a5dc8063f622ee2ad0be640e84a Mon Sep 17 00:00:00 2001 From: RaidMax Date: Mon, 7 Feb 2022 22:02:50 -0600 Subject: [PATCH] fix issue with plugin registration --- Application/ApplicationManager.cs | 2 +- Application/Main.cs | 5 +++- Application/Misc/PluginImporter.cs | 6 ++--- Plugins/ScriptPlugins/GameInterface.js | 23 ++++++++++++++----- .../Interfaces/IPluginImporter.cs | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index fc72178f0..f3f3b2b6c 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -419,7 +419,7 @@ namespace IW4MAdmin.Application if (!validationResult.IsValid) { - throw new ConfigurationException("MANAGER_CONFIGURATION_ERROR") + throw new ConfigurationException(_translationLookup["MANAGER_CONFIGURATION_ERROR"]) { Errors = validationResult.Errors.Select(_error => _error.ErrorMessage).ToArray(), ConfigurationFileName = ConfigHandler.FileName diff --git a/Application/Main.cs b/Application/Main.cs index 9735172d3..4d5f4bd43 100644 --- a/Application/Main.cs +++ b/Application/Main.cs @@ -311,7 +311,10 @@ namespace IW4MAdmin.Application } // register any script plugins - serviceCollection.AddSingleton(sp => pluginImporter.DiscoverScriptPlugins(sp)); + foreach (var func in pluginImporter.DiscoverScriptPlugins()) + { + serviceCollection.AddSingleton(sp => func(sp)); + } // register any eventable types foreach (var assemblyType in typeof(Program).Assembly.GetTypes() diff --git a/Application/Misc/PluginImporter.cs b/Application/Misc/PluginImporter.cs index 65f9cf868..7bff527af 100644 --- a/Application/Misc/PluginImporter.cs +++ b/Application/Misc/PluginImporter.cs @@ -38,13 +38,13 @@ namespace IW4MAdmin.Application.Misc /// discovers all the script plugins in the plugins dir /// /// - public IEnumerable DiscoverScriptPlugins(IServiceProvider serviceProvider) + public IEnumerable> DiscoverScriptPlugins() { var pluginDir = $"{Utilities.OperatingDirectory}{PLUGIN_DIR}{Path.DirectorySeparatorChar}"; if (!Directory.Exists(pluginDir)) { - return Enumerable.Empty(); + return Enumerable.Empty>(); } var scriptPluginFiles = @@ -52,7 +52,7 @@ namespace IW4MAdmin.Application.Misc _logger.LogDebug("Discovered {count} potential script plugins", scriptPluginFiles.Count); - return scriptPluginFiles.Select(fileName => + return scriptPluginFiles.Select>(fileName => serviceProvider => { _logger.LogDebug("Discovered script plugin {fileName}", fileName); return new ScriptPlugin(_logger, diff --git a/Plugins/ScriptPlugins/GameInterface.js b/Plugins/ScriptPlugins/GameInterface.js index 588c25c14..347ae2976 100644 --- a/Plugins/ScriptPlugins/GameInterface.js +++ b/Plugins/ScriptPlugins/GameInterface.js @@ -15,21 +15,28 @@ let plugin = { author: 'RaidMax', version: 1.0, name: 'Game Interface', - enabled: true, // indicates if the plugin is enabled onEventAsync: (gameEvent, server) => { const eventType = eventTypes[gameEvent.Type]; + if (servers[server.EndPoint] != null && !servers[server.EndPoint].enabled) { + return; + } + switch (eventType) { case 'start': - this.enabled = initialize(server); + const enabled = initialize(server); + + if (!enabled) { + return; + } break; case 'preconnect': // when the plugin is reloaded after the servers are started if (servers[server.EndPoint] == null) { - this.enabled = initialize(server); + const enabled = initialize(server); - if (!this.enabled) { + if (!enabled) { return; } } @@ -265,9 +272,12 @@ const initialize = (server) => { logger.WriteError(`Could not get integration status of ${server.EndPoint} - ${error}`); } - logger.WriteDebug(`GSC Integration enabled = ${enabled}`); + logger.WriteDebug(`GSC Integration enabledGSC Integration enabled = ${enabled}`); if (!enabled) { + servers[server.EndPoint] = { + enabled: false + } return false; } @@ -277,7 +287,8 @@ const initialize = (server) => { timer.OnTick(() => pollForEvents(server), `GameEventPoller ${server.ToString()}`) servers[server.EndPoint] = { - timer: timer + timer: timer, + enabled: true } try { diff --git a/SharedLibraryCore/Interfaces/IPluginImporter.cs b/SharedLibraryCore/Interfaces/IPluginImporter.cs index 1002f0f37..03dd9d856 100644 --- a/SharedLibraryCore/Interfaces/IPluginImporter.cs +++ b/SharedLibraryCore/Interfaces/IPluginImporter.cs @@ -18,6 +18,6 @@ namespace SharedLibraryCore.Interfaces /// discovers the script plugins /// /// initialized script plugin collection - IEnumerable DiscoverScriptPlugins(IServiceProvider serviceProvider); + IEnumerable> DiscoverScriptPlugins(); } }