chore: configure await

This commit is contained in:
Timothy Schenk 2023-11-19 15:05:48 +01:00
parent 600f4a2f50
commit 6589a9f890
6 changed files with 16 additions and 12 deletions

View file

@ -29,14 +29,14 @@ public class AuthSession : TcpSession
return base.Send(buffer); return base.Send(buffer);
} }
public void Send(IPacket packet) public Task SendAsync(IPacket packet)
{ {
var type = packet.GetType(); var type = packet.GetType();
this._logger.LogInformation("Packet of type {Type} is being serialized", type.Name); this._logger.LogInformation("Packet of type {Type} is being serialized", type.Name);
var packetIdAttribute = type.GetCustomAttribute<PacketIdAttribute>(); var packetIdAttribute = type.GetCustomAttribute<PacketIdAttribute>();
if (packetIdAttribute == null) if (packetIdAttribute == null)
{ {
return; return Task.CompletedTask;
} }
var opcode = packetIdAttribute.Code; 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 data being parsed is: {Data}", BitConverter.ToString(packetData.ToArray()));
this._logger.LogInformation("Packet being parsed is: {Data}", BitConverter.ToString(buffer.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) protected override void OnReceived(byte[] buffer, long offset, long size)

View file

@ -80,11 +80,11 @@ public class ChannelSelectionHandler : IPacketHandler<ChannelSelectionPacket>
}; };
} }
authSession.Send(responsePacket); await authSession.SendAsync(responsePacket).ConfigureAwait(false);
if (guildNameResponsePacket.GuildNames.Length > 0 && if (guildNameResponsePacket.GuildNames.Length > 0 &&
guildNameResponsePacket.GuildNames.Select(n => n != string.Empty).Any()) guildNameResponsePacket.GuildNames.Select(n => n != string.Empty).Any())
{ {
authSession.Send(guildNameResponsePacket); await authSession.SendAsync(guildNameResponsePacket).ConfigureAwait(false);
} }
} }

View file

@ -107,12 +107,12 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
.Select(item => item.ItemId) .Select(item => item.ItemId)
.ToArray(), .ToArray(),
}).FirstAsync().ConfigureAwait(true); }).FirstAsync().ConfigureAwait(true);
authSession?.Send(new CharacterCreationResponsePacket await authSession.SendAsync(new CharacterCreationResponsePacket
{ {
Character = character, Character = character,
Slot = amountOfCharacters - 1, Slot = amountOfCharacters - 1,
isDuplicate = false, isDuplicate = false,
}); }).ConfigureAwait(false);
} }
private static int CalculateCurrentHealth(ushort level, JobSpecificMapping firstJobConfig) private static int CalculateCurrentHealth(ushort level, JobSpecificMapping firstJobConfig)

View file

@ -30,13 +30,13 @@ public class CharacterDeletionHandler : IPacketHandler<CharacterDeletePacket>
var response = new CharacterDeleteResponsePacket { IsDeleted = 0 }; var response = new CharacterDeleteResponsePacket { IsDeleted = 0 };
if (character == null) if (character == null)
{ {
authSession.Send(response); await authSession.SendAsync(response).ConfigureAwait(false);
return; return;
} }
//_wonderkingContext.Characters.Remove(character); //_wonderkingContext.Characters.Remove(character);
//await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false); //await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false);
authSession.Send(response); await authSession.SendAsync(response).ConfigureAwait(false);
} }
} }

View file

@ -18,8 +18,11 @@ public class CharacterNameCheckHandler : IPacketHandler<CharacterNameCheckPacket
{ {
var isTaken = _wonderkingContext.Characters.Any(c => c.Name == packet.Name); var isTaken = _wonderkingContext.Characters.Any(c => c.Name == packet.Name);
var responsePacket = new CharacterNameCheckPacketResponse { IsTaken = isTaken }; var responsePacket = new CharacterNameCheckPacketResponse { IsTaken = isTaken };
var authSession = session as AuthSession; if (session is AuthSession authSession)
authSession?.Send(responsePacket); {
return authSession.SendAsync(responsePacket);
}
return Task.CompletedTask; return Task.CompletedTask;
} }
} }

View file

@ -119,6 +119,6 @@ public class LoginHandler : IPacketHandler<LoginInfoPacket>
} }
_logger.LogInformation("LoginResponsePacket: {@LoginResponsePacket}", loginResponsePacket); _logger.LogInformation("LoginResponsePacket: {@LoginResponsePacket}", loginResponsePacket);
sess?.Send(loginResponsePacket); sess?.SendAsync(loginResponsePacket);
} }
} }