Limit chat messages to 2500 characters.

This commit is contained in:
Paul Chote
2017-10-12 20:04:35 +01:00
committed by reaperrr
parent 249e813444
commit 75d4062698
3 changed files with 14 additions and 4 deletions

View File

@@ -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;
}

View File

@@ -71,6 +71,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
chatMode.IsDisabled = () => disableTeamChat;
chatText = chatChrome.Get<TextFieldWidget>("CHAT_TEXTFIELD");
chatText.MaxLength = UnitOrders.ChatMessageMaxLength;
chatText.OnEnterKey = () =>
{
var team = teamChat && !disableTeamChat;

View File

@@ -469,6 +469,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
chatLabel = lobby.Get<LabelWidget>("LABEL_CHATTYPE");
var chatTextField = lobby.Get<TextFieldWidget>("CHAT_TEXTFIELD");
chatTextField.MaxLength = UnitOrders.ChatMessageMaxLength;
chatTextField.TakeKeyboardFocus();
chatTextField.OnEnterKey = () =>
{