Anonymise client IPs and allow server operators to disable sharing.
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using OpenRA.Primitives;
|
||||
|
||||
namespace OpenRA.Network
|
||||
@@ -26,6 +28,18 @@ namespace OpenRA.Network
|
||||
|
||||
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)
|
||||
{
|
||||
try
|
||||
@@ -115,8 +129,14 @@ namespace OpenRA.Network
|
||||
public string Faction;
|
||||
public int SpawnPoint;
|
||||
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 AnonymizedIPAddress;
|
||||
public string Location;
|
||||
|
||||
public ClientState State = ClientState.Invalid;
|
||||
public int Team;
|
||||
public string Slot; // Slot ID, or null for observer
|
||||
|
||||
@@ -348,6 +348,7 @@ namespace OpenRA.Server
|
||||
{
|
||||
Name = OpenRA.Settings.SanitizedPlayerName(handshake.Client.Name),
|
||||
IpAddress = ipAddress.ToString(),
|
||||
AnonymizedIPAddress = Settings.ShareAnonymizedIPs ? Session.AnonymizeIP(ipAddress) : null,
|
||||
Location = GeoIP.LookupCountry(ipAddress),
|
||||
Index = newConn.PlayerIndex,
|
||||
PreferredColor = handshake.Client.PreferredColor,
|
||||
|
||||
@@ -86,6 +86,9 @@ namespace OpenRA
|
||||
"Database files can be downloaded from https://dev.maxmind.com/geoip/geoip2/geolite2/")]
|
||||
public string GeoIPDatabase = null;
|
||||
|
||||
[Desc("Allow clients to see anonymised IPs for other clients.")]
|
||||
public bool ShareAnonymizedIPs = true;
|
||||
|
||||
public ServerSettings Clone()
|
||||
{
|
||||
return (ServerSettings)MemberwiseClone();
|
||||
|
||||
@@ -329,10 +329,10 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
adminLabel.Bounds.Y += locationLabel.Bounds.Height;
|
||||
}
|
||||
|
||||
if (client.IpAddress != null)
|
||||
if (client.AnonymizedIPAddress != null)
|
||||
{
|
||||
ipLabel.IsVisible = () => true;
|
||||
ipLabel.GetText = () => client.IpAddress;
|
||||
ipLabel.GetText = () => client.AnonymizedIPAddress;
|
||||
widget.Bounds.Height += ipLabel.Bounds.Height;
|
||||
adminLabel.Bounds.Y += locationLabel.Bounds.Height;
|
||||
}
|
||||
|
||||
@@ -16,9 +16,10 @@ set ProfileIDWhitelist=""
|
||||
|
||||
set EnableSingleplayer=False
|
||||
set EnableSyncReports=False
|
||||
set ShareAnonymizedIPs=True
|
||||
|
||||
: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
|
||||
|
||||
@@ -20,6 +20,7 @@ ProfileIDWhitelist="${ProfileIDWhitelist:-""}"
|
||||
|
||||
EnableSingleplayer="${EnableSingleplayer:-"False"}"
|
||||
EnableSyncReports="${EnableSyncReports:-"False"}"
|
||||
ShareAnonymizedIPs="${ShareAnonymizedIPs:-"True"}"
|
||||
|
||||
while true; do
|
||||
mono --debug OpenRA.Server.exe Game.Mod="$Mod" \
|
||||
@@ -32,5 +33,6 @@ while true; do
|
||||
Server.RequireAuthentication="$RequireAuthentication" \
|
||||
Server.ProfileIDBlacklist="$ProfileIDBlacklist" \
|
||||
Server.ProfileIDWhitelist="$ProfileIDWhitelist" \
|
||||
Server.EnableSyncReports="$EnableSyncReports"
|
||||
Server.EnableSyncReports="$EnableSyncReports" \
|
||||
Server.ShareAnonymizedIPs="$ShareAnonymizedIPs"
|
||||
done
|
||||
|
||||
Reference in New Issue
Block a user