continuity/Server/Services/WonderkingAuthServer.cs

62 lines
1.6 KiB
C#

namespace Server.Services;
using System.Net;
using System.Net.Sockets;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using NetCoreServer;
public class WonderkingAuthServer : TcpServer, IHostedService
{
private readonly ILogger<WonderkingAuthServer> logger;
private readonly IServiceProvider serviceProvider;
public WonderkingAuthServer(IPAddress address, int port, ILogger<WonderkingAuthServer> logger,
IServiceProvider serviceProvider) : base(address, port)
{
this.logger = logger;
this.serviceProvider = serviceProvider;
}
public Task StartAsync(CancellationToken cancellationToken)
{
this.Start();
return Task.CompletedTask;
}
public Task StopAsync(CancellationToken cancellationToken)
{
this.Stop();
return Task.CompletedTask;
}
protected override TcpSession CreateSession() =>
ActivatorUtilities.CreateInstance<AuthSession>(this.serviceProvider, this);
protected override void OnStarting()
{
this.logger.LogInformation("Starting");
base.OnStarting();
}
protected override void OnStarted()
{
this.logger.LogInformation("Started");
base.OnStarted();
}
protected override void OnStopping()
{
this.logger.LogInformation("Stopping");
base.OnStopping();
}
protected override void OnStopped()
{
this.logger.LogInformation("Stopped");
base.OnStopped();
}
protected override void OnError(SocketError error) => this.logger.LogError("An error has occured {Error}", error);
}