continuity/Continuity.AuthServer/PacketHandlers/CharacterNameCheckHandler.cs
Timothy Schenk 6d9a72ded4
Some checks failed
Build, Package and Push Images / preprocess (push) Successful in 2s
Build, Package and Push Images / build (push) Successful in 25s
Build, Package and Push Images / sbom-scan (push) Successful in 36s
Build, Package and Push Images / sonarqube (push) Failing after 1m36s
Build, Package and Push Images / container-build (push) Successful in 2m4s
Build, Package and Push Images / container-sbom-scan (push) Successful in 39s
chore: dependency upgrade & missing refactor from Server to AuthServer
2024-01-29 08:39:18 +01:00

29 lines
982 B
C#

// 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<CharacterNameCheckPacket>
{
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);
}
}
}