modify rule shortcut to just have 1 list

This commit is contained in:
RaidMax 2021-02-27 09:40:25 -06:00
parent 191a68e7dd
commit db2e1deb2f

View File

@ -1013,7 +1013,7 @@ namespace SharedLibraryCore
return appConfig.PresetPenaltyReasons[reason.ToLower()]; return appConfig.PresetPenaltyReasons[reason.ToLower()];
} }
var regex = Regex.Match(reason, @"(rule|serverrule)(\d+)", RegexOptions.IgnoreCase); var regex = Regex.Match(reason, @"rule(\d+)", RegexOptions.IgnoreCase);
if (!regex.Success) if (!regex.Success)
{ {
return reason; return reason;
@ -1023,18 +1023,20 @@ namespace SharedLibraryCore
.FirstOrDefault(configServer => .FirstOrDefault(configServer =>
configServer.IPAddress == server.IP && configServer.Port == server.Port); configServer.IPAddress == server.IP && configServer.Port == server.Port);
var index = int.Parse(regex.Groups[2].ToString()) - 1; var allRules = appConfig.GlobalRules?.ToList() ?? new List<string>();
if (serverConfig?.Rules != null)
return regex.Groups[1].ToString().ToLower() switch
{ {
"rule" => appConfig.GlobalRules?.Length > 0 && appConfig.GlobalRules.Length >= index allRules.AddRange(serverConfig.Rules);
? appConfig.GlobalRules[index] : }
reason,
"serverrule" => serverConfig?.Rules?.Length > 0 && serverConfig.Rules?.Length >= index var index = int.Parse(regex.Groups[1].ToString()) - 1;
? serverConfig.Rules[index] :
reason, if (!allRules.Any() || index > allRules.Count - 1 || index < 0)
_ => reason {
}; return reason;
}
return allRules[index];
} }
} }
} }