From 42c53584f7164cefa270b3de91acec7633042635 Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Fri, 17 Nov 2023 08:25:29 +0100 Subject: [PATCH] refactor: slight adjustments --- Server/AuthSession.cs | 6 ++++++ Server/PacketHandlers/ChannelSelectionHandler.cs | 12 ++++++------ Wonderking/Packets/Outgoing/LoginResponsePacket.cs | 5 ++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Server/AuthSession.cs b/Server/AuthSession.cs index d871bb0..ae0f4c9 100644 --- a/Server/AuthSession.cs +++ b/Server/AuthSession.cs @@ -1,3 +1,4 @@ +using System.Net.Sockets; using Wonderking.Packets; namespace Server; @@ -105,4 +106,9 @@ public class AuthSession : TcpSession return buffer; } + + protected override void OnError(SocketError error) + { + _logger.LogWarning("An error has occured: {Error}", error); + } } diff --git a/Server/PacketHandlers/ChannelSelectionHandler.cs b/Server/PacketHandlers/ChannelSelectionHandler.cs index 8a66499..9e474ff 100644 --- a/Server/PacketHandlers/ChannelSelectionHandler.cs +++ b/Server/PacketHandlers/ChannelSelectionHandler.cs @@ -25,10 +25,6 @@ public class ChannelSelectionHandler : IPacketHandler this._wonderkingContext = wonderkingContext; } - public ChannelSelectionHandler() - { - } - public async Task HandleAsync(ChannelSelectionPacket packet, TcpSession session) { var authSession = (AuthSession)session; @@ -80,12 +76,16 @@ public class ChannelSelectionHandler : IPacketHandler { ChannelIsFullFlag = 0, Endpoint = "127.0.0.1", - Port = 12345, + Port = 2000, Characters = Array.Empty() }; } authSession.Send(responsePacket); - authSession.Send(guildNameResponsePacket); + if (guildNameResponsePacket.GuildNames.Length > 0 && + guildNameResponsePacket.GuildNames.Select(n => n != string.Empty).Any()) + { + authSession.Send(guildNameResponsePacket); + } } } diff --git a/Wonderking/Packets/Outgoing/LoginResponsePacket.cs b/Wonderking/Packets/Outgoing/LoginResponsePacket.cs index e3060bb..de08649 100644 --- a/Wonderking/Packets/Outgoing/LoginResponsePacket.cs +++ b/Wonderking/Packets/Outgoing/LoginResponsePacket.cs @@ -1,3 +1,4 @@ +using System.Buffers.Binary; using Wonderking.Packets.Outgoing.Data; namespace Wonderking.Packets.Outgoing; @@ -34,9 +35,7 @@ public class LoginResponsePacket : IPacket dataSpan[0] = (byte)this.ResponseReason; dataSpan[1] = this.UnknownFlag; dataSpan[2] = BitConverter.GetBytes(this.IsGameMaster)[0]; - var bytesOfChannelAmount = BitConverter.GetBytes((ushort)this.ChannelData.Length); - dataSpan[3] = bytesOfChannelAmount[0]; - dataSpan[4] = bytesOfChannelAmount[1]; + BinaryPrimitives.WriteUInt16LittleEndian(dataSpan.Slice(3, 2), (ushort)this.ChannelData.Length); for (var i = 0; i < this.ChannelData.Length; i++) {