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