Merge pull request #8057 from RoosterDragon/location-fix

Safer country lookup
This commit is contained in:
Pavel Penev
2015-04-29 23:57:20 +03:00

View File

@@ -237,14 +237,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic
public static string LookupCountry(string ip) public static string LookupCountry(string ip)
{ {
const string Unknown = "Unknown Location";
try try
{ {
return Game.GeoIpDatabase.Country(ip).Country.Name; return Game.GeoIpDatabase.Country(ip).Country.Name ?? Unknown;
} }
catch (Exception e) catch (Exception e)
{ {
Log.Write("geoip", "LookupCountry failed: {0}", e); Log.Write("geoip", "LookupCountry failed: {0}", e);
return "Unknown Location"; return Unknown;
} }
} }