Disable chat for the first 5s (configurable) after joining a server.
This commit is contained in:
@@ -34,6 +34,21 @@ namespace OpenRA.Network
|
||||
TextNotificationsManager.AddSystemLine(order.TargetString);
|
||||
break;
|
||||
|
||||
case "DisableChatEntry":
|
||||
{
|
||||
// Order must originate from the server
|
||||
if (clientId != 0)
|
||||
break;
|
||||
|
||||
// Server may send MaxValue to indicate that it is disabled until further notice
|
||||
if (order.ExtraData == uint.MaxValue)
|
||||
TextNotificationsManager.ChatDisabledUntil = uint.MaxValue;
|
||||
else
|
||||
TextNotificationsManager.ChatDisabledUntil = Game.RunTime + order.ExtraData;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "Chat":
|
||||
{
|
||||
var client = orderManager.LobbyInfo.ClientWithIndex(clientId);
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace OpenRA.Server
|
||||
public readonly int PlayerIndex;
|
||||
public readonly string AuthToken;
|
||||
public readonly EndPoint EndPoint;
|
||||
public readonly Stopwatch ConnectionTimer = Stopwatch.StartNew();
|
||||
|
||||
public long TimeSinceLastResponse => Game.RunTime - lastReceivedTime;
|
||||
|
||||
|
||||
@@ -476,6 +476,10 @@ namespace OpenRA.Server
|
||||
LobbyInfo.Clients.Add(client);
|
||||
newConn.Validated = true;
|
||||
|
||||
// Disable chat UI to stop the client sending messages that we know we will reject
|
||||
if (!client.IsAdmin && Settings.JoinChatDelay > 0)
|
||||
DispatchOrdersToClient(newConn, 0, 0, new Order("DisableChatEntry", null, false) { ExtraData = (uint)Settings.JoinChatDelay }.Serialize());
|
||||
|
||||
Log.Write("server", "Client {0}: Accepted connection from {1}.", newConn.PlayerIndex, newConn.EndPoint);
|
||||
|
||||
if (client.Fingerprint != null)
|
||||
@@ -892,8 +896,19 @@ namespace OpenRA.Server
|
||||
}
|
||||
|
||||
case "Chat":
|
||||
DispatchOrdersToClients(conn, 0, o.Serialize());
|
||||
break;
|
||||
{
|
||||
var isAdmin = GetClient(conn)?.IsAdmin ?? false;
|
||||
var connected = conn.ConnectionTimer.ElapsedMilliseconds;
|
||||
if (!isAdmin && connected < Settings.JoinChatDelay)
|
||||
{
|
||||
var remaining = (Settings.JoinChatDelay - connected + 999) / 1000;
|
||||
SendOrderTo(conn, "Message", "Chat is disabled. Please try again in {0} seconds".F(remaining));
|
||||
}
|
||||
else
|
||||
DispatchOrdersToClients(conn, 0, o.Serialize());
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case "GameSaveTraitData":
|
||||
{
|
||||
|
||||
@@ -101,6 +101,9 @@ namespace OpenRA
|
||||
[Desc("For dedicated servers only, treat maps that fail the lint checks as invalid.")]
|
||||
public bool EnableLintChecks = true;
|
||||
|
||||
[Desc("Delay in milliseconds before newly joined players can send chat messages.")]
|
||||
public int JoinChatDelay = 5000;
|
||||
|
||||
public ServerSettings Clone()
|
||||
{
|
||||
return (ServerSettings)MemberwiseClone();
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace OpenRA
|
||||
static Color chatMessageColor = Color.White;
|
||||
static string systemMessageLabel;
|
||||
|
||||
public static long ChatDisabledUntil { get; internal set; }
|
||||
|
||||
static TextNotificationsManager()
|
||||
{
|
||||
ChromeMetrics.TryGet("ChatMessageColor", out chatMessageColor);
|
||||
|
||||
Reference in New Issue
Block a user