From 63b04be4c7ba9aff01e27cdb31b7965984d06414 Mon Sep 17 00:00:00 2001 From: RaidMax Date: Wed, 23 Mar 2022 11:38:09 -0500 Subject: [PATCH] add tell async and update SharedLibraryCore version --- SharedLibraryCore/Commands/NativeCommands.cs | 28 +++++++++---------- SharedLibraryCore/Events/GameEvent.cs | 8 ++++++ SharedLibraryCore/PartialEntities/EFClient.cs | 9 ++++++ SharedLibraryCore/RCon/StaticHelpers.cs | 13 +-------- SharedLibraryCore/SharedLibraryCore.csproj | 10 +++++-- SharedLibraryCore/Utilities.cs | 3 +- 6 files changed, 41 insertions(+), 30 deletions(-) diff --git a/SharedLibraryCore/Commands/NativeCommands.cs b/SharedLibraryCore/Commands/NativeCommands.cs index ae9624f20..b28d0c1e6 100644 --- a/SharedLibraryCore/Commands/NativeCommands.cs +++ b/SharedLibraryCore/Commands/NativeCommands.cs @@ -709,37 +709,35 @@ namespace SharedLibraryCore.Commands RequiresTarget = false; } - public override Task ExecuteAsync(GameEvent E) + public override async Task ExecuteAsync(GameEvent gameEvent) { - if (E.Owner.Manager.GetApplicationSettings().Configuration().GlobalRules?.Length < 1 && - E.Owner.ServerConfig.Rules?.Length < 1) + if (gameEvent.Owner.Manager.GetApplicationSettings().Configuration().GlobalRules?.Length < 1 && + gameEvent.Owner.ServerConfig.Rules?.Length < 1) { - var _ = E.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix) - ? E.Owner.Broadcast(_translationLookup["COMMANDS_RULES_NONE"]) - : E.Origin.Tell(_translationLookup["COMMANDS_RULES_NONE"]); + var _ = gameEvent.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix) + ? gameEvent.Owner.Broadcast(_translationLookup["COMMANDS_RULES_NONE"]) + : gameEvent.Origin.Tell(_translationLookup["COMMANDS_RULES_NONE"]); } else { var rules = new List(); - rules.AddRange(E.Owner.Manager.GetApplicationSettings().Configuration().GlobalRules); - if (E.Owner.ServerConfig.Rules != null) + rules.AddRange(gameEvent.Owner.Manager.GetApplicationSettings().Configuration().GlobalRules); + if (gameEvent.Owner.ServerConfig.Rules != null) { - rules.AddRange(E.Owner.ServerConfig.Rules); + rules.AddRange(gameEvent.Owner.ServerConfig.Rules); } - var ruleFomat = rules.Select(r => $"- {r}"); - if (E.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix)) + var ruleFormat = rules.Select(r => $"- {r}"); + if (gameEvent.Message.IsBroadcastCommand(_config.BroadcastCommandPrefix)) { - E.Owner.Broadcast(ruleFomat); + gameEvent.Owner.Broadcast(ruleFormat); } else { - E.Origin.Tell(ruleFomat); + await gameEvent.Origin.TellAsync(ruleFormat, gameEvent.Owner.Manager.CancellationToken); } } - - return Task.CompletedTask; } } diff --git a/SharedLibraryCore/Events/GameEvent.cs b/SharedLibraryCore/Events/GameEvent.cs index 198036ddb..e6e029c63 100644 --- a/SharedLibraryCore/Events/GameEvent.cs +++ b/SharedLibraryCore/Events/GameEvent.cs @@ -335,6 +335,14 @@ namespace SharedLibraryCore processed = true; } + finally + { + if (_eventFinishedWaiter.CurrentCount == 0) + { + _eventFinishedWaiter.Release(); + } + } + if (!processed) { using (LogContext.PushProperty("Server", Owner?.ToString())) diff --git a/SharedLibraryCore/PartialEntities/EFClient.cs b/SharedLibraryCore/PartialEntities/EFClient.cs index dcc3c17a6..9cdd3dc60 100644 --- a/SharedLibraryCore/PartialEntities/EFClient.cs +++ b/SharedLibraryCore/PartialEntities/EFClient.cs @@ -177,6 +177,7 @@ namespace SharedLibraryCore.Database.Models return e; } + [Obsolete] public void Tell(IEnumerable messages) { foreach (var message in messages) @@ -187,6 +188,14 @@ namespace SharedLibraryCore.Database.Models } } + public async Task TellAsync(IEnumerable messages, CancellationToken token =default) + { + foreach (var message in messages) + { + await Tell(message).WaitAsync(Utilities.DefaultCommandTimeout, token); + } + } + /// /// warn a client with given reason /// diff --git a/SharedLibraryCore/RCon/StaticHelpers.cs b/SharedLibraryCore/RCon/StaticHelpers.cs index 36407d141..1b20e86e9 100644 --- a/SharedLibraryCore/RCon/StaticHelpers.cs +++ b/SharedLibraryCore/RCon/StaticHelpers.cs @@ -1,5 +1,4 @@ using System; -using System.Globalization; namespace SharedLibraryCore.RCon { @@ -48,16 +47,6 @@ namespace SharedLibraryCore.RCon COMMAND_STATUS } - /// - /// line seperator char included in response from the server - /// - public static char SeperatorChar = (char)int.Parse("0a", NumberStyles.AllowHexSpecifier); - - /// - /// interval in milliseconds to wait before sending the next RCon request - /// - public static readonly int FloodProtectionInterval = 750; - /// /// timeout in seconds to wait for a socket send or receive before giving up /// @@ -73,4 +62,4 @@ namespace SharedLibraryCore.RCon }; } } -} \ No newline at end of file +} diff --git a/SharedLibraryCore/SharedLibraryCore.csproj b/SharedLibraryCore/SharedLibraryCore.csproj index afdded57d..5065efb5c 100644 --- a/SharedLibraryCore/SharedLibraryCore.csproj +++ b/SharedLibraryCore/SharedLibraryCore.csproj @@ -4,7 +4,7 @@ Library net6.0 RaidMax.IW4MAdmin.SharedLibraryCore - 2022.2.28.1 + 2022.3.23.1 RaidMax Forever None Debug;Release;Prerelease @@ -19,7 +19,9 @@ true MIT Shared Library for IW4MAdmin - 2022.2.28.1 + 2022.3.23.1 + true + $(NoWarn);1591 @@ -27,6 +29,10 @@ true + + bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml + + diff --git a/SharedLibraryCore/Utilities.cs b/SharedLibraryCore/Utilities.cs index 6d5dfde11..4e37c29d0 100644 --- a/SharedLibraryCore/Utilities.cs +++ b/SharedLibraryCore/Utilities.cs @@ -42,7 +42,8 @@ namespace SharedLibraryCore #endif public static Encoding EncodingType; public static Layout CurrentLocalization = new Layout(new Dictionary()); - public static TimeSpan DefaultCommandTimeout { get; set; } = new TimeSpan(0, 0, 25); + + public static TimeSpan DefaultCommandTimeout { get; set; } = new(0, 0, Utilities.IsDevelopment ? 360 : 25); public static char[] DirectorySeparatorChars = { '\\', '/' }; public static char CommandPrefix { get; set; } = '!';