Add chat.max_announcement_length cvar (#23571)

* Add announce message length to UI and make a cvar for it

* Update comm console server-side trim to use the cvar

* Rely on the new OnTextChanged event

Because OnKeyBindUp only works for keys that have binds

* Add a similar indicator to nukies' war declaration UI

* Remove message length indicators for now cuz it requires the engine update

* Rename cvar slightly

* Refactor duplicated code to a helper method

* Remove message trimming from *Window class as it's better to live in the BoundUserInterface where the other message handling happens

* Rename to chat.max_announcement_length
This commit is contained in:
Kot
2024-01-21 13:14:01 +04:00
committed by GitHub
parent a2d5d74b46
commit 8c5898b006
9 changed files with 61 additions and 69 deletions

View File

@@ -3,9 +3,12 @@ using Content.Server.GameTicking.Rules;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.Popups;
using Content.Server.UserInterface;
using Content.Shared.CCVar;
using Content.Shared.Chat;
using Content.Shared.Database;
using Content.Shared.NukeOps;
using Robust.Server.GameObjects;
using Robust.Shared.Configuration;
namespace Content.Server.NukeOps;
@@ -18,6 +21,7 @@ public sealed class WarDeclaratorSystem : EntitySystem
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly NukeopsRuleSystem _nukeopsRuleSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
public override void Initialize()
{
@@ -52,22 +56,8 @@ public sealed class WarDeclaratorSystem : EntitySystem
return;
}
var text = (args.Message.Length <= component.MaxMessageLength ? args.Message.Trim() : $"{args.Message.Trim().Substring(0, 256)}...").ToCharArray();
// No more than 2 newlines, other replaced to spaces
var newlines = 0;
for (var i = 0; i < text.Length; i++)
{
if (text[i] != '\n')
continue;
if (newlines >= 2)
text[i] = ' ';
newlines++;
}
string message = new string(text);
var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
var message = SharedChatSystem.SanitizeAnnouncement(args.Message, maxLength);
if (component.AllowEditingMessage && message != string.Empty)
{
component.Message = message;