1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-19 00:26:30 +09:00

Merge pull request #126 from Badartefact/master

Fixed bugs after introducing IPv6 dual mode
This commit is contained in:
Michael Lidgren
2019-06-15 00:07:26 +02:00
committed by GitHub
5 changed files with 22 additions and 8 deletions

View File

@@ -135,7 +135,11 @@ namespace Lidgren.Network
if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6) if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6)
m_socket.DualMode = true; m_socket.DualMode = true;
var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress.MapToIPv6(), reBind ? m_listenPort : m_configuration.Port); var localAddress = m_configuration.DualStack
? m_configuration.LocalAddress.MapToIPv6()
: m_configuration.LocalAddress;
var ep = (EndPoint)new NetEndPoint(localAddress, reBind ? m_listenPort : m_configuration.Port);
m_socket.Bind(ep); m_socket.Bind(ep);
try try

View File

@@ -155,6 +155,11 @@ namespace Lidgren.Network
} }
else if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6) else if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6)
NetUtility.CopyEndpoint(target, targetCopy); //Maps to IPv6 for Dual Mode NetUtility.CopyEndpoint(target, targetCopy); //Maps to IPv6 for Dual Mode
else
{
targetCopy.Port = target.Port;
targetCopy.Address = target.Address;
}
int bytesSent = m_socket.SendTo(data, 0, numBytes, SocketFlags.None, targetCopy); int bytesSent = m_socket.SendTo(data, 0, numBytes, SocketFlags.None, targetCopy);
if (numBytes != bytesSent) if (numBytes != bytesSent)

View File

@@ -121,7 +121,8 @@ namespace Lidgren.Network
m_connections = new List<NetConnection>(); m_connections = new List<NetConnection>();
m_connectionLookup = new Dictionary<NetEndPoint, NetConnection>(); m_connectionLookup = new Dictionary<NetEndPoint, NetConnection>();
m_handshakes = new Dictionary<NetEndPoint, NetConnection>(); m_handshakes = new Dictionary<NetEndPoint, NetConnection>();
m_senderRemote = (EndPoint)new NetEndPoint(IPAddress.IPv6Any, 0); var address = config.DualStack ? IPAddress.IPv6Any : IPAddress.Any;
m_senderRemote = (EndPoint)new NetEndPoint(address, 0);
m_status = NetPeerStatus.NotRunning; m_status = NetPeerStatus.NotRunning;
m_receivedFragmentGroups = new Dictionary<NetConnection, Dictionary<int, ReceivedFragmentGroup>>(); m_receivedFragmentGroups = new Dictionary<NetConnection, Dictionary<int, ReceivedFragmentGroup>>();
} }

View File

@@ -95,7 +95,7 @@ namespace Lidgren.Network
// //
m_disabledTypes = NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.ConnectionLatencyUpdated | NetIncomingMessageType.NatIntroductionSuccess; m_disabledTypes = NetIncomingMessageType.ConnectionApproval | NetIncomingMessageType.UnconnectedData | NetIncomingMessageType.VerboseDebugMessage | NetIncomingMessageType.ConnectionLatencyUpdated | NetIncomingMessageType.NatIntroductionSuccess;
m_networkThreadName = "Lidgren network thread"; m_networkThreadName = "Lidgren network thread";
m_localAddress = IPAddress.IPv6Any; m_localAddress = IPAddress.Any;
m_broadcastAddress = IPAddress.Broadcast; m_broadcastAddress = IPAddress.Broadcast;
var ip = NetUtility.GetBroadcastAddress(); var ip = NetUtility.GetBroadcastAddress();
if (ip != null) if (ip != null)
@@ -330,7 +330,7 @@ namespace Lidgren.Network
} }
/// <summary> /// <summary>
/// Gets or sets the local ip address to bind to. Defaults to IPAddress.IPv6Any. Cannot be changed once NetPeer is initialized. /// Gets or sets the local ip address to bind to. Defaults to IPAddress.Any. Cannot be changed once NetPeer is initialized.
/// </summary> /// </summary>
public IPAddress LocalAddress public IPAddress LocalAddress
{ {
@@ -354,6 +354,10 @@ namespace Lidgren.Network
if (m_isLocked) if (m_isLocked)
throw new NetException(c_isLockedMessage); throw new NetException(c_isLockedMessage);
m_dualStack = value; m_dualStack = value;
if (m_dualStack && m_localAddress.Equals(IPAddress.Any))
m_localAddress = IPAddress.IPv6Any;
if (!m_dualStack && m_localAddress.Equals(IPAddress.IPv6Any))
m_localAddress = IPAddress.Any;
} }
} }

View File

@@ -189,7 +189,7 @@ namespace Lidgren.Network
return null; return null;
foreach (var address in addresses) foreach (var address in addresses)
{ {
if (address.AddressFamily == AddressFamily.InterNetwork || ipAddress.AddressFamily == AddressFamily.InterNetworkV6) if (address.AddressFamily == AddressFamily.InterNetwork || address.AddressFamily == AddressFamily.InterNetworkV6)
return address; return address;
} }
return null; return null;