From 756031b186599ae67cd1dc861c2a5b5bb0811a4a Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Mon, 14 Aug 2023 22:22:43 +0200 Subject: [PATCH] feat: initial ChannelSelection --- Server/AuthSession.cs | 1 + .../PacketHandlers/ChannelSelectionHandler.cs | 33 +++++++++++++++++++ .../Incoming/ChannelSelectionPacket.cs | 16 +++++++++ Server/Packets/OperationCode.cs | 3 +- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 Server/PacketHandlers/ChannelSelectionHandler.cs create mode 100644 Server/Packets/Incoming/ChannelSelectionPacket.cs diff --git a/Server/AuthSession.cs b/Server/AuthSession.cs index eeb925d..2dec4ab 100644 --- a/Server/AuthSession.cs +++ b/Server/AuthSession.cs @@ -10,6 +10,7 @@ public class AuthSession : TcpSession { private readonly ILogger logger; private readonly IMediator mediator; + public Guid AccountId { get; set; } public AuthSession(TcpServer server, IMediator mediator, ILogger logger) : base(server) diff --git a/Server/PacketHandlers/ChannelSelectionHandler.cs b/Server/PacketHandlers/ChannelSelectionHandler.cs new file mode 100644 index 0000000..99a69cd --- /dev/null +++ b/Server/PacketHandlers/ChannelSelectionHandler.cs @@ -0,0 +1,33 @@ +namespace Server.PacketHandlers; + +using DB; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using NetCoreServer; +using Packets.Incoming; + +public class ChannelSelectionHandler : IPacketHandler +{ + private readonly IConfiguration configuration; + private readonly ILogger logger; + private readonly WonderkingContext wonderkingContext; + + public ChannelSelectionHandler(IConfiguration configuration, ILogger logger, + WonderkingContext wonderkingContext) + { + this.configuration = configuration; + this.logger = logger; + this.wonderkingContext = wonderkingContext; + } + + public ChannelSelectionHandler() + { + } + + public Task HandleAsync(ChannelSelectionPacket packet, TcpSession session) + { + var authSession = (AuthSession)session; + var charactersOfAccount = this.wonderkingContext.Accounts.FirstOrDefault(a => a.Id == authSession.AccountId); + return Task.CompletedTask; + } +} diff --git a/Server/Packets/Incoming/ChannelSelectionPacket.cs b/Server/Packets/Incoming/ChannelSelectionPacket.cs new file mode 100644 index 0000000..4163895 --- /dev/null +++ b/Server/Packets/Incoming/ChannelSelectionPacket.cs @@ -0,0 +1,16 @@ +namespace Server.Packets.Incoming; + +[PacketId(OperationCode.ChannelSelection)] +public class ChannelSelectionPacket : IPacket +{ + public required ushort ServerId { get; set; } + public required ushort ChannelId { get; set; } + + public void Deserialize(byte[] data) + { + this.ServerId = BitConverter.ToUInt16(data, 0); + this.ChannelId = BitConverter.ToUInt16(data, 2); + } + + public byte[] Serialize() => throw new NotImplementedException(); +} diff --git a/Server/Packets/OperationCode.cs b/Server/Packets/OperationCode.cs index c3099f2..96a3310 100644 --- a/Server/Packets/OperationCode.cs +++ b/Server/Packets/OperationCode.cs @@ -3,5 +3,6 @@ public enum OperationCode : ushort { LoginInfo = 11, - LoginResponse = 12 + LoginResponse = 12, + ChannelSelection }