From de24413bd5505a43a91e9e6474640b5a8d08ca30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=81da?= Date: Sat, 17 May 2025 00:27:39 -0500 Subject: [PATCH] HumanoidCharacterProfile and IdCardConsoleComponent constants moved to cvar. Sync id card length with character name length (#35407) * commit * mark TODOs * compiles * cleanup * cleanup * oops * changed my mind * requested changes * genpop fix --- .../UI/IdCardConsoleBoundUserInterface.cs | 18 ++++++++++--- .../Access/UI/IdCardConsoleWindow.xaml.cs | 12 +++++++++ .../Lobby/UI/HumanoidProfileEditor.xaml.cs | 11 +++++++- .../Lobby/UI/Loadouts/LoadoutWindow.xaml.cs | 12 +++++++-- .../Pinpointer/UI/NavMapBeaconWindow.xaml.cs | 11 ++++++-- .../Security/Ui/GenpopLockerMenu.xaml.cs | 11 +++++++- .../Silicons/Borgs/BorgMenu.xaml.cs | 14 +++++++--- Content.Server/Mind/Commands/RenameCommand.cs | 5 +++- .../Silicons/Borgs/BorgSystem.Ui.cs | 9 ++++++- Content.Server/Silicons/Borgs/BorgSystem.cs | 2 ++ Content.Server/VoiceMask/VoiceMaskSystem.cs | 10 ++++++- .../Components/IdCardConsoleComponent.cs | 3 --- .../Access/Systems/SharedIdCardSystem.cs | 18 ++++++++++--- Content.Shared/CCVar/CCVars.Ic.cs | 26 ++++++++++++++++++- .../Preferences/HumanoidCharacterProfile.cs | 14 +++++----- .../Preferences/Loadouts/RoleLoadout.cs | 8 ++++-- .../Security/Systems/SharedGenpopSystem.cs | 9 ++++++- 17 files changed, 158 insertions(+), 35 deletions(-) diff --git a/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs b/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs index a321b4121e..f3a37f054e 100644 --- a/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs +++ b/Content.Client/Access/UI/IdCardConsoleBoundUserInterface.cs @@ -1,8 +1,10 @@ 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 Robust.Shared.Configuration; using Robust.Shared.Prototypes; using static Content.Shared.Access.Components.IdCardConsoleComponent; @@ -11,13 +13,21 @@ 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() @@ -66,11 +76,11 @@ namespace Content.Client.Access.UI public void SubmitData(string newFullName, string newJobTitle, List> newAccessList, string newJobPrototype) { - if (newFullName.Length > MaxFullNameLength) - newFullName = newFullName[..MaxFullNameLength]; + if (newFullName.Length > _maxNameLength) + newFullName = newFullName[.._maxNameLength]; - if (newJobTitle.Length > MaxJobTitleLength) - newJobTitle = newJobTitle[..MaxJobTitleLength]; + if (newJobTitle.Length > _maxIdJobLength) + newJobTitle = newJobTitle[.._maxIdJobLength]; SendMessage(new WriteToTargetIdMessage( newFullName, diff --git a/Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs b/Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs index c133e0b107..48ae1b0ced 100644 --- a/Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs +++ b/Content.Client/Access/UI/IdCardConsoleWindow.xaml.cs @@ -1,11 +1,13 @@ using System.Linq; using Content.Shared.Access; using Content.Shared.Access.Systems; +using Content.Shared.CCVar; using Content.Shared.Roles; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; +using Robust.Shared.Configuration; using Robust.Shared.Prototypes; using static Content.Shared.Access.Components.IdCardConsoleComponent; @@ -14,12 +16,17 @@ namespace Content.Client.Access.UI [GenerateTypedNameReferences] public sealed partial class IdCardConsoleWindow : DefaultWindow { + [Dependency] private readonly IConfigurationManager _cfgManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly ILogManager _logManager = default!; private readonly ISawmill _logMill = default!; private readonly IdCardConsoleBoundUserInterface _owner; + // CCVar. + private int _maxNameLength; + private int _maxIdJobLength; + private AccessLevelControl _accessButtons = new(); private readonly List _jobPrototypeIds = new(); @@ -39,7 +46,11 @@ 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.OnTextChanged += _ => { FullNameSaveButton.Disabled = FullNameSaveButton.Text == _lastFullName; @@ -47,6 +58,7 @@ namespace Content.Client.Access.UI FullNameSaveButton.OnPressed += _ => SubmitData(); JobTitleLineEdit.OnTextEntered += _ => SubmitData(); + JobTitleLineEdit.IsValid = s => s.Length <= _maxIdJobLength; JobTitleLineEdit.OnTextChanged += _ => { JobTitleSaveButton.Disabled = JobTitleLineEdit.Text == _lastJobTitle; diff --git a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs index 135bd58d78..aa18751db0 100644 --- a/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs @@ -53,6 +53,10 @@ namespace Content.Client.Lobby.UI private readonly SpriteSystem _sprite; + // CCvar. + private int _maxNameLength; + private bool _allowFlavorText; + private FlavorText.FlavorText? _flavorText; private TextEdit? _flavorTextEdit; @@ -131,6 +135,10 @@ namespace Content.Client.Lobby.UI _requirements = requirements; _controller = UserInterfaceManager.GetUIController(); _sprite = _entManager.System(); + + _maxNameLength = _cfgManager.GetCVar(CCVars.MaxNameLength); + _allowFlavorText = _cfgManager.GetCVar(CCVars.FlavorText); + ImportButton.OnPressed += args => { ImportProfile(); @@ -166,6 +174,7 @@ namespace Content.Client.Lobby.UI #region Name NameEdit.OnTextChanged += args => { SetName(args.Text); }; + NameEdit.IsValid = args => args.Length <= _maxNameLength; NameRandomize.OnPressed += args => RandomizeName(); RandomizeEverythingButton.OnPressed += args => { RandomizeEverything(); }; WarningLabel.SetMarkup($"[color=red]{Loc.GetString("humanoid-profile-editor-naming-rules-warning")}[/color]"); @@ -451,7 +460,7 @@ namespace Content.Client.Lobby.UI /// public void RefreshFlavorText() { - if (_cfgManager.GetCVar(CCVars.FlavorText)) + if (_allowFlavorText) { if (_flavorText != null) return; diff --git a/Content.Client/Lobby/UI/Loadouts/LoadoutWindow.xaml.cs b/Content.Client/Lobby/UI/Loadouts/LoadoutWindow.xaml.cs index 48b5289efc..68e1ecbeae 100644 --- a/Content.Client/Lobby/UI/Loadouts/LoadoutWindow.xaml.cs +++ b/Content.Client/Lobby/UI/Loadouts/LoadoutWindow.xaml.cs @@ -1,11 +1,13 @@ using System.Numerics; using Content.Client.UserInterface.Controls; +using Content.Shared.CCVar; using Content.Shared.Dataset; using Content.Shared.Preferences; using Content.Shared.Preferences.Loadouts; using Content.Shared.Random.Helpers; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.XAML; +using Robust.Shared.Configuration; using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Random; @@ -23,12 +25,18 @@ public sealed partial class LoadoutWindow : FancyWindow public HumanoidCharacterProfile Profile; + // CCvar. + private int _maxLoadoutNameLength; + public LoadoutWindow(HumanoidCharacterProfile profile, RoleLoadout loadout, RoleLoadoutPrototype proto, ICommonSession session, IDependencyCollection collection) { RobustXamlLoader.Load(this); Profile = profile; var protoManager = collection.Resolve(); - RoleNameEdit.IsValid = text => text.Length <= HumanoidCharacterProfile.MaxLoadoutNameLength; + var configManager = collection.Resolve(); + + _maxLoadoutNameLength = configManager.GetCVar(CCVars.MaxLoadoutNameLength); + RoleNameEdit.IsValid = text => text.Length <= _maxLoadoutNameLength; // Hide if we can't edit the name. if (!proto.CanCustomizeName) @@ -45,7 +53,7 @@ public sealed partial class LoadoutWindow : FancyWindow RoleNameEdit.ToolTip = Loc.GetString( "loadout-name-edit-tooltip", - ("max", HumanoidCharacterProfile.MaxLoadoutNameLength)); + ("max", _maxLoadoutNameLength)); RoleNameEdit.Text = name ?? string.Empty; RoleNameEdit.OnTextChanged += args => OnNameChanged?.Invoke(args.Text); } diff --git a/Content.Client/Pinpointer/UI/NavMapBeaconWindow.xaml.cs b/Content.Client/Pinpointer/UI/NavMapBeaconWindow.xaml.cs index b77f1af047..291270f05a 100644 --- a/Content.Client/Pinpointer/UI/NavMapBeaconWindow.xaml.cs +++ b/Content.Client/Pinpointer/UI/NavMapBeaconWindow.xaml.cs @@ -1,19 +1,25 @@ using Content.Client.UserInterface.Controls; +using Content.Shared.CCVar; using Content.Shared.Pinpointer; using Content.Shared.Preferences; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; +using Robust.Shared.Configuration; namespace Content.Client.Pinpointer.UI; [GenerateTypedNameReferences] public sealed partial class NavMapBeaconWindow : FancyWindow { + [Dependency] private readonly IConfigurationManager _cfgManager = default!; private string? _defaultLabel; private bool _defaultEnabled; private Color _defaultColor; + // CCVar. + private int _maxNameLength; + public event Action? OnApplyButtonPressed; public NavMapBeaconWindow() @@ -21,6 +27,7 @@ public sealed partial class NavMapBeaconWindow : FancyWindow RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); + _maxNameLength = _cfgManager.GetCVar(CCVars.MaxNameLength); VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed); LabelLineEdit.OnTextChanged += OnTextChanged; @@ -53,8 +60,8 @@ public sealed partial class NavMapBeaconWindow : FancyWindow private void OnTextChanged(LineEdit.LineEditEventArgs obj) { - if (obj.Text.Length > HumanoidCharacterProfile.MaxNameLength) - obj.Control.Text = obj.Text.Substring(0, HumanoidCharacterProfile.MaxNameLength); + if (obj.Text.Length > _maxNameLength) + obj.Control.Text = obj.Text.Substring(0, _maxNameLength); TryEnableApplyButton(); } diff --git a/Content.Client/Security/Ui/GenpopLockerMenu.xaml.cs b/Content.Client/Security/Ui/GenpopLockerMenu.xaml.cs index 575b2f50df..70081211d2 100644 --- a/Content.Client/Security/Ui/GenpopLockerMenu.xaml.cs +++ b/Content.Client/Security/Ui/GenpopLockerMenu.xaml.cs @@ -1,21 +1,30 @@ using Content.Client.Message; using Content.Client.UserInterface.Controls; using Content.Shared.Access.Components; +using Content.Shared.CCVar; using Content.Shared.Security.Components; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.XAML; +using Robust.Shared.Configuration; namespace Content.Client.Security.Ui; [GenerateTypedNameReferences] public sealed partial class GenpopLockerMenu : FancyWindow { + [Dependency] private readonly IConfigurationManager _cfgManager = default!; + public event Action? OnConfigurationComplete; + // CCVar. + private int _maxIdJobLength; + public GenpopLockerMenu(EntityUid owner, IEntityManager entMan) { RobustXamlLoader.Load(this); + _maxIdJobLength = _cfgManager.GetCVar(CCVars.MaxIdJobLength); + Title = entMan.GetComponent(owner).EntityName; NameLabel.SetMarkup(Loc.GetString("genpop-locker-ui-label-name")); @@ -25,7 +34,7 @@ public sealed partial class GenpopLockerMenu : FancyWindow SentenceEdit.Text = "5"; CrimeEdit.Text = Loc.GetString("genpop-prisoner-id-crime-default"); - NameEdit.IsValid = val => !string.IsNullOrWhiteSpace(val) && val.Length <= IdCardConsoleComponent.MaxFullNameLength; + NameEdit.IsValid = val => !string.IsNullOrWhiteSpace(val) && val.Length <= _maxIdJobLength; SentenceEdit.IsValid = val => float.TryParse(val, out var f) && f >= 0; CrimeEdit.IsValid = val => !string.IsNullOrWhiteSpace(val) && val.Length <= GenpopLockerComponent.MaxCrimeLength; diff --git a/Content.Client/Silicons/Borgs/BorgMenu.xaml.cs b/Content.Client/Silicons/Borgs/BorgMenu.xaml.cs index 007a0cc5cb..b9e07adef0 100644 --- a/Content.Client/Silicons/Borgs/BorgMenu.xaml.cs +++ b/Content.Client/Silicons/Borgs/BorgMenu.xaml.cs @@ -1,5 +1,6 @@ using Content.Client.Stylesheets; using Content.Client.UserInterface.Controls; +using Content.Shared.CCVar; using Content.Shared.NameIdentifier; using Content.Shared.NameModifier.EntitySystems; using Content.Shared.Preferences; @@ -8,6 +9,7 @@ using Content.Shared.Silicons.Borgs.Components; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.XAML; +using Robust.Shared.Configuration; using Robust.Shared.Timing; namespace Content.Client.Silicons.Borgs; @@ -15,6 +17,7 @@ namespace Content.Client.Silicons.Borgs; [GenerateTypedNameReferences] public sealed partial class BorgMenu : FancyWindow { + [Dependency] private readonly IConfigurationManager _cfgManager = default!; [Dependency] private readonly IEntityManager _entity = default!; private readonly NameModifierSystem _nameModifier; @@ -27,6 +30,9 @@ public sealed partial class BorgMenu : FancyWindow private string _lastValidName; private List _modules = new(); + // CCVar. + private int _maxNameLength; + public EntityUid Entity; public BorgMenu() @@ -36,6 +42,8 @@ public sealed partial class BorgMenu : FancyWindow _nameModifier = _entity.System(); + _maxNameLength = _cfgManager.GetCVar(CCVars.MaxNameLength); + _lastValidName = NameLineEdit.Text; EjectBatteryButton.OnPressed += _ => EjectBatteryButtonPressed?.Invoke(); @@ -153,9 +161,9 @@ public sealed partial class BorgMenu : FancyWindow return; } - if (obj.Text.Length > HumanoidCharacterProfile.MaxNameLength) + if (obj.Text.Length > _maxNameLength) { - obj.Control.Text = obj.Text.Substring(0, HumanoidCharacterProfile.MaxNameLength); + obj.Control.Text = obj.Text.Substring(0, _maxNameLength); } _lastValidName = obj.Control.Text; @@ -169,7 +177,7 @@ public sealed partial class BorgMenu : FancyWindow private void OnNameFocusExit(LineEdit.LineEditEventArgs obj) { - if (obj.Text.Length > HumanoidCharacterProfile.MaxNameLength || + if (obj.Text.Length > _maxNameLength || obj.Text.Length == 0 || string.IsNullOrWhiteSpace(obj.Text) || string.IsNullOrEmpty(obj.Text)) diff --git a/Content.Server/Mind/Commands/RenameCommand.cs b/Content.Server/Mind/Commands/RenameCommand.cs index f283fe5d19..b0059ab425 100644 --- a/Content.Server/Mind/Commands/RenameCommand.cs +++ b/Content.Server/Mind/Commands/RenameCommand.cs @@ -2,7 +2,9 @@ using System.Diagnostics.CodeAnalysis; using Content.Server.Administration; using Content.Shared.Access.Components; using Content.Shared.Administration; +using Content.Shared.CCVar; using Robust.Server.Player; +using Robust.Shared.Configuration; using Robust.Shared.Console; namespace Content.Server.Mind.Commands; @@ -10,6 +12,7 @@ namespace Content.Server.Mind.Commands; [AdminCommand(AdminFlags.VarEdit)] public sealed class RenameCommand : LocalizedEntityCommands { + [Dependency] private readonly IConfigurationManager _cfgManager = default!; [Dependency] private readonly IEntityManager _entManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly MetaDataSystem _metaSystem = default!; @@ -25,7 +28,7 @@ public sealed class RenameCommand : LocalizedEntityCommands } var name = args[1]; - if (name.Length > IdCardConsoleComponent.MaxFullNameLength) + if (name.Length > _cfgManager.GetCVar(CCVars.MaxNameLength)) { shell.WriteLine(Loc.GetString("cmd-rename-too-long")); return; diff --git a/Content.Server/Silicons/Borgs/BorgSystem.Ui.cs b/Content.Server/Silicons/Borgs/BorgSystem.Ui.cs index 191b226421..58cd7135af 100644 --- a/Content.Server/Silicons/Borgs/BorgSystem.Ui.cs +++ b/Content.Server/Silicons/Borgs/BorgSystem.Ui.cs @@ -1,17 +1,22 @@ using System.Linq; using Content.Shared.UserInterface; +using Content.Shared.CCVar; using Content.Shared.Database; using Content.Shared.NameIdentifier; using Content.Shared.PowerCell.Components; using Content.Shared.Preferences; using Content.Shared.Silicons.Borgs; using Content.Shared.Silicons.Borgs.Components; +using Robust.Shared.Configuration; namespace Content.Server.Silicons.Borgs; /// public sealed partial class BorgSystem { + // CCvar. + private int _maxNameLength; + public void InitializeUI() { SubscribeLocalEvent(OnBeforeBorgUiOpen); @@ -19,6 +24,8 @@ public sealed partial class BorgSystem SubscribeLocalEvent(OnEjectBatteryBuiMessage); SubscribeLocalEvent(OnSetNameBuiMessage); SubscribeLocalEvent(OnRemoveModuleBuiMessage); + + Subs.CVar(_cfgManager, CCVars.MaxNameLength, value => _maxNameLength = value, true); } private void OnBeforeBorgUiOpen(EntityUid uid, BorgChassisComponent component, BeforeActivatableUIOpenEvent args) @@ -46,7 +53,7 @@ public sealed partial class BorgSystem private void OnSetNameBuiMessage(EntityUid uid, BorgChassisComponent component, BorgSetNameBuiMessage args) { - if (args.Name.Length > HumanoidCharacterProfile.MaxNameLength || + if (args.Name.Length > _maxNameLength || args.Name.Length == 0 || string.IsNullOrWhiteSpace(args.Name) || string.IsNullOrEmpty(args.Name)) diff --git a/Content.Server/Silicons/Borgs/BorgSystem.cs b/Content.Server/Silicons/Borgs/BorgSystem.cs index e9d8a08c6f..65154601dd 100644 --- a/Content.Server/Silicons/Borgs/BorgSystem.cs +++ b/Content.Server/Silicons/Borgs/BorgSystem.cs @@ -27,6 +27,7 @@ using Content.Shared.Throwing; using Content.Shared.Whitelist; using Content.Shared.Wires; using Robust.Server.GameObjects; +using Robust.Shared.Configuration; using Robust.Shared.Containers; using Robust.Shared.Player; using Robust.Shared.Random; @@ -41,6 +42,7 @@ public sealed partial class BorgSystem : SharedBorgSystem { [Dependency] private readonly IAdminLogManager _adminLog = default!; [Dependency] private readonly IBanManager _banManager = default!; + [Dependency] private readonly IConfigurationManager _cfgManager = default!; [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly ActionsSystem _actions = default!; diff --git a/Content.Server/VoiceMask/VoiceMaskSystem.cs b/Content.Server/VoiceMask/VoiceMaskSystem.cs index 47ea98d2cc..cd85ff2428 100644 --- a/Content.Server/VoiceMask/VoiceMaskSystem.cs +++ b/Content.Server/VoiceMask/VoiceMaskSystem.cs @@ -1,5 +1,6 @@ using Content.Shared.Actions; using Content.Shared.Administration.Logs; +using Content.Shared.CCVar; using Content.Shared.Chat; using Content.Shared.Clothing; using Content.Shared.Database; @@ -8,6 +9,7 @@ using Content.Shared.Popups; using Content.Shared.Preferences; using Content.Shared.Speech; using Content.Shared.VoiceMask; +using Robust.Shared.Configuration; using Robust.Shared.Prototypes; namespace Content.Server.VoiceMask; @@ -16,10 +18,14 @@ public sealed partial class VoiceMaskSystem : EntitySystem { [Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!; + [Dependency] private readonly IConfigurationManager _cfgManager = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly SharedActionsSystem _actions = default!; + // CCVar. + private int _maxNameLength; + public override void Initialize() { base.Initialize(); @@ -28,6 +34,8 @@ public sealed partial class VoiceMaskSystem : EntitySystem SubscribeLocalEvent(OnChangeVerb); SubscribeLocalEvent(OnEquip); SubscribeLocalEvent(OpenUI); + + Subs.CVar(_cfgManager, CCVars.MaxNameLength, value => _maxNameLength = value, true); } private void OnTransformSpeakerName(Entity entity, ref InventoryRelayedEvent args) @@ -52,7 +60,7 @@ public sealed partial class VoiceMaskSystem : EntitySystem private void OnChangeName(Entity entity, ref VoiceMaskChangeNameMessage message) { - if (message.Name.Length > HumanoidCharacterProfile.MaxNameLength || message.Name.Length <= 0) + if (message.Name.Length > _maxNameLength || message.Name.Length <= 0) { _popupSystem.PopupEntity(Loc.GetString("voice-mask-popup-failure"), entity, message.Actor, PopupType.SmallCaution); return; diff --git a/Content.Shared/Access/Components/IdCardConsoleComponent.cs b/Content.Shared/Access/Components/IdCardConsoleComponent.cs index 4f1c27fb4d..8d54024f72 100644 --- a/Content.Shared/Access/Components/IdCardConsoleComponent.cs +++ b/Content.Shared/Access/Components/IdCardConsoleComponent.cs @@ -10,9 +10,6 @@ namespace Content.Shared.Access.Components; [Access(typeof(SharedIdCardConsoleSystem))] public sealed partial class IdCardConsoleComponent : Component { - public const int MaxFullNameLength = 30; - public const int MaxJobTitleLength = 30; - public static string PrivilegedIdCardSlotId = "IdCardConsole-privilegedId"; public static string TargetIdCardSlotId = "IdCardConsole-targetId"; diff --git a/Content.Shared/Access/Systems/SharedIdCardSystem.cs b/Content.Shared/Access/Systems/SharedIdCardSystem.cs index 69d77fe9ec..a2f59a5a34 100644 --- a/Content.Shared/Access/Systems/SharedIdCardSystem.cs +++ b/Content.Shared/Access/Systems/SharedIdCardSystem.cs @@ -1,6 +1,7 @@ using System.Globalization; using Content.Shared.Access.Components; using Content.Shared.Administration.Logs; +using Content.Shared.CCVar; using Content.Shared.Database; using Content.Shared.Hands.Components; using Content.Shared.IdentityManagement; @@ -8,6 +9,7 @@ using Content.Shared.Inventory; using Content.Shared.PDA; using Content.Shared.Roles; using Content.Shared.StatusIcon; +using Robust.Shared.Configuration; using Robust.Shared.Prototypes; using Robust.Shared.Timing; @@ -15,6 +17,7 @@ namespace Content.Shared.Access.Systems; public abstract class SharedIdCardSystem : EntitySystem { + [Dependency] private readonly IConfigurationManager _cfgManager = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly SharedAccessSystem _access = default!; @@ -22,6 +25,10 @@ public abstract class SharedIdCardSystem : EntitySystem [Dependency] private readonly MetaDataSystem _metaSystem = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; + // CCVar. + private int _maxNameLength; + private int _maxIdJobLength; + public override void Initialize() { base.Initialize(); @@ -29,6 +36,9 @@ public abstract class SharedIdCardSystem : EntitySystem SubscribeLocalEvent(OnMapInit); SubscribeLocalEvent(OnTryGetIdentityShortInfo); SubscribeLocalEvent(OnRename); + + Subs.CVar(_cfgManager, CCVars.MaxNameLength, value => _maxNameLength = value, true); + Subs.CVar(_cfgManager, CCVars.MaxIdJobLength, value => _maxIdJobLength = value, true); } private void OnRename(ref EntityRenamedEvent ev) @@ -131,8 +141,8 @@ public abstract class SharedIdCardSystem : EntitySystem { jobTitle = jobTitle.Trim(); - if (jobTitle.Length > IdCardConsoleComponent.MaxJobTitleLength) - jobTitle = jobTitle[..IdCardConsoleComponent.MaxJobTitleLength]; + if (jobTitle.Length > _maxIdJobLength) + jobTitle = jobTitle[.._maxIdJobLength]; } else { @@ -209,8 +219,8 @@ public abstract class SharedIdCardSystem : EntitySystem if (!string.IsNullOrWhiteSpace(fullName)) { fullName = fullName.Trim(); - if (fullName.Length > IdCardConsoleComponent.MaxFullNameLength) - fullName = fullName[..IdCardConsoleComponent.MaxFullNameLength]; + if (fullName.Length > _maxNameLength) + fullName = fullName[.._maxNameLength]; } else { diff --git a/Content.Shared/CCVar/CCVars.Ic.cs b/Content.Shared/CCVar/CCVars.Ic.cs index b835a8f20e..5f8d108a22 100644 --- a/Content.Shared/CCVar/CCVars.Ic.cs +++ b/Content.Shared/CCVar/CCVars.Ic.cs @@ -11,11 +11,35 @@ public sealed partial class CCVars CVarDef.Create("ic.restricted_names", true, CVar.SERVER | CVar.REPLICATED); /// - /// Allows flavor text (character descriptions) + /// Sets the maximum IC name length. + /// + public static readonly CVarDef MaxNameLength = + CVarDef.Create("ic.name_length", 32, CVar.SERVER | CVar.REPLICATED); + + /// + /// Sets the maximum name length for a loadout name (e.g. cyborg name). + /// + public static readonly CVarDef MaxLoadoutNameLength = + CVarDef.Create("ic.loadout_name_length", 32, CVar.SERVER | CVar.REPLICATED); + + /// + /// Allows flavor text (character descriptions). /// public static readonly CVarDef FlavorText = CVarDef.Create("ic.flavor_text", false, CVar.SERVER | CVar.REPLICATED); + /// + /// Sets the maximum length for flavor text (character descriptions). + /// + public static readonly CVarDef MaxFlavorTextLength = + CVarDef.Create("ic.flavor_text_length", 512, CVar.SERVER | CVar.REPLICATED); + + /// + /// Sets the maximum character length of a job on an ID. + /// + public static readonly CVarDef MaxIdJobLength = + CVarDef.Create("ic.id_job_length", 30, CVar.SERVER | CVar.REPLICATED); + /// /// Adds a period at the end of a sentence if the sentence ends in a letter. /// diff --git a/Content.Shared/Preferences/HumanoidCharacterProfile.cs b/Content.Shared/Preferences/HumanoidCharacterProfile.cs index 16064e61ac..616b213194 100644 --- a/Content.Shared/Preferences/HumanoidCharacterProfile.cs +++ b/Content.Shared/Preferences/HumanoidCharacterProfile.cs @@ -28,10 +28,6 @@ namespace Content.Shared.Preferences private static readonly Regex RestrictedNameRegex = new(@"[^A-Za-z0-9 '\-]"); private static readonly Regex ICNameCaseRegex = new(@"^(?\w)|\b(?\w)(?=\w*$)"); - public const int MaxNameLength = 32; - public const int MaxLoadoutNameLength = 32; - public const int MaxDescLength = 512; - /// /// Job preferences for initial spawn. /// @@ -508,13 +504,14 @@ namespace Content.Shared.Preferences }; string name; + var maxNameLength = configManager.GetCVar(CCVars.MaxNameLength); if (string.IsNullOrEmpty(Name)) { name = GetName(Species, gender); } - else if (Name.Length > MaxNameLength) + else if (Name.Length > maxNameLength) { - name = Name[..MaxNameLength]; + name = Name[..maxNameLength]; } else { @@ -540,9 +537,10 @@ namespace Content.Shared.Preferences } string flavortext; - if (FlavorText.Length > MaxDescLength) + var maxFlavorTextLength = configManager.GetCVar(CCVars.MaxFlavorTextLength); + if (FlavorText.Length > maxFlavorTextLength) { - flavortext = FormattedMessage.RemoveMarkupOrThrow(FlavorText)[..MaxDescLength]; + flavortext = FormattedMessage.RemoveMarkupOrThrow(FlavorText)[..maxFlavorTextLength]; } else { diff --git a/Content.Shared/Preferences/Loadouts/RoleLoadout.cs b/Content.Shared/Preferences/Loadouts/RoleLoadout.cs index 47f2d62784..9b7f4ae05e 100644 --- a/Content.Shared/Preferences/Loadouts/RoleLoadout.cs +++ b/Content.Shared/Preferences/Loadouts/RoleLoadout.cs @@ -1,8 +1,10 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; +using Content.Shared.CCVar; using Content.Shared.Humanoid.Prototypes; using Content.Shared.Random; using Robust.Shared.Collections; +using Robust.Shared.Configuration; using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; @@ -59,6 +61,7 @@ public sealed partial class RoleLoadout : IEquatable { var groupRemove = new ValueList(); var protoManager = collection.Resolve(); + var configManager = collection.Resolve(); if (!protoManager.TryIndex(Role, out var roleProto)) { @@ -78,10 +81,11 @@ public sealed partial class RoleLoadout : IEquatable if (EntityName != null) { var name = EntityName.Trim(); + var maxNameLength = configManager.GetCVar(CCVars.MaxNameLength); - if (name.Length > HumanoidCharacterProfile.MaxNameLength) + if (name.Length > maxNameLength) { - EntityName = name[..HumanoidCharacterProfile.MaxNameLength]; + EntityName = name[..maxNameLength]; } if (name.Length == 0) diff --git a/Content.Shared/Security/Systems/SharedGenpopSystem.cs b/Content.Shared/Security/Systems/SharedGenpopSystem.cs index 39fc87f665..66bf5ca254 100644 --- a/Content.Shared/Security/Systems/SharedGenpopSystem.cs +++ b/Content.Shared/Security/Systems/SharedGenpopSystem.cs @@ -1,5 +1,6 @@ using Content.Shared.Access.Components; using Content.Shared.Access.Systems; +using Content.Shared.CCVar; using Content.Shared.Database; using Content.Shared.Examine; using Content.Shared.Lock; @@ -8,12 +9,14 @@ using Content.Shared.Security.Components; using Content.Shared.Storage.Components; using Content.Shared.Storage.EntitySystems; using Content.Shared.Verbs; +using Robust.Shared.Configuration; using Robust.Shared.Timing; namespace Content.Shared.Security.Systems; public abstract class SharedGenpopSystem : EntitySystem { + [Dependency] private readonly IConfigurationManager _cfgManager = default!; [Dependency] protected readonly IGameTiming Timing = default!; [Dependency] private readonly AccessReaderSystem _accessReader = default!; [Dependency] private readonly SharedEntityStorageSystem _entityStorage = default!; @@ -23,6 +26,8 @@ public abstract class SharedGenpopSystem : EntitySystem [Dependency] private readonly SharedPopupSystem _popup = default!; [Dependency] private readonly SharedUserInterfaceSystem _userInterface = default!; + // CCvar. + private int _maxIdJobLength; /// public override void Initialize() @@ -33,12 +38,14 @@ public abstract class SharedGenpopSystem : EntitySystem SubscribeLocalEvent(OnLockToggled); SubscribeLocalEvent>(OnGetVerbs); SubscribeLocalEvent(OnExamine); + + Subs.CVar(_cfgManager, CCVars.MaxIdJobLength, value => _maxIdJobLength = value, true); } private void OnIdConfigured(Entity ent, ref GenpopLockerIdConfiguredMessage args) { // validation. - if (string.IsNullOrWhiteSpace(args.Name) || args.Name.Length > IdCardConsoleComponent.MaxFullNameLength || + if (string.IsNullOrWhiteSpace(args.Name) || args.Name.Length > _maxIdJobLength || args.Sentence < 0 || string.IsNullOrWhiteSpace(args.Crime) || args.Crime.Length > GenpopLockerComponent.MaxCrimeLength) {