~ruther/NosSmooth

aa2fdc4455c4df918f5e0a42b22216fd0856350b — František Boháček 2 years ago 04d24b6
feat(packets): make lists and conditional parameters non-optional non-nullable
M Core/NosSmooth.Game/PacketHandlers/Raids/RaidResponder.cs => Core/NosSmooth.Game/PacketHandlers/Raids/RaidResponder.cs +3 -3
@@ 41,7 41,7 @@ public class RaidResponder : IPacketResponder<RaidPacket>
    public async Task<Result> Respond(PacketEventArgs<RaidPacket> 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<RaidPacket>
                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
                            {

M Packets/NosSmooth.Packets/Client/Inventory/UseItemPacket.cs => Packets/NosSmooth.Packets/Client/Inventory/UseItemPacket.cs +1 -1
@@ 21,5 21,5 @@ public record UseItemPacket
    [PacketIndex(0)]
    BagType BagType,
    [PacketIndex(1)]
    short Slot
    long Slot
) : IPacket;
\ No newline at end of file

M Packets/NosSmooth.Packets/Client/Misc/PulsePacket.cs => Packets/NosSmooth.Packets/Client/Misc/PulsePacket.cs +1 -1
@@ 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

R Packets/NosSmooth.Packets/Enums/Raids/RaidLeaveType.cs => Packets/NosSmooth.Packets/Enums/Raids/RaidJoinLeaveType.cs +5 -5
@@ 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 <see cref="RaidPacket"/>
/// in case the type of the packet is Leave.
/// </summary>
public enum RaidLeaveType
public enum RaidJoinLeaveType
{
    /// <summary>
    /// The player has left the raid by himself.
    /// The player has left the raid.
    /// </summary>
    PlayerLeft = 0,

    /// <summary>
    /// The raid is finished.
    /// The player has joined the raid.
    /// </summary>
    RaidFinished = 1
    PlayerJoined = 1
}
\ No newline at end of file

M Packets/NosSmooth.Packets/Enums/Raids/RaidPacketType.cs => Packets/NosSmooth.Packets/Enums/Raids/RaidPacketType.cs +1 -1
@@ 21,7 21,7 @@ public enum RaidPacketType
    /// <summary>
    /// Character left or the raid is finished.
    /// </summary>
    Leave = 1,
    JoinLeave = 1,

    /// <summary>
    /// Leader id follows (or -1 in case of leave).

M Packets/NosSmooth.Packets/Server/Entities/StPacket.cs => Packets/NosSmooth.Packets/Server/Entities/StPacket.cs +1 -1
@@ 42,6 42,6 @@ public record StPacket
    long Hp,
    [PacketIndex(7)]
    long Mp,
    [PacketListIndex(8, ListSeparator = ' ', InnerSeparator = '.', IsOptional = true)]
    [PacketListIndex(8, ListSeparator = ' ', InnerSeparator = '.')]
    IReadOnlyList<EffectsSubPacket>? BuffVNums
) : IPacket;
\ No newline at end of file

M Packets/NosSmooth.Packets/Server/Families/GidxPacket.cs => Packets/NosSmooth.Packets/Server/Families/GidxPacket.cs +2 -2
@@ 35,6 35,6 @@ public record GidxPacket
    NameString? FamilyName,
    [PacketIndex(4)]
    NameString? FamilyCustomRank,
    [PacketListIndex(5, ListSeparator = '|', IsOptional = true)]
    IReadOnlyList<bool>? FamilyIcons
    [PacketListIndex(5, ListSeparator = '|')]
    IReadOnlyList<bool> FamilyIcons
) : IPacket;
\ No newline at end of file

M Packets/NosSmooth.Packets/Server/Groups/PinitPacket.cs => Packets/NosSmooth.Packets/Server/Groups/PinitPacket.cs +2 -2
@@ 22,6 22,6 @@ public record PinitPacket
(
    [PacketIndex(0)]
    byte SubPacketsCount,
    [PacketListIndex(1, ListSeparator = ' ', InnerSeparator = '|', IsOptional = true)]
    IReadOnlyList<PinitSubPacket>? PinitSubPackets
    [PacketListIndex(1, ListSeparator = ' ', InnerSeparator = '|')]
    IReadOnlyList<PinitSubPacket> PinitSubPackets
) : IPacket;
\ No newline at end of file

M Packets/NosSmooth.Packets/Server/Groups/PinitSubPacket.cs => Packets/NosSmooth.Packets/Server/Groups/PinitSubPacket.cs +2 -2
@@ 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

M Packets/NosSmooth.Packets/Server/Inventory/InvPacket.cs => Packets/NosSmooth.Packets/Server/Inventory/InvPacket.cs +1 -1
@@ 25,6 25,6 @@ public record InvPacket
(
    [PacketIndex(0)]
    BagType Bag,
    [PacketListIndex(1, InnerSeparator = '.', ListSeparator = ' ', IsOptional = true)]
    [PacketListIndex(1, InnerSeparator = '.', ListSeparator = ' ')]
    IReadOnlyList<InvSubPacket>? InvSubPackets
) : IPacket;
\ No newline at end of file

M Packets/NosSmooth.Packets/Server/Raids/RaidPacket.cs => Packets/NosSmooth.Packets/Server/Raids/RaidPacket.cs +6 -6
@@ 18,7 18,7 @@ namespace NosSmooth.Packets.Server.Raids;
/// </remarks>
/// <param name="Type">The status type.</param>
/// <param name="LeaderId">The id of the leader, null if leaving. Present only for Leader type.</param>
/// <param name="LeaveType">The type of the leave type. Present only for Leave  type.</param>
/// <param name="JoinLeaveType">The type of the leave type. Present only for Leave  type.</param>
/// <param name="ListMembersPlayerIds">The ids of players in the raid. Present only for ListMembers.</param>
/// <param name="PlayerHealths">Health of the players. Present only for PlayerHealths.</param>
[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<long>? ListMembersPlayerIds,
    [PacketConditionalListIndex(4, "Type", false, RaidPacketType.PlayerHealths, InnerSeparator = '.', ListSeparator = ' ', IsOptional = true)]
    [PacketConditionalListIndex(4, "Type", false, RaidPacketType.PlayerHealths, InnerSeparator = '.', ListSeparator = ' ')]
    IReadOnlyList<RaidPlayerHealthsSubPacket>? PlayerHealths
) : IPacket;
\ No newline at end of file

M Packets/NosSmooth.Packets/Server/Skills/CancelPacket.cs => Packets/NosSmooth.Packets/Server/Skills/CancelPacket.cs +3 -3
@@ 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

M Packets/NosSmooth.Packets/Server/UI/Act6Packet.cs => Packets/NosSmooth.Packets/Server/UI/Act6Packet.cs +1 -1
@@ 11,6 11,6 @@ namespace NosSmooth.Packets.Server.UI;
/// <summary>
/// Unknown TODO.
/// </summary>
[PacketHeader(null, PacketSource.Server)]
[PacketHeader("act6", PacketSource.Server)]
[GenerateSerializer(true)]
public record Act6Packet() : IPacket;
\ No newline at end of file

M Tests/NosSmooth.Packets.Tests/Converters/Packets/RaidPacketConverterTests.cs => Tests/NosSmooth.Packets.Tests/Converters/Packets/RaidPacketConverterTests.cs +6 -6
@@ 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);
    }

    /// <summary>


@@ 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);


Do not follow this link