From cad016ccefea1f55d99517d116a77b47327d1e0f Mon Sep 17 00:00:00 2001 From: Tayrtahn Date: Sun, 15 Mar 2026 04:23:56 -0400 Subject: [PATCH] Move ID card name/title length limit to server (#43237) * Validate string lengths serverside * Organize usings * Remove clientside check * Also remove the cvar caching in the UI It's one dictionary call, Michael. What could it cost? --- .../UI/IdCardConsoleBoundUserInterface.cs | 16 --------------- .../Access/UI/IdCardConsoleWindow.xaml.cs | 11 ++-------- .../Access/Systems/IdCardConsoleSystem.cs | 20 +++++++++++++++---- 3 files changed, 18 insertions(+), 29 deletions(-) diff --git a/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs b/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs index d6eefa8afc7..89044ce692e 100644 --- a/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs +++ b/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs @@ -2,11 +2,9 @@ using System.Linq; // DeltaV using Content.Shared.Access; using Content.Shared.Access.Components; using Content.Shared.Access.Systems; -using Content.Shared.CCVar; using Content.Shared.Containers.ItemSlots; using Content.Shared.CrewManifest; using Content.Shared.Roles; -using Robust.Shared.Configuration; using Robust.Shared.Prototypes; using static Content.Shared.Access.Components.IdCardConsoleComponent; @@ -15,21 +13,13 @@ namespace Content.Client.Access.UI public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface { [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - [Dependency] private readonly IConfigurationManager _cfgManager = default!; private readonly SharedIdCardConsoleSystem _idCardConsoleSystem = default!; private IdCardConsoleWindow? _window; - // CCVar. - private int _maxNameLength; - private int _maxIdJobLength; - public IdCardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) { _idCardConsoleSystem = EntMan.System(); - - _maxNameLength =_cfgManager.GetCVar(CCVars.MaxNameLength); - _maxIdJobLength = _cfgManager.GetCVar(CCVars.MaxIdJobLength); } protected override void Open() @@ -79,12 +69,6 @@ namespace Content.Client.Access.UI public void SubmitData(string newFullName, string newJobTitle, List> newAccessList, ProtoId newJobPrototype) { - if (newFullName.Length > _maxNameLength) - newFullName = newFullName[.._maxNameLength]; - - if (newJobTitle.Length > _maxIdJobLength) - newJobTitle = newJobTitle[.._maxIdJobLength]; - SendMessage(new WriteToTargetIdMessage( newFullName, newJobTitle, diff --git a/Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs b/Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs index 30a7d969b61..bb44ae26155 100644 --- a/Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs +++ b/Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs @@ -23,10 +23,6 @@ namespace Content.Client.Access.UI private readonly IdCardConsoleBoundUserInterface _owner; - // CCVar. - private int _maxNameLength; - private int _maxIdJobLength; - private AccessLevelControl _accessButtons = new(); private readonly List _jobPrototypeIds = new(); @@ -46,11 +42,8 @@ namespace Content.Client.Access.UI _owner = owner; - _maxNameLength = _cfgManager.GetCVar(CCVars.MaxNameLength); - _maxIdJobLength = _cfgManager.GetCVar(CCVars.MaxIdJobLength); - FullNameLineEdit.OnTextEntered += _ => SubmitData(); - FullNameLineEdit.IsValid = s => s.Length <= _maxNameLength; + FullNameLineEdit.IsValid = s => s.Length <= _cfgManager.GetCVar(CCVars.MaxNameLength); FullNameLineEdit.OnTextChanged += _ => { FullNameSaveButton.Disabled = FullNameSaveButton.Text == _lastFullName; @@ -58,7 +51,7 @@ namespace Content.Client.Access.UI FullNameSaveButton.OnPressed += _ => SubmitData(); JobTitleLineEdit.OnTextEntered += _ => SubmitData(); - JobTitleLineEdit.IsValid = s => s.Length <= _maxIdJobLength; + JobTitleLineEdit.IsValid = s => s.Length <= _cfgManager.GetCVar(CCVars.MaxIdJobLength); JobTitleLineEdit.OnTextChanged += _ => { JobTitleSaveButton.Disabled = JobTitleLineEdit.Text == _lastJobTitle; diff --git a/Content.Server/Access/Systems/IdCardConsoleSystem.cs b/Content.Server/Access/Systems/IdCardConsoleSystem.cs index 1ac657810f2..37de21c4688 100644 --- a/Content.Server/Access/Systems/IdCardConsoleSystem.cs +++ b/Content.Server/Access/Systems/IdCardConsoleSystem.cs @@ -3,15 +3,14 @@ using System.Linq; using Content.Server.Chat.Systems; using Content.Server.Containers; using Content.Server.StationRecords.Systems; -using Content.Shared.Access.Components; -using static Content.Shared.Access.Components.IdCardConsoleComponent; -using Content.Shared.Access.Systems; using Content.Shared.Access; +using Content.Shared.Access.Components; +using Content.Shared.Access.Systems; using Content.Shared.Administration.Logs; +using Content.Shared.CCVar; using Content.Shared.Chat; using Content.Shared.Construction; using Content.Shared.Containers.ItemSlots; -using Content.Shared.Damage; using Content.Shared.Damage.Systems; using Content.Shared.Database; using Content.Shared.Roles; @@ -19,15 +18,18 @@ using Content.Shared.StationRecords; using Content.Shared.Throwing; using JetBrains.Annotations; using Robust.Server.GameObjects; +using Robust.Shared.Configuration; using Robust.Shared.Containers; using Robust.Shared.Prototypes; using Robust.Shared.Random; +using static Content.Shared.Access.Components.IdCardConsoleComponent; namespace Content.Server.Access.Systems; [UsedImplicitly] public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem { + [Dependency] private readonly IConfigurationManager _cfgManager = default!; [Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] private readonly StationRecordsSystem _record = default!; [Dependency] private readonly UserInterfaceSystem _userInterface = default!; @@ -143,6 +145,16 @@ public sealed class IdCardConsoleSystem : SharedIdCardConsoleSystem if (component.TargetIdSlot.Item is not { Valid: true } targetId || !PrivilegedIdIsAuthorized(uid, component, out var privilegedId)) return; + // Limit name and job title lengths + var maxNameLength = _cfgManager.GetCVar(CCVars.MaxNameLength); + var maxIdJobLength = _cfgManager.GetCVar(CCVars.MaxIdJobLength); + + if (newFullName.Length > maxNameLength) + newFullName = newFullName[..maxNameLength]; + + if (newJobTitle.Length > maxIdJobLength) + newJobTitle = newJobTitle[..maxIdJobLength]; + _idCard.TryChangeFullName(targetId, newFullName, player: player); _idCard.TryChangeJobTitle(targetId, newJobTitle, player: player);