continuity/Server/Services/WonderkingAuthServer.cs
Timothy Schenk 0077d380f3
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 2s
Build, Package and Push Images / build (push) Successful in 25s
Build, Package and Push Images / sonarqube (push) Has been skipped
Build, Package and Push Images / sbom-scan (push) Successful in 32s
Build, Package and Push Images / container-build (push) Successful in 1m23s
Build, Package and Push Images / container-sbom-scan (push) Successful in 37s
chore: I don't know right now
2023-11-16 23:51:30 +01:00

74 lines
2 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 OnConnected(TcpSession session)
{
this._logger.LogInformation("Client connected {Session}", session.Id);
base.OnConnected(session);
}
protected override void OnDisconnected(TcpSession session)
{
this._logger.LogInformation("Client disconnected {Session}", session.Id);
base.OnDisconnected(session);
}
protected override void OnError(SocketError error) => this._logger.LogError("An error has occured {Error}", error);
}