Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/NosCore.Packets/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private Expression PacketSerializer(Expression injectedPacket, PacketIndexAttrib

return Expression.Condition(
Expression.Equal(specificTypeExpression, Expression.Constant(null, typeof(object))),
Expression.Constant(indexAttr.IsOptional ? null : $"{discriminator}-1", typeof(object)),
Expression.Constant(indexAttr.IsOptional ? null : "-1", typeof(object)),
Expression.Convert(propExp, typeof(object))
);
}
Expand Down
19 changes: 0 additions & 19 deletions src/NosCore.Packets/ServerPackets/Families/GidxFamilySubPacket.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/NosCore.Packets/ServerPackets/Families/GidxPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public class GidxPacket : PacketBase
[PacketIndex(1)]
public long VisualId { get; set; }

[PacketIndex(2, SpecialSeparator = ".")]
public GidxFamilySubPacket? FamilyIdentifier { get; set; }
[PacketIndex(2)]
public long? FamilyId { get; set; }

[PacketIndex(3)]
public string? FamilyName { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/NosCore.Packets/ServerPackets/Mates/ScnPacket.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ScnPacket : PacketBase
[PacketIndex(8, SpecialSeparator = ".")]
public ScEquipmentDetails? GauntletInstanceDetails { get; set; }

[PacketIndex(9)]
[PacketIndex(9, SpecialSeparator = ".")]
public ScEquipmentDetails? BootsInstanceDetails { get; set; }

[PacketIndex(10)]
Expand Down
42 changes: 29 additions & 13 deletions test/NosCore.Packets.Tests/SerializerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
using NosCore.Shared.Enumerations;
using System.Collections.Generic;
using System.Linq;
using ServerGidxPacket = NosCore.Packets.ServerPackets.Families.GidxPacket;

namespace NosCore.Packets.Tests
{
Expand Down Expand Up @@ -519,24 +520,39 @@ public void SerializeWithNullFirstParam()
packet);
}

// gidx exists on both sides with different shapes, and the serializer keys on the simple
// type name, so the server one needs its own instance.
private static readonly ISerializer ServerSerializer =
new Serializer(new[] { typeof(ServerGidxPacket) });

[TestMethod]
public void SerializeGidxWithoutFamily()
{
var packet = ServerSerializer.Serialize(new ServerGidxPacket
{
VisualType = VisualType.Player,
VisualId = 741328,
FamilyId = null,
FamilyName = "-",
FamilyLevel = 0
});

Assert.AreEqual("gidx 1 741328 -1 - 0 ", packet);
}

[TestMethod]
public void SerializeWithNullSubPacketKeepsTheSeparator()
public void SerializeGidxWithFamily()
{
var packet = Serializer.Serialize(new ScnPacket
var packet = ServerSerializer.Serialize(new ServerGidxPacket
{
PetId = 1,
NpcMonsterVNum = 319,
TransportId = 26719,
Level = 50,
Loyalty = 1000,
Experience = 1536,
WeaponInstanceDetails = new ScnPacket.ScEquipmentDetails { ItemId = 990 },
Name = "Kliff",
MorphId = -1
VisualType = VisualType.Player,
VisualId = 741328,
FamilyId = 5052,
FamilyName = "-Nemesis-",
FamilyLevel = 7
});

Assert.IsTrue(packet.StartsWith("sc_n 1 319 26719 50 1000 1536 990.0.0 -1 -1 -1 "),
$"the -1 of a null sub-packet must not be glued to the field before it: {packet}");
Assert.AreEqual("gidx 1 741328 5052 -Nemesis- 7 ", packet);
}

[TestMethod]
Expand Down
Loading