1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-09 14:47:59 -05:00

support for loading minimum permission level from config for script commands

This commit is contained in:
RaidMax 2024-07-14 11:21:47 -05:00
parent a34ac7d224
commit 95523885b8
No known key found for this signature in database
GPG Key ID: 97D1158CFCDAF9B2
3 changed files with 35 additions and 22 deletions

View File

@ -10,23 +10,12 @@ namespace IW4MAdmin.Application.Extensions
{ {
public static class CommandExtensions public static class CommandExtensions
{ {
/// <summary>
/// determines the command configuration name for given manager command
/// </summary>
/// <param name="command">command to determine config name for</param>
/// <returns></returns>
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<Map> FindMap(this Server server, string mapName) => server.Maps.Where(map => public static IList<Map> FindMap(this Server server, string mapName) => server.Maps.Where(map =>
map.Name.Equals(mapName, StringComparison.InvariantCultureIgnoreCase) || map.Name.Equals(mapName, StringComparison.InvariantCultureIgnoreCase) ||
map.Alias.Equals(mapName, StringComparison.InvariantCultureIgnoreCase)).ToList(); map.Alias.Equals(mapName, StringComparison.InvariantCultureIgnoreCase)).ToList();
public static IList<Gametype> FindGametype(this DefaultSettings settings, string gameType, Server.Game? game = null) => public static IList<Gametype> FindGametype(this DefaultSettings settings, string gameType,
Server.Game? game = null) =>
settings.Gametypes?.Where(gt => game == null || gt.Game == game) settings.Gametypes?.Where(gt => game == null || gt.Game == game)
.SelectMany(gt => gt.Gametypes).Where(gt => .SelectMany(gt => gt.Gametypes).Where(gt =>
gt.Alias.Contains(gameType, StringComparison.CurrentCultureIgnoreCase) || gt.Alias.Contains(gameType, StringComparison.CurrentCultureIgnoreCase) ||

View File

@ -112,15 +112,25 @@ namespace SharedLibraryCore
get => permission; get => permission;
protected set protected set
{ {
try if (_config is null)
{
permission = _config?.Commands[GetType().Name].MinimumPermission ?? value;
}
catch (KeyNotFoundException)
{ {
permission = value; 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;
} }
} }

View File

@ -1,4 +1,6 @@
namespace SharedLibraryCore.Commands using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore.Commands
{ {
public static class CommandExtensions public static class CommandExtensions
{ {
@ -11,5 +13,17 @@
{ {
return gameEvent.Origin?.Level > gameEvent.Target?.Level; return gameEvent.Origin?.Level > gameEvent.Target?.Level;
} }
/// <summary>
/// determines the command configuration name for given manager command
/// </summary>
/// <param name="command">command to determine config name for</param>
/// <returns></returns>
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;
}
} }
} }