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