continuity/Continuity.AuthServer/PacketHandlers/CharacterDeletionHandler.cs

35 lines
1.2 KiB
C#
Raw Permalink Normal View History

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
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;
namespace Continuity.AuthServer.PacketHandlers;
2023-11-16 16:55:36 +00:00
public class CharacterDeletionHandler : IPacketHandler<CharacterDeletePacket, AuthSession> {
2023-11-16 16:55:36 +00:00
private readonly WonderkingContext _wonderkingContext;
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,
CancellationToken cancellationToken) {
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 };
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
}
}