using System; using SharedLibraryCore.Interfaces; using System.Text; using Integrations.Cod; using Integrations.Source; using Integrations.Source.Interfaces; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; namespace IW4MAdmin.Application.Factories { /// /// implementation of IRConConnectionFactory /// internal class RConConnectionFactory : IRConConnectionFactory { private static readonly Encoding GameEncoding = Encoding.GetEncoding("windows-1252"); private readonly IServiceProvider _serviceProvider; /// /// Base constructor /// /// public RConConnectionFactory(IServiceProvider serviceProvider) { _serviceProvider = serviceProvider; } /// /// creates a new rcon connection instance /// /// ip address of the server /// port of the server /// rcon password of the server /// public IRConConnection CreateConnection(string ipAddress, int port, string password, string rconEngine) { return rconEngine switch { "COD" => new CodRConConnection(ipAddress, port, password, _serviceProvider.GetRequiredService>(), GameEncoding), "Source" => new SourceRConConnection(_serviceProvider.GetRequiredService>(), _serviceProvider.GetRequiredService(), ipAddress, port, password), _ => throw new ArgumentException($"No supported RCon engine available for '{rconEngine}'") }; } } }