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

@@ -11,6 +11,7 @@ using Content.Server.Station.Systems;
using Content.Shared.Access.Components;
using Content.Shared.Access.Systems;
using Content.Shared.CCVar;
using Content.Shared.Chat;
using Content.Shared.Communications;
using Content.Shared.Database;
using Content.Shared.Emag.Components;
@@ -35,8 +36,6 @@ namespace Content.Server.Communications
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
private const int MaxMessageLength = 256;
private const int MaxMessageNewlines = 2;
private const float UIUpdateInterval = 5.0f;
public override void Initialize()
@@ -231,22 +230,8 @@ namespace Content.Server.Communications
private void OnAnnounceMessage(EntityUid uid, CommunicationsConsoleComponent comp,
CommunicationsConsoleAnnounceMessage message)
{
var msgWords = message.Message.Trim();
var msgChars = (msgWords.Length <= MaxMessageLength ? msgWords : $"{msgWords[0..MaxMessageLength]}...").ToCharArray();
var newlines = 0;
for (var i = 0; i < msgChars.Length; i++)
{
if (msgChars[i] != '\n')
continue;
if (newlines >= MaxMessageNewlines)
msgChars[i] = ' ';
newlines++;
}
var msg = new string(msgChars);
var maxLength = _cfg.GetCVar(CCVars.ChatMaxAnnouncementLength);
var msg = SharedChatSystem.SanitizeAnnouncement(message.Message, maxLength);
var author = Loc.GetString("comms-console-announcement-unknown-sender");
if (message.Session.AttachedEntity is { Valid: true } mob)
{