Require GeoLite2 database path to be specified by the server operator.
This commit is contained in:
@@ -54,13 +54,16 @@ namespace OpenRA.Network
|
|||||||
|
|
||||||
static Reader database;
|
static Reader database;
|
||||||
|
|
||||||
public static void Initialize()
|
public static void Initialize(string databasePath)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(databasePath))
|
||||||
|
return;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
using (var fileStream = new FileStream("GeoLite2-Country.mmdb.gz", FileMode.Open, FileAccess.Read))
|
using (var fileStream = new FileStream(databasePath, FileMode.Open, FileAccess.Read))
|
||||||
using (var gzipStream = new GZipInputStream(fileStream))
|
using (var gzipStream = new GZipInputStream(fileStream))
|
||||||
database = new Reader(gzipStream);
|
database = new Reader(gzipStream);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@@ -68,23 +71,23 @@ namespace OpenRA.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string LookupCountry(string ip)
|
public static string LookupCountry(IPAddress ip)
|
||||||
{
|
{
|
||||||
const string Unknown = "Unknown Location";
|
if (database != null)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var record = database.Find<GeoIP2Record>(ip);
|
||||||
|
if (record != null)
|
||||||
|
return record.Country.Names.English;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Write("geoip", "LookupCountry failed: {0}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
try
|
return "Unknown Location";
|
||||||
{
|
|
||||||
var record = database.Find<GeoIP2Record>(IPAddress.Parse(ip));
|
|
||||||
if (record != null)
|
|
||||||
return record.Country.Names.English;
|
|
||||||
else
|
|
||||||
return Unknown;
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.Write("geoip", "LookupCountry failed: {0}", e);
|
|
||||||
return Unknown;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,7 +149,7 @@ namespace OpenRA.Server
|
|||||||
|
|
||||||
randomSeed = (int)DateTime.Now.ToBinary();
|
randomSeed = (int)DateTime.Now.ToBinary();
|
||||||
|
|
||||||
GeoIP.Initialize();
|
GeoIP.Initialize(settings.GeoIPDatabase);
|
||||||
|
|
||||||
if (UPnP.Status == UPnPStatus.Enabled)
|
if (UPnP.Status == UPnPStatus.Enabled)
|
||||||
UPnP.ForwardPort(Settings.ListenPort, Settings.ListenPort).Wait();
|
UPnP.ForwardPort(Settings.ListenPort, Settings.ListenPort).Wait();
|
||||||
@@ -348,7 +348,7 @@ namespace OpenRA.Server
|
|||||||
{
|
{
|
||||||
Name = OpenRA.Settings.SanitizedPlayerName(handshake.Client.Name),
|
Name = OpenRA.Settings.SanitizedPlayerName(handshake.Client.Name),
|
||||||
IpAddress = ipAddress.ToString(),
|
IpAddress = ipAddress.ToString(),
|
||||||
Location = GeoIP.LookupCountry(ipAddress.ToString()),
|
Location = GeoIP.LookupCountry(ipAddress),
|
||||||
Index = newConn.PlayerIndex,
|
Index = newConn.PlayerIndex,
|
||||||
PreferredColor = handshake.Client.PreferredColor,
|
PreferredColor = handshake.Client.PreferredColor,
|
||||||
Color = handshake.Client.Color,
|
Color = handshake.Client.Color,
|
||||||
|
|||||||
@@ -82,6 +82,10 @@ namespace OpenRA
|
|||||||
[Desc("Sets the timestamp format. Defaults to the ISO 8601 standard.")]
|
[Desc("Sets the timestamp format. Defaults to the ISO 8601 standard.")]
|
||||||
public string TimestampFormat = "yyyy-MM-ddTHH:mm:ss";
|
public string TimestampFormat = "yyyy-MM-ddTHH:mm:ss";
|
||||||
|
|
||||||
|
[Desc("Path to a MaxMind GeoLite2 database to use for player geo-location.",
|
||||||
|
"Database files can be downloaded from https://dev.maxmind.com/geoip/geoip2/geolite2/")]
|
||||||
|
public string GeoIPDatabase = null;
|
||||||
|
|
||||||
public ServerSettings Clone()
|
public ServerSettings Clone()
|
||||||
{
|
{
|
||||||
return (ServerSettings)MemberwiseClone();
|
return (ServerSettings)MemberwiseClone();
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ set ListenPort=1234
|
|||||||
set AdvertiseOnline=True
|
set AdvertiseOnline=True
|
||||||
set Password=""
|
set Password=""
|
||||||
|
|
||||||
|
set GeoIPDatabase=""
|
||||||
|
|
||||||
set RequireAuthentication=False
|
set RequireAuthentication=False
|
||||||
set ProfileIDBlacklist=""
|
set ProfileIDBlacklist=""
|
||||||
set ProfileIDWhitelist=""
|
set ProfileIDWhitelist=""
|
||||||
@@ -17,6 +19,6 @@ set EnableSyncReports=False
|
|||||||
|
|
||||||
:loop
|
:loop
|
||||||
|
|
||||||
OpenRA.Server.exe Game.Mod=%Mod% Server.Name=%Name% Server.ListenPort=%ListenPort% Server.AdvertiseOnline=%AdvertiseOnline% Server.EnableSingleplayer=%EnableSingleplayer% Server.Password=%Password% Server.RequireAuthentication=%RequireAuthentication% Server.ProfileIDBlacklist=%ProfileIDBlacklist% Server.ProfileIDWhitelist=%ProfileIDWhitelist% Server.EnableSyncReports=%EnableSyncReports%
|
OpenRA.Server.exe Game.Mod=%Mod% Server.Name=%Name% Server.ListenPort=%ListenPort% Server.AdvertiseOnline=%AdvertiseOnline% Server.EnableSingleplayer=%EnableSingleplayer% Server.Password=%Password% Server.GeoIPDatabase=%GeoIPDatabase% Server.RequireAuthentication=%RequireAuthentication% Server.ProfileIDBlacklist=%ProfileIDBlacklist% Server.ProfileIDWhitelist=%ProfileIDWhitelist% Server.EnableSyncReports=%EnableSyncReports%
|
||||||
|
|
||||||
goto loop
|
goto loop
|
||||||
@@ -12,6 +12,8 @@ ListenPort="${ListenPort:-"1234"}"
|
|||||||
AdvertiseOnline="${AdvertiseOnline:-"True"}"
|
AdvertiseOnline="${AdvertiseOnline:-"True"}"
|
||||||
Password="${Password:-""}"
|
Password="${Password:-""}"
|
||||||
|
|
||||||
|
GeoIPDatabase="${GeoIPDatabase:-""}"
|
||||||
|
|
||||||
RequireAuthentication="${RequireAuthentication:-"False"}"
|
RequireAuthentication="${RequireAuthentication:-"False"}"
|
||||||
ProfileIDBlacklist="${ProfileIDBlacklist:-""}"
|
ProfileIDBlacklist="${ProfileIDBlacklist:-""}"
|
||||||
ProfileIDWhitelist="${ProfileIDWhitelist:-""}"
|
ProfileIDWhitelist="${ProfileIDWhitelist:-""}"
|
||||||
@@ -26,6 +28,7 @@ while true; do
|
|||||||
Server.AdvertiseOnline="$AdvertiseOnline" \
|
Server.AdvertiseOnline="$AdvertiseOnline" \
|
||||||
Server.EnableSingleplayer="$EnableSingleplayer" \
|
Server.EnableSingleplayer="$EnableSingleplayer" \
|
||||||
Server.Password="$Password" \
|
Server.Password="$Password" \
|
||||||
|
Server.GeoIPDatabase="$GeoIPDatabase" \
|
||||||
Server.RequireAuthentication="$RequireAuthentication" \
|
Server.RequireAuthentication="$RequireAuthentication" \
|
||||||
Server.ProfileIDBlacklist="$ProfileIDBlacklist" \
|
Server.ProfileIDBlacklist="$ProfileIDBlacklist" \
|
||||||
Server.ProfileIDWhitelist="$ProfileIDWhitelist" \
|
Server.ProfileIDWhitelist="$ProfileIDWhitelist" \
|
||||||
|
|||||||
Reference in New Issue
Block a user