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/NosCore.Packets.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<RepositoryUrl>https://github.com/NosCoreIO/NosCore.Packets.git</RepositoryUrl>
<PackageIconUrl></PackageIconUrl>
<PackageTags>nostale, noscore, chickenapi, nostale private server source, nostale emulator</PackageTags>
<Version>21.1.0</Version>
<Version>21.1.1</Version>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Description>NosCore's Packets (Nostale packets) defined over classes</Description>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand Down
8 changes: 7 additions & 1 deletion src/NosCore.Packets/Serializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,13 @@ private Expression PropertySerializer(Expression injectedPacket, PacketIndexAttr
header = " ";
}

specificTypeExpression = PacketSerializer(injectedPacket, indexAttr, specificTypeExpression, t, maxIndex,
// A sub-packet's fields are numbered from its own zero, so the parent's
// maxIndex would mark whichever field happens to share that number as last.
var subMaxIndex = t.GetProperties()
.SelectMany(x => x.GetCustomAttributes(true).OfType<PacketIndexAttribute>())
.Select(x => x.Index).DefaultIfEmpty(0).Max();

specificTypeExpression = PacketSerializer(injectedPacket, indexAttr, specificTypeExpression, t, subMaxIndex,
propertySplitter, indexAttr.RemoveHeader ? "" : header ?? "");
break;
case var t when t == typeof(IPacket):
Expand Down
16 changes: 16 additions & 0 deletions test/NosCore.Packets.Tests/StringFieldSeparatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,21 @@ public void AFieldThatOptsInIsEscapedEvenThoughItIsLast()
Serializer.Serialize(new MlInfoBrPacket { Name = "Bob", MinilandMessage = "hello there" }),
"hello^there");
}

[TestMethod]
public void ASubPacketFieldIsNotTreatedAsLastBecauseTheParentEndsThere()
{
// InNonPlayerSubPacket.Name is index 9, and so is the sub-packet on InPacket, so
// the name used to inherit the parent's last-field exemption and keep its spaces.
var wire = Serializer.Serialize(new InPacket
{
VisualType = VisualType.Npc,
VNum = "333",
VisualId = 2000001,
InNonPlayerSubPacket = new InNonPlayerSubPacket { Name = "Joyeux Mouton" }
});

StringAssert.Contains(wire, "Joyeux^Mouton");
}
}
}
Loading