From 6589a9f8904880272e4da77e78215d533691c15b Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Sun, 19 Nov 2023 15:05:48 +0100 Subject: [PATCH] chore: configure await --- Server/AuthSession.cs | 7 ++++--- Server/PacketHandlers/ChannelSelectionHandler.cs | 4 ++-- Server/PacketHandlers/CharacterCreationHandler.cs | 4 ++-- Server/PacketHandlers/CharacterDeletionHandler.cs | 4 ++-- Server/PacketHandlers/CharacterNameCheckHandler.cs | 7 +++++-- Server/PacketHandlers/LoginHandler.cs | 2 +- 6 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Server/AuthSession.cs b/Server/AuthSession.cs index ae0f4c9..788c4c3 100644 --- a/Server/AuthSession.cs +++ b/Server/AuthSession.cs @@ -29,14 +29,14 @@ public class AuthSession : TcpSession return base.Send(buffer); } - public void Send(IPacket packet) + public Task SendAsync(IPacket packet) { var type = packet.GetType(); this._logger.LogInformation("Packet of type {Type} is being serialized", type.Name); var packetIdAttribute = type.GetCustomAttribute(); if (packetIdAttribute == null) { - return; + return Task.CompletedTask; } var opcode = packetIdAttribute.Code; @@ -63,7 +63,8 @@ public class AuthSession : TcpSession this._logger.LogInformation("Packet data being parsed is: {Data}", BitConverter.ToString(packetData.ToArray())); this._logger.LogInformation("Packet being parsed is: {Data}", BitConverter.ToString(buffer.ToArray())); - this.Send(buffer); + this.SendAsync(buffer); + return Task.CompletedTask; } protected override void OnReceived(byte[] buffer, long offset, long size) diff --git a/Server/PacketHandlers/ChannelSelectionHandler.cs b/Server/PacketHandlers/ChannelSelectionHandler.cs index a515d1e..0a399a9 100644 --- a/Server/PacketHandlers/ChannelSelectionHandler.cs +++ b/Server/PacketHandlers/ChannelSelectionHandler.cs @@ -80,11 +80,11 @@ public class ChannelSelectionHandler : IPacketHandler }; } - authSession.Send(responsePacket); + await authSession.SendAsync(responsePacket).ConfigureAwait(false); if (guildNameResponsePacket.GuildNames.Length > 0 && guildNameResponsePacket.GuildNames.Select(n => n != string.Empty).Any()) { - authSession.Send(guildNameResponsePacket); + await authSession.SendAsync(guildNameResponsePacket).ConfigureAwait(false); } } diff --git a/Server/PacketHandlers/CharacterCreationHandler.cs b/Server/PacketHandlers/CharacterCreationHandler.cs index 7e9dcb4..99fdd20 100644 --- a/Server/PacketHandlers/CharacterCreationHandler.cs +++ b/Server/PacketHandlers/CharacterCreationHandler.cs @@ -107,12 +107,12 @@ public class CharacterCreationHandler : IPacketHandler .Select(item => item.ItemId) .ToArray(), }).FirstAsync().ConfigureAwait(true); - authSession?.Send(new CharacterCreationResponsePacket + await authSession.SendAsync(new CharacterCreationResponsePacket { Character = character, Slot = amountOfCharacters - 1, isDuplicate = false, - }); + }).ConfigureAwait(false); } private static int CalculateCurrentHealth(ushort level, JobSpecificMapping firstJobConfig) diff --git a/Server/PacketHandlers/CharacterDeletionHandler.cs b/Server/PacketHandlers/CharacterDeletionHandler.cs index 2c256c0..a849f46 100644 --- a/Server/PacketHandlers/CharacterDeletionHandler.cs +++ b/Server/PacketHandlers/CharacterDeletionHandler.cs @@ -30,13 +30,13 @@ public class CharacterDeletionHandler : IPacketHandler var response = new CharacterDeleteResponsePacket { IsDeleted = 0 }; if (character == null) { - authSession.Send(response); + await authSession.SendAsync(response).ConfigureAwait(false); return; } //_wonderkingContext.Characters.Remove(character); //await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false); - authSession.Send(response); + await authSession.SendAsync(response).ConfigureAwait(false); } } diff --git a/Server/PacketHandlers/CharacterNameCheckHandler.cs b/Server/PacketHandlers/CharacterNameCheckHandler.cs index c97af26..7804da6 100644 --- a/Server/PacketHandlers/CharacterNameCheckHandler.cs +++ b/Server/PacketHandlers/CharacterNameCheckHandler.cs @@ -18,8 +18,11 @@ public class CharacterNameCheckHandler : IPacketHandler c.Name == packet.Name); var responsePacket = new CharacterNameCheckPacketResponse { IsTaken = isTaken }; - var authSession = session as AuthSession; - authSession?.Send(responsePacket); + if (session is AuthSession authSession) + { + return authSession.SendAsync(responsePacket); + } + return Task.CompletedTask; } } diff --git a/Server/PacketHandlers/LoginHandler.cs b/Server/PacketHandlers/LoginHandler.cs index 1d60f1b..86f57ae 100644 --- a/Server/PacketHandlers/LoginHandler.cs +++ b/Server/PacketHandlers/LoginHandler.cs @@ -119,6 +119,6 @@ public class LoginHandler : IPacketHandler } _logger.LogInformation("LoginResponsePacket: {@LoginResponsePacket}", loginResponsePacket); - sess?.Send(loginResponsePacket); + sess?.SendAsync(loginResponsePacket); } }