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

@@ -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)