1
0
mirror of https://github.com/RaidMax/IW4M-Admin.git synced 2025-06-10 15:20:48 -05:00

add option to normalize diacritics for rcon parsers (applied to T6)

This commit is contained in:
RaidMax
2022-07-06 15:42:31 -05:00
parent 627a27110d
commit 490f37b990
7 changed files with 39 additions and 10 deletions

View File

@ -107,5 +107,9 @@ namespace SharedLibraryCore.Interfaces
ColorCodeMapping ColorCodeMapping { get; }
short FloodProtectInterval { get; }
/// <summary>
/// indicates if diacritics (accented characters) should be normalized
/// </summary>
bool ShouldRemoveDiacritics { get; }
}
}

View File

@ -173,7 +173,7 @@ namespace SharedLibraryCore.Database.Models
?.CorrelationId ?? Guid.NewGuid()
};
e.Output.Add(message.FormatMessageForEngine(CurrentServer?.RconParser.Configuration.ColorCodeMapping)
e.Output.Add(message.FormatMessageForEngine(CurrentServer?.RconParser.Configuration)
.StripColors());
CurrentServer?.Manager.AddEvent(e);

View File

@ -225,7 +225,7 @@ namespace SharedLibraryCore
var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Say ?? "",
$"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message}");
ServerLogger.LogDebug("All-> {Message}",
message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping).StripColors());
message.FormatMessageForEngine(RconParser.Configuration).StripColors());
var e = new GameEvent
{
@ -289,13 +289,13 @@ namespace SharedLibraryCore
else
{
ServerLogger.LogDebug("Tell[{ClientNumber}]->{Message}", targetClient.ClientNumber,
message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping).StripColors());
message.FormatMessageForEngine(RconParser.Configuration).StripColors());
}
if (targetClient.Level == Data.Models.Client.EFClient.Permission.Console)
{
Console.ForegroundColor = ConsoleColor.Green;
var cleanMessage = message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping)
var cleanMessage = message.FormatMessageForEngine(RconParser.Configuration)
.StripColors();
using (LogContext.PushProperty("Server", ToString()))
{

View File

@ -170,10 +170,28 @@ namespace SharedLibraryCore
{
return str.Replace("//", "/ /");
}
public static string FormatMessageForEngine(this string str, ColorCodeMapping mapping)
public static string RemoveDiacritics(this string text)
{
if (mapping == null || string.IsNullOrEmpty(str))
var normalizedString = text.Normalize(NormalizationForm.FormD);
var stringBuilder = new StringBuilder(normalizedString.Length);
foreach (var c in from c in normalizedString
let unicodeCategory = CharUnicodeInfo.GetUnicodeCategory(c)
where unicodeCategory != UnicodeCategory.NonSpacingMark
select c)
{
stringBuilder.Append(c);
}
return stringBuilder
.ToString()
.Normalize(NormalizationForm.FormC);
}
public static string FormatMessageForEngine(this string str, IRConParserConfiguration config)
{
if (config == null || string.IsNullOrEmpty(str))
{
return str;
}
@ -184,7 +202,12 @@ namespace SharedLibraryCore
foreach (var match in colorCodeMatches.Where(m => m.Success))
{
var key = match.Groups[1].ToString();
output = output.Replace(match.Value, mapping.TryGetValue(key, out var code) ? code : "");
output = output.Replace(match.Value, config.ColorCodeMapping.TryGetValue(key, out var code) ? code : "");
}
if (config.ShouldRemoveDiacritics)
{
output = output.RemoveDiacritics();
}
return output.FixIW4ForwardSlash();