1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-17 07:36:32 +09:00

GetBroadcastAddress problem fixed... again.

This commit is contained in:
Michael Lidgren
2015-05-08 19:07:42 +02:00
parent 513d4d6da1
commit 0b4d688fc2

View File

@@ -135,10 +135,13 @@ namespace Lidgren.Network
internal bool ActuallySendPacket(byte[] data, int numBytes, NetEndPoint target, out bool connectionReset) internal bool ActuallySendPacket(byte[] data, int numBytes, NetEndPoint target, out bool connectionReset)
{ {
connectionReset = false; connectionReset = false;
IPAddress ba = default(IPAddress);
try try
{ {
ba = NetUtility.GetCachedBroadcastAddress();
// TODO: refactor this check outta here // TODO: refactor this check outta here
if (target.Address == NetUtility.GetCachedBroadcastAddress()) if (target.Address == ba)
{ {
// Some networks do not allow // Some networks do not allow
// a global broadcast so we use the BroadcastAddress from the configuration // a global broadcast so we use the BroadcastAddress from the configuration
@@ -175,7 +178,7 @@ namespace Lidgren.Network
} }
finally finally
{ {
if (target.Address == IPAddress.Broadcast) if (target.Address == ba)
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, false); m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, false);
} }
return true; return true;
@@ -260,10 +263,12 @@ namespace Lidgren.Network
m_statistics.PacketSent(numBytes, numMessages); m_statistics.PacketSent(numBytes, numMessages);
#endif #endif
connectionReset = false; connectionReset = false;
IPAddress ba = default(IPAddress);
try try
{ {
// TODO: refactor this check outta here // TODO: refactor this check outta here
if (target.Address == NetUtility.GetCachedBroadcastAddress()) ba = NetUtility.GetCachedBroadcastAddress();
if (target.Address == ba)
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true); m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
int bytesSent = m_socket.SendTo(m_sendBuffer, 0, numBytes, SocketFlags.None, target); int bytesSent = m_socket.SendTo(m_sendBuffer, 0, numBytes, SocketFlags.None, target);
@@ -292,7 +297,7 @@ namespace Lidgren.Network
} }
finally finally
{ {
if (target.Address == NetUtility.GetBroadcastAddress()) if (target.Address == ba)
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, false); m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, false);
} }
return; return;