From e305ce49aa378f604b56242cd00a35b00c7b811a Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Sun, 4 Feb 2024 20:05:39 +0100 Subject: [PATCH] chore: cleanup leftovers --- Rai.PacketMediator/IIncomingPacket.cs | 4 ++++ Rai.PacketMediator/IOutgoingPacket.cs | 4 ++++ .../Packets/Incoming/ChannelSelectionPacket.cs | 5 ----- .../Incoming/CharacterCreationPacket.cs | 5 ----- .../Packets/Incoming/CharacterDeletePacket.cs | 5 ----- .../Incoming/CharacterNameCheckPacket.cs | 5 ----- Wonderking/Packets/Incoming/LoginInfoPacket.cs | 18 ------------------ .../Outgoing/ChannelSelectionResponsePacket.cs | 5 ----- .../CharacterCreationResponsePacket.cs | 5 ----- .../Outgoing/CharacterDeleteResponsePacket.cs | 6 ------ .../CharacterNameCheckPacketResponse.cs | 6 ------ .../CharacterSelectionSetGuildNamePacket.cs | 6 ------ .../Packets/Outgoing/LoginResponsePacket.cs | 16 ---------------- 13 files changed, 8 insertions(+), 82 deletions(-) diff --git a/Rai.PacketMediator/IIncomingPacket.cs b/Rai.PacketMediator/IIncomingPacket.cs index 40e3c19..34e162d 100644 --- a/Rai.PacketMediator/IIncomingPacket.cs +++ b/Rai.PacketMediator/IIncomingPacket.cs @@ -1,8 +1,12 @@ // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License. +using JetBrains.Annotations; + namespace Rai.PacketMediator; +[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)] public interface IIncomingPacket : IPacket { + [UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)] public void Deserialize(byte[] data); } diff --git a/Rai.PacketMediator/IOutgoingPacket.cs b/Rai.PacketMediator/IOutgoingPacket.cs index eb1feb7..a63aa27 100644 --- a/Rai.PacketMediator/IOutgoingPacket.cs +++ b/Rai.PacketMediator/IOutgoingPacket.cs @@ -1,8 +1,12 @@ // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License. +using JetBrains.Annotations; + namespace Rai.PacketMediator; +[UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)] public interface IOutgoingPacket : IPacket { + [UsedImplicitly(ImplicitUseTargetFlags.WithInheritors)] public byte[] Serialize(); } diff --git a/Wonderking/Packets/Incoming/ChannelSelectionPacket.cs b/Wonderking/Packets/Incoming/ChannelSelectionPacket.cs index c7ec7af..9d122ef 100644 --- a/Wonderking/Packets/Incoming/ChannelSelectionPacket.cs +++ b/Wonderking/Packets/Incoming/ChannelSelectionPacket.cs @@ -15,9 +15,4 @@ public class ChannelSelectionPacket : IIncomingPacket ServerId = BitConverter.ToUInt16(data, 0); ChannelId = BitConverter.ToUInt16(data, 2); } - - public byte[] Serialize() - { - throw new NotSupportedException(); - } } diff --git a/Wonderking/Packets/Incoming/CharacterCreationPacket.cs b/Wonderking/Packets/Incoming/CharacterCreationPacket.cs index b0f6259..7516212 100644 --- a/Wonderking/Packets/Incoming/CharacterCreationPacket.cs +++ b/Wonderking/Packets/Incoming/CharacterCreationPacket.cs @@ -34,9 +34,4 @@ public class CharacterCreationPacket : IIncomingPacket Shirt = data[28]; Pants = data[29]; } - - public byte[] Serialize() - { - throw new NotSupportedException(); - } } diff --git a/Wonderking/Packets/Incoming/CharacterDeletePacket.cs b/Wonderking/Packets/Incoming/CharacterDeletePacket.cs index da7780b..c5625f9 100644 --- a/Wonderking/Packets/Incoming/CharacterDeletePacket.cs +++ b/Wonderking/Packets/Incoming/CharacterDeletePacket.cs @@ -19,9 +19,4 @@ public class CharacterDeletePacket : IIncomingPacket Name = Encoding.ASCII.GetString(span.Slice(1, 20)).TrimEnd('\0').TrimEnd('\n').TrimEnd('\0'); Unknown = BitConverter.ToUInt32(span.Slice(21, 4)); } - - public byte[] Serialize() - { - throw new NotSupportedException(); - } } diff --git a/Wonderking/Packets/Incoming/CharacterNameCheckPacket.cs b/Wonderking/Packets/Incoming/CharacterNameCheckPacket.cs index 4b4521a..23d19b0 100644 --- a/Wonderking/Packets/Incoming/CharacterNameCheckPacket.cs +++ b/Wonderking/Packets/Incoming/CharacterNameCheckPacket.cs @@ -14,9 +14,4 @@ public class CharacterNameCheckPacket : IIncomingPacket { Name = Encoding.ASCII.GetString(data, 0, 20).TrimEnd('\0').TrimEnd('\n').TrimEnd('\0'); } - - public byte[] Serialize() - { - throw new NotSupportedException(); - } } diff --git a/Wonderking/Packets/Incoming/LoginInfoPacket.cs b/Wonderking/Packets/Incoming/LoginInfoPacket.cs index faf6cd3..967ca07 100644 --- a/Wonderking/Packets/Incoming/LoginInfoPacket.cs +++ b/Wonderking/Packets/Incoming/LoginInfoPacket.cs @@ -18,22 +18,4 @@ public class LoginInfoPacket : IIncomingPacket // Remove unnecessary Symbols Password = Encoding.ASCII.GetString(data, 20, 31).TrimEnd('\0').TrimEnd('\n').TrimEnd('\0'); } - - public byte[] Serialize() - { - Span dataSpan = stackalloc byte[20 + 31]; - var usernameBytes = Encoding.ASCII.GetBytes(Username); - var passwordBytes = Encoding.ASCII.GetBytes(Password); - for (var i = 0; i < 20 || i < Username.Length; i++) - { - dataSpan[i] = usernameBytes[i]; - } - - for (var i = 0; i < 31 || i < Password.Length; i++) - { - dataSpan[20 + i] = passwordBytes[i]; - } - - return dataSpan.ToArray(); - } } diff --git a/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs b/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs index 44f809f..5d5dc24 100644 --- a/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs +++ b/Wonderking/Packets/Outgoing/ChannelSelectionResponsePacket.cs @@ -15,11 +15,6 @@ public class ChannelSelectionResponsePacket : IOutgoingPacket public required ushort Port { get; set; } public required CharacterData[] Characters { get; set; } - public void Deserialize(byte[] data) - { - throw new NotSupportedException(); - } - public byte[] Serialize() { Span data = stackalloc byte[1 + 16 + 2 + 1 + 132 * Characters.Length]; diff --git a/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs b/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs index e6a1eb5..d3d6087 100644 --- a/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs +++ b/Wonderking/Packets/Outgoing/CharacterCreationResponsePacket.cs @@ -14,11 +14,6 @@ public class CharacterCreationResponsePacket : IOutgoingPacket public required int Slot { get; set; } public required bool isDuplicate { get; set; } - public void Deserialize(byte[] data) - { - throw new NotSupportedException(); - } - public byte[] Serialize() { Span data = stackalloc byte[1 + 132]; diff --git a/Wonderking/Packets/Outgoing/CharacterDeleteResponsePacket.cs b/Wonderking/Packets/Outgoing/CharacterDeleteResponsePacket.cs index 01b0911..6e04c25 100644 --- a/Wonderking/Packets/Outgoing/CharacterDeleteResponsePacket.cs +++ b/Wonderking/Packets/Outgoing/CharacterDeleteResponsePacket.cs @@ -1,7 +1,6 @@ // Copyright (c) 2023 Timothy Schenk. Subject to the GNU AGPL Version 3 License. using Rai.PacketMediator; -using NotSupportedException = System.NotSupportedException; namespace Wonderking.Packets.Outgoing; @@ -10,11 +9,6 @@ public class CharacterDeleteResponsePacket : IOutgoingPacket { public required byte HasToBeZero { get; set; } - public void Deserialize(byte[] data) - { - throw new NotSupportedException(); - } - public byte[] Serialize() { Span data = stackalloc byte[1]; diff --git a/Wonderking/Packets/Outgoing/CharacterNameCheckPacketResponse.cs b/Wonderking/Packets/Outgoing/CharacterNameCheckPacketResponse.cs index 97ff542..c91a18b 100644 --- a/Wonderking/Packets/Outgoing/CharacterNameCheckPacketResponse.cs +++ b/Wonderking/Packets/Outgoing/CharacterNameCheckPacketResponse.cs @@ -8,12 +8,6 @@ namespace Wonderking.Packets.Outgoing; public class CharacterNameCheckPacketResponse : IOutgoingPacket { public required bool IsTaken { get; set; } - - public void Deserialize(byte[] data) - { - throw new NotSupportedException(); - } - public byte[] Serialize() { Span data = stackalloc byte[1]; diff --git a/Wonderking/Packets/Outgoing/CharacterSelectionSetGuildNamePacket.cs b/Wonderking/Packets/Outgoing/CharacterSelectionSetGuildNamePacket.cs index be90526..0c89ce9 100644 --- a/Wonderking/Packets/Outgoing/CharacterSelectionSetGuildNamePacket.cs +++ b/Wonderking/Packets/Outgoing/CharacterSelectionSetGuildNamePacket.cs @@ -9,12 +9,6 @@ namespace Wonderking.Packets.Outgoing; public class CharacterSelectionSetGuildNamePacket : IOutgoingPacket { public required string[] GuildNames { get; set; } - - public void Deserialize(byte[] data) - { - throw new NotSupportedException(); - } - public byte[] Serialize() { Span data = stackalloc byte[1 + (1 + 16 + 1) * GuildNames.Length]; diff --git a/Wonderking/Packets/Outgoing/LoginResponsePacket.cs b/Wonderking/Packets/Outgoing/LoginResponsePacket.cs index 1e9e668..98870f2 100644 --- a/Wonderking/Packets/Outgoing/LoginResponsePacket.cs +++ b/Wonderking/Packets/Outgoing/LoginResponsePacket.cs @@ -14,22 +14,6 @@ public class LoginResponsePacket : IOutgoingPacket public required bool IsGameMaster { get; set; } public required ServerChannelData[] ChannelData { get; set; } - - public void Deserialize(byte[] data) - { - ResponseReason = (LoginResponseReason)data[0]; - UnknownFlag = data[1]; - IsGameMaster = BitConverter.ToBoolean(data, 2); - var channelAmount = BitConverter.ToUInt16(data, 3); - const int sizeOfServerChannelData = 5; - ChannelData = Enumerable.Repeat(0, channelAmount).Select(i => new ServerChannelData - { - ServerId = BitConverter.ToUInt16(data, 5 + 0 + i * sizeOfServerChannelData), - ChannelId = BitConverter.ToUInt16(data, 5 + 2 + i * sizeOfServerChannelData), - LoadPercentage = data[5 + 4 + i * sizeOfServerChannelData] - }).ToArray(); - } - public byte[] Serialize() { const int sizeOfServerChannelData = 5;