diff --git a/OpenRA.Game/Network/UPnP.cs b/OpenRA.Game/Network/UPnP.cs index e65679967b..29525a10f0 100644 --- a/OpenRA.Game/Network/UPnP.cs +++ b/OpenRA.Game/Network/UPnP.cs @@ -9,7 +9,7 @@ #endregion using System; - +using System.Net; using Mono.Nat; namespace OpenRA.Network @@ -116,5 +116,21 @@ namespace OpenRA.Network 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; + } + } } } \ No newline at end of file diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index cfe9f0ae20..6fa7b03f36 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -497,9 +497,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic public static string GetExternalIP(int clientIndex, OrderManager orderManager) { 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) address = externalIP.ToString(); }