Anonymise client IPs and allow server operators to disable sharing.

This commit is contained in:
Paul Chote
2020-01-12 10:52:34 +00:00
committed by abcdefg30
parent 422cc2b0d0
commit 38cb818469
6 changed files with 31 additions and 4 deletions

View File

@@ -12,6 +12,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net;
using System.Net.Sockets;
using OpenRA.Primitives; using OpenRA.Primitives;
namespace OpenRA.Network namespace OpenRA.Network
@@ -26,6 +28,18 @@ namespace OpenRA.Network
public Global GlobalSettings = new Global(); public Global GlobalSettings = new Global();
public static string AnonymizeIP(IPAddress ip)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
// Follow convention used by Google Analytics: remove last octet
var b = ip.GetAddressBytes();
return "{0}.{1}.{2}.*".F(b[0], b[1], b[2]);
}
return null;
}
public static Session Deserialize(string data) public static Session Deserialize(string data)
{ {
try try
@@ -115,8 +129,14 @@ namespace OpenRA.Network
public string Faction; public string Faction;
public int SpawnPoint; public int SpawnPoint;
public string Name; public string Name;
// The full IP address is required for the IP banning moderation feature
// but we must not share the un-anonymized address with other players.
[FieldLoader.Ignore]
public string IpAddress; public string IpAddress;
public string AnonymizedIPAddress;
public string Location; public string Location;
public ClientState State = ClientState.Invalid; public ClientState State = ClientState.Invalid;
public int Team; public int Team;
public string Slot; // Slot ID, or null for observer public string Slot; // Slot ID, or null for observer

View File

@@ -348,6 +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(),
AnonymizedIPAddress = Settings.ShareAnonymizedIPs ? Session.AnonymizeIP(ipAddress) : null,
Location = GeoIP.LookupCountry(ipAddress), Location = GeoIP.LookupCountry(ipAddress),
Index = newConn.PlayerIndex, Index = newConn.PlayerIndex,
PreferredColor = handshake.Client.PreferredColor, PreferredColor = handshake.Client.PreferredColor,

View File

@@ -86,6 +86,9 @@ namespace OpenRA
"Database files can be downloaded from https://dev.maxmind.com/geoip/geoip2/geolite2/")] "Database files can be downloaded from https://dev.maxmind.com/geoip/geoip2/geolite2/")]
public string GeoIPDatabase = null; public string GeoIPDatabase = null;
[Desc("Allow clients to see anonymised IPs for other clients.")]
public bool ShareAnonymizedIPs = true;
public ServerSettings Clone() public ServerSettings Clone()
{ {
return (ServerSettings)MemberwiseClone(); return (ServerSettings)MemberwiseClone();

View File

@@ -329,10 +329,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
adminLabel.Bounds.Y += locationLabel.Bounds.Height; adminLabel.Bounds.Y += locationLabel.Bounds.Height;
} }
if (client.IpAddress != null) if (client.AnonymizedIPAddress != null)
{ {
ipLabel.IsVisible = () => true; ipLabel.IsVisible = () => true;
ipLabel.GetText = () => client.IpAddress; ipLabel.GetText = () => client.AnonymizedIPAddress;
widget.Bounds.Height += ipLabel.Bounds.Height; widget.Bounds.Height += ipLabel.Bounds.Height;
adminLabel.Bounds.Y += locationLabel.Bounds.Height; adminLabel.Bounds.Y += locationLabel.Bounds.Height;
} }

View File

@@ -16,9 +16,10 @@ set ProfileIDWhitelist=""
set EnableSingleplayer=False set EnableSingleplayer=False
set EnableSyncReports=False set EnableSyncReports=False
set ShareAnonymizedIPs=True
:loop :loop
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% 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% Server.ShareAnonymizedIPs=%ShareAnonymizedIPs%
goto loop goto loop

View File

@@ -20,6 +20,7 @@ ProfileIDWhitelist="${ProfileIDWhitelist:-""}"
EnableSingleplayer="${EnableSingleplayer:-"False"}" EnableSingleplayer="${EnableSingleplayer:-"False"}"
EnableSyncReports="${EnableSyncReports:-"False"}" EnableSyncReports="${EnableSyncReports:-"False"}"
ShareAnonymizedIPs="${ShareAnonymizedIPs:-"True"}"
while true; do while true; do
mono --debug OpenRA.Server.exe Game.Mod="$Mod" \ mono --debug OpenRA.Server.exe Game.Mod="$Mod" \
@@ -32,5 +33,6 @@ while true; do
Server.RequireAuthentication="$RequireAuthentication" \ Server.RequireAuthentication="$RequireAuthentication" \
Server.ProfileIDBlacklist="$ProfileIDBlacklist" \ Server.ProfileIDBlacklist="$ProfileIDBlacklist" \
Server.ProfileIDWhitelist="$ProfileIDWhitelist" \ Server.ProfileIDWhitelist="$ProfileIDWhitelist" \
Server.EnableSyncReports="$EnableSyncReports" Server.EnableSyncReports="$EnableSyncReports" \
Server.ShareAnonymizedIPs="$ShareAnonymizedIPs"
done done