diff --git a/Application/Extensions/CommandExtensions.cs b/Application/Extensions/CommandExtensions.cs index d2681363..b99f5840 100644 --- a/Application/Extensions/CommandExtensions.cs +++ b/Application/Extensions/CommandExtensions.cs @@ -10,23 +10,12 @@ 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; - } - public static IList FindMap(this Server server, string mapName) => server.Maps.Where(map => map.Name.Equals(mapName, StringComparison.InvariantCultureIgnoreCase) || map.Alias.Equals(mapName, StringComparison.InvariantCultureIgnoreCase)).ToList(); - public static IList FindGametype(this DefaultSettings settings, string gameType, Server.Game? game = null) => + public static IList FindGametype(this DefaultSettings settings, string gameType, + Server.Game? game = null) => settings.Gametypes?.Where(gt => game == null || gt.Game == game) .SelectMany(gt => gt.Gametypes).Where(gt => gt.Alias.Contains(gameType, StringComparison.CurrentCultureIgnoreCase) || diff --git a/SharedLibraryCore/Command.cs b/SharedLibraryCore/Command.cs index ef72b036..6164c54a 100644 --- a/SharedLibraryCore/Command.cs +++ b/SharedLibraryCore/Command.cs @@ -112,15 +112,25 @@ namespace SharedLibraryCore get => permission; protected set { - try - { - permission = _config?.Commands[GetType().Name].MinimumPermission ?? value; - } - - catch (KeyNotFoundException) + if (_config is null) { permission = value; + return; } + + if (_config.Commands.TryGetValue(GetType().Name, out var byClassName)) + { + permission = byClassName.MinimumPermission; + return; + } + + if (_config.Commands.TryGetValue(this.CommandConfigNameForType(), out var byCommandName)) + { + permission = byCommandName.MinimumPermission; + return; + } + + permission = value; } } @@ -149,4 +159,4 @@ namespace SharedLibraryCore public bool IsBroadcast { get; set; } } -} \ No newline at end of file +} diff --git a/SharedLibraryCore/Commands/CommandExtensions.cs b/SharedLibraryCore/Commands/CommandExtensions.cs index 33977b6d..f4308912 100644 --- a/SharedLibraryCore/Commands/CommandExtensions.cs +++ b/SharedLibraryCore/Commands/CommandExtensions.cs @@ -1,4 +1,6 @@ -namespace SharedLibraryCore.Commands +using SharedLibraryCore.Interfaces; + +namespace SharedLibraryCore.Commands { public static class CommandExtensions { @@ -11,5 +13,17 @@ { return gameEvent.Origin?.Level > gameEvent.Target?.Level; } + + /// + /// 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().Name is "ScriptCommand" + ? $"{char.ToUpper(command.Name[0])}{command.Name[1..]}Command" + : command.GetType().Name; + } } -} \ No newline at end of file +}