2023-11-21 20:37:50 +00:00
|
|
|
// Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License.
|
2023-11-20 18:58:30 +00:00
|
|
|
|
2024-01-29 07:39:18 +00:00
|
|
|
using Continuity.AuthServer.DB;
|
2023-11-21 20:36:05 +00:00
|
|
|
using Microsoft.EntityFrameworkCore;
|
2023-11-15 19:00:08 +00:00
|
|
|
using NetCoreServer;
|
|
|
|
using Wonderking.Packets.Incoming;
|
|
|
|
using Wonderking.Packets.Outgoing;
|
|
|
|
|
2024-01-29 07:39:18 +00:00
|
|
|
namespace Continuity.AuthServer.PacketHandlers;
|
2023-11-15 19:00:08 +00:00
|
|
|
|
|
|
|
public class CharacterNameCheckHandler : IPacketHandler<CharacterNameCheckPacket>
|
|
|
|
{
|
|
|
|
private readonly WonderkingContext _wonderkingContext;
|
|
|
|
|
|
|
|
public CharacterNameCheckHandler(WonderkingContext wonderkingContext)
|
|
|
|
{
|
|
|
|
_wonderkingContext = wonderkingContext;
|
|
|
|
}
|
|
|
|
|
2023-11-21 20:36:05 +00:00
|
|
|
public async Task HandleAsync(CharacterNameCheckPacket packet, TcpSession session)
|
2023-11-15 19:00:08 +00:00
|
|
|
{
|
2023-11-21 20:36:05 +00:00
|
|
|
var isTaken = await _wonderkingContext.Characters.AnyAsync(c => c.Name == packet.Name);
|
2023-11-15 19:00:08 +00:00
|
|
|
var responsePacket = new CharacterNameCheckPacketResponse { IsTaken = isTaken };
|
2023-11-19 14:05:48 +00:00
|
|
|
if (session is AuthSession authSession)
|
|
|
|
{
|
2023-11-21 20:36:05 +00:00
|
|
|
await authSession.SendAsync(responsePacket);
|
2023-11-19 14:05:48 +00:00
|
|
|
}
|
2023-11-15 19:00:08 +00:00
|
|
|
}
|
|
|
|
}
|