diff --git a/Lidgren.Network/NetPeer.Send.cs b/Lidgren.Network/NetPeer.Send.cs index 7eab62d..664c4e0 100644 --- a/Lidgren.Network/NetPeer.Send.cs +++ b/Lidgren.Network/NetPeer.Send.cs @@ -62,6 +62,8 @@ namespace Lidgren.Network internal int GetMTU(IList recipients) { + NetException.Assert(recipients.Count > 0); + int mtu = int.MaxValue; foreach (NetConnection conn in recipients) { @@ -85,6 +87,8 @@ namespace Lidgren.Network throw new ArgumentNullException("msg"); if (recipients == null) throw new ArgumentNullException("recipients"); + if (recipients.Count < 1) + throw new NetException("recipients must contain at least one item"); if (method == NetDeliveryMethod.Unreliable || method == NetDeliveryMethod.ReliableUnordered) NetException.Assert(sequenceChannel == 0, "Delivery method " + method + " cannot use sequence channels other than 0!"); if (msg.m_isSent) @@ -95,7 +99,7 @@ namespace Lidgren.Network msg.m_isSent = true; int len = msg.LengthBytes; - if (len <= m_configuration.MaximumTransmissionUnit) + if (len <= mtu) { Interlocked.Add(ref msg.m_recyclingCount, recipients.Count); foreach (NetConnection conn in recipients) @@ -176,6 +180,8 @@ namespace Lidgren.Network throw new ArgumentNullException("msg"); if (recipients == null) throw new ArgumentNullException("recipients"); + if (recipients.Count < 1) + throw new NetException("recipients must contain at least one item"); if (msg.m_isSent) throw new NetException("This message has already been sent! Use NetPeer.SendMessage() to send to multiple recipients efficiently"); if (msg.LengthBytes > m_configuration.MaximumTransmissionUnit) diff --git a/Lidgren.Network/NetPeerConfiguration.cs b/Lidgren.Network/NetPeerConfiguration.cs index 33f2784..c610d58 100644 --- a/Lidgren.Network/NetPeerConfiguration.cs +++ b/Lidgren.Network/NetPeerConfiguration.cs @@ -187,13 +187,15 @@ namespace Lidgren.Network } /// - /// Gets or sets the maximum amount of bytes to send in a single packet, excluding ip, udp and lidgren headers + /// Gets or sets the maximum amount of bytes to send in a single packet, excluding ip, udp and lidgren headers. Cannot be changed once NetPeer is initialized. /// public int MaximumTransmissionUnit { get { return m_maximumTransmissionUnit; } set { + if (m_isLocked) + throw new NetException(c_isLockedMessage); if (value < 1 || value >= ((ushort.MaxValue + 1) / 8)) throw new NetException("MaximumTransmissionUnit must be between 1 and " + (((ushort.MaxValue + 1) / 8) - 1) + " bytes"); m_maximumTransmissionUnit = value;