Merge pull request #3164 from pchote/lobby-tooltips

New/Improved lobby tooltips which show IP, admin status and explain ping.
This commit is contained in:
Matthias Mailänder
2013-04-25 00:59:31 -07:00
19 changed files with 403 additions and 75 deletions

View File

@@ -53,6 +53,7 @@ namespace OpenRA.Network
public string Country;
public int SpawnPoint;
public string Name;
public string IpAddress;
public ClientState State;
public int Team;
public string Slot; // slot ID, or null for observer
@@ -61,9 +62,9 @@ namespace OpenRA.Network
public bool IsAdmin;
public bool IsReady { get { return State == ClientState.Ready; } }
public bool IsObserver { get { return Slot == null; } }
public int Ping = -1;
public int PingJitter = -1;
public int[] PingHistory = {};
public int Latency = -1;
public int LatencyJitter = -1;
public int[] LatencyHistory = {};
}
public class Slot

View File

@@ -223,6 +223,7 @@
<Compile Include="Widgets\TooltipContainerWidget.cs" />
<Compile Include="Traits\DebugPauseState.cs" />
<Compile Include="Network\UPnP.cs" />
<Compile Include="Widgets\ClientTooltipRegionWidget.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">

View File

@@ -263,11 +263,13 @@ namespace OpenRA.Server
return;
}
client.IpAddress = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString();
// Check if IP is banned
if (lobbyInfo.GlobalSettings.Ban != null)
{
var remote_addr = ((IPEndPoint)newConn.socket.RemoteEndPoint).Address.ToString();
if (lobbyInfo.GlobalSettings.Ban.Contains(remote_addr))
if (lobbyInfo.GlobalSettings.Ban.Contains(client.IpAddress))
{
Console.WriteLine("Rejected connection from "+client.Name+"("+newConn.socket.RemoteEndPoint+"); Banned.");
Log.Write("server", "Rejected connection from {0}; Banned.",
@@ -469,16 +471,16 @@ namespace OpenRA.Server
break;
}
var history = fromClient.PingHistory.ToList();
var history = fromClient.LatencyHistory.ToList();
history.Add(Environment.TickCount - pingSent);
// Cap ping history at 5 values (25 seconds)
if (history.Count > 5)
history.RemoveRange(0, history.Count - 5);
fromClient.Ping = history.Sum() / history.Count;
fromClient.PingJitter = (history.Max() - history.Min())/2;
fromClient.PingHistory = history.ToArray();
fromClient.Latency = history.Sum() / history.Count;
fromClient.LatencyJitter = (history.Max() - history.Min())/2;
fromClient.LatencyHistory = history.ToArray();
if (State == ServerState.WaitingPlayers)
SyncLobbyInfo();

View File

@@ -0,0 +1,67 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Threading;
using OpenRA.FileFormats;
using OpenRA.Graphics;
using OpenRA.Network;
namespace OpenRA.Widgets
{
public class ClientTooltipRegionWidget : Widget
{
public readonly string Template;
public readonly string TooltipContainer;
Lazy<TooltipContainerWidget> tooltipContainer;
OrderManager orderManager;
int clientIndex;
public ClientTooltipRegionWidget() : base()
{
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}
protected ClientTooltipRegionWidget(ClientTooltipRegionWidget other)
: base(other)
{
Template = other.Template;
TooltipContainer = other.TooltipContainer;
tooltipContainer = Lazy.New(() => Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
orderManager = other.orderManager;
clientIndex = other.clientIndex;
}
public override Widget Clone() { return new ClientTooltipRegionWidget(this); }
public void Bind(OrderManager orderManager, int clientIndex)
{
this.orderManager = orderManager;
this.clientIndex = clientIndex;
}
public override void MouseEntered()
{
if (TooltipContainer == null)
return;
tooltipContainer.Value.SetTooltip(Template, new WidgetArgs() {{"orderManager", orderManager}, {"clientIndex", clientIndex}});
}
public override void MouseExited()
{
if (TooltipContainer == null)
return;
tooltipContainer.Value.RemoveTooltip();
}
}
}

View File

@@ -24,7 +24,6 @@ namespace OpenRA.Widgets
public Func<Map> Map = () => null;
public Func<Dictionary<int2, Session.Client>> SpawnClients = () => new Dictionary<int2, Session.Client>();
public Action<MouseInput> OnMouseDown = _ => {};
public Action<int, int2> OnTooltip = (_, __) => { };
public bool IgnoreMouseInput = false;
public bool ShowSpawnPoints = true;
@@ -147,13 +146,7 @@ namespace OpenRA.Widgets
Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos + offset);
if ((pos - Viewport.LastMousePos).LengthSquared < 64)
{
TooltipSpawnIndex = spawnPoints.IndexOf(p) + 1;
// Legacy tooltip behavior
if (TooltipContainer == null)
OnTooltip(TooltipSpawnIndex, pos);
}
}
}
}