diff --git a/src/NosCore.Packets/Attributes/PacketIndexAttribute.cs b/src/NosCore.Packets/Attributes/PacketIndexAttribute.cs index 5d37525..bd5222d 100644 --- a/src/NosCore.Packets/Attributes/PacketIndexAttribute.cs +++ b/src/NosCore.Packets/Attributes/PacketIndexAttribute.cs @@ -32,11 +32,6 @@ public PacketIndexAttribute(int index, string specialSeparator) public bool RemoveHash { get; set; } - /// - /// Encode spaces as "^" even when nothing would break without it. The last field of a - /// packet keeps its spaces by default, which is what chat lines need; a few fields - /// carry text the client expects "^"-encoded regardless of where they sit. - /// public bool EscapeSpaces { get; set; } } } \ No newline at end of file diff --git a/src/NosCore.Packets/Serializer.cs b/src/NosCore.Packets/Serializer.cs index 1c443d6..356c48e 100644 --- a/src/NosCore.Packets/Serializer.cs +++ b/src/NosCore.Packets/Serializer.cs @@ -80,21 +80,16 @@ private Expression DefaultSerializer(Expression specificTypeExpression, Expressi return ConcatExpression(splitter, specificTypeExpression); } - // escapeSeparator is the separator this field is joined to the packet with, which is - // what a value has to avoid containing. It is not the same expression as splitter: an - // ordinary property declares no special separator, so escaping against that one left - // every plain space-separated string free to split its own field in two. private Expression StringSerializer(Expression exp, bool isLastIndex, bool isOptional, Expression splitter, Expression escapeSeparator, bool isNested, bool escapeSpaces) { var replaceMethod = typeof(string).GetMethod("Replace", new[] { typeof(string), typeof(string) })!; - // A nested value sits inside a field of the packet above it, so its own separator is - // not the only one it can break: a space in a sub-packet splits the outer field. Expression escaped = Expression.Call(exp, replaceMethod, Expression.Convert(escapeSeparator, typeof(string)), Expression.Constant("^", typeof(string))); + // A nested value also sits inside a field of the packet above it. if (isNested || escapeSpaces) { escaped = Expression.Call(escaped, replaceMethod, diff --git a/test/NosCore.Packets.Tests/StringFieldSeparatorTests.cs b/test/NosCore.Packets.Tests/StringFieldSeparatorTests.cs index 6cc59bf..212b577 100644 --- a/test/NosCore.Packets.Tests/StringFieldSeparatorTests.cs +++ b/test/NosCore.Packets.Tests/StringFieldSeparatorTests.cs @@ -34,9 +34,6 @@ public class DottedProbePacket : PacketBase [PacketIndex(2)] public int After { get; set; } } - // A value that contains the field separator used to split its own field in two and shift - // every field after it. The escaping existed but was aimed at SpecialSeparator, which an - // ordinary property never declares. [TestClass] public class StringFieldSeparatorTests { @@ -58,7 +55,6 @@ public void ASpaceInAMiddleFieldIsEscaped() [TestMethod] public void TheLastFieldKeepsItsSpaces() { - // Nothing follows it, so nothing can shift - and chat lines rely on this. Assert.AreEqual("tstsep 1 - 2 hello there", Serializer.Serialize(new SeparatorProbePacket { Before = 1, After = 2, Last = "hello there" })); } @@ -85,9 +81,6 @@ public void ASpacedNameNoLongerSplitsTheMatePacket() [TestMethod] public void TheSameHoldsForTheOtherPacketsThatCarryAName() { - // ScnPacket.Name is index 36 of more, InPacket.Name is index 1 of many - neither is - // last, so both are escaped now. ScnPacket has said "Spaces should be replaced by ^" - // in a doc comment the whole time without anything enforcing it. var scn = Serializer.Serialize(new ScnPacket { PetId = 1, NpcMonsterVNum = 333, Level = 15, Name = "Joyeux Mouton" @@ -106,8 +99,6 @@ public void TheSameHoldsForTheOtherPacketsThatCarryAName() [TestMethod] public void AStringInsideASubPacketEscapesTheOuterSeparatorToo() { - // Its own separator is "|", but the sub-packet sits inside a space-separated field, - // so an unescaped space here splits the packet above it. Assert.AreEqual("pinit 0 0|0|1|10|Joyeux^Mouton|0|0|0|0|0|0", Serializer.Serialize(new PinitPacket { @@ -121,7 +112,6 @@ public void AStringInsideASubPacketEscapesTheOuterSeparatorToo() [TestMethod] public void AFieldThatOptsInIsEscapedEvenThoughItIsLast() { - // Nothing would break without it - the client simply expects these encoded. Assert.AreEqual("mlintro Bienvenue^chez^moi", Serializer.Serialize(new MlintroPacket { Intro = "Bienvenue chez moi" }));