using System;
using System.Net;
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;
}
///
public IRConConnection CreateConnection(IPEndPoint ipEndpoint, string password, string rconEngine)
{
return rconEngine switch
{
"COD" => new CodRConConnection(ipEndpoint, password,
_serviceProvider.GetRequiredService>(), GameEncoding),
"Source" => new SourceRConConnection(_serviceProvider.GetRequiredService>(),
_serviceProvider.GetRequiredService(), ipEndpoint, password),
_ => throw new ArgumentException($"No supported RCon engine available for '{rconEngine}'")
};
}
}
}