continuity/Continuity.AuthServer/PacketHandlers/CharacterNameCheckHandler.cs

31 lines
1,005 B
C#
Raw Normal View History

2024-02-07 15:40:36 +00:00
// Licensed to Timothy Schenk under the GNU AGPL Version 3 License.
2023-11-20 18:58:30 +00:00
using Continuity.AuthServer.DB;
2023-11-21 20:36:05 +00:00
using Microsoft.EntityFrameworkCore;
using Rai.PacketMediator;
using Wonderking.Packets.Incoming;
using Wonderking.Packets.Outgoing;
namespace Continuity.AuthServer.PacketHandlers;
2024-02-05 17:12:12 +00:00
public class CharacterNameCheckHandler : IPacketHandler<CharacterNameCheckPacket, AuthSession>
{
private readonly WonderkingContext _wonderkingContext;
public CharacterNameCheckHandler(WonderkingContext wonderkingContext)
{
_wonderkingContext = wonderkingContext;
}
2024-02-05 17:12:12 +00:00
public async Task HandleAsync(CharacterNameCheckPacket packet, AuthSession session,
2024-02-05 11:08:00 +00:00
CancellationToken cancellationToken)
{
2024-02-05 17:12:12 +00:00
var isTaken =
await _wonderkingContext.Characters.AnyAsync(c => c.Name == packet.Name,
2024-02-07 15:40:36 +00:00
cancellationToken);
var responsePacket = new CharacterNameCheckPacketResponse { IsTaken = isTaken };
2024-02-05 17:12:12 +00:00
await session.SendAsync(responsePacket);
}
}