diff --git a/Application/ApplicationManager.cs b/Application/ApplicationManager.cs index bb8960063..38a4e065f 100644 --- a/Application/ApplicationManager.cs +++ b/Application/ApplicationManager.cs @@ -61,7 +61,7 @@ namespace IW4MAdmin.Application public IConfigurationHandler ConfigHandler; readonly IPageList PageList; private readonly TimeSpan _throttleTimeout = new TimeSpan(0, 1, 0); - private readonly CancellationTokenSource _tokenSource; + private CancellationTokenSource _tokenSource; private readonly Dictionary> _operationLookup = new Dictionary>(); private readonly ITranslationLookup _translationLookup; private readonly IConfigurationHandler _commandConfiguration; @@ -94,8 +94,8 @@ namespace IW4MAdmin.Application ConfigHandler = appConfigHandler; StartTime = DateTime.UtcNow; PageList = new PageList(); - AdditionalEventParsers = new List() { new BaseEventParser(parserRegexFactory, logger, _appConfig) }; - AdditionalRConParsers = new List() { new BaseRConParser(serviceProvider.GetRequiredService>(), parserRegexFactory) }; + AdditionalEventParsers = new List { new BaseEventParser(parserRegexFactory, logger, _appConfig) }; + AdditionalRConParsers = new List { new BaseRConParser(serviceProvider.GetRequiredService>(), parserRegexFactory) }; TokenAuthenticator = new TokenAuthentication(); _logger = logger; _tokenSource = new CancellationTokenSource(); @@ -613,6 +613,7 @@ namespace IW4MAdmin.Application { IsRestartRequested = true; Stop().GetAwaiter().GetResult(); + _tokenSource = new CancellationTokenSource(); } [Obsolete] diff --git a/Integrations/Cod/CodRConConnection.cs b/Integrations/Cod/CodRConConnection.cs index f1842763f..0942cad75 100644 --- a/Integrations/Cod/CodRConConnection.cs +++ b/Integrations/Cod/CodRConConnection.cs @@ -458,6 +458,12 @@ namespace Integrations.Cod connectionState.SendEventArgs.DisconnectReuseSocket = true; } + if (connectionState.ReceiveEventArgs.UserToken is ConnectionUserToken { CancellationToken.IsCancellationRequested: true }) + { + // after a graceful restart we need to reset the receive user token as the cancellation has been updated + connectionState.ReceiveEventArgs.UserToken = connectionState.SendEventArgs.UserToken; + } + connectionState.SendEventArgs.SetBuffer(payload); // send the data to the server diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index bf722a104..56024160a 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -71,31 +71,7 @@ namespace SharedLibraryCore /// public const long WORLD_ID = -1; - public static Dictionary PermissionLevelOverrides { get; } = - new Dictionary(); - - public static string HttpRequest(string location, string header, string headerValue) - { - using (var RequestClient = new HttpClient()) - { - RequestClient.DefaultRequestHeaders.Add(header, headerValue); - var response = RequestClient.GetStringAsync(location).Result; - return response; - } - } - - //Get string with specified number of spaces -- really only for visual output - public static string GetSpaces(int Num) - { - var SpaceString = string.Empty; - while (Num > 0) - { - SpaceString += ' '; - Num--; - } - - return SpaceString; - } + public static Dictionary PermissionLevelOverrides { get; } = new (); //Remove words from a space delimited string public static string RemoveWords(this string str, int num) @@ -133,12 +109,12 @@ namespace SharedLibraryCore { var lookingFor = str.ToLower(); - for (var Perm = Permission.User; Perm < Permission.Console; Perm++) - if (lookingFor.Contains(Perm.ToString().ToLower()) + for (var perm = Permission.User; perm < Permission.Console; perm++) + if (lookingFor.Contains(perm.ToString().ToLower()) || lookingFor.Contains(CurrentLocalization - .LocalizationIndex[$"GLOBAL_PERMISSION_{Perm.ToString().ToUpper()}"].ToLower())) + .LocalizationIndex[$"GLOBAL_PERMISSION_{perm.ToString().ToUpper()}"].ToLower())) { - return Perm; + return perm; } return Permission.Banned; @@ -211,7 +187,8 @@ namespace SharedLibraryCore return output.FixIW4ForwardSlash(); } - private static readonly IList _zmGameTypes = new[] { "zclassic", "zstandard", "zcleansed", "zgrief" }; + private static readonly IList ZmGameTypes = new[] + { "zclassic", "zstandard", "zcleansed", "zgrief", "zom", "cmp" }; /// /// indicates if the given server is running a zombie game mode @@ -220,7 +197,8 @@ namespace SharedLibraryCore /// public static bool IsZombieServer(this Server server) { - return server.GameName == Game.T6 && _zmGameTypes.Contains(server.Gametype.ToLower()); + return new[] { Game.T4, Game.T5, Game.T6 }.Contains(server.GameName) && + ZmGameTypes.Contains(server.Gametype.ToLower()); } public static bool IsCodGame(this Server server) @@ -283,11 +261,6 @@ namespace SharedLibraryCore return str.StartsWith(broadcastCommandPrefix); } - public static IManagerCommand AsCommand(this GameEvent gameEvent) - { - return gameEvent.Extra as IManagerCommand; - } - /// /// Get the full gametype name /// @@ -454,7 +427,7 @@ namespace SharedLibraryCore { var success = IPAddress.TryParse(str, out var ip); return success && ip.GetAddressBytes().Count(_byte => _byte == 0) != 4 - ? (int?)BitConverter.ToInt32(ip.GetAddressBytes(), 0) + ? BitConverter.ToInt32(ip.GetAddressBytes(), 0) : null; } @@ -503,11 +476,6 @@ namespace SharedLibraryCore return Game.UKN; } - public static string EscapeMarkdown(this string markdownString) - { - return markdownString.Replace("<", "\\<").Replace(">", "\\>").Replace("|", "\\|"); - } - public static TimeSpan ParseTimespan(this string input) { var expressionMatch = Regex.Match(input, @"([0-9]+)(\w+)"); @@ -629,7 +597,7 @@ namespace SharedLibraryCore public static bool PromptBool(this string question, string description = null, bool defaultValue = true) { Console.Write($"{question}?{(string.IsNullOrEmpty(description) ? " " : $" ({description}) ")}[y/n]: "); - var response = Console.ReadLine().ToLower().FirstOrDefault(); + var response = Console.ReadLine()?.ToLower().FirstOrDefault(); return response != 0 ? response == 'y' : defaultValue; } @@ -660,7 +628,7 @@ namespace SharedLibraryCore Console.WriteLine(new string('=', 52)); var selectionIndex = PromptInt(CurrentLocalization.LocalizationIndex["SETUP_PROMPT_MAKE_SELECTION"], null, - hasDefault ? 0 : 1, selections.Length, hasDefault ? 0 : (int?)null); + hasDefault ? 0 : 1, selections.Length, hasDefault ? 0 : null); if (!hasDefault) { @@ -688,13 +656,13 @@ namespace SharedLibraryCore $"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue.Value.ToString()}]")}: "); int response; - string inputOrDefault() + string InputOrDefault() { var input = Console.ReadLine(); return string.IsNullOrEmpty(input) && defaultValue != null ? defaultValue.ToString() : input; } - while (!int.TryParse(inputOrDefault(), out response) || + while (!int.TryParse(InputOrDefault(), out response) || response < minValue || response > maxValue) { @@ -719,7 +687,7 @@ namespace SharedLibraryCore /// public static string PromptString(this string question, string description = null, string defaultValue = null) { - string inputOrDefault() + string InputOrDefault() { var input = Console.ReadLine(); return string.IsNullOrEmpty(input) && defaultValue != null ? defaultValue : input; @@ -730,7 +698,7 @@ namespace SharedLibraryCore { Console.Write( $"{question}{(string.IsNullOrEmpty(description) ? "" : $" ({description})")}{(defaultValue == null ? "" : $" [{CurrentLocalization.LocalizationIndex["SETUP_PROMPT_DEFAULT"]} {defaultValue}]")}: "); - response = inputOrDefault(); + response = InputOrDefault(); } while (string.IsNullOrWhiteSpace(response) && response != defaultValue); return response; diff --git a/WebfrontCore/Views/Admin/_BanEntries.cshtml b/WebfrontCore/Views/Admin/_BanEntries.cshtml index 2a1b71f37..cc91e2f36 100644 --- a/WebfrontCore/Views/Admin/_BanEntries.cshtml +++ b/WebfrontCore/Views/Admin/_BanEntries.cshtml @@ -34,7 +34,7 @@
@ban.AttachedPenalty.DateTime.ToStandardFormat()

-
@ViewBag.Localization["WEBFRONT_BAN_MGMT_ACTION_UNBAN"]
+
@ViewBag.Localization["WEBFRONT_BAN_MGMT_ACTION_UNBAN"]
} else { @@ -51,7 +51,7 @@ {