continuity/Server/PacketHandlers/CharacterDeletionHandler.cs
Timothy Schenk efdbad09d0
All checks were successful
Build, Package and Push Images / preprocess (push) Successful in 3s
Build, Package and Push Images / build (push) Successful in 25s
Build, Package and Push Images / sonarqube (push) Has been skipped
Build, Package and Push Images / sbom-scan (push) Successful in 40s
Build, Package and Push Images / container-build (push) Successful in 1m32s
Build, Package and Push Images / container-sbom-scan (push) Successful in 33s
feat: identical to item listing, stats not being calculated in its entirety
2023-11-17 11:14:42 +01:00

42 lines
1.2 KiB
C#

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;
if (authSession == null)
{
session.Disconnect();
return;
}
var character = await _wonderkingContext.Characters.FirstOrDefaultAsync(x => x.Name == packet.Name &&
x.Account.Id == authSession.AccountId)
.ConfigureAwait(true);
var response = new CharacterDeleteResponsePacket { IsDeleted = 0 };
if (character == null)
{
authSession.Send(response);
return;
}
//_wonderkingContext.Characters.Remove(character);
//await _wonderkingContext.SaveChangesAsync().ConfigureAwait(false);
authSession.Send(response);
}
}