From 4a7cffce028081a01c1d17f4c101957a0c8d0c00 Mon Sep 17 00:00:00 2001 From: lidgren Date: Thu, 14 Oct 2010 20:28:31 +0000 Subject: [PATCH] Added code to prevent multiple connection approval messages from being spawned and more sending serverfull when connections + pending connections exceed maxconnections --- Lidgren.Network/NetPeer.Internal.cs | 43 +++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/Lidgren.Network/NetPeer.Internal.cs b/Lidgren.Network/NetPeer.Internal.cs index c53c114..a4f3f71 100644 --- a/Lidgren.Network/NetPeer.Internal.cs +++ b/Lidgren.Network/NetPeer.Internal.cs @@ -519,25 +519,46 @@ namespace Lidgren.Network } // ok, someone wants to connect to us, and we're accepting connections! - if (m_connections.Count >= m_configuration.MaximumConnections) + int reservedSlots = m_connections.Count; + if (m_pendingConnections != null) + reservedSlots += m_pendingConnections.Count; + if (reservedSlots >= m_configuration.MaximumConnections) { HandleServerFull(senderEndpoint); break; } - NetConnection conn = new NetConnection(this, senderEndpoint); - conn.m_connectionInitiator = false; - conn.m_connectInitationTime = NetTime.Now; - conn.m_remoteUniqueIdentifier = remoteUniqueIdentifier; - - if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval)) + bool isAlreadyPending = false; + if (m_pendingConnections != null) { - // do connection approval before accepting this connection - AddPendingConnection(conn, approval); - break; + // check so we don't already have a pending connection to this endpoint + foreach (NetConnection conn in m_pendingConnections) + { + if (conn.RemoteEndpoint.Equals(senderEndpoint)) + { + // Yes, we do. + isAlreadyPending = true; + break; + } + } } - AcceptConnection(conn); + if (!isAlreadyPending) + { + NetConnection conn = new NetConnection(this, senderEndpoint); + conn.m_connectionInitiator = false; + conn.m_connectInitationTime = NetTime.Now; + conn.m_remoteUniqueIdentifier = remoteUniqueIdentifier; + + if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval)) + { + // do connection approval before accepting this connection + AddPendingConnection(conn, approval); + break; + } + + AcceptConnection(conn); + } break; default: LogWarning("Received unconnected library message of type " + libType);