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