diff --git a/.gitignore b/.gitignore
index 5e7a49b8fa..b6069737a3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -29,6 +29,7 @@ mods/*/*.mdb
/*.mdb
/*.exe
thirdparty/download/*
+*.mmdb.gz
# backup files by various editors
*~
diff --git a/GeoLite2-Country.mmdb b/GeoLite2-Country.mmdb
deleted file mode 100644
index 77f4441ed0..0000000000
Binary files a/GeoLite2-Country.mmdb and /dev/null differ
diff --git a/Makefile b/Makefile
index f3fb454104..dafecafed7 100644
--- a/Makefile
+++ b/Makefile
@@ -318,6 +318,7 @@ osx-dependencies: cli-dependencies
@ $(CP_R) thirdparty/download/osx/*.dll.config .
dependencies: $(os-dependencies)
+ @./thirdparty/fetch-geoip-db.sh
all-dependencies: cli-dependencies windows-dependencies osx-dependencies
@@ -353,7 +354,7 @@ install-core: default
@$(CP_R) mods/modchooser "$(DATA_INSTALL_DIR)/mods/"
@$(INSTALL_DATA) "global mix database.dat" "$(DATA_INSTALL_DIR)/global mix database.dat"
- @$(INSTALL_DATA) "GeoLite2-Country.mmdb" "$(DATA_INSTALL_DIR)/GeoLite2-Country.mmdb"
+ @$(INSTALL_DATA) "GeoLite2-Country.mmdb.gz" "$(DATA_INSTALL_DIR)/GeoLite2-Country.mmdb.gz"
@$(INSTALL_DATA) AUTHORS "$(DATA_INSTALL_DIR)/AUTHORS"
@$(INSTALL_DATA) COPYING "$(DATA_INSTALL_DIR)/COPYING"
diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs
index 77fd66493a..c875403264 100644
--- a/OpenRA.Game/Game.cs
+++ b/OpenRA.Game/Game.cs
@@ -15,7 +15,6 @@ using System.IO;
using System.Linq;
using System.Net;
using System.Threading;
-using MaxMind.GeoIP2;
using OpenRA.FileSystem;
using OpenRA.Graphics;
using OpenRA.Network;
@@ -44,8 +43,6 @@ namespace OpenRA
public static Renderer Renderer;
public static bool HasInputFocus = false;
- public static DatabaseReader GeoIpDatabase;
-
public static OrderManager JoinServer(string host, int port, string password, bool recordReplay = true)
{
IConnection connection = new NetworkConnection(host, port);
@@ -216,14 +213,7 @@ namespace OpenRA
Settings.Server.AllowPortForward = false;
}
- try
- {
- GeoIpDatabase = new DatabaseReader("GeoLite2-Country.mmdb");
- }
- catch (Exception e)
- {
- Log.Write("geoip", "DatabaseReader failed: {0}", e);
- }
+ GeoIP.Initialize();
GlobalFileSystem.Mount(Platform.GameDir); // Needed to access shaders
var renderers = new[] { Settings.Graphics.Renderer, "Sdl2", null };
diff --git a/OpenRA.Game/Network/GeoIP.cs b/OpenRA.Game/Network/GeoIP.cs
new file mode 100644
index 0000000000..fb42d78051
--- /dev/null
+++ b/OpenRA.Game/Network/GeoIP.cs
@@ -0,0 +1,52 @@
+#region Copyright & License Information
+/*
+ * Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
+ * This file is part of OpenRA, which is free software. It is made
+ * available to you under the terms of the GNU General Public License
+ * as published by the Free Software Foundation. For more information,
+ * see COPYING.
+ */
+#endregion
+
+using System;
+using System.IO;
+using ICSharpCode.SharpZipLib.Core;
+using ICSharpCode.SharpZipLib.GZip;
+using MaxMind.GeoIP2;
+
+namespace OpenRA.Network
+{
+ public class GeoIP
+ {
+ static DatabaseReader database;
+
+ public static void Initialize()
+ {
+ try
+ {
+ using (var fileStream = new FileStream("GeoLite2-Country.mmdb.gz", FileMode.Open, FileAccess.Read))
+ using (var gzipStream = new GZipInputStream(fileStream))
+ database = new DatabaseReader(gzipStream);
+ }
+ catch (Exception e)
+ {
+ Log.Write("geoip", "DatabaseReader failed: {0}", e);
+ }
+ }
+
+ public static string LookupCountry(string ip)
+ {
+ const string Unknown = "Unknown Location";
+
+ try
+ {
+ return database.Country(ip).Country.Name ?? Unknown;
+ }
+ catch (Exception e)
+ {
+ Log.Write("geoip", "LookupCountry failed: {0}", e);
+ return Unknown;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj
index b211f9c12c..6ce8a3c793 100644
--- a/OpenRA.Game/OpenRA.Game.csproj
+++ b/OpenRA.Game/OpenRA.Game.csproj
@@ -128,6 +128,7 @@
+
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs
index f028d99dc1..c6b48fb265 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/ClientTooltipLogic.cs
@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
address = UPnP.NatDevice.GetExternalIP().ToString();
var cachedDescriptiveIP = LobbyUtils.DescriptiveIpAddress(address);
ip.GetText = () => cachedDescriptiveIP;
- var cachedCountryLookup = LobbyUtils.LookupCountry(address);
+ var cachedCountryLookup = GeoIP.LookupCountry(address);
location.GetText = () => cachedCountryLookup;
}
}
diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs
index cc61b42482..13f6ebaf57 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs
@@ -235,21 +235,6 @@ namespace OpenRA.Mods.Common.Widgets.Logic
return ip;
}
- public static string LookupCountry(string ip)
- {
- const string Unknown = "Unknown Location";
-
- try
- {
- return Game.GeoIpDatabase.Country(ip).Country.Name ?? Unknown;
- }
- catch (Exception e)
- {
- Log.Write("geoip", "LookupCountry failed: {0}", e);
- return Unknown;
- }
- }
-
public static void SetupClientWidget(Widget parent, Session.Slot s, Session.Client c, OrderManager orderManager, bool visible)
{
parent.Get("ADMIN_INDICATOR").IsVisible = () => c.IsAdmin;
diff --git a/OpenRA.Mods.Common/Widgets/Logic/ServerBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ServerBrowserLogic.cs
index a18dc9d68a..a00fb47a80 100644
--- a/OpenRA.Mods.Common/Widgets/Logic/ServerBrowserLogic.cs
+++ b/OpenRA.Mods.Common/Widgets/Logic/ServerBrowserLogic.cs
@@ -252,7 +252,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
var location = item.GetOrNull("LOCATION");
if (location != null)
{
- var cachedServerLocation = LobbyUtils.LookupCountry(game.Address.Split(':')[0]);
+ var cachedServerLocation = GeoIP.LookupCountry(game.Address.Split(':')[0]);
location.GetText = () => cachedServerLocation;
location.GetColor = () => !compatible ? Color.DarkGray : !canJoin ? Color.LightGray : location.TextColor;
}
diff --git a/packaging/package-all.sh b/packaging/package-all.sh
index 08b46e70b2..d804fcfc05 100755
--- a/packaging/package-all.sh
+++ b/packaging/package-all.sh
@@ -35,7 +35,7 @@ FILES=('OpenRA.Game.exe' 'OpenRA.Game.exe.config' 'OpenRA.Editor.exe' 'OpenRA.Ut
'OpenRA.Renderer.Sdl2.dll' 'OpenRA.Renderer.Null.dll' \
'lua' 'glsl' 'mods/common' 'mods/ra' 'mods/cnc' 'mods/d2k' 'mods/modchooser' \
'AUTHORS' 'COPYING' 'README.html' 'CONTRIBUTING.html' 'DOCUMENTATION.html' 'CHANGELOG.html' \
-'global mix database.dat' 'GeoLite2-Country.mmdb')
+'global mix database.dat' 'GeoLite2-Country.mmdb.gz')
echo "Copying files..."
for i in "${FILES[@]}"; do
diff --git a/packaging/windows/OpenRA.nsi b/packaging/windows/OpenRA.nsi
index f9d661bbeb..1b0b16af99 100644
--- a/packaging/windows/OpenRA.nsi
+++ b/packaging/windows/OpenRA.nsi
@@ -103,7 +103,7 @@ Section "Game" GAME
File "${SRCDIR}\MaxMind.GeoIP2.dll"
File "${SRCDIR}\Newtonsoft.Json.dll"
File "${SRCDIR}\RestSharp.dll"
- File "${SRCDIR}\GeoLite2-Country.mmdb"
+ File "${SRCDIR}\GeoLite2-Country.mmdb.gz"
File "${SRCDIR}\eluant.dll"
File "${DEPSDIR}\soft_oal.dll"
File "${DEPSDIR}\SDL2.dll"
@@ -219,7 +219,7 @@ Function ${UN}Clean
Delete $INSTDIR\MaxMind.GeoIP2.dll
Delete $INSTDIR\Newtonsoft.Json.dll
Delete $INSTDIR\RestSharp.dll
- Delete $INSTDIR\GeoLite2-Country.mmdb
+ Delete $INSTDIR\GeoLite2-Country.mmdb.gz
Delete $INSTDIR\KopiLua.dll
Delete $INSTDIR\soft_oal.dll
Delete $INSTDIR\SDL2.dll
diff --git a/thirdparty/fetch-geoip-db.sh b/thirdparty/fetch-geoip-db.sh
new file mode 100755
index 0000000000..b490bb828c
--- /dev/null
+++ b/thirdparty/fetch-geoip-db.sh
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+# Die on any error for Travis CI to automatically retry:
+set -e
+
+download_dir="${0%/*}/download"
+mkdir -p "${download_dir}"
+cd "${download_dir}"
+
+filename="GeoLite2-Country.mmdb.gz"
+
+# Database does not exist or is older than 30 days.
+if [[ ! -e $filename ]] || [[ -n $(find . -name $filename -mtime +30 -print) ]]; then
+ rm -f $filename
+ echo "Updating GeoIP country database from MaxMind."
+ curl -s -L -O http://geolite.maxmind.com/download/geoip/database/$filename
+ cp $filename ../..
+fi
+
diff --git a/thirdparty/fetch-thirdparty-deps.ps1 b/thirdparty/fetch-thirdparty-deps.ps1
index 21eb138daa..2f2878d8f7 100644
--- a/thirdparty/fetch-thirdparty-deps.ps1
+++ b/thirdparty/fetch-thirdparty-deps.ps1
@@ -130,4 +130,12 @@ if (!(Test-Path "Eluant.dll"))
(New-Object System.Net.WebClient).DownloadFile("https://github.com/OpenRA/Eluant/releases/download/20140425/Eluant.dll", $target)
}
+if (!(Test-Path "GeoLite2-Country.mmdb.gz") -Or (((get-date) - (get-item "GeoLite2-Country.mmdb").LastWriteTime) -gt (new-timespan -days 30)))
+{
+ echo "Updating GeoIP country database from MaxMind."
+ $target = Join-Path $pwd.ToString() "GeoLite2-Country.mmdb.gz"
+ (New-Object System.Net.WebClient).DownloadFile("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.mmdb.gz", $target)
+ cp GeoLite2-Country.mmdb.gz ..\..
+}
+
cd ..