continuity/Server/PacketHandlers/CharacterDeletionHandler.cs

42 lines
1.3 KiB
C#
Raw Normal View History

2023-11-16 16:55:36 +00:00
using Microsoft.EntityFrameworkCore;
using NetCoreServer;
using Server.DB;
using Wonderking.Packets.Incoming;
using Wonderking.Packets.Outgoing;
namespace Server.PacketHandlers;
public class CharacterDeletionHandler : IPacketHandler<CharacterDeletePacket>
{
private readonly WonderkingContext _wonderkingContext;
public CharacterDeletionHandler(WonderkingContext wonderkingContext)
{
_wonderkingContext = wonderkingContext;
}
public async Task HandleAsync(CharacterDeletePacket packet, TcpSession session)
{
if (session is not AuthSession authSession)
2023-11-16 16:55:36 +00:00
{
2023-11-16 22:51:30 +00:00
session.Disconnect();
2023-11-16 16:55:36 +00:00
return;
}
var character = await _wonderkingContext.Characters.FirstOrDefaultAsync(x => x.Name == packet.Name &&
x.Account.Id == authSession.AccountId)
2023-11-16 22:51:30 +00:00
.ConfigureAwait(true);
var response = new CharacterDeleteResponsePacket { IsDeleted = 0 };
2023-11-16 16:55:36 +00:00
if (character == null)
{
2023-11-19 14:05:48 +00:00
await authSession.SendAsync(response).ConfigureAwait(false);
2023-11-16 16:55:36 +00:00
return;
}
//_wonderkingContext.Characters.Remove(character);
//await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false);
2023-11-16 16:55:36 +00:00
2023-11-19 14:05:48 +00:00
await authSession.SendAsync(response).ConfigureAwait(false);
2023-11-16 16:55:36 +00:00
}
}