Use replicated CVars for max chat message length.
This commit is contained in:
@@ -4,12 +4,14 @@ using Content.Client.Administration.Managers;
|
||||
using Content.Client.Chat.UI;
|
||||
using Content.Client.Ghost;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Chat;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Player;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
@@ -52,7 +54,7 @@ namespace Content.Client.Chat.Managers
|
||||
/// <summary>
|
||||
/// The max amount of characters an entity can send in one message
|
||||
/// </summary>
|
||||
private int _maxMessageLength = 1000;
|
||||
private int MaxMessageLength => _cfg.GetCVar(CCVars.ChatMaxMessageLength);
|
||||
|
||||
public const char ConCmdSlash = '/';
|
||||
public const char OOCAlias = '[';
|
||||
@@ -100,6 +102,7 @@ namespace Content.Client.Chat.Managers
|
||||
[Dependency] private readonly IEyeManager _eyeManager = default!;
|
||||
[Dependency] private readonly IUserInterfaceManager _userInterfaceManager = default!;
|
||||
[Dependency] private readonly IClientAdminManager _adminMgr = default!;
|
||||
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Current chat box control. This can be modified, so do not depend on saving a reference to this.
|
||||
@@ -128,15 +131,11 @@ namespace Content.Client.Chat.Managers
|
||||
public void Initialize()
|
||||
{
|
||||
_netManager.RegisterNetMessage<MsgChatMessage>(OnChatMessage);
|
||||
_netManager.RegisterNetMessage<ChatMaxMsgLengthMessage>(OnMaxLengthReceived);
|
||||
|
||||
_speechBubbleRoot = new LayoutContainer();
|
||||
LayoutContainer.SetAnchorPreset(_speechBubbleRoot, LayoutContainer.LayoutPreset.Wide);
|
||||
_userInterfaceManager.StateRoot.AddChild(_speechBubbleRoot);
|
||||
_speechBubbleRoot.SetPositionFirst();
|
||||
|
||||
// When connexion is achieved, request the max chat message length
|
||||
_netManager.Connected += RequestMaxLength;
|
||||
}
|
||||
|
||||
public void PostInject()
|
||||
@@ -383,12 +382,12 @@ namespace Content.Client.Chat.Managers
|
||||
return;
|
||||
|
||||
// Check if message is longer than the character limit
|
||||
if (text.Length > _maxMessageLength)
|
||||
if (text.Length > MaxMessageLength)
|
||||
{
|
||||
if (CurrentChatBox != null)
|
||||
{
|
||||
string locWarning = Loc.GetString("chat-manager-max-message-length",
|
||||
("maxMessageLength", _maxMessageLength));
|
||||
("maxMessageLength", MaxMessageLength));
|
||||
CurrentChatBox.AddLine(locWarning, ChatChannel.Server, Color.Orange);
|
||||
CurrentChatBox.ClearOnEnter = false; // The text shouldn't be cleared if it hasn't been sent
|
||||
}
|
||||
@@ -510,17 +509,6 @@ namespace Content.Client.Chat.Managers
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMaxLengthReceived(ChatMaxMsgLengthMessage msg)
|
||||
{
|
||||
_maxMessageLength = msg.MaxMessageLength;
|
||||
}
|
||||
|
||||
private void RequestMaxLength(object? sender, NetChannelArgs args)
|
||||
{
|
||||
ChatMaxMsgLengthMessage msg = _netManager.CreateNetMessage<ChatMaxMsgLengthMessage>();
|
||||
_netManager.ClientSendMessage(msg);
|
||||
}
|
||||
|
||||
private void AddSpeechBubble(MsgChatMessage msg, SpeechBubble.SpeechType speechType)
|
||||
{
|
||||
if (!_entityManager.TryGetEntity(msg.SenderEntity, out var entity))
|
||||
|
||||
@@ -12,10 +12,8 @@ using Content.Shared.ActionBlocker;
|
||||
using Content.Shared.Administration;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.Chat;
|
||||
using Content.Shared.Emoting;
|
||||
using Content.Shared.Inventory;
|
||||
using Content.Shared.Notification.Managers;
|
||||
using Content.Shared.Speech;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
@@ -52,7 +50,7 @@ namespace Content.Server.Chat.Managers
|
||||
/// <summary>
|
||||
/// The maximum length a player-sent message can be sent
|
||||
/// </summary>
|
||||
public const int MaxMessageLength = 1000;
|
||||
public int MaxMessageLength => _configurationManager.GetCVar(CCVars.ChatMaxMessageLength);
|
||||
|
||||
private const int VoiceRange = 7; // how far voice goes in world units
|
||||
|
||||
@@ -64,12 +62,6 @@ namespace Content.Server.Chat.Managers
|
||||
public void Initialize()
|
||||
{
|
||||
_netManager.RegisterNetMessage<MsgChatMessage>();
|
||||
_netManager.RegisterNetMessage<ChatMaxMsgLengthMessage>(OnMaxLengthRequest);
|
||||
|
||||
// Tell all the connected players the chat's character limit
|
||||
var msg = _netManager.CreateNetMessage<ChatMaxMsgLengthMessage>();
|
||||
msg.MaxMessageLength = MaxMessageLength;
|
||||
_netManager.ServerSendToAll(msg);
|
||||
|
||||
_configurationManager.OnValueChanged(CCVars.OocEnabled, OnOocEnabledChanged, true);
|
||||
_configurationManager.OnValueChanged(CCVars.AdminOocEnabled, OnAdminOocEnabledChanged, true);
|
||||
@@ -368,13 +360,6 @@ namespace Content.Server.Chat.Managers
|
||||
_netManager.ServerSendToAll(msg);
|
||||
}
|
||||
|
||||
private void OnMaxLengthRequest(ChatMaxMsgLengthMessage msg)
|
||||
{
|
||||
var response = _netManager.CreateNetMessage<ChatMaxMsgLengthMessage>();
|
||||
response.MaxMessageLength = MaxMessageLength;
|
||||
_netManager.ServerSendMessage(response, msg.MsgChannel);
|
||||
}
|
||||
|
||||
public void RegisterChatTransform(TransformChat handler)
|
||||
{
|
||||
_chatTransformHandlers.Add(handler);
|
||||
|
||||
@@ -345,5 +345,12 @@ namespace Content.Shared.CCVar
|
||||
|
||||
public static readonly CVarDef<bool> ViewportScaleRender =
|
||||
CVarDef.Create("viewport.scale_render", true, CVar.CLIENTONLY | CVar.ARCHIVE);
|
||||
|
||||
/*
|
||||
* CHAT
|
||||
*/
|
||||
|
||||
public static readonly CVarDef<int> ChatMaxMessageLength =
|
||||
CVarDef.Create("chat.max_message_length", 1000, CVar.SERVER | CVar.REPLICATED);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
using Lidgren.Network;
|
||||
using Robust.Shared.Network;
|
||||
|
||||
namespace Content.Shared.Chat
|
||||
{
|
||||
/// <summary>
|
||||
/// This message is sent by the server to let clients know what is the chat's character limit for this server.
|
||||
/// It is first sent by the client as a request
|
||||
/// </summary>
|
||||
public sealed class ChatMaxMsgLengthMessage : NetMessage
|
||||
{
|
||||
public override MsgGroups MsgGroup => MsgGroups.Command;
|
||||
|
||||
/// <summary>
|
||||
/// The max length a player-sent message can get
|
||||
/// </summary>
|
||||
public int MaxMessageLength { get; set; }
|
||||
|
||||
public override void ReadFromBuffer(NetIncomingMessage buffer)
|
||||
{
|
||||
MaxMessageLength = buffer.ReadInt32();
|
||||
}
|
||||
|
||||
public override void WriteToBuffer(NetOutgoingMessage buffer)
|
||||
{
|
||||
buffer.Write(MaxMessageLength);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user