Zero-terminate Data to prevent client-side bugs.

- Fixes chat messages displaying stale memory as the client discards the data length.
This commit is contained in:
Ray 2024-05-16 21:30:35 +02:00
parent b4e6433545
commit 914acc2e1b
2 changed files with 5 additions and 3 deletions

View File

@ -222,7 +222,7 @@ namespace Syroot.Worms.Worms2.GameServer
+ add(PacketField.Value4, packet.Value4, sizeof(int))
+ add(PacketField.Value10, packet.Value10, sizeof(int))
+ add(PacketField.DataLength, packet.Data, sizeof(int))
+ add(PacketField.Data, packet.Data, packet.Data?.Length ?? 0)
+ add(PacketField.Data, packet.Data, (packet.Data?.Length ?? 0) + 1)
+ add(PacketField.Error, packet.Error, sizeof(int))
+ add(PacketField.Name, packet.Name, 20)
+ add(PacketField.Session, packet.Session, Unsafe.SizeOf<SessionInfo>());
@ -244,8 +244,10 @@ namespace Syroot.Worms.Worms2.GameServer
if (packet.Value10 != null) writeInt(ref span, packet.Value10.Value);
if (packet.Data != null)
{
writeInt(ref span, packet.Data.Length);
writeInt(ref span, packet.Data.Length + 1);
span = span.Slice(Encodings.Windows1252.GetBytes(packet.Data, span));
span[0] = 0;
span = span.Slice(1);
}
if (packet.Error != null) writeInt(ref span, packet.Error.Value);
if (packet.Name != null)

View File

@ -8,7 +8,7 @@
<Authors>Syroot</Authors>
<Copyright>(c) Syroot, licensed under MIT</Copyright>
<Description>Worms 2 Game Server</Description>
<Version>1.1.0</Version>
<Version>1.1.1</Version>
</PropertyGroup>
<!-- References -->