Skip to content

Commit c8c78ba

Browse files
committed
LiteNetLib only puts arrays that are up to 65K into the packet if you use the PutArrays() method
1 parent 805dc6a commit c8c78ba

File tree

4 files changed

+48
-9
lines changed

4 files changed

+48
-9
lines changed

Intersect.Network/LiteNetLib/LiteNetLibConnection.cs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,20 @@ internal bool TryProcessInboundMessage(
9393
{
9494
buffer = default;
9595

96-
var cipherdata = reader.GetBytesWithLength();
96+
reader.Get(out int cipherdataLength);
97+
var cipherdata = new byte[cipherdataLength];
98+
reader.GetBytes(cipherdata, cipherdataLength);
9799

98100
#if DEBUG
99101
byte[]? debugPlaindata = null;
102+
int debugPlaindataLength;
100103
if (Debugger.IsAttached)
101104
{
102105
if (!reader.EndOfData)
103106
{
104-
debugPlaindata = reader.GetBytesWithLength();
107+
reader.Get(out debugPlaindataLength);
108+
debugPlaindata = new byte[debugPlaindataLength];
109+
reader.GetBytes(debugPlaindata, debugPlaindataLength);
105110
}
106111
}
107112
#endif
@@ -167,12 +172,18 @@ public override bool Send(IPacket packet, TransmissionMode transmissionMode = Tr
167172
#endif
168173

169174
NetDataWriter data = new(true, cipherdata.Length + sizeof(byte));
170-
data.Put((byte)1);
171-
data.PutBytesWithLength(cipherdata.ToArray());
175+
data.Put((byte)0x20);
176+
data.Put((byte)0x21);
177+
data.Put((byte)0x22);
178+
data.Put((byte)0x23);
179+
180+
data.Put(cipherdata.Length);
181+
data.Put(cipherdata);
172182
#if DEBUG
173183
if (Debugger.IsAttached)
174184
{
175-
data.PutBytesWithLength(packetData);
185+
data.Put(packetData.Length);
186+
data.Put(packetData);
176187
}
177188
#endif
178189
return Send(data, transmissionMode);

Intersect.Network/LiteNetLib/LiteNetLibInterface.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,29 @@ DeliveryMethod deliveryMethod
304304
// ReSharper disable once ConvertIfStatementToSwitchStatement
305305
if (packetCode > 1)
306306
{
307-
ApplicationContext.Context.Value?.Logger.LogWarning($"Invalid packet code from {peer} / {connection.Guid}");
308-
return;
307+
if (packetCode != 0x20)
308+
{
309+
ApplicationContext.Context.Value?.Logger.LogWarning($"Invalid packet code from {peer} / {connection.Guid}");
310+
return;
311+
}
312+
313+
if (reader.GetByte() != 0x21)
314+
{
315+
ApplicationContext.Context.Value?.Logger.LogWarning($"Invalid packet code from {peer} / {connection.Guid}");
316+
return;
317+
}
318+
319+
if (reader.GetByte() != 0x22)
320+
{
321+
ApplicationContext.Context.Value?.Logger.LogWarning($"Invalid packet code from {peer} / {connection.Guid}");
322+
return;
323+
}
324+
325+
if (reader.GetByte() != 0x23)
326+
{
327+
ApplicationContext.Context.Value?.Logger.LogWarning($"Invalid packet code from {peer} / {connection.Guid}");
328+
return;
329+
}
309330
}
310331

311332
if (packetCode == 0)

Intersect.Server.Core/Networking/PacketSender.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,14 @@ public static void SendGameData(Client client)
726726
}
727727

728728
//Now send the cached game data that we send to all clients
729-
client.Send(CachedGameDataPacket);
729+
if (!client.Send(CachedGameDataPacket))
730+
{
731+
ApplicationContext.CurrentContext.Logger.LogError(
732+
"Failed to send cached game data packet to {ClientId} ({ClientType})",
733+
client.Id,
734+
client.IsEditor ? "editor" : "player"
735+
);
736+
}
730737
}
731738

732739
//GameDataPacket

vendor/LiteNetLib

0 commit comments

Comments
 (0)