add tell async and update SharedLibraryCore version

This commit is contained in:
RaidMax 2022-03-23 11:38:09 -05:00
parent 36eb45bb2e
commit 63b04be4c7
6 changed files with 41 additions and 30 deletions

View File

@ -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<string>();
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;
}
}

View File

@ -335,6 +335,14 @@ namespace SharedLibraryCore
processed = true;
}
finally
{
if (_eventFinishedWaiter.CurrentCount == 0)
{
_eventFinishedWaiter.Release();
}
}
if (!processed)
{
using (LogContext.PushProperty("Server", Owner?.ToString()))

View File

@ -177,6 +177,7 @@ namespace SharedLibraryCore.Database.Models
return e;
}
[Obsolete]
public void Tell(IEnumerable<string> messages)
{
foreach (var message in messages)
@ -187,6 +188,14 @@ namespace SharedLibraryCore.Database.Models
}
}
public async Task TellAsync(IEnumerable<string> messages, CancellationToken token =default)
{
foreach (var message in messages)
{
await Tell(message).WaitAsync(Utilities.DefaultCommandTimeout, token);
}
}
/// <summary>
/// warn a client with given reason
/// </summary>

View File

@ -1,5 +1,4 @@
using System;
using System.Globalization;
namespace SharedLibraryCore.RCon
{
@ -48,16 +47,6 @@ namespace SharedLibraryCore.RCon
COMMAND_STATUS
}
/// <summary>
/// line seperator char included in response from the server
/// </summary>
public static char SeperatorChar = (char)int.Parse("0a", NumberStyles.AllowHexSpecifier);
/// <summary>
/// interval in milliseconds to wait before sending the next RCon request
/// </summary>
public static readonly int FloodProtectionInterval = 750;
/// <summary>
/// timeout in seconds to wait for a socket send or receive before giving up
/// </summary>

View File

@ -4,7 +4,7 @@
<OutputType>Library</OutputType>
<TargetFramework>net6.0</TargetFramework>
<PackageId>RaidMax.IW4MAdmin.SharedLibraryCore</PackageId>
<Version>2022.2.28.1</Version>
<Version>2022.3.23.1</Version>
<Authors>RaidMax</Authors>
<Company>Forever None</Company>
<Configurations>Debug;Release;Prerelease</Configurations>
@ -19,7 +19,9 @@
<IsPackable>true</IsPackable>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<Description>Shared Library for IW4MAdmin</Description>
<PackageVersion>2022.2.28.1</PackageVersion>
<PackageVersion>2022.3.23.1</PackageVersion>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Prerelease|AnyCPU'">
@ -27,6 +29,10 @@
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<PropertyGroup>
<DocumentationFile>bin\$(Configuration)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation" Version="10.3.6" />
<PackageReference Include="Humanizer.Core" Version="2.13.14" />

View File

@ -42,7 +42,8 @@ namespace SharedLibraryCore
#endif
public static Encoding EncodingType;
public static Layout CurrentLocalization = new Layout(new Dictionary<string, string>());
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; } = '!';