diff --git a/Makefile b/Makefile index 5e5cca3568..5bb87d9fdb 100644 --- a/Makefile +++ b/Makefile @@ -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) diff --git a/OpenRA.Game/Network/GeoIP.cs b/OpenRA.Game/Network/GeoIP.cs index bf4b99ed24..151360825d 100644 --- a/OpenRA.Game/Network/GeoIP.cs +++ b/OpenRA.Game/Network/GeoIP.cs @@ -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(IPAddress.Parse(ip)); + if (record != null) + return record.Country.Names.English; + else + return Unknown; } catch (Exception e) { diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 96b0fe5cf7..0bf91e7d6f 100644 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -74,10 +74,6 @@ ..\thirdparty\download\ICSharpCode.SharpZipLib.dll False - - ..\thirdparty\download\MaxMind.GeoIP2.dll - False - ..\thirdparty\download\MaxMind.Db.dll False diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index ef7508cd05..4d8ec85339 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -54,10 +54,6 @@ ..\thirdparty\download\StyleCop.dll - - ..\thirdparty\download\MaxMind.GeoIP2.dll - False - ..\thirdparty\download\ICSharpCode.SharpZipLib.dll False diff --git a/packaging/package-all.sh b/packaging/package-all.sh index d7065ffe5b..5261da70e2 100755 --- a/packaging/package-all.sh +++ b/packaging/package-all.sh @@ -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 diff --git a/packaging/windows/OpenRA.nsi b/packaging/windows/OpenRA.nsi index 0b58ed947d..90bfc48ff1 100644 --- a/packaging/windows/OpenRA.nsi +++ b/packaging/windows/OpenRA.nsi @@ -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 @@ -215,15 +211,15 @@ Function ${UN}Clean Delete $INSTDIR\OpenAL-CS.dll Delete $INSTDIR\SmarIrc4net.dll RMDir /r $INSTDIR\Support - + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenRA" DeleteRegKey HKLM "Software\Classes\.orarep" DeleteRegKey HKLM "Software\Classes\OpenRA_replay" DeleteRegKey HKLM "Software\Classes\openra" - + Delete $INSTDIR\uninstaller.exe RMDir $INSTDIR - + !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder RMDir /r "$SMPROGRAMS\$StartMenuFolder" Delete $DESKTOP\OpenRA.lnk diff --git a/thirdparty/fetch-thirdparty-deps.ps1 b/thirdparty/fetch-thirdparty-deps.ps1 index 73f4af0a42..dd2266e99d 100644 --- a/thirdparty/fetch-thirdparty-deps.ps1 +++ b/thirdparty/fetch-thirdparty-deps.ps1 @@ -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")) diff --git a/thirdparty/fetch-thirdparty-deps.sh b/thirdparty/fetch-thirdparty-deps.sh index ca4414b2d9..f9788d5806 100755 --- a/thirdparty/fetch-thirdparty-deps.sh +++ b/thirdparty/fetch-thirdparty-deps.sh @@ -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