// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License. using Continuity.AuthServer.DB; using Microsoft.EntityFrameworkCore; using NetCoreServer; using Wonderking.Packets.Incoming; using Wonderking.Packets.Outgoing; namespace Continuity.AuthServer.PacketHandlers; public class CharacterNameCheckHandler : IPacketHandler { private readonly WonderkingContext _wonderkingContext; public CharacterNameCheckHandler(WonderkingContext wonderkingContext) { _wonderkingContext = wonderkingContext; } public async Task HandleAsync(CharacterNameCheckPacket packet, TcpSession session) { var isTaken = await _wonderkingContext.Characters.AnyAsync(c => c.Name == packet.Name); var responsePacket = new CharacterNameCheckPacketResponse { IsTaken = isTaken }; if (session is AuthSession authSession) { await authSession.SendAsync(responsePacket); } } }