From 8ef2959f636a1f5a2aa6e72ec96d1d21f2287946 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Thu, 19 Nov 2020 20:48:25 -0600 Subject: [PATCH] make notice line separator configurable for different parsers (updated tekno's as it doesn't support \n) --- Application/Localization/Configure.cs | 4 +++ .../Misc/ClientNoticeMessageFormatter.cs | 35 ++++++++++++++----- .../DynamicRConParserConfiguration.cs | 4 ++- Plugins/ScriptPlugins/ParserTeknoMW3.js | 3 +- .../Interfaces/IRConParserConfiguration.cs | 11 ++++++ 5 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Application/Localization/Configure.cs b/Application/Localization/Configure.cs index 8d759fd56..b2155e97d 100644 --- a/Application/Localization/Configure.cs +++ b/Application/Localization/Configure.cs @@ -63,6 +63,10 @@ namespace IW4MAdmin.Application.Localization { var localizationContents = File.ReadAllText(filePath, Encoding.UTF8); var eachLocalizationFile = Newtonsoft.Json.JsonConvert.DeserializeObject(localizationContents); + if (eachLocalizationFile == null) + { + continue; + } foreach (var item in eachLocalizationFile.LocalizationIndex.Set) { diff --git a/Application/Misc/ClientNoticeMessageFormatter.cs b/Application/Misc/ClientNoticeMessageFormatter.cs index e0d9302cc..d4885c6d2 100644 --- a/Application/Misc/ClientNoticeMessageFormatter.cs +++ b/Application/Misc/ClientNoticeMessageFormatter.cs @@ -25,18 +25,29 @@ namespace IW4MAdmin.Application.Misc public string BuildFormattedMessage(IRConParserConfiguration config, EFPenalty currentPenalty, EFPenalty originalPenalty = null) { + var isNewLineSeparator = config.NoticeLineSeparator == Environment.NewLine; var penalty = originalPenalty ?? currentPenalty; var builder = new StringBuilder(); // build the top level header var header = _transLookup[$"SERVER_{penalty.Type.ToString().ToUpper()}_TEXT"]; builder.Append(header); - builder.Append(Environment.NewLine); + builder.Append(config.NoticeLineSeparator); // build the reason var reason = _transLookup["GAME_MESSAGE_PENALTY_REASON"].FormatExt(penalty.Offense); - foreach (var splitReason in SplitOverMaxLength(reason, config.NoticeMaxCharactersPerLine)) + + if (isNewLineSeparator) { - builder.Append(splitReason); - builder.Append(Environment.NewLine); + foreach (var splitReason in SplitOverMaxLength(reason, config.NoticeMaxCharactersPerLine)) + { + builder.Append(splitReason); + builder.Append(config.NoticeLineSeparator); + } + } + + else + { + builder.Append(reason); + builder.Append(config.NoticeLineSeparator); } if (penalty.Type == EFPenalty.PenaltyType.TempBan) @@ -46,11 +57,19 @@ namespace IW4MAdmin.Application.Misc ? (penalty.Expires - DateTime.UtcNow).Value.HumanizeForCurrentCulture() : "--"; var timeRemaining = _transLookup["GAME_MESSAGE_PENALTY_TIME_REMAINING"].FormatExt(timeRemainingValue); - - foreach (var splitReason in SplitOverMaxLength(timeRemaining, config.NoticeMaxCharactersPerLine)) + + if (isNewLineSeparator) { - builder.Append(splitReason); - builder.Append(Environment.NewLine); + foreach (var splitReason in SplitOverMaxLength(timeRemaining, config.NoticeMaxCharactersPerLine)) + { + builder.Append(splitReason); + builder.Append(config.NoticeLineSeparator); + } + } + + else + { + builder.Append(timeRemaining); } } diff --git a/Application/RconParsers/DynamicRConParserConfiguration.cs b/Application/RconParsers/DynamicRConParserConfiguration.cs index c57589092..05b5de611 100644 --- a/Application/RconParsers/DynamicRConParserConfiguration.cs +++ b/Application/RconParsers/DynamicRConParserConfiguration.cs @@ -1,4 +1,5 @@ -using SharedLibraryCore.Interfaces; +using System; +using SharedLibraryCore.Interfaces; using SharedLibraryCore.RCon; using System.Collections.Generic; using System.Globalization; @@ -24,6 +25,7 @@ namespace IW4MAdmin.Application.RconParsers public IDictionary DefaultDvarValues { get; set; } = new Dictionary(); public int NoticeMaximumLines { get; set; } = 8; public int NoticeMaxCharactersPerLine { get; set; } = 50; + public string NoticeLineSeparator { get; set; } = Environment.NewLine; public DynamicRConParserConfiguration(IParserRegexFactory parserRegexFactory) { diff --git a/Plugins/ScriptPlugins/ParserTeknoMW3.js b/Plugins/ScriptPlugins/ParserTeknoMW3.js index 951181d12..0cdd2971d 100644 --- a/Plugins/ScriptPlugins/ParserTeknoMW3.js +++ b/Plugins/ScriptPlugins/ParserTeknoMW3.js @@ -3,7 +3,7 @@ var eventParser; var plugin = { author: 'RaidMax', - version: 0.7, + version: 0.8, name: 'Tekno MW3 Parser', isParser: true, @@ -27,6 +27,7 @@ var plugin = { rconParser.Configuration.CommandPrefixes.TempBan = 'tempbanclient {0} "{1}"'; rconParser.Configuration.Dvar.AddMapping(107, 1); // RCon DvarValue rconParser.Configuration.Dvar.Pattern = '^(.*)$'; + rconParser.Configuration.NoticeLineSeparator = '. '; rconParser.Configuration.DefaultDvarValues.Add('sv_running', '1'); rconParser.Configuration.OverrideDvarNameMapping.Add('_website', 'sv_clanWebsite'); diff --git a/SharedLibraryCore/Interfaces/IRConParserConfiguration.cs b/SharedLibraryCore/Interfaces/IRConParserConfiguration.cs index 819aa9561..d53c8f923 100644 --- a/SharedLibraryCore/Interfaces/IRConParserConfiguration.cs +++ b/SharedLibraryCore/Interfaces/IRConParserConfiguration.cs @@ -63,8 +63,19 @@ namespace SharedLibraryCore.Interfaces /// IDictionary DefaultDvarValues { get; set; } + /// + /// specifies how many lines can be used for ingame notice + /// int NoticeMaximumLines { get; set; } + /// + /// specifies how many characters can be displayed per notice line + /// int NoticeMaxCharactersPerLine { get; set; } + + /// + /// specifies the characters used to split a line + /// + string NoticeLineSeparator { get; set; } } }