From bccfaa77eff71a86f8811bc502b5d6c1e1e50cca Mon Sep 17 00:00:00 2001 From: lidgren Date: Wed, 25 May 2011 13:21:56 +0000 Subject: [PATCH] Fixed maximum handshake attempts one-off error Fixed better disconnect messages when not yet fully connected (aborting connection attempt) --- Lidgren.Network/Lidgren.Network.csproj | 3 +-- Lidgren.Network/NetClient.cs | 11 +++++++++++ Lidgren.Network/NetConnection.Handshake.cs | 3 ++- Lidgren.Network/NetConnection.cs | 3 --- Lidgren.Network/NetPeerConfiguration.cs | 7 ++++++- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Lidgren.Network/Lidgren.Network.csproj b/Lidgren.Network/Lidgren.Network.csproj index 30d0e8b..6ae062f 100644 --- a/Lidgren.Network/Lidgren.Network.csproj +++ b/Lidgren.Network/Lidgren.Network.csproj @@ -3,7 +3,7 @@ Debug AnyCPU - 9.0.21022 + 9.0.30729 2.0 {AE483C29-042E-4226-BA52-D247CE7676DA} Library @@ -55,7 +55,6 @@ - diff --git a/Lidgren.Network/NetClient.cs b/Lidgren.Network/NetClient.cs index 1d1cd8f..d1b63b8 100644 --- a/Lidgren.Network/NetClient.cs +++ b/Lidgren.Network/NetClient.cs @@ -102,6 +102,17 @@ namespace Lidgren.Network NetConnection serverConnection = ServerConnection; if (serverConnection == null) { + lock (m_handshakes) + { + if (m_handshakes.Count > 0) + { + LogVerbose("Aborting connection attempt"); + foreach(var hs in m_handshakes) + hs.Value.Disconnect(byeMessage); + return; + } + } + LogWarning("Disconnect requested when not connected!"); return; } diff --git a/Lidgren.Network/NetConnection.Handshake.cs b/Lidgren.Network/NetConnection.Handshake.cs index 9f7f632..7620a3d 100644 --- a/Lidgren.Network/NetConnection.Handshake.cs +++ b/Lidgren.Network/NetConnection.Handshake.cs @@ -59,7 +59,7 @@ namespace Lidgren.Network if (now - m_lastHandshakeSendTime > m_peerConfiguration.m_resendHandshakeInterval) { - if (m_handshakeAttempts > m_peerConfiguration.m_maximumHandshakeAttempts) + if (m_handshakeAttempts >= m_peerConfiguration.m_maximumHandshakeAttempts) { // failed to connect ExecuteDisconnect("Failed to establish connection - no response from remote host", true); @@ -431,6 +431,7 @@ namespace Lidgren.Network if (m_status != NetConnectionStatus.Disconnected && m_status != NetConnectionStatus.None) SetStatus(NetConnectionStatus.Disconnecting, byeMessage); + m_handshakeAttempts = 0; m_disconnectRequested = true; } } diff --git a/Lidgren.Network/NetConnection.cs b/Lidgren.Network/NetConnection.cs index a5c3c10..34fb639 100644 --- a/Lidgren.Network/NetConnection.cs +++ b/Lidgren.Network/NetConnection.cs @@ -109,9 +109,6 @@ namespace Lidgren.Network if (reason == null) reason = string.Empty; - // new status equals potentially new handshake attempts - m_handshakeAttempts = 0; - if (m_status == NetConnectionStatus.Connected) { m_timeoutDeadline = (float)NetTime.Now + m_peerConfiguration.m_connectionTimeout; diff --git a/Lidgren.Network/NetPeerConfiguration.cs b/Lidgren.Network/NetPeerConfiguration.cs index 524948c..81966df 100644 --- a/Lidgren.Network/NetPeerConfiguration.cs +++ b/Lidgren.Network/NetPeerConfiguration.cs @@ -338,7 +338,12 @@ namespace Lidgren.Network public int MaximumHandshakeAttempts { get { return m_maximumHandshakeAttempts; } - set { m_maximumHandshakeAttempts = value; } + set + { + if (value < 1) + throw new NetException("MaximumHandshakeAttempts must be at least 1"); + m_maximumHandshakeAttempts = value; + } } ///