diff --git a/Server/PacketHandlers/IPacketHandler.cs b/Server/PacketHandlers/IPacketHandler.cs index 2de9c93..c0f4bd8 100644 --- a/Server/PacketHandlers/IPacketHandler.cs +++ b/Server/PacketHandlers/IPacketHandler.cs @@ -1,8 +1,9 @@ -using Server.Packets; +using NetCoreServer; +using Server.Packets; namespace Server.PacketHandlers; -public interface IPacketHandler where T: IPacket +public interface IPacketHandler where T : IPacket { - public void Handle(T packet); + public Task HandleAsync(T packet, TcpSession session); } \ No newline at end of file diff --git a/Server/PacketHandlers/LoginInfoHandler.cs b/Server/PacketHandlers/LoginInfoHandler.cs index d90ac7c..5e34941 100644 --- a/Server/PacketHandlers/LoginInfoHandler.cs +++ b/Server/PacketHandlers/LoginInfoHandler.cs @@ -20,7 +20,7 @@ public class LoginHandler : IPacketHandler _configuration = configuration; } - public void Handle(LoginInfoPacket packet) + public async Task HandleAsync(LoginInfoPacket packet, TcpSession session) { _logger.LogInformation("Login data: Username {Username} & Password {Password}", packet.Username, packet.Password); @@ -29,7 +29,8 @@ public class LoginHandler : IPacketHandler { if (_configuration.GetSection("Testing").GetValue("CreateAccountOnLogin")) { - _wonderkingContext.Accounts.AddAsync(new Account(packet.Username, packet.Password, "", 0)); + var result = _wonderkingContext.Accounts.AddAsync(new Account(packet.Username, packet.Password, "", 0)); + await result; } else { diff --git a/Server/Services/PacketDistributorService.cs b/Server/Services/PacketDistributorService.cs index cfb1d8a..0543a8c 100644 --- a/Server/Services/PacketDistributorService.cs +++ b/Server/Services/PacketDistributorService.cs @@ -80,10 +80,10 @@ public class PacketDistributorService : IHostedService _logger.LogInformation("Packet with ID: {MessageOperationCode} has been received", rawPacket.OperationCode); _concurrentQueue.Enqueue(rawPacket); - Parallel.Invoke(DequeueAndProcessAsync); + Parallel.Invoke(() => DequeueAndProcessAsync()); } - private async void DequeueAndProcessAsync() + private async Task DequeueAndProcessAsync() { if (_concurrentQueue.TryDequeue(out var item)) { @@ -97,7 +97,8 @@ public class PacketDistributorService : IHostedService var packetHandler = ActivatorUtilities.GetServiceOrCreateInstance(_serviceProvider, _packetHandlers[item.OperationCode]); - packetHandler.GetType().GetMethod("Handle")?.Invoke(packetHandler, new[] { packet }); + packetHandler.GetType().GetMethod("HandleAsync") + ?.Invoke(packetHandler, new Object[] { packet, item.Session }); _logger.LogDebug("Packet data {PacketData}", JsonConvert.SerializeObject(packet)); _logger.LogTrace("[{TempId}] Packet with ID: {MessageOperationCode} has finished", item.Session.Id,