2021-06-03 11:51:03 -04:00
|
|
|
|
using System;
|
2021-07-11 18:26:30 -04:00
|
|
|
|
using System.Net;
|
2020-02-11 17:44:06 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
using System.Text;
|
2021-06-03 11:51:03 -04:00
|
|
|
|
using Integrations.Cod;
|
|
|
|
|
using Integrations.Source;
|
|
|
|
|
using Integrations.Source.Interfaces;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-11-11 18:31:26 -05:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2021-09-18 19:25:02 -04:00
|
|
|
|
using SharedLibraryCore.Configuration;
|
2020-02-11 17:44:06 -05:00
|
|
|
|
|
|
|
|
|
namespace IW4MAdmin.Application.Factories
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// implementation of IRConConnectionFactory
|
|
|
|
|
/// </summary>
|
|
|
|
|
internal class RConConnectionFactory : IRConConnectionFactory
|
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
private static readonly Encoding GameEncoding = Encoding.GetEncoding("windows-1252");
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
|
2020-02-11 17:44:06 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Base constructor
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="logger"></param>
|
2021-06-03 11:51:03 -04:00
|
|
|
|
public RConConnectionFactory(IServiceProvider serviceProvider)
|
2020-02-11 17:44:06 -05:00
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
_serviceProvider = serviceProvider;
|
2020-02-11 17:44:06 -05:00
|
|
|
|
}
|
|
|
|
|
|
2021-07-11 18:26:30 -04:00
|
|
|
|
/// <inheritdoc/>
|
|
|
|
|
public IRConConnection CreateConnection(IPEndPoint ipEndpoint, string password, string rconEngine)
|
2020-02-11 17:44:06 -05:00
|
|
|
|
{
|
2021-06-03 11:51:03 -04:00
|
|
|
|
return rconEngine switch
|
|
|
|
|
{
|
2021-07-11 18:26:30 -04:00
|
|
|
|
"COD" => new CodRConConnection(ipEndpoint, password,
|
2021-09-18 19:25:02 -04:00
|
|
|
|
_serviceProvider.GetRequiredService<ILogger<CodRConConnection>>(), GameEncoding,
|
|
|
|
|
_serviceProvider.GetRequiredService<ApplicationConfiguration>()?.ServerConnectionAttempts ?? 6),
|
|
|
|
|
"Source" => new SourceRConConnection(
|
|
|
|
|
_serviceProvider.GetRequiredService<ILogger<SourceRConConnection>>(),
|
2021-07-11 18:26:30 -04:00
|
|
|
|
_serviceProvider.GetRequiredService<IRConClientFactory>(), ipEndpoint, password),
|
2021-06-03 11:51:03 -04:00
|
|
|
|
_ => throw new ArgumentException($"No supported RCon engine available for '{rconEngine}'")
|
|
|
|
|
};
|
2020-02-11 17:44:06 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-03 11:51:03 -04:00
|
|
|
|
}
|