From aa2fdc4455c4df918f5e0a42b22216fd0856350b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sun, 15 Jan 2023 17:08:32 +0100 Subject: [PATCH] feat(packets): make lists and conditional parameters non-optional non-nullable --- .../PacketHandlers/Raids/RaidResponder.cs | 6 +++--- .../Client/Inventory/UseItemPacket.cs | 2 +- Packets/NosSmooth.Packets/Client/Misc/PulsePacket.cs | 2 +- .../Raids/{RaidLeaveType.cs => RaidJoinLeaveType.cs} | 10 +++++----- .../NosSmooth.Packets/Enums/Raids/RaidPacketType.cs | 2 +- .../NosSmooth.Packets/Server/Entities/StPacket.cs | 2 +- .../NosSmooth.Packets/Server/Families/GidxPacket.cs | 4 ++-- .../NosSmooth.Packets/Server/Groups/PinitPacket.cs | 4 ++-- .../Server/Groups/PinitSubPacket.cs | 4 ++-- .../NosSmooth.Packets/Server/Inventory/InvPacket.cs | 2 +- Packets/NosSmooth.Packets/Server/Raids/RaidPacket.cs | 12 ++++++------ .../NosSmooth.Packets/Server/Skills/CancelPacket.cs | 6 +++--- Packets/NosSmooth.Packets/Server/UI/Act6Packet.cs | 2 +- .../Converters/Packets/RaidPacketConverterTests.cs | 12 ++++++------ 14 files changed, 35 insertions(+), 35 deletions(-) rename Packets/NosSmooth.Packets/Enums/Raids/{RaidLeaveType.cs => RaidJoinLeaveType.cs} (75%) diff --git a/Core/NosSmooth.Game/PacketHandlers/Raids/RaidResponder.cs b/Core/NosSmooth.Game/PacketHandlers/Raids/RaidResponder.cs index 9c986dd6caa959fdc590e96438ce43b5ae32d319..894468216d6f226642eacbbed49045dac3270995 100644 --- a/Core/NosSmooth.Game/PacketHandlers/Raids/RaidResponder.cs +++ b/Core/NosSmooth.Game/PacketHandlers/Raids/RaidResponder.cs @@ -41,7 +41,7 @@ public class RaidResponder : IPacketResponder public async Task Respond(PacketEventArgs packetArgs, CancellationToken ct = default) { var packet = packetArgs.Packet; - if (packet.Type is not(RaidPacketType.Leader or RaidPacketType.ListMembers or RaidPacketType.PlayerHealths or RaidPacketType.Leave)) + if (packet.Type is not(RaidPacketType.Leader or RaidPacketType.ListMembers or RaidPacketType.PlayerHealths or RaidPacketType.JoinLeave)) { return Result.FromSuccess(); } @@ -54,8 +54,8 @@ public class RaidResponder : IPacketResponder prevRaid = raid; switch (packet.Type) { - case RaidPacketType.Leave: - if (packet.LeaveType is not null && packet.LeaveType == RaidLeaveType.PlayerLeft) + case RaidPacketType.JoinLeave: + if (packet.JoinLeaveType is not null && packet.JoinLeaveType == RaidJoinLeaveType.PlayerLeft) { // the player has left. prevRaid = raid with { diff --git a/Packets/NosSmooth.Packets/Client/Inventory/UseItemPacket.cs b/Packets/NosSmooth.Packets/Client/Inventory/UseItemPacket.cs index 1f2c9a683e6e01735ae3530d277ea0c6ec4e9820..6fb7560ea95cb42007871f9a518f69b9610a5e29 100644 --- a/Packets/NosSmooth.Packets/Client/Inventory/UseItemPacket.cs +++ b/Packets/NosSmooth.Packets/Client/Inventory/UseItemPacket.cs @@ -21,5 +21,5 @@ public record UseItemPacket [PacketIndex(0)] BagType BagType, [PacketIndex(1)] - short Slot + long Slot ) : IPacket; \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Client/Misc/PulsePacket.cs b/Packets/NosSmooth.Packets/Client/Misc/PulsePacket.cs index cecd5242b04f576e6bd5229f5b6a738f26fe8930..f8aaa65ada3b3bdec0c29fceda6f2243a291dffd 100644 --- a/Packets/NosSmooth.Packets/Client/Misc/PulsePacket.cs +++ b/Packets/NosSmooth.Packets/Client/Misc/PulsePacket.cs @@ -24,4 +24,4 @@ public record PulsePacket long Seconds, [PacketIndex(1)] short Unknown -); \ No newline at end of file +) : IPacket; \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Enums/Raids/RaidLeaveType.cs b/Packets/NosSmooth.Packets/Enums/Raids/RaidJoinLeaveType.cs similarity index 75% rename from Packets/NosSmooth.Packets/Enums/Raids/RaidLeaveType.cs rename to Packets/NosSmooth.Packets/Enums/Raids/RaidJoinLeaveType.cs index 098eb5940a907dea426587a33b7247d3bf62ab12..a6ab9ba429e3eb88eabea07e522ce9c04037272b 100644 --- a/Packets/NosSmooth.Packets/Enums/Raids/RaidLeaveType.cs +++ b/Packets/NosSmooth.Packets/Enums/Raids/RaidJoinLeaveType.cs @@ -1,5 +1,5 @@ // -// RaidLeaveType.cs +// RaidJoinLeaveType.cs // // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. @@ -12,15 +12,15 @@ namespace NosSmooth.Packets.Enums.Raids; /// A sub type of /// in case the type of the packet is Leave. /// -public enum RaidLeaveType +public enum RaidJoinLeaveType { /// - /// The player has left the raid by himself. + /// The player has left the raid. /// PlayerLeft = 0, /// - /// The raid is finished. + /// The player has joined the raid. /// - RaidFinished = 1 + PlayerJoined = 1 } \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Enums/Raids/RaidPacketType.cs b/Packets/NosSmooth.Packets/Enums/Raids/RaidPacketType.cs index 7888e7edb5168757fd462b1fcdc8285c2a028e9d..c12ab2c394a35dbb84078fa5890a1d62b586a8f8 100644 --- a/Packets/NosSmooth.Packets/Enums/Raids/RaidPacketType.cs +++ b/Packets/NosSmooth.Packets/Enums/Raids/RaidPacketType.cs @@ -21,7 +21,7 @@ public enum RaidPacketType /// /// Character left or the raid is finished. /// - Leave = 1, + JoinLeave = 1, /// /// Leader id follows (or -1 in case of leave). diff --git a/Packets/NosSmooth.Packets/Server/Entities/StPacket.cs b/Packets/NosSmooth.Packets/Server/Entities/StPacket.cs index 272895b7ccb04bfdaab8ac37be034c9601e945a6..32eba072fdad9e8ca75286bde9b44ea5119b3bf4 100644 --- a/Packets/NosSmooth.Packets/Server/Entities/StPacket.cs +++ b/Packets/NosSmooth.Packets/Server/Entities/StPacket.cs @@ -42,6 +42,6 @@ public record StPacket long Hp, [PacketIndex(7)] long Mp, - [PacketListIndex(8, ListSeparator = ' ', InnerSeparator = '.', IsOptional = true)] + [PacketListIndex(8, ListSeparator = ' ', InnerSeparator = '.')] IReadOnlyList? BuffVNums ) : IPacket; \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Server/Families/GidxPacket.cs b/Packets/NosSmooth.Packets/Server/Families/GidxPacket.cs index 4b66af673ee3dfc8324c3c25f6cb0002e2e6dd7f..b7b187c8258133432b23fb085682d0f037602ee3 100644 --- a/Packets/NosSmooth.Packets/Server/Families/GidxPacket.cs +++ b/Packets/NosSmooth.Packets/Server/Families/GidxPacket.cs @@ -35,6 +35,6 @@ public record GidxPacket NameString? FamilyName, [PacketIndex(4)] NameString? FamilyCustomRank, - [PacketListIndex(5, ListSeparator = '|', IsOptional = true)] - IReadOnlyList? FamilyIcons + [PacketListIndex(5, ListSeparator = '|')] + IReadOnlyList FamilyIcons ) : IPacket; \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Server/Groups/PinitPacket.cs b/Packets/NosSmooth.Packets/Server/Groups/PinitPacket.cs index e1341a81e07ec591d93068fdd3c96ecaeb5a2fd0..30f0a71705bc3b305fa13f9c9dcfb705315a1c41 100644 --- a/Packets/NosSmooth.Packets/Server/Groups/PinitPacket.cs +++ b/Packets/NosSmooth.Packets/Server/Groups/PinitPacket.cs @@ -22,6 +22,6 @@ public record PinitPacket ( [PacketIndex(0)] byte SubPacketsCount, - [PacketListIndex(1, ListSeparator = ' ', InnerSeparator = '|', IsOptional = true)] - IReadOnlyList? PinitSubPackets + [PacketListIndex(1, ListSeparator = ' ', InnerSeparator = '|')] + IReadOnlyList PinitSubPackets ) : IPacket; \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Server/Groups/PinitSubPacket.cs b/Packets/NosSmooth.Packets/Server/Groups/PinitSubPacket.cs index bc8e0357217b1a7ddf709ff3e223e47aae722c06..2d15869f948aed2a667b85fd68e2262cad15245e 100644 --- a/Packets/NosSmooth.Packets/Server/Groups/PinitSubPacket.cs +++ b/Packets/NosSmooth.Packets/Server/Groups/PinitSubPacket.cs @@ -29,8 +29,8 @@ public record PinitSubPacket EntityType EntityType, [PacketIndex(1)] long EntityId, - [PacketConditionalIndex(2, "EntityType", false, EntityType.Npc, IsOptional = true)] + [PacketConditionalIndex(2, "EntityType", false, EntityType.Npc)] PinitMateSubPacket? MateSubPacket, - [PacketConditionalIndex(3, "EntityType", false, EntityType.Player, IsOptional = true)] + [PacketConditionalIndex(3, "EntityType", false, EntityType.Player)] PinitPlayerSubPacket? PlayerSubPacket ) : IPacket; \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Server/Inventory/InvPacket.cs b/Packets/NosSmooth.Packets/Server/Inventory/InvPacket.cs index 39462f8e8621fa952b9798a24addf4140dc94f80..6d76e63b995bb28a35bc6ce2b9f846fa585dfb73 100644 --- a/Packets/NosSmooth.Packets/Server/Inventory/InvPacket.cs +++ b/Packets/NosSmooth.Packets/Server/Inventory/InvPacket.cs @@ -25,6 +25,6 @@ public record InvPacket ( [PacketIndex(0)] BagType Bag, - [PacketListIndex(1, InnerSeparator = '.', ListSeparator = ' ', IsOptional = true)] + [PacketListIndex(1, InnerSeparator = '.', ListSeparator = ' ')] IReadOnlyList? InvSubPackets ) : IPacket; \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Server/Raids/RaidPacket.cs b/Packets/NosSmooth.Packets/Server/Raids/RaidPacket.cs index 597d74f994ff2e89dba914423e8a78f7f9a416f8..74e764d77ecdb78a1f4c4ac07311e489e0907289 100644 --- a/Packets/NosSmooth.Packets/Server/Raids/RaidPacket.cs +++ b/Packets/NosSmooth.Packets/Server/Raids/RaidPacket.cs @@ -18,7 +18,7 @@ namespace NosSmooth.Packets.Server.Raids; /// /// The status type. /// The id of the leader, null if leaving. Present only for Leader type. -/// The type of the leave type. Present only for Leave type. +/// The type of the leave type. Present only for Leave type. /// The ids of players in the raid. Present only for ListMembers. /// Health of the players. Present only for PlayerHealths. [PacketHeader("raidf", PacketSource.Server)] @@ -28,12 +28,12 @@ public record RaidPacket ( [PacketIndex(0)] RaidPacketType Type, - [PacketConditionalIndex(1, "Type", false, RaidPacketType.Leader, IsOptional = true)] + [PacketConditionalIndex(1, "Type", false, RaidPacketType.Leader)] long? LeaderId, - [PacketConditionalIndex(2, "Type", false, RaidPacketType.Leave, IsOptional = true)] - RaidLeaveType? LeaveType, - [PacketConditionalListIndex(3, "Type", false, RaidPacketType.ListMembers, ListSeparator = ' ', IsOptional = true)] + [PacketConditionalIndex(2, "Type", false, RaidPacketType.JoinLeave)] + RaidJoinLeaveType? JoinLeaveType, + [PacketConditionalListIndex(3, "Type", false, RaidPacketType.ListMembers, ListSeparator = ' ')] IReadOnlyList? ListMembersPlayerIds, - [PacketConditionalListIndex(4, "Type", false, RaidPacketType.PlayerHealths, InnerSeparator = '.', ListSeparator = ' ', IsOptional = true)] + [PacketConditionalListIndex(4, "Type", false, RaidPacketType.PlayerHealths, InnerSeparator = '.', ListSeparator = ' ')] IReadOnlyList? PlayerHealths ) : IPacket; \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Server/Skills/CancelPacket.cs b/Packets/NosSmooth.Packets/Server/Skills/CancelPacket.cs index 07700639303f3603ac7285c4641f8b3f2c3dc8f6..9878d5f2c40c46a11b9d35184cc72fccc0583091 100644 --- a/Packets/NosSmooth.Packets/Server/Skills/CancelPacket.cs +++ b/Packets/NosSmooth.Packets/Server/Skills/CancelPacket.cs @@ -20,8 +20,8 @@ public record CancelPacket ( [PacketIndex(0)] short Type, - [PacketIndex(1)] - long TargetId, - [PacketIndex(2)] + [PacketIndex(1, IsOptional = true)] + long? TargetId, + [PacketIndex(2, IsOptional = true)] long? Unknown = null ) : IPacket; \ No newline at end of file diff --git a/Packets/NosSmooth.Packets/Server/UI/Act6Packet.cs b/Packets/NosSmooth.Packets/Server/UI/Act6Packet.cs index 7fcae5b6ccb9736c8d775433f4be5f19291c8e4c..39822e2680cca5375e266078e26b1f8fe5dc7469 100644 --- a/Packets/NosSmooth.Packets/Server/UI/Act6Packet.cs +++ b/Packets/NosSmooth.Packets/Server/UI/Act6Packet.cs @@ -11,6 +11,6 @@ namespace NosSmooth.Packets.Server.UI; /// /// Unknown TODO. /// -[PacketHeader(null, PacketSource.Server)] +[PacketHeader("act6", PacketSource.Server)] [GenerateSerializer(true)] public record Act6Packet() : IPacket; \ No newline at end of file diff --git a/Tests/NosSmooth.Packets.Tests/Converters/Packets/RaidPacketConverterTests.cs b/Tests/NosSmooth.Packets.Tests/Converters/Packets/RaidPacketConverterTests.cs index 0271172491d5910bac026deaae1140c9598f16f8..8733414f1ab50133245586f3965758acac7e7c50 100644 --- a/Tests/NosSmooth.Packets.Tests/Converters/Packets/RaidPacketConverterTests.cs +++ b/Tests/NosSmooth.Packets.Tests/Converters/Packets/RaidPacketConverterTests.cs @@ -50,7 +50,7 @@ public class RaidPacketConverterTests var packet = (RaidPacket)packetResult.Entity; Assert.Equal(RaidPacketType.ListMembers, packet.Type); Assert.NotNull(packet.ListMembersPlayerIds); - Assert.Null(packet.LeaveType); + Assert.Null(packet.JoinLeaveType); Assert.Null(packet.LeaderId); Assert.Null(packet.PlayerHealths); @@ -70,13 +70,13 @@ public class RaidPacketConverterTests ); Assert.True(packetResult.IsSuccess); var packet = (RaidPacket)packetResult.Entity; - Assert.Equal(RaidPacketType.Leave, packet.Type); + Assert.Equal(RaidPacketType.JoinLeave, packet.Type); Assert.Null(packet.ListMembersPlayerIds); - Assert.NotNull(packet.LeaveType); + Assert.NotNull(packet.JoinLeaveType); Assert.Null(packet.LeaderId); Assert.Null(packet.PlayerHealths); - Assert.Equal(RaidLeaveType.PlayerLeft, packet.LeaveType); + Assert.Equal(RaidJoinLeaveType.PlayerLeft, packet.JoinLeaveType); } /// @@ -94,7 +94,7 @@ public class RaidPacketConverterTests var packet = (RaidPacket)packetResult.Entity; Assert.Equal(RaidPacketType.Leader, packet.Type); Assert.Null(packet.ListMembersPlayerIds); - Assert.Null(packet.LeaveType); + Assert.Null(packet.JoinLeaveType); Assert.NotNull(packet.LeaderId); Assert.Null(packet.PlayerHealths); @@ -116,7 +116,7 @@ public class RaidPacketConverterTests var packet = (RaidPacket)packetResult.Entity; Assert.Equal(RaidPacketType.PlayerHealths, packet.Type); Assert.Null(packet.ListMembersPlayerIds); - Assert.Null(packet.LeaveType); + Assert.Null(packet.JoinLeaveType); Assert.Null(packet.LeaderId); Assert.NotNull(packet.PlayerHealths);