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)
{
throw new ConfigurationException("MANAGER_CONFIGURATION_ERROR")
throw new ConfigurationException(_translationLookup["MANAGER_CONFIGURATION_ERROR"])
{
Errors = validationResult.Errors.Select(_error => _error.ErrorMessage).ToArray(),
ConfigurationFileName = ConfigHandler.FileName

View File

@ -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()

View File

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

View File

@ -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 {

View File

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