2023-08-09 14:23:41 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Hosting;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
using NetCoreServer;
|
|
|
|
|
|
2023-08-10 08:47:35 +00:00
|
|
|
|
namespace Server.Services;
|
2023-08-09 14:23:41 +00:00
|
|
|
|
|
|
|
|
|
public class WonderkingAuthServer : TcpServer, IHostedService
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<WonderkingAuthServer> _logger;
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
|
|
|
|
|
public WonderkingAuthServer(IPAddress address, int port, ILogger<WonderkingAuthServer> logger,
|
2023-08-10 08:47:35 +00:00
|
|
|
|
IServiceProvider serviceProvider) : base(address, port)
|
2023-08-09 14:23:41 +00:00
|
|
|
|
{
|
2023-08-11 09:31:30 +00:00
|
|
|
|
this._logger = logger;
|
|
|
|
|
this._serviceProvider = serviceProvider;
|
2023-08-09 14:23:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-08-10 06:28:05 +00:00
|
|
|
|
protected override TcpSession CreateSession() =>
|
2023-08-11 09:31:30 +00:00
|
|
|
|
ActivatorUtilities.CreateInstance<AuthSession>(this._serviceProvider, this);
|
2023-08-09 14:23:41 +00:00
|
|
|
|
|
|
|
|
|
protected override void OnStarting()
|
|
|
|
|
{
|
2023-08-11 09:31:30 +00:00
|
|
|
|
this._logger.LogInformation("Starting");
|
2023-08-09 14:23:41 +00:00
|
|
|
|
base.OnStarting();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStarted()
|
|
|
|
|
{
|
2023-08-11 09:31:30 +00:00
|
|
|
|
this._logger.LogInformation("Started");
|
2023-08-09 14:23:41 +00:00
|
|
|
|
base.OnStarted();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStopping()
|
|
|
|
|
{
|
2023-08-11 09:31:30 +00:00
|
|
|
|
this._logger.LogInformation("Stopping");
|
2023-08-09 14:23:41 +00:00
|
|
|
|
base.OnStopping();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnStopped()
|
|
|
|
|
{
|
2023-08-11 09:31:30 +00:00
|
|
|
|
this._logger.LogInformation("Stopped");
|
2023-08-09 14:23:41 +00:00
|
|
|
|
base.OnStopped();
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-11 09:31:30 +00:00
|
|
|
|
protected override void OnError(SocketError error) => this._logger.LogError("An error has occured {Error}", error);
|
2023-08-09 14:23:41 +00:00
|
|
|
|
|
|
|
|
|
public Task StartAsync(CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-08-11 09:31:30 +00:00
|
|
|
|
this.Start();
|
2023-08-09 14:23:41 +00:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task StopAsync(CancellationToken cancellationToken)
|
|
|
|
|
{
|
2023-08-11 09:31:30 +00:00
|
|
|
|
this.Stop();
|
2023-08-09 14:23:41 +00:00
|
|
|
|
return Task.CompletedTask;
|
|
|
|
|
}
|
2023-08-11 09:31:30 +00:00
|
|
|
|
}
|