From e24f1a7848e1e82c02c1f3ec0587d4e4968aad3c Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Fri, 30 Oct 2020 16:01:12 +0100 Subject: [PATCH] Implement unreliable message size limit error. Not a proper solution to the unreliable fragmentation issue, but better than nothing. See https://github.com/lidgren/lidgren-network-gen3/issues/148 --- Lidgren.Network/NetUnreliableSenderChannel.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Lidgren.Network/NetUnreliableSenderChannel.cs b/Lidgren.Network/NetUnreliableSenderChannel.cs index 46408315..b857ca64 100644 --- a/Lidgren.Network/NetUnreliableSenderChannel.cs +++ b/Lidgren.Network/NetUnreliableSenderChannel.cs @@ -59,6 +59,17 @@ internal override NetSendResult Enqueue(NetOutgoingMessage message) return NetSendResult.Dropped; } + if (message.LengthBits >= ushort.MaxValue + && m_connection.m_peerConfiguration.UnreliableSizeBehaviour == NetUnreliableSizeBehaviour.IgnoreMTU) + { + // drop message + this.m_connection.m_peer.LogError( + string.Format("Unreliable message max size exceeded: {0} bits (max {1})", + message.LengthBits, + ushort.MaxValue)); + return NetSendResult.Dropped; + } + m_queuedSends.Enqueue(message); m_connection.m_peer.m_needFlushSendQueue = true; // a race condition to this variable will simply result in a single superflous call to FlushSendQueue() return NetSendResult.Sent;