From 8a1a6945f14972b37980ef79e09368e5dda62e3b Mon Sep 17 00:00:00 2001 From: Guido L Date: Mon, 14 Sep 2015 23:18:29 +0200 Subject: [PATCH] Fix and move Logic into its own Function in LobbyUtils --- .../Widgets/Logic/Lobby/ClientTooltipLogic.cs | 6 ++---- .../Widgets/Logic/Lobby/LobbyUtils.cs | 13 +++++++++++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs index c6b48fb265..ebfe9486b4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs @@ -79,10 +79,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic var ping = orderManager.LobbyInfo.PingFromClient(client); latency.GetText = () => LobbyUtils.LatencyDescription(ping); latency.GetColor = () => LobbyUtils.LatencyColor(ping); - var address = orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress; - if (clientIndex == orderManager.LocalClient.Index && UPnP.NatDevice != null - && address == IPAddress.Loopback.ToString()) - address = UPnP.NatDevice.GetExternalIP().ToString(); + + var address = LobbyUtils.GetExternalIP(clientIndex, orderManager); var cachedDescriptiveIP = LobbyUtils.DescriptiveIpAddress(address); ip.GetText = () => cachedDescriptiveIP; var cachedCountryLookup = GeoIP.LookupCountry(address); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs index fe76073eb0..61db02b4c2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs @@ -482,5 +482,18 @@ namespace OpenRA.Mods.Common.Widgets.Logic }; playerName.GetColor = () => player.Color.RGB; } + + 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) + { + var externalIP = UPnP.NatDevice.GetExternalIP(); + if (externalIP != null) + address = externalIP.ToString(); + } + + return address; + } } }