make connection attempts for CoD configurable as "ServerConnectionAttempts"
This commit is contained in:
parent
d4fb75d07c
commit
e80753a4d3
@ -7,6 +7,7 @@ using Integrations.Source;
|
||||
using Integrations.Source.Interfaces;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SharedLibraryCore.Configuration;
|
||||
|
||||
namespace IW4MAdmin.Application.Factories
|
||||
{
|
||||
@ -33,8 +34,10 @@ namespace IW4MAdmin.Application.Factories
|
||||
return rconEngine switch
|
||||
{
|
||||
"COD" => new CodRConConnection(ipEndpoint, password,
|
||||
_serviceProvider.GetRequiredService<ILogger<CodRConConnection>>(), GameEncoding),
|
||||
"Source" => new SourceRConConnection(_serviceProvider.GetRequiredService<ILogger<SourceRConConnection>>(),
|
||||
_serviceProvider.GetRequiredService<ILogger<CodRConConnection>>(), GameEncoding,
|
||||
_serviceProvider.GetRequiredService<ApplicationConfiguration>()?.ServerConnectionAttempts ?? 6),
|
||||
"Source" => new SourceRConConnection(
|
||||
_serviceProvider.GetRequiredService<ILogger<SourceRConConnection>>(),
|
||||
_serviceProvider.GetRequiredService<IRConClientFactory>(), ipEndpoint, password),
|
||||
_ => throw new ArgumentException($"No supported RCon engine available for '{rconEngine}'")
|
||||
};
|
||||
|
@ -31,13 +31,15 @@ namespace Integrations.Cod
|
||||
private IRConParserConfiguration config;
|
||||
private readonly ILogger _log;
|
||||
private readonly Encoding _gameEncoding;
|
||||
private readonly int _retryAttempts;
|
||||
|
||||
public CodRConConnection(IPEndPoint ipEndpoint, string password, ILogger<CodRConConnection> log, Encoding gameEncoding)
|
||||
public CodRConConnection(IPEndPoint ipEndpoint, string password, ILogger<CodRConConnection> log, Encoding gameEncoding, int retryAttempts)
|
||||
{
|
||||
RConPassword = password;
|
||||
_gameEncoding = gameEncoding;
|
||||
_log = log;
|
||||
Endpoint = ipEndpoint;
|
||||
_retryAttempts = retryAttempts;
|
||||
}
|
||||
|
||||
public void SetConfiguration(IRConParser parser)
|
||||
@ -137,7 +139,7 @@ namespace Integrations.Cod
|
||||
_log.LogInformation(
|
||||
"Retrying RCon message ({connectionAttempts}/{allowedConnectionFailures} attempts) with parameters {payload}",
|
||||
connectionState.ConnectionAttempts,
|
||||
StaticHelpers.AllowedConnectionFails, parameters);
|
||||
_retryAttempts, parameters);
|
||||
}
|
||||
}
|
||||
using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
|
||||
@ -155,7 +157,7 @@ namespace Integrations.Cod
|
||||
bool exceptionCaught = false;
|
||||
|
||||
_log.LogDebug("Sending {payloadLength} bytes to [{endpoint}] ({connectionAttempts}/{allowedConnectionFailures})",
|
||||
payload.Length, Endpoint, connectionState.ConnectionAttempts, StaticHelpers.AllowedConnectionFails);
|
||||
payload.Length, Endpoint, connectionState.ConnectionAttempts, _retryAttempts);
|
||||
|
||||
try
|
||||
{
|
||||
@ -173,7 +175,7 @@ namespace Integrations.Cod
|
||||
catch
|
||||
{
|
||||
// we want to retry with a delay
|
||||
if (connectionState.ConnectionAttempts < StaticHelpers.AllowedConnectionFails)
|
||||
if (connectionState.ConnectionAttempts < _retryAttempts)
|
||||
{
|
||||
exceptionCaught = true;
|
||||
await Task.Delay(StaticHelpers.SocketTimeout(connectionState.ConnectionAttempts));
|
||||
|
@ -150,6 +150,8 @@ namespace SharedLibraryCore.Configuration
|
||||
|
||||
[ConfigurationIgnore]
|
||||
public TimeSpan ServerDataCollectionInterval { get; set; } = TimeSpan.FromMinutes(5);
|
||||
|
||||
public int ServerConnectionAttempts { get; set; } = 6;
|
||||
|
||||
[ConfigurationIgnore]
|
||||
public Dictionary<Permission, string> OverridePermissionLevelNames { get; set; } = Enum
|
||||
|
@ -64,9 +64,5 @@ namespace SharedLibraryCore.RCon
|
||||
/// interval in milliseconds to wait before sending the next RCon request
|
||||
/// </summary>
|
||||
public static readonly int FloodProtectionInterval = 750;
|
||||
/// <summary>
|
||||
/// how many failed connection attempts before aborting connection
|
||||
/// </summary>
|
||||
public static readonly int AllowedConnectionFails = 5;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user