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