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)
|
|
|
|
{
|
|
|
|
using var authSession = session as AuthSession;
|
|
|
|
var response = new CharacterDeleteResponsePacket { Response = CharacterDeletionResponse.MakeClientStuck };
|
|
|
|
if (authSession == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-16 20:01:55 +00:00
|
|
|
var character = await _wonderkingContext.Characters.FirstOrDefaultAsync(x => x.Name == packet.Name &&
|
|
|
|
x.Account.Id == authSession.AccountId)
|
2023-11-16 16:55:36 +00:00
|
|
|
.ConfigureAwait(false);
|
|
|
|
if (character == null)
|
|
|
|
{
|
|
|
|
authSession.Send(response);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_wonderkingContext.Characters.Remove(character);
|
|
|
|
await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false);
|
|
|
|
response.Response = CharacterDeletionResponse.Ok;
|
|
|
|
|
|
|
|
authSession.Send(response);
|
|
|
|
}
|
|
|
|
}
|