continuity/Server/Services/WonderkingAuthServer.cs

63 lines
1.6 KiB
C#
Raw Normal View History

namespace Server.Services;
using System.Net;
2023-08-09 14:23:41 +00:00
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;
2023-08-09 14:23:41 +00:00
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
{
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;
2023-08-09 14:23:41 +00:00
}
protected override TcpSession CreateSession() =>
ActivatorUtilities.CreateInstance<AuthSession>(this.serviceProvider, this);
2023-08-09 14:23:41 +00:00
protected override void OnStarting()
{
this.logger.LogInformation("Starting");
2023-08-09 14:23:41 +00:00
base.OnStarting();
}
protected override void OnStarted()
{
this.logger.LogInformation("Started");
2023-08-09 14:23:41 +00:00
base.OnStarted();
}
protected override void OnStopping()
{
this.logger.LogInformation("Stopping");
2023-08-09 14:23:41 +00:00
base.OnStopping();
}
protected override void OnStopped()
{
this.logger.LogInformation("Stopped");
2023-08-09 14:23:41 +00:00
base.OnStopped();
}
protected override void OnError(SocketError error) => this.logger.LogError("An error has occured {Error}", error);
2023-08-11 09:31:30 +00:00
}