From fa79f4af73eaf87326c7b0a4a4f78a1229b4a601 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Sat, 30 May 2020 14:06:04 -0500 Subject: [PATCH] fix issue with registering multiple script commands in command configuration --- Application/ApplicationManager.cs | 5 +++-- Application/Extensions/CommandExtensions.cs | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Application/Extensions/CommandExtensions.cs diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index a1b8cd665..6c15459bc 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -1,5 +1,6 @@ using IW4MAdmin.Application.API.Master; using IW4MAdmin.Application.EventParsers; +using IW4MAdmin.Application.Extensions; using IW4MAdmin.Application.Misc; using IW4MAdmin.Application.RconParsers; using SharedLibraryCore; @@ -427,13 +428,13 @@ namespace IW4MAdmin.Application else { - var unsavedCommands = _commands.Where(_cmd => !cmdConfig.Commands.Keys.Contains(_cmd.GetType().Name)); + var unsavedCommands = _commands.Where(_cmd => !cmdConfig.Commands.Keys.Contains(_cmd.CommandConfigNameForType())); commandsToAddToConfig.AddRange(unsavedCommands); } foreach (var cmd in commandsToAddToConfig) { - cmdConfig.Commands.Add(cmd.GetType().Name, + cmdConfig.Commands.Add(cmd.CommandConfigNameForType(), new CommandProperties() { Name = cmd.Name, diff --git a/Application/Extensions/CommandExtensions.cs b/Application/Extensions/CommandExtensions.cs new file mode 100644 index 000000000..ca27dfb30 --- /dev/null +++ b/Application/Extensions/CommandExtensions.cs @@ -0,0 +1,21 @@ +using IW4MAdmin.Application.Misc; +using SharedLibraryCore.Interfaces; +using System.Linq; + +namespace IW4MAdmin.Application.Extensions +{ + public static class CommandExtensions + { + /// + /// determines the command configuration name for given manager command + /// + /// command to determine config name for + /// + public static string CommandConfigNameForType(this IManagerCommand command) + { + return command.GetType() == typeof(ScriptCommand) ? + $"{char.ToUpper(command.Name[0])}{command.Name.Substring(1)}Command" : + command.GetType().Name; + } + } +}