diff --git a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj index 54a3cfd217..75191b6a01 100644 --- a/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj +++ b/OpenRA.Mods.RA/OpenRA.Mods.RA.csproj @@ -479,6 +479,10 @@ {F33337BE-CB69-4B24-850F-07D23E408DDF} OpenRA.Utility + + {021DDD6A-A608-424C-9A9A-252D8A9989E0} + GeoIP + diff --git a/OpenRA.Mods.RA/Widgets/Logic/ClientTooltipLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ClientTooltipLogic.cs index cd20347024..07d911c033 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ClientTooltipLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ClientTooltipLogic.cs @@ -30,6 +30,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic var ip = widget.Get("IP"); var ipFont = Game.Renderer.Fonts[ip.Font]; + var location = widget.Get("LOCATION"); + var locationFont = Game.Renderer.Fonts[location.Font]; + + var locationOffset = location.Bounds.Y; var ipOffset = ip.Bounds.Y; var latencyOffset = latency.Bounds.Y; var tooltipHeight = widget.Bounds.Height; @@ -39,27 +43,33 @@ namespace OpenRA.Mods.RA.Widgets.Logic tooltipContainer.IsVisible = () => (orderManager.LobbyInfo.ClientWithIndex(clientIndex) != null); tooltipContainer.BeforeRender = () => { - var width = Math.Max(adminFont.Measure(admin.GetText()).X, Math.Max(ipFont.Measure(ip.GetText()).X, latencyFont.Measure(latency.GetText()).X)); - widget.Bounds.Width = width + 2*margin; + var width = Math.Max(locationFont.Measure(location.GetText()).X, (Math.Max(adminFont.Measure(admin.GetText()).X, + Math.Max(ipFont.Measure(ip.GetText()).X, latencyFont.Measure(latency.GetText()).X)))); + widget.Bounds.Width = width + 2 * margin; latency.Bounds.Width = widget.Bounds.Width; ip.Bounds.Width = widget.Bounds.Width; admin.Bounds.Width = widget.Bounds.Width; + location.Bounds.Width = widget.Bounds.Width; ip.Bounds.Y = ipOffset; latency.Bounds.Y = latencyOffset; + location.Bounds.Y = locationOffset; widget.Bounds.Height = tooltipHeight; if (admin.IsVisible()) { ip.Bounds.Y += admin.Bounds.Height; latency.Bounds.Y += admin.Bounds.Height; + location.Bounds.Y += admin.Bounds.Height; widget.Bounds.Height += admin.Bounds.Height; } }; admin.IsVisible = () => orderManager.LobbyInfo.ClientWithIndex(clientIndex).IsAdmin; latency.GetText = () => "Latency: {0}".F(LobbyUtils.LatencyDescription(orderManager.LobbyInfo.ClientWithIndex(clientIndex).Latency)); - ip.GetText = () => LobbyUtils.DescriptiveIpAddress(orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress); + var ipAddress = orderManager.LobbyInfo.ClientWithIndex(clientIndex).IpAddress; + ip.GetText = () => LobbyUtils.DescriptiveIpAddress(ipAddress); + location.GetText = () => LobbyUtils.LookupCountry(ipAddress); } } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs index 5f1e18ae9a..d87e1a327e 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/LobbyUtils.cs @@ -194,6 +194,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic return ip; } + public static string LookupCountry(string ip) + { + var ip2geo = new GeoIP.LookupService("GeoIP.dat", GeoIP.LookupService.GEOIP_MEMORY_CACHE); + var country = ip2geo.getCountry(ip); + return country.getName(); + } + public static void SetupClientWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, bool visible) { parent.Get("ADMIN_INDICATOR").IsVisible = () => c.IsAdmin; diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index 5edbf1862b..5bcc0b36be 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -130,7 +130,7 @@ Background@SPAWN_TOOLTIP: Background@CLIENT_TOOLTIP: Logic:ClientTooltipLogic Background:panel-black - Height:35 + Height:47 Width:5 Children: Label@ADMIN: @@ -145,8 +145,13 @@ Background@CLIENT_TOOLTIP: Height:10 Font:TinyBold Align:Center - Label@LATENCY: + Label@LOCATION: Y:17 Height:10 Font:TinyBold Align:Center + Label@LATENCY: + Y:29 + Height:10 + Font:TinyBold + Align:Center \ No newline at end of file diff --git a/mods/ra/chrome/tooltips.yaml b/mods/ra/chrome/tooltips.yaml index 762d84914f..4e824144ff 100644 --- a/mods/ra/chrome/tooltips.yaml +++ b/mods/ra/chrome/tooltips.yaml @@ -60,7 +60,7 @@ Background@SPAWN_TOOLTIP: Background@CLIENT_TOOLTIP: Logic:ClientTooltipLogic Background:dialog4 - Height:39 + Height:51 Width:7 Children: Label@ADMIN: @@ -75,8 +75,13 @@ Background@CLIENT_TOOLTIP: Height:10 Font:TinyBold Align:Center - Label@LATENCY: + Label@LOCATION: Y:19 Height:10 Font:TinyBold Align:Center + Label@LATENCY: + Y:31 + Height:10 + Font:TinyBold + Align:Center \ No newline at end of file