Drop Maxmind.GeoIP and Newtonsoft.Json dependencies

This commit is contained in:
Matthias Mailänder
2017-02-05 09:36:27 +01:00
parent b018c3d837
commit 13263f7bb2
8 changed files with 49 additions and 40 deletions

View File

@@ -46,7 +46,7 @@ SDK ?=
CSC = mcs $(SDK)
CSFLAGS = -nologo -warn:4 -codepage:utf8 -unsafe -warnaserror
DEFINE = TRACE
COMMON_LIBS = System.dll System.Core.dll System.Data.dll System.Data.DataSetExtensions.dll System.Drawing.dll System.Xml.dll thirdparty/download/ICSharpCode.SharpZipLib.dll thirdparty/download/FuzzyLogicLibrary.dll thirdparty/download/MaxMind.Db.dll thirdparty/download/MaxMind.GeoIP2.dll thirdparty/download/Eluant.dll thirdparty/download/SmarIrc4net.dll
COMMON_LIBS = System.dll System.Core.dll System.Data.dll System.Data.DataSetExtensions.dll System.Drawing.dll System.Xml.dll thirdparty/download/ICSharpCode.SharpZipLib.dll thirdparty/download/FuzzyLogicLibrary.dll thirdparty/download/MaxMind.Db.dll thirdparty/download/Eluant.dll thirdparty/download/SmarIrc4net.dll
NUNIT_LIBS_PATH :=
NUNIT_LIBS := $(NUNIT_LIBS_PATH)nunit.framework.dll
@@ -400,8 +400,6 @@ install-core: default
@$(CP) SharpFont.dll.config "$(DATA_INSTALL_DIR)"
@$(INSTALL_PROGRAM) Open.Nat.dll "$(DATA_INSTALL_DIR)"
@$(INSTALL_PROGRAM) MaxMind.Db.dll "$(DATA_INSTALL_DIR)"
@$(INSTALL_PROGRAM) MaxMind.GeoIP2.dll "$(DATA_INSTALL_DIR)"
@$(INSTALL_PROGRAM) Newtonsoft.Json.dll "$(DATA_INSTALL_DIR)"
@$(INSTALL_PROGRAM) SmarIrc4net.dll "$(DATA_INSTALL_DIR)"
ifneq ($(UNAME_S),Darwin)

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>

View File

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

View File

@@ -65,8 +65,6 @@ cp thirdparty/download/Eluant* packaging/built
# GeoIP database access
cp thirdparty/download/MaxMind.Db.dll packaging/built
cp thirdparty/download/MaxMind.GeoIP2.dll packaging/built
cp thirdparty/download/Newtonsoft.Json.dll packaging/built
# global chat
cp thirdparty/download/SmarIrc4net.dll packaging/built

View File

@@ -107,8 +107,6 @@ Section "Game" GAME
File "${SRCDIR}\OpenAL-CS.dll"
File "${SRCDIR}\global mix database.dat"
File "${SRCDIR}\MaxMind.Db.dll"
File "${SRCDIR}\MaxMind.GeoIP2.dll"
File "${SRCDIR}\Newtonsoft.Json.dll"
File "${SRCDIR}\GeoLite2-Country.mmdb.gz"
File "${SRCDIR}\eluant.dll"
File "${SRCDIR}\SmarIrc4net.dll"
@@ -202,8 +200,6 @@ Function ${UN}Clean
Delete $INSTDIR\OpenRA.ico
Delete "$INSTDIR\global mix database.dat"
Delete $INSTDIR\MaxMind.Db.dll
Delete $INSTDIR\MaxMind.GeoIP2.dll
Delete $INSTDIR\Newtonsoft.Json.dll
Delete $INSTDIR\GeoLite2-Country.mmdb.gz
Delete $INSTDIR\KopiLua.dll
Delete $INSTDIR\soft_oal.dll

View File

@@ -35,16 +35,12 @@ if (!(Test-Path "ICSharpCode.SharpZipLib.dll"))
rmdir SharpZipLib -Recurse
}
if (!(Test-Path "MaxMind.GeoIP2.dll"))
if (!(Test-Path "MaxMind.Db.dll"))
{
echo "Fetching MaxMind.GeoIP2 from NuGet."
./nuget.exe install MaxMind.GeoIP2 -Version 2.6.0 -ExcludeVersion
echo "Fetching MaxMind.Db from NuGet."
./nuget.exe install MaxMind.Db -Version 2.0.0 -ExcludeVersion
cp MaxMind.Db/lib/net45/MaxMind.Db.* .
rmdir MaxMind.Db -Recurse
cp MaxMind.GeoIP2/lib/net45/MaxMind.GeoIP2* .
rmdir MaxMind.GeoIP2 -Recurse
cp Newtonsoft.Json/lib/net45/Newtonsoft.Json* .
rmdir Newtonsoft.Json -Recurse
}
if (!(Test-Path "SharpFont.dll"))

View File

@@ -47,17 +47,11 @@ if [ ! -f ICSharpCode.SharpZipLib.dll ]; then
rm -rf SharpZipLib
fi
if [ ! -f MaxMind.GeoIP2.dll ]; then
echo "Fetching MaxMind.GeoIP2 from NuGet"
get Newtonsoft.Json 8.0.3
get MaxMind.Db 2.0.0
get MaxMind.GeoIP2 2.6.0
if [ ! -f MaxMind.Db.dll ]; then
echo "Fetching MaxMind.Db from NuGet"
get MaxMind.Db 2.0.0 -IgnoreDependencies
cp ./MaxMind.Db/lib/net45/MaxMind.Db.* .
rm -rf MaxMind.Db
cp ./MaxMind.GeoIP2/lib/net45/MaxMind.GeoIP2* .
rm -rf MaxMind.GeoIP2
cp ./Newtonsoft.Json/lib/net45/Newtonsoft.Json* .
rm -rf Newtonsoft.Json
fi
if [ ! -f SharpFont.dll ]; then