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

add shortcut for rules in penalty reasons for issue #159

This commit is contained in:
RaidMax
2020-11-18 18:48:24 -06:00
parent 5f912aad7f
commit d067c1d4d5
5 changed files with 238 additions and 26 deletions

View File

@ -18,6 +18,7 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using SharedLibraryCore.Configuration;
using static SharedLibraryCore.Database.Models.EFClient;
using static SharedLibraryCore.Database.Models.EFPenalty;
using static SharedLibraryCore.Server;
@ -997,5 +998,31 @@ namespace SharedLibraryCore
{
return CurrentLocalization.LocalizationIndex[$"META_TYPE_{metaType.ToString().ToUpper()}_NAME"];
}
public static string FindRuleForReason(this string reason, ApplicationConfiguration appConfig, Server server)
{
var regex = Regex.Match(reason, @"(rule|serverrule)(\d+)", RegexOptions.IgnoreCase);
if (!regex.Success)
{
return reason;
}
var serverConfig = appConfig.Servers?
.FirstOrDefault(configServer =>
configServer.IPAddress == server.IP && configServer.Port == server.Port);
var index = int.Parse(regex.Groups[2].ToString()) - 1;
return regex.Groups[1].ToString().ToLower() switch
{
"rule" => appConfig.GlobalRules?.Length > 0 && appConfig.GlobalRules.Length >= index
? appConfig.GlobalRules[index] :
reason,
"serverrule" => serverConfig?.Rules?.Length > 0 && serverConfig.Rules?.Length >= index
? serverConfig.Rules[index] :
reason,
_ => reason
};
}
}
}