Merge pull request #12702 from Mailaender/maxmind.db-2.1.2

Drop dependency on Maxmind.GeoIP and Newtonsoft.Json
This commit is contained in:
abcdefg30
2017-02-11 17:50:35 +01:00
committed by GitHub
8 changed files with 49 additions and 40 deletions

View File

@@ -11,14 +11,45 @@
using System;
using System.IO;
using System.Net;
using ICSharpCode.SharpZipLib.GZip;
using MaxMind.GeoIP2;
using MaxMind.Db;
namespace OpenRA.Network
{
public class GeoIP
{
static DatabaseReader database;
public class GeoIP2Record
{
[MaxMind.Db.Constructor] public GeoIP2Record(GeoIP2Country country)
{
Country = country;
}
public GeoIP2Country Country { get; set; }
}
public class GeoIP2Country
{
[MaxMind.Db.Constructor] public GeoIP2Country(GeoIP2CountryNames names)
{
Names = names;
}
public GeoIP2CountryNames Names { get; set; }
}
public class GeoIP2CountryNames
{
[MaxMind.Db.Constructor] public GeoIP2CountryNames(string en)
{
English = en;
}
public string English { get; set; }
}
static Reader database;
public static void Initialize()
{
@@ -26,7 +57,7 @@ namespace OpenRA.Network
{
using (var fileStream = new FileStream("GeoLite2-Country.mmdb.gz", FileMode.Open, FileAccess.Read))
using (var gzipStream = new GZipInputStream(fileStream))
database = new DatabaseReader(gzipStream);
database = new Reader(gzipStream);
}
catch (Exception e)
{
@@ -40,7 +71,11 @@ namespace OpenRA.Network
try
{
return database.Country(ip).Country.Name ?? Unknown;
var record = database.Find<GeoIP2Record>(IPAddress.Parse(ip));
if (record != null)
return record.Country.Names.English;
else
return Unknown;
}
catch (Exception e)
{

View File

@@ -74,10 +74,6 @@
<HintPath>..\thirdparty\download\ICSharpCode.SharpZipLib.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MaxMind.GeoIP2">
<HintPath>..\thirdparty\download\MaxMind.GeoIP2.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="MaxMind.Db">
<HintPath>..\thirdparty\download\MaxMind.Db.dll</HintPath>
<Private>False</Private>