update to GeoIP2 and parse the database only once

closes #4227
This commit is contained in:
Matthias Mailänder
2014-02-15 19:12:57 +01:00
parent c5ccb0ef4a
commit 9099e987d3
23 changed files with 54 additions and 6015 deletions

View File

@@ -502,10 +502,6 @@
<Project>{85B48234-8B31-4BE6-AF9C-665CC6866841}</Project>
<Name>OpenRA.Irc</Name>
</ProjectReference>
<ProjectReference Include="..\GeoIP\GeoIP.csproj">
<Project>{021DDD6A-A608-424C-9A9A-252D8A9989E0}</Project>
<Name>GeoIP</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">

View File

@@ -12,6 +12,7 @@ using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using MaxMind.GeoIP2;
using OpenRA.Graphics;
using OpenRA.Network;
using OpenRA.Primitives;
@@ -197,9 +198,15 @@ namespace OpenRA.Mods.RA.Widgets.Logic
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();
try
{
return Game.GeoIpDatabase.Omni(ip).Country.Name;
}
catch (Exception e)
{
Log.Write("geoip", "LookupCountry failed: {0}", e);
return "Unknown Location";
}
}
public static void SetupClientWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, bool visible)