fix issue with plugin registration
This commit is contained in:
parent
576d7015fa
commit
07f675eadc
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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,
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user