fix issue with plugin registration

This commit is contained in:
RaidMax 2022-02-07 22:02:50 -06:00
parent 576d7015fa
commit 07f675eadc
5 changed files with 26 additions and 12 deletions

View File

@ -419,7 +419,7 @@ namespace IW4MAdmin.Application
if (!validationResult.IsValid) if (!validationResult.IsValid)
{ {
throw new ConfigurationException("MANAGER_CONFIGURATION_ERROR") throw new ConfigurationException(_translationLookup["MANAGER_CONFIGURATION_ERROR"])
{ {
Errors = validationResult.Errors.Select(_error => _error.ErrorMessage).ToArray(), Errors = validationResult.Errors.Select(_error => _error.ErrorMessage).ToArray(),
ConfigurationFileName = ConfigHandler.FileName ConfigurationFileName = ConfigHandler.FileName

View File

@ -311,7 +311,10 @@ namespace IW4MAdmin.Application
} }
// register any script plugins // 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 // register any eventable types
foreach (var assemblyType in typeof(Program).Assembly.GetTypes() foreach (var assemblyType in typeof(Program).Assembly.GetTypes()

View File

@ -38,13 +38,13 @@ namespace IW4MAdmin.Application.Misc
/// discovers all the script plugins in the plugins dir /// discovers all the script plugins in the plugins dir
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public IEnumerable<IPlugin> DiscoverScriptPlugins(IServiceProvider serviceProvider) public IEnumerable<Func<IServiceProvider, IPlugin>> DiscoverScriptPlugins()
{ {
var pluginDir = $"{Utilities.OperatingDirectory}{PLUGIN_DIR}{Path.DirectorySeparatorChar}"; var pluginDir = $"{Utilities.OperatingDirectory}{PLUGIN_DIR}{Path.DirectorySeparatorChar}";
if (!Directory.Exists(pluginDir)) if (!Directory.Exists(pluginDir))
{ {
return Enumerable.Empty<IPlugin>(); return Enumerable.Empty<Func<IServiceProvider, IPlugin>>();
} }
var scriptPluginFiles = var scriptPluginFiles =
@ -52,7 +52,7 @@ namespace IW4MAdmin.Application.Misc
_logger.LogDebug("Discovered {count} potential script plugins", scriptPluginFiles.Count); _logger.LogDebug("Discovered {count} potential script plugins", scriptPluginFiles.Count);
return scriptPluginFiles.Select(fileName => return scriptPluginFiles.Select<string, Func<IServiceProvider, IPlugin>>(fileName => serviceProvider =>
{ {
_logger.LogDebug("Discovered script plugin {fileName}", fileName); _logger.LogDebug("Discovered script plugin {fileName}", fileName);
return new ScriptPlugin(_logger, return new ScriptPlugin(_logger,

View File

@ -15,21 +15,28 @@ let plugin = {
author: 'RaidMax', author: 'RaidMax',
version: 1.0, version: 1.0,
name: 'Game Interface', name: 'Game Interface',
enabled: true, // indicates if the plugin is enabled
onEventAsync: (gameEvent, server) => { onEventAsync: (gameEvent, server) => {
const eventType = eventTypes[gameEvent.Type]; const eventType = eventTypes[gameEvent.Type];
if (servers[server.EndPoint] != null && !servers[server.EndPoint].enabled) {
return;
}
switch (eventType) { switch (eventType) {
case 'start': case 'start':
this.enabled = initialize(server); const enabled = initialize(server);
if (!enabled) {
return;
}
break; break;
case 'preconnect': case 'preconnect':
// when the plugin is reloaded after the servers are started // when the plugin is reloaded after the servers are started
if (servers[server.EndPoint] == null) { if (servers[server.EndPoint] == null) {
this.enabled = initialize(server); const enabled = initialize(server);
if (!this.enabled) { if (!enabled) {
return; return;
} }
} }
@ -265,9 +272,12 @@ const initialize = (server) => {
logger.WriteError(`Could not get integration status of ${server.EndPoint} - ${error}`); 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) { if (!enabled) {
servers[server.EndPoint] = {
enabled: false
}
return false; return false;
} }
@ -277,7 +287,8 @@ const initialize = (server) => {
timer.OnTick(() => pollForEvents(server), `GameEventPoller ${server.ToString()}`) timer.OnTick(() => pollForEvents(server), `GameEventPoller ${server.ToString()}`)
servers[server.EndPoint] = { servers[server.EndPoint] = {
timer: timer timer: timer,
enabled: true
} }
try { try {

View File

@ -18,6 +18,6 @@ namespace SharedLibraryCore.Interfaces
/// discovers the script plugins /// discovers the script plugins
/// </summary> /// </summary>
/// <returns>initialized script plugin collection</returns> /// <returns>initialized script plugin collection</returns>
IEnumerable<IPlugin> DiscoverScriptPlugins(IServiceProvider serviceProvider); IEnumerable<Func<IServiceProvider, IPlugin>> DiscoverScriptPlugins();
} }
} }