Skip to content

Commit

Permalink
Evaluate player location on the server.
Browse files Browse the repository at this point in the history
  • Loading branch information
pchote authored and abcdefg30 committed Jan 15, 2020
1 parent c430884 commit 6b2c019
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 26 deletions.
3 changes: 0 additions & 3 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@ Using OpenAL Soft distributed under the GNU LGPL.
Using MaxMind GeoIP2 .NET API distributed under
the Apache 2.0 license.

Using GeoLite2 data created by MaxMind and
distributed under the CC BY-SA 3.0 license.

Using SDL2-CS and OpenAL-CS created by Ethan
Lee and released under the zlib license.

Expand Down
2 changes: 0 additions & 2 deletions OpenRA.Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,6 @@ static void Initialize(Arguments args)
}
}

GeoIP.Initialize();

if (Settings.Server.DiscoverNatDevices)
discoverNat = UPnP.DiscoverNatDevices(Settings.Server.NatDiscoveryTimeout);

Expand Down
1 change: 1 addition & 0 deletions OpenRA.Game/Network/Session.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public static Client Deserialize(MiniYaml data)
public int SpawnPoint;
public string Name;
public string IpAddress;
public string Location;
public ClientState State = ClientState.Invalid;
public int Team;
public string Slot; // Slot ID, or null for observer
Expand Down
6 changes: 5 additions & 1 deletion OpenRA.Game/Server/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ public Server(IPEndPoint endpoint, ServerSettings settings, ModData modData, Ser

randomSeed = (int)DateTime.Now.ToBinary();

GeoIP.Initialize();

if (UPnP.Status == UPnPStatus.Enabled)
UPnP.ForwardPort(Settings.ListenPort, Settings.ListenPort).Wait();

Expand Down Expand Up @@ -341,10 +343,12 @@ void ValidateClient(Connection newConn, string data)
return;
}

var ipAddress = ((IPEndPoint)newConn.Socket.RemoteEndPoint).Address;
var client = new Session.Client
{
Name = OpenRA.Settings.SanitizedPlayerName(handshake.Client.Name),
IpAddress = ((IPEndPoint)newConn.Socket.RemoteEndPoint).Address.ToString(),
IpAddress = ipAddress.ToString(),
Location = GeoIP.LookupCountry(ipAddress.ToString()),
Index = newConn.PlayerIndex,
PreferredColor = handshake.Client.PreferredColor,
Color = handshake.Client.Color,
Expand Down
14 changes: 0 additions & 14 deletions OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -593,20 +593,6 @@ public static void HideReadyWidgets(Widget parent)
HideChildWidget(parent, "STATUS_IMAGE");
}

public static string GetExternalIP(Session.Client client, OrderManager orderManager)
{
var address = client != null ? client.IpAddress : "";
var lc = orderManager.LocalClient;
if (lc != null && lc.Index == client.Index && address == IPAddress.Loopback.ToString())
{
var externalIP = UPnP.ExternalIP;
if (externalIP != null)
address = externalIP.ToString();
}

return address;
}

public static void SetupChatLine(ContainerWidget template, DateTime time, string name, Color nameColor, string text, Color textColor)
{
var nameLabel = template.Get<LabelWidget>("NAME");
Expand Down
8 changes: 2 additions & 6 deletions OpenRA.Mods.Common/Widgets/Logic/PlayerProfileLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,19 +312,15 @@ public class AnonymousProfileTooltipLogic : ChromeLogic
[ObjectCreator.UseCtor]
public AnonymousProfileTooltipLogic(Widget widget, OrderManager orderManager, Session.Client client)
{
var address = LobbyUtils.GetExternalIP(client, orderManager);
var cachedDescriptiveIP = address ?? "Unknown IP";

var nameLabel = widget.Get<LabelWidget>("NAME");
var nameFont = Game.Renderer.Fonts[nameLabel.Font];
widget.Bounds.Width = nameFont.Measure(nameLabel.Text).X + 2 * nameLabel.Bounds.Left;

var ipLabel = widget.Get<LabelWidget>("IP");
ipLabel.GetText = () => cachedDescriptiveIP;
ipLabel.GetText = () => client.IpAddress;

var locationLabel = widget.Get<LabelWidget>("LOCATION");
var cachedCountryLookup = GeoIP.LookupCountry(address);
locationLabel.GetText = () => cachedCountryLookup;
locationLabel.GetText = () => client.Location;

if (client.IsAdmin)
{
Expand Down

0 comments on commit 6b2c019

Please sign in to comment.