diff --git a/Application/Factories/RConConnectionFactory.cs b/Application/Factories/RConConnectionFactory.cs index 14cb1e790..55d222b0c 100644 --- a/Application/Factories/RConConnectionFactory.cs +++ b/Application/Factories/RConConnectionFactory.cs @@ -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>(), GameEncoding), - "Source" => new SourceRConConnection(_serviceProvider.GetRequiredService>(), + _serviceProvider.GetRequiredService>(), GameEncoding, + _serviceProvider.GetRequiredService()?.ServerConnectionAttempts ?? 6), + "Source" => new SourceRConConnection( + _serviceProvider.GetRequiredService>(), _serviceProvider.GetRequiredService(), ipEndpoint, password), _ => throw new ArgumentException($"No supported RCon engine available for '{rconEngine}'") }; diff --git a/Integrations/Cod/CodRConConnection.cs b/Integrations/Cod/CodRConConnection.cs index 15eb1ad07..a93b58488 100644 --- a/Integrations/Cod/CodRConConnection.cs +++ b/Integrations/Cod/CodRConConnection.cs @@ -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 log, Encoding gameEncoding) + public CodRConConnection(IPEndPoint ipEndpoint, string password, ILogger 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)); diff --git a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs index 45f5fd561..6aff83723 100644 --- a/SharedLibraryCore/Configuration/ApplicationConfiguration.cs +++ b/SharedLibraryCore/Configuration/ApplicationConfiguration.cs @@ -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 OverridePermissionLevelNames { get; set; } = Enum diff --git a/SharedLibraryCore/RCon/StaticHelpers.cs b/SharedLibraryCore/RCon/StaticHelpers.cs index 1fc58b625..540fa0231 100644 --- a/SharedLibraryCore/RCon/StaticHelpers.cs +++ b/SharedLibraryCore/RCon/StaticHelpers.cs @@ -64,9 +64,5 @@ namespace SharedLibraryCore.RCon /// interval in milliseconds to wait before sending the next RCon request /// public static readonly int FloodProtectionInterval = 750; - /// - /// how many failed connection attempts before aborting connection - /// - public static readonly int AllowedConnectionFails = 5; } }