2024-02-07 16:40:36 +01:00
|
|
|
// Licensed to Timothy Schenk under the GNU AGPL Version 3 License.
|
2023-11-20 19:58:30 +01:00
|
|
|
|
2024-01-29 08:39:18 +01:00
|
|
|
using Continuity.AuthServer.DB;
|
2023-11-16 17:55:36 +01:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2024-02-04 19:52:45 +01:00
|
|
|
using Rai.PacketMediator;
|
2023-11-16 17:55:36 +01:00
|
|
|
using Wonderking.Packets.Incoming;
|
|
|
|
using Wonderking.Packets.Outgoing;
|
|
|
|
|
2024-01-29 08:39:18 +01:00
|
|
|
namespace Continuity.AuthServer.PacketHandlers;
|
2023-11-16 17:55:36 +01:00
|
|
|
|
2024-02-05 18:12:12 +01:00
|
|
|
public class CharacterDeletionHandler : IPacketHandler<CharacterDeletePacket, AuthSession>
|
2023-11-16 17:55:36 +01:00
|
|
|
{
|
|
|
|
private readonly WonderkingContext _wonderkingContext;
|
|
|
|
|
|
|
|
public CharacterDeletionHandler(WonderkingContext wonderkingContext)
|
|
|
|
{
|
|
|
|
_wonderkingContext = wonderkingContext;
|
|
|
|
}
|
|
|
|
|
2024-02-07 16:40:36 +01:00
|
|
|
public async Task HandleAsync(CharacterDeletePacket packet, AuthSession session,
|
|
|
|
CancellationToken cancellationToken)
|
2023-11-16 17:55:36 +01:00
|
|
|
{
|
2023-11-16 21:01:55 +01:00
|
|
|
var character = await _wonderkingContext.Characters.FirstOrDefaultAsync(x => x.Name == packet.Name &&
|
2024-02-07 16:40:36 +01:00
|
|
|
x.Account.Id == session.AccountId, cancellationToken);
|
2023-11-25 17:59:17 +01:00
|
|
|
|
2023-11-25 17:57:15 +01:00
|
|
|
var response = new CharacterDeleteResponsePacket { HasToBeZero = 0 };
|
2023-11-16 17:55:36 +01:00
|
|
|
if (character == null)
|
|
|
|
{
|
2024-02-05 18:12:12 +01:00
|
|
|
await session.SendAsync(response);
|
2023-11-16 17:55:36 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-19 15:08:17 +01:00
|
|
|
_wonderkingContext.Characters.Remove(character);
|
2024-02-05 12:08:00 +01:00
|
|
|
await _wonderkingContext.SaveChangesAsync(cancellationToken);
|
2023-11-16 17:55:36 +01:00
|
|
|
|
2024-02-05 18:12:12 +01:00
|
|
|
await session.SendAsync(response);
|
2023-11-16 17:55:36 +01:00
|
|
|
}
|
|
|
|
}
|