catch MappingExceptions in NatDevice.GetExternalIP
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Net;
|
||||||
using Mono.Nat;
|
using Mono.Nat;
|
||||||
|
|
||||||
namespace OpenRA.Network
|
namespace OpenRA.Network
|
||||||
@@ -116,5 +116,21 @@ namespace OpenRA.Network
|
|||||||
Game.Settings.Server.AllowPortForward = false;
|
Game.Settings.Server.AllowPortForward = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IPAddress GetExternalIP()
|
||||||
|
{
|
||||||
|
if (NatDevice == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return NatDevice.GetExternalIP();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Write("server", "Failed to get the external IP from NAT device: {0}", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -497,9 +497,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
public static string GetExternalIP(int clientIndex, OrderManager orderManager)
|
public static string GetExternalIP(int clientIndex, OrderManager orderManager)
|
||||||
{
|
{
|
||||||
var address = orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress;
|
var address = orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress;
|
||||||
if (clientIndex == orderManager.LocalClient.Index && address == IPAddress.Loopback.ToString() && UPnP.NatDevice != null)
|
if (clientIndex == orderManager.LocalClient.Index && address == IPAddress.Loopback.ToString())
|
||||||
{
|
{
|
||||||
var externalIP = UPnP.NatDevice.GetExternalIP();
|
var externalIP = UPnP.GetExternalIP();
|
||||||
if (externalIP != null)
|
if (externalIP != null)
|
||||||
address = externalIP.ToString();
|
address = externalIP.ToString();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user