diff --git a/Lidgren.Network/NetConnection.cs b/Lidgren.Network/NetConnection.cs index c100414..a568fd0 100644 --- a/Lidgren.Network/NetConnection.cs +++ b/Lidgren.Network/NetConnection.cs @@ -620,6 +620,9 @@ namespace Lidgren.Network public bool SendMessage(NetOutgoingMessage msg, NetDeliveryMethod method, int sequenceChannel) { + if (msg == null) + throw new ArgumentNullException("msg"); + NetException.Assert(msg.m_libType == NetMessageLibraryType.Error, "Use SendLibrary() instead!"); if (msg.IsSent) diff --git a/Lidgren.Network/NetIncomingMessage.Read.Reflection.cs b/Lidgren.Network/NetIncomingMessage.Read.Reflection.cs index 8937490..99f1548 100644 --- a/Lidgren.Network/NetIncomingMessage.Read.Reflection.cs +++ b/Lidgren.Network/NetIncomingMessage.Read.Reflection.cs @@ -73,6 +73,9 @@ namespace Lidgren.Network /// public void ReadAllProperties(object target, BindingFlags flags) { + if (target == null) + throw new ArgumentNullException("target"); + if (target == null) return; Type tp = target.GetType(); diff --git a/Lidgren.Network/NetPeer.Recycling.cs b/Lidgren.Network/NetPeer.Recycling.cs index f622bdf..7dbf768 100644 --- a/Lidgren.Network/NetPeer.Recycling.cs +++ b/Lidgren.Network/NetPeer.Recycling.cs @@ -106,6 +106,9 @@ namespace Lidgren.Network /// public void Recycle(NetIncomingMessage msg) { + if (msg == null) + throw new ArgumentNullException("msg"); + if (msg.m_status != NetIncomingMessageReleaseStatus.ReleasedToApplication) throw new NetException("Message not under application control; recycled more than once?"); diff --git a/Lidgren.Network/NetPeer.cs b/Lidgren.Network/NetPeer.cs index 8dd4587..2f18c46 100644 --- a/Lidgren.Network/NetPeer.cs +++ b/Lidgren.Network/NetPeer.cs @@ -96,6 +96,9 @@ namespace Lidgren.Network public NetPeer(NetPeerConfiguration configuration) { + if (configuration == null) + throw new ArgumentNullException("configuration"); + m_status = NetPeerStatus.NotRunning; m_configuration = configuration; m_connections = new List(m_configuration.MaximumConnections); @@ -109,6 +112,9 @@ namespace Lidgren.Network /// public NetConnection GetConnection(IPEndPoint remoteEndPoint) { + if (remoteEndPoint == null) + throw new ArgumentNullException("remoteEndPoint"); + NetConnection retval; if (m_connectionLookup.TryGetValue(remoteEndPoint, out retval)) return retval; @@ -219,6 +225,9 @@ namespace Lidgren.Network /// public virtual NetConnection Connect(IPEndPoint remoteEndpoint, NetOutgoingMessage approvalMessage) { + if (remoteEndpoint == null) + throw new ArgumentNullException("remoteEndpoint"); + lock (m_connections) { if (m_status == NetPeerStatus.NotRunning) @@ -259,6 +268,11 @@ namespace Lidgren.Network /// True if the message was queued for delivery, else false public bool SendMessage(NetOutgoingMessage msg, NetConnection recipient, NetDeliveryMethod deliveryMethod, int channel) { + if (msg == null) + throw new ArgumentNullException("msg"); + if (recipient == null) + throw new ArgumentNullException("recipient"); + if (msg.IsSent) throw new NetException("Message has already been sent!"); if (channel < 0 || channel > 63) @@ -278,6 +292,11 @@ namespace Lidgren.Network /// Delivery channel (0-31) public bool SendMessage(NetOutgoingMessage msg, IEnumerable recipients, NetDeliveryMethod deliveryMethod, int sequenceChannel) { + if (msg == null) + throw new ArgumentNullException("msg"); + if (recipients == null) + throw new ArgumentNullException("recipients"); + if (msg.IsSent) throw new NetException("Message has already been sent!"); if (sequenceChannel < 0 || sequenceChannel > NetConstants.NetChannelsPerDeliveryMethod) @@ -307,6 +326,11 @@ namespace Lidgren.Network /// public void SendUnconnectedMessage(NetOutgoingMessage msg, string host, int port) { + if (msg == null) + throw new ArgumentNullException("msg"); + if (host == null) + throw new ArgumentNullException("host"); + IPAddress adr = NetUtility.Resolve(host); if (adr == null) throw new NetException("Failed to resolve " + host); @@ -319,6 +343,11 @@ namespace Lidgren.Network /// public void SendUnconnectedMessage(NetOutgoingMessage msg, IPEndPoint recipient) { + if (msg == null) + throw new ArgumentNullException("msg"); + if (recipient == null) + throw new ArgumentNullException("recipient"); + if (msg.IsSent) throw new NetException("Message has already been sent!"); msg.m_wasSent = true; @@ -331,6 +360,10 @@ namespace Lidgren.Network /// public void SendUnconnectedMessage(NetOutgoingMessage msg, IEnumerable recipients) { + if (msg == null) + throw new ArgumentNullException("msg"); + if (recipients == null) + throw new ArgumentNullException("recipients"); if (msg.IsSent) throw new NetException("Message has already been sent!"); msg.m_wasSent = true; @@ -344,9 +377,12 @@ namespace Lidgren.Network /// public void SendDiscoveryResponse(NetOutgoingMessage msg, IPEndPoint recipient) { + if (recipient == null) + throw new ArgumentNullException("recipient"); + if (msg == null) msg = CreateMessage(0); - if (msg.IsSent) + else if (msg.IsSent) throw new NetException("Message has already been sent!"); msg.m_libType = NetMessageLibraryType.DiscoveryResponse; diff --git a/Lidgren.Network/NetServer.cs b/Lidgren.Network/NetServer.cs index 64f6f4f..9098eb4 100644 --- a/Lidgren.Network/NetServer.cs +++ b/Lidgren.Network/NetServer.cs @@ -32,6 +32,9 @@ namespace Lidgren.Network public void Disconnect(NetConnection connection, string byeMessage) { + if (connection == null) + throw new ArgumentNullException("connection"); + connection.Disconnect(byeMessage); } }