From 75d4062698892140a316417711b2ec88301a738a Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Thu, 12 Oct 2017 20:04:35 +0100 Subject: [PATCH] Limit chat messages to 2500 characters. --- OpenRA.Game/Network/UnitOrders.cs | 15 +++++++++++---- .../Widgets/Logic/Ingame/IngameChatLogic.cs | 1 + .../Widgets/Logic/Lobby/LobbyLogic.cs | 2 ++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Network/UnitOrders.cs b/OpenRA.Game/Network/UnitOrders.cs index a698430674..c59d75d1fe 100644 --- a/OpenRA.Game/Network/UnitOrders.cs +++ b/OpenRA.Game/Network/UnitOrders.cs @@ -16,8 +16,9 @@ using OpenRA.Traits; namespace OpenRA.Network { - static class UnitOrders + public static class UnitOrders { + public const int ChatMessageMaxLength = 2500; const string ServerChatName = "Battlefield Control"; static Player FindPlayerByClient(this World world, Session.Client c) @@ -28,7 +29,7 @@ namespace OpenRA.Network p => (p.ClientIndex == c.Index && p.PlayerReference.Playable)); } - public static void ProcessOrder(OrderManager orderManager, World world, int clientId, Order order) + internal static void ProcessOrder(OrderManager orderManager, World world, int clientId, Order order) { if (world != null) { @@ -42,6 +43,12 @@ namespace OpenRA.Network case "Chat": { var client = orderManager.LobbyInfo.ClientWithIndex(clientId); + + // Cut chat messages to the hard limit to avoid exploits + var message = order.TargetString; + if (message.Length > ChatMessageMaxLength) + message = order.TargetString.Substring(0, ChatMessageMaxLength); + if (client != null) { var player = world != null ? world.FindPlayerByClient(client) : null; @@ -51,10 +58,10 @@ namespace OpenRA.Network if (orderManager.LocalClient != null && client != orderManager.LocalClient && client.Team > 0 && client.Team == orderManager.LocalClient.Team) suffix += " (Ally)"; - Game.AddChatLine(client.Color.RGB, client.Name + suffix, order.TargetString); + Game.AddChatLine(client.Color.RGB, client.Name + suffix, message); } else - Game.AddChatLine(Color.White, "(player {0})".F(clientId), order.TargetString); + Game.AddChatLine(Color.White, "(player {0})".F(clientId), message); break; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index 343fbd2778..d69ae8be1e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -71,6 +71,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatMode.IsDisabled = () => disableTeamChat; chatText = chatChrome.Get("CHAT_TEXTFIELD"); + chatText.MaxLength = UnitOrders.ChatMessageMaxLength; chatText.OnEnterKey = () => { var team = teamChat && !disableTeamChat; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index 7e7a5d9428..0c07926e05 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -469,6 +469,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic chatLabel = lobby.Get("LABEL_CHATTYPE"); var chatTextField = lobby.Get("CHAT_TEXTFIELD"); + chatTextField.MaxLength = UnitOrders.ChatMessageMaxLength; + chatTextField.TakeKeyboardFocus(); chatTextField.OnEnterKey = () => {