continuity/Continuity.AuthServer/PacketHandlers/CharacterNameCheckHandler.cs
Timothy Schenk 3a24dabdf2
chore: formatting and slnx
Signed-off-by: Timothy Schenk <admin@rainote.dev>
2025-01-16 14:30:40 +01:00

27 lines
1,001 B
C#

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