You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-19 00:26:30 +09:00
Added fix for discovery requests arriving when handshake in progress
Added sanity checks for handshake connections (in DEBUG)
This commit is contained in:
@@ -361,6 +361,7 @@ namespace Lidgren.Network
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NetMessageType.Disconnect:
|
case NetMessageType.Disconnect:
|
||||||
// ouch
|
// ouch
|
||||||
string reason = "Ouch";
|
string reason = "Ouch";
|
||||||
@@ -374,6 +375,15 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
ExecuteDisconnect(reason, false);
|
ExecuteDisconnect(reason, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case NetMessageType.Discovery:
|
||||||
|
m_peer.HandleIncomingDiscoveryRequest(now, m_remoteEndpoint, ptr, payloadLength);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case NetMessageType.DiscoveryResponse:
|
||||||
|
m_peer.HandleIncomingDiscoveryResponse(now, m_remoteEndpoint, ptr, payloadLength);
|
||||||
|
return;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
m_peer.LogDebug("Unhandled type during handshake: " + tp + " length: " + payloadLength);
|
m_peer.LogDebug("Unhandled type during handshake: " + tp + " length: " + payloadLength);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -253,13 +253,29 @@ namespace Lidgren.Network
|
|||||||
// do handshake heartbeats
|
// do handshake heartbeats
|
||||||
if ((m_frameCounter % 3) == 0)
|
if ((m_frameCounter % 3) == 0)
|
||||||
{
|
{
|
||||||
foreach (NetConnection conn in m_handshakes.Values)
|
foreach (var kvp in m_handshakes)
|
||||||
{
|
{
|
||||||
|
NetConnection conn = kvp.Value as NetConnection;
|
||||||
|
#if DEBUG
|
||||||
|
// sanity check
|
||||||
|
if (kvp.Key != kvp.Key)
|
||||||
|
LogWarning("Sanity fail! Connection in handshake list under wrong key!");
|
||||||
|
#endif
|
||||||
conn.UnconnectedHeartbeat(now);
|
conn.UnconnectedHeartbeat(now);
|
||||||
if (conn.m_status == NetConnectionStatus.Connected || conn.m_status == NetConnectionStatus.Disconnected)
|
if (conn.m_status == NetConnectionStatus.Connected || conn.m_status == NetConnectionStatus.Disconnected)
|
||||||
|
{
|
||||||
|
#if DEBUG
|
||||||
|
// sanity check
|
||||||
|
if (conn.m_status == NetConnectionStatus.Disconnected && m_handshakes.ContainsKey(conn.RemoteEndpoint))
|
||||||
|
{
|
||||||
|
LogWarning("Sanity fail! Handshakes list contained disconnected connection!");
|
||||||
|
m_handshakes.Remove(conn.RemoteEndpoint);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
break; // collection has been modified
|
break; // collection has been modified
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
SendDelayedPackets();
|
SendDelayedPackets();
|
||||||
@@ -454,6 +470,34 @@ namespace Lidgren.Network
|
|||||||
} while (m_socket.Available > 0);
|
} while (m_socket.Available > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal void HandleIncomingDiscoveryRequest(double now, IPEndPoint senderEndpoint, int ptr, int payloadByteLength)
|
||||||
|
{
|
||||||
|
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryRequest))
|
||||||
|
{
|
||||||
|
NetIncomingMessage dm = CreateIncomingMessage(NetIncomingMessageType.DiscoveryRequest, payloadByteLength);
|
||||||
|
if (payloadByteLength > 0)
|
||||||
|
Buffer.BlockCopy(m_receiveBuffer, ptr, dm.m_data, 0, payloadByteLength);
|
||||||
|
dm.m_receiveTime = now;
|
||||||
|
dm.m_bitLength = payloadByteLength * 8;
|
||||||
|
dm.m_senderEndpoint = senderEndpoint;
|
||||||
|
ReleaseMessage(dm);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void HandleIncomingDiscoveryResponse(double now, IPEndPoint senderEndpoint, int ptr, int payloadByteLength)
|
||||||
|
{
|
||||||
|
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryResponse))
|
||||||
|
{
|
||||||
|
NetIncomingMessage dr = CreateIncomingMessage(NetIncomingMessageType.DiscoveryResponse, payloadByteLength);
|
||||||
|
if (payloadByteLength > 0)
|
||||||
|
Buffer.BlockCopy(m_receiveBuffer, ptr, dr.m_data, 0, payloadByteLength);
|
||||||
|
dr.m_receiveTime = now;
|
||||||
|
dr.m_bitLength = payloadByteLength * 8;
|
||||||
|
dr.m_senderEndpoint = senderEndpoint;
|
||||||
|
ReleaseMessage(dr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndpoint, NetMessageType tp, int ptr, int payloadByteLength)
|
private void ReceivedUnconnectedLibraryMessage(double now, IPEndPoint senderEndpoint, NetMessageType tp, int ptr, int payloadByteLength)
|
||||||
{
|
{
|
||||||
NetConnection shake;
|
NetConnection shake;
|
||||||
@@ -469,29 +513,10 @@ namespace Lidgren.Network
|
|||||||
switch (tp)
|
switch (tp)
|
||||||
{
|
{
|
||||||
case NetMessageType.Discovery:
|
case NetMessageType.Discovery:
|
||||||
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryRequest))
|
HandleIncomingDiscoveryRequest(now, senderEndpoint, ptr, payloadByteLength);
|
||||||
{
|
|
||||||
NetIncomingMessage dm = CreateIncomingMessage(NetIncomingMessageType.DiscoveryRequest, payloadByteLength);
|
|
||||||
if (payloadByteLength > 0)
|
|
||||||
Buffer.BlockCopy(m_receiveBuffer, ptr, dm.m_data, 0, payloadByteLength);
|
|
||||||
dm.m_receiveTime = now;
|
|
||||||
dm.m_bitLength = payloadByteLength * 8;
|
|
||||||
dm.m_senderEndpoint = senderEndpoint;
|
|
||||||
ReleaseMessage(dm);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
case NetMessageType.DiscoveryResponse:
|
case NetMessageType.DiscoveryResponse:
|
||||||
if (m_configuration.IsMessageTypeEnabled(NetIncomingMessageType.DiscoveryResponse))
|
HandleIncomingDiscoveryResponse(now, senderEndpoint, ptr, payloadByteLength);
|
||||||
{
|
|
||||||
NetIncomingMessage dr = CreateIncomingMessage(NetIncomingMessageType.DiscoveryResponse, payloadByteLength);
|
|
||||||
if (payloadByteLength > 0)
|
|
||||||
Buffer.BlockCopy(m_receiveBuffer, ptr, dr.m_data, 0, payloadByteLength);
|
|
||||||
dr.m_receiveTime = now;
|
|
||||||
dr.m_bitLength = payloadByteLength * 8;
|
|
||||||
dr.m_senderEndpoint = senderEndpoint;
|
|
||||||
ReleaseMessage(dr);
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
case NetMessageType.NatIntroduction:
|
case NetMessageType.NatIntroduction:
|
||||||
HandleNatIntroduction(ptr);
|
HandleNatIntroduction(ptr);
|
||||||
|
|||||||
Reference in New Issue
Block a user