add option to normalize diacritics for rcon parsers (applied to T6)
This commit is contained in:
parent
5db94723aa
commit
88e67747fe
@ -82,7 +82,7 @@ namespace IW4MAdmin.Application.RConParsers
|
|||||||
|
|
||||||
public async Task<string[]> ExecuteCommandAsync(IRConConnection connection, string command, CancellationToken token = default)
|
public async Task<string[]> ExecuteCommandAsync(IRConConnection connection, string command, CancellationToken token = default)
|
||||||
{
|
{
|
||||||
command = command.FormatMessageForEngine(Configuration?.ColorCodeMapping);
|
command = command.FormatMessageForEngine(Configuration);
|
||||||
var response = await connection.SendQueryAsync(StaticHelpers.QueryType.COMMAND, command, token);
|
var response = await connection.SendQueryAsync(StaticHelpers.QueryType.COMMAND, command, token);
|
||||||
return response.Where(item => item != Configuration.CommandPrefixes.RConResponse).ToArray();
|
return response.Where(item => item != Configuration.CommandPrefixes.RConResponse).ToArray();
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ namespace IW4MAdmin.Application.RConParsers
|
|||||||
public int? DefaultRConPort { get; set; }
|
public int? DefaultRConPort { get; set; }
|
||||||
public string DefaultInstallationDirectoryHint { get; set; }
|
public string DefaultInstallationDirectoryHint { get; set; }
|
||||||
public short FloodProtectInterval { get; set; } = 750;
|
public short FloodProtectInterval { get; set; } = 750;
|
||||||
|
public bool ShouldRemoveDiacritics { get; set; }
|
||||||
|
|
||||||
public ColorCodeMapping ColorCodeMapping { get; set; } = new ColorCodeMapping
|
public ColorCodeMapping ColorCodeMapping { get; set; } = new ColorCodeMapping
|
||||||
{
|
{
|
||||||
|
@ -3,7 +3,7 @@ var eventParser;
|
|||||||
|
|
||||||
var plugin = {
|
var plugin = {
|
||||||
author: 'RaidMax, Xerxes',
|
author: 'RaidMax, Xerxes',
|
||||||
version: 1.2,
|
version: 1.3,
|
||||||
name: 'Plutonium T6 Parser',
|
name: 'Plutonium T6 Parser',
|
||||||
isParser: true,
|
isParser: true,
|
||||||
|
|
||||||
@ -29,6 +29,7 @@ var plugin = {
|
|||||||
rconParser.Configuration.NoticeLineSeparator = '. ';
|
rconParser.Configuration.NoticeLineSeparator = '. ';
|
||||||
rconParser.Configuration.DefaultRConPort = 4976;
|
rconParser.Configuration.DefaultRConPort = 4976;
|
||||||
rconParser.Configuration.DefaultInstallationDirectoryHint = '{LocalAppData}/Plutonium/storage/t6';
|
rconParser.Configuration.DefaultInstallationDirectoryHint = '{LocalAppData}/Plutonium/storage/t6';
|
||||||
|
rconParser.Configuration.ShouldRemoveDiacritics = true;
|
||||||
|
|
||||||
rconParser.Configuration.StatusHeader.Pattern = 'num +score +bot +ping +guid +name +lastmsg +address +qport +rate *';
|
rconParser.Configuration.StatusHeader.Pattern = 'num +score +bot +ping +guid +name +lastmsg +address +qport +rate *';
|
||||||
rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +([0-9]+) +(?:[0-1]{1}) +([0-9]+) +([A-F0-9]+|0) +(.+?) +(?:[0-9]+) +(\\d+\\.\\d+\\.\\d+\\.\\d+\\:-?\\d{1,5}|0+\\.0+:-?\\d{1,5}|loopback) +(?:-?[0-9]+) +(?:[0-9]+) *$';
|
rconParser.Configuration.Status.Pattern = '^ *([0-9]+) +([0-9]+) +(?:[0-1]{1}) +([0-9]+) +([A-F0-9]+|0) +(.+?) +(?:[0-9]+) +(\\d+\\.\\d+\\.\\d+\\.\\d+\\:-?\\d{1,5}|0+\\.0+:-?\\d{1,5}|loopback) +(?:-?[0-9]+) +(?:[0-9]+) *$';
|
||||||
|
@ -107,5 +107,9 @@ namespace SharedLibraryCore.Interfaces
|
|||||||
ColorCodeMapping ColorCodeMapping { get; }
|
ColorCodeMapping ColorCodeMapping { get; }
|
||||||
|
|
||||||
short FloodProtectInterval { get; }
|
short FloodProtectInterval { get; }
|
||||||
|
/// <summary>
|
||||||
|
/// indicates if diacritics (accented characters) should be normalized
|
||||||
|
/// </summary>
|
||||||
|
bool ShouldRemoveDiacritics { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ namespace SharedLibraryCore.Database.Models
|
|||||||
?.CorrelationId ?? Guid.NewGuid()
|
?.CorrelationId ?? Guid.NewGuid()
|
||||||
};
|
};
|
||||||
|
|
||||||
e.Output.Add(message.FormatMessageForEngine(CurrentServer?.RconParser.Configuration.ColorCodeMapping)
|
e.Output.Add(message.FormatMessageForEngine(CurrentServer?.RconParser.Configuration)
|
||||||
.StripColors());
|
.StripColors());
|
||||||
|
|
||||||
CurrentServer?.Manager.AddEvent(e);
|
CurrentServer?.Manager.AddEvent(e);
|
||||||
|
@ -225,7 +225,7 @@ namespace SharedLibraryCore
|
|||||||
var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Say ?? "",
|
var formattedMessage = string.Format(RconParser.Configuration.CommandPrefixes.Say ?? "",
|
||||||
$"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message}");
|
$"{(CustomSayEnabled && GameName == Game.IW4 ? $"{CustomSayName}: " : "")}{message}");
|
||||||
ServerLogger.LogDebug("All-> {Message}",
|
ServerLogger.LogDebug("All-> {Message}",
|
||||||
message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping).StripColors());
|
message.FormatMessageForEngine(RconParser.Configuration).StripColors());
|
||||||
|
|
||||||
var e = new GameEvent
|
var e = new GameEvent
|
||||||
{
|
{
|
||||||
@ -289,13 +289,13 @@ namespace SharedLibraryCore
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
ServerLogger.LogDebug("Tell[{ClientNumber}]->{Message}", targetClient.ClientNumber,
|
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)
|
if (targetClient.Level == Data.Models.Client.EFClient.Permission.Console)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
var cleanMessage = message.FormatMessageForEngine(RconParser.Configuration.ColorCodeMapping)
|
var cleanMessage = message.FormatMessageForEngine(RconParser.Configuration)
|
||||||
.StripColors();
|
.StripColors();
|
||||||
using (LogContext.PushProperty("Server", ToString()))
|
using (LogContext.PushProperty("Server", ToString()))
|
||||||
{
|
{
|
||||||
|
@ -171,9 +171,27 @@ namespace SharedLibraryCore
|
|||||||
return str.Replace("//", "/ /");
|
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;
|
return str;
|
||||||
}
|
}
|
||||||
@ -184,7 +202,12 @@ namespace SharedLibraryCore
|
|||||||
foreach (var match in colorCodeMatches.Where(m => m.Success))
|
foreach (var match in colorCodeMatches.Where(m => m.Success))
|
||||||
{
|
{
|
||||||
var key = match.Groups[1].ToString();
|
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();
|
return output.FixIW4ForwardSlash();
|
||||||
|
Loading…
Reference in New Issue
Block a user