From 94de2bea3d7e74889419d69a0359ab63cc5f487e Mon Sep 17 00:00:00 2001 From: Morb <14136326+Morb0@users.noreply.github.com> Date: Fri, 15 Sep 2023 00:12:11 +0300 Subject: [PATCH] News fix (#1417) --- .../MassMedia/Ui/NewsWriteBoundUserInterface.cs | 14 +++++++++++--- Content.Server/MassMedia/Systems/NewsSystem.cs | 10 ++++++++-- Content.Shared/CCVar/CCVars.cs | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Content.Client/MassMedia/Ui/NewsWriteBoundUserInterface.cs b/Content.Client/MassMedia/Ui/NewsWriteBoundUserInterface.cs index 975dfa3f81..a3e2d210b7 100644 --- a/Content.Client/MassMedia/Ui/NewsWriteBoundUserInterface.cs +++ b/Content.Client/MassMedia/Ui/NewsWriteBoundUserInterface.cs @@ -4,6 +4,8 @@ using Robust.Client.GameObjects; using Content.Shared.MassMedia.Systems; using Content.Shared.MassMedia.Components; using Content.Client.GameTicking.Managers; +using Content.Shared.CCVar; +using Robust.Shared.Configuration; using Robust.Shared.Utility; namespace Content.Client.MassMedia.Ui @@ -15,7 +17,7 @@ namespace Content.Client.MassMedia.Ui private NewsWriteMenu? _menu; [Dependency] private readonly IEntitySystemManager _entitySystem = default!; - [Dependency] private readonly IGameTiming _gameTiming = default!; + [Dependency] private readonly IConfigurationManager _cfg = default!; private ClientGameTicker? _gameTicker; [ViewVariables] @@ -71,10 +73,16 @@ namespace Content.Client.MassMedia.Ui return; var stringName = _menu.NameInput.Text; - var name = (stringName.Length <= 25 ? stringName.Trim() : $"{stringName.Trim().Substring(0, 25)}..."); + + var maxNameLength = _cfg.GetCVar(CCVars.NewsNameLimit); + var maxContentLength = _cfg.GetCVar(CCVars.NewsContentLimit); + + var name = (stringName.Length <= maxNameLength ? stringName.Trim() : $"{stringName.Trim().Substring(0, maxNameLength)}..."); + var content = (stringContent.Length <= maxContentLength ? stringContent.Trim() : $"{stringContent.Trim().Substring(0, maxContentLength)}..."); + _menu.ContentInput.TextRope = new Rope.Leaf(string.Empty); _menu.NameInput.Text = string.Empty; - SendMessage(new NewsWriteShareMessage(name, stringContent)); + SendMessage(new NewsWriteShareMessage(name, content)); } private void OnDeleteButtonPressed(int articleNum) diff --git a/Content.Server/MassMedia/Systems/NewsSystem.cs b/Content.Server/MassMedia/Systems/NewsSystem.cs index f5b17fefb8..343c30a92b 100644 --- a/Content.Server/MassMedia/Systems/NewsSystem.cs +++ b/Content.Server/MassMedia/Systems/NewsSystem.cs @@ -17,7 +17,9 @@ using Content.Server.GameTicking; using Robust.Shared.Timing; using Content.Server.Popups; using Content.Server.StationRecords.Systems; +using Content.Shared.CCVar; using Content.Shared.Database; +using Robust.Shared.Configuration; using Robust.Shared.Containers; using Robust.Shared.Utility; @@ -26,6 +28,7 @@ namespace Content.Server.MassMedia.Systems; public sealed class NewsSystem : EntitySystem { [Dependency] private readonly IGameTiming _timing = default!; + [Dependency] private readonly IConfigurationManager _cfg = default!; [Dependency] private readonly UserInterfaceSystem _ui = default!; [Dependency] private readonly RingerSystem _ringer = default!; [Dependency] private readonly CartridgeLoaderSystem _cartridgeLoaderSystem = default!; @@ -142,11 +145,14 @@ public sealed class NewsSystem : EntitySystem } } + var maxNameLength = _cfg.GetCVar(CCVars.NewsNameLimit); + var maxContentLength = _cfg.GetCVar(CCVars.NewsContentLimit); + NewsArticle article = new NewsArticle { Author = authorName, - Name = (msg.Name.Length <= 25 ? msg.Name.Trim() : $"{msg.Name.Trim().Substring(0, 25)}..."), - Content = msg.Content, + Name = (msg.Name.Length <= maxNameLength ? msg.Name.Trim() : $"{msg.Name.Trim().Substring(0, maxNameLength)}..."), + Content = (msg.Content.Length <= maxContentLength ? msg.Name.Trim() : $"{msg.Content.Trim().Substring(0, maxContentLength)}..."), ShareTime = _ticker.RoundDuration() }; diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 34294ebcbd..9cdecf47fc 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -1757,5 +1757,21 @@ namespace Content.Shared.CCVar /// public static readonly CVarDef ReplayAutoRecordTempDir = CVarDef.Create("replay.auto_record_temp_dir", "", CVar.SERVERONLY); + + /* + * News + */ + + /// + /// Maximum number of characters that can be specified in the news name + /// + public static readonly CVarDef NewsNameLimit = + CVarDef.Create("news.name_limit", 25, CVar.SERVER | CVar.REPLICATED); + + /// + /// Maximum number of characters that can be specified in the news content + /// + public static readonly CVarDef NewsContentLimit = + CVarDef.Create("news.content_limit", 2048, CVar.SERVER | CVar.REPLICATED); } }