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
This commit is contained in:
āda
2025-05-17 00:27:39 -05:00
committed by GitHub
parent 0fed68d240
commit de24413bd5
17 changed files with 158 additions and 35 deletions

View File

@@ -1,8 +1,10 @@
using Content.Shared.Access; using Content.Shared.Access;
using Content.Shared.Access.Components; using Content.Shared.Access.Components;
using Content.Shared.Access.Systems; using Content.Shared.Access.Systems;
using Content.Shared.CCVar;
using Content.Shared.Containers.ItemSlots; using Content.Shared.Containers.ItemSlots;
using Content.Shared.CrewManifest; using Content.Shared.CrewManifest;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using static Content.Shared.Access.Components.IdCardConsoleComponent; using static Content.Shared.Access.Components.IdCardConsoleComponent;
@@ -11,13 +13,21 @@ namespace Content.Client.Access.UI
public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface public sealed class IdCardConsoleBoundUserInterface : BoundUserInterface
{ {
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
private readonly SharedIdCardConsoleSystem _idCardConsoleSystem = default!; private readonly SharedIdCardConsoleSystem _idCardConsoleSystem = default!;
private IdCardConsoleWindow? _window; private IdCardConsoleWindow? _window;
// CCVar.
private int _maxNameLength;
private int _maxIdJobLength;
public IdCardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey) public IdCardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{ {
_idCardConsoleSystem = EntMan.System<SharedIdCardConsoleSystem>(); _idCardConsoleSystem = EntMan.System<SharedIdCardConsoleSystem>();
_maxNameLength =_cfgManager.GetCVar(CCVars.MaxNameLength);
_maxIdJobLength = _cfgManager.GetCVar(CCVars.MaxIdJobLength);
} }
protected override void Open() protected override void Open()
@@ -66,11 +76,11 @@ namespace Content.Client.Access.UI
public void SubmitData(string newFullName, string newJobTitle, List<ProtoId<AccessLevelPrototype>> newAccessList, string newJobPrototype) public void SubmitData(string newFullName, string newJobTitle, List<ProtoId<AccessLevelPrototype>> newAccessList, string newJobPrototype)
{ {
if (newFullName.Length > MaxFullNameLength) if (newFullName.Length > _maxNameLength)
newFullName = newFullName[..MaxFullNameLength]; newFullName = newFullName[.._maxNameLength];
if (newJobTitle.Length > MaxJobTitleLength) if (newJobTitle.Length > _maxIdJobLength)
newJobTitle = newJobTitle[..MaxJobTitleLength]; newJobTitle = newJobTitle[.._maxIdJobLength];
SendMessage(new WriteToTargetIdMessage( SendMessage(new WriteToTargetIdMessage(
newFullName, newFullName,

View File

@@ -1,11 +1,13 @@
using System.Linq; using System.Linq;
using Content.Shared.Access; using Content.Shared.Access;
using Content.Shared.Access.Systems; using Content.Shared.Access.Systems;
using Content.Shared.CCVar;
using Content.Shared.Roles; using Content.Shared.Roles;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using static Content.Shared.Access.Components.IdCardConsoleComponent; using static Content.Shared.Access.Components.IdCardConsoleComponent;
@@ -14,12 +16,17 @@ namespace Content.Client.Access.UI
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class IdCardConsoleWindow : DefaultWindow public sealed partial class IdCardConsoleWindow : DefaultWindow
{ {
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly ILogManager _logManager = default!; [Dependency] private readonly ILogManager _logManager = default!;
private readonly ISawmill _logMill = default!; private readonly ISawmill _logMill = default!;
private readonly IdCardConsoleBoundUserInterface _owner; private readonly IdCardConsoleBoundUserInterface _owner;
// CCVar.
private int _maxNameLength;
private int _maxIdJobLength;
private AccessLevelControl _accessButtons = new(); private AccessLevelControl _accessButtons = new();
private readonly List<string> _jobPrototypeIds = new(); private readonly List<string> _jobPrototypeIds = new();
@@ -39,7 +46,11 @@ namespace Content.Client.Access.UI
_owner = owner; _owner = owner;
_maxNameLength = _cfgManager.GetCVar(CCVars.MaxNameLength);
_maxIdJobLength = _cfgManager.GetCVar(CCVars.MaxIdJobLength);
FullNameLineEdit.OnTextEntered += _ => SubmitData(); FullNameLineEdit.OnTextEntered += _ => SubmitData();
FullNameLineEdit.IsValid = s => s.Length <= _maxNameLength;
FullNameLineEdit.OnTextChanged += _ => FullNameLineEdit.OnTextChanged += _ =>
{ {
FullNameSaveButton.Disabled = FullNameSaveButton.Text == _lastFullName; FullNameSaveButton.Disabled = FullNameSaveButton.Text == _lastFullName;
@@ -47,6 +58,7 @@ namespace Content.Client.Access.UI
FullNameSaveButton.OnPressed += _ => SubmitData(); FullNameSaveButton.OnPressed += _ => SubmitData();
JobTitleLineEdit.OnTextEntered += _ => SubmitData(); JobTitleLineEdit.OnTextEntered += _ => SubmitData();
JobTitleLineEdit.IsValid = s => s.Length <= _maxIdJobLength;
JobTitleLineEdit.OnTextChanged += _ => JobTitleLineEdit.OnTextChanged += _ =>
{ {
JobTitleSaveButton.Disabled = JobTitleLineEdit.Text == _lastJobTitle; JobTitleSaveButton.Disabled = JobTitleLineEdit.Text == _lastJobTitle;

View File

@@ -53,6 +53,10 @@ namespace Content.Client.Lobby.UI
private readonly SpriteSystem _sprite; private readonly SpriteSystem _sprite;
// CCvar.
private int _maxNameLength;
private bool _allowFlavorText;
private FlavorText.FlavorText? _flavorText; private FlavorText.FlavorText? _flavorText;
private TextEdit? _flavorTextEdit; private TextEdit? _flavorTextEdit;
@@ -131,6 +135,10 @@ namespace Content.Client.Lobby.UI
_requirements = requirements; _requirements = requirements;
_controller = UserInterfaceManager.GetUIController<LobbyUIController>(); _controller = UserInterfaceManager.GetUIController<LobbyUIController>();
_sprite = _entManager.System<SpriteSystem>(); _sprite = _entManager.System<SpriteSystem>();
_maxNameLength = _cfgManager.GetCVar(CCVars.MaxNameLength);
_allowFlavorText = _cfgManager.GetCVar(CCVars.FlavorText);
ImportButton.OnPressed += args => ImportButton.OnPressed += args =>
{ {
ImportProfile(); ImportProfile();
@@ -166,6 +174,7 @@ namespace Content.Client.Lobby.UI
#region Name #region Name
NameEdit.OnTextChanged += args => { SetName(args.Text); }; NameEdit.OnTextChanged += args => { SetName(args.Text); };
NameEdit.IsValid = args => args.Length <= _maxNameLength;
NameRandomize.OnPressed += args => RandomizeName(); NameRandomize.OnPressed += args => RandomizeName();
RandomizeEverythingButton.OnPressed += args => { RandomizeEverything(); }; RandomizeEverythingButton.OnPressed += args => { RandomizeEverything(); };
WarningLabel.SetMarkup($"[color=red]{Loc.GetString("humanoid-profile-editor-naming-rules-warning")}[/color]"); WarningLabel.SetMarkup($"[color=red]{Loc.GetString("humanoid-profile-editor-naming-rules-warning")}[/color]");
@@ -451,7 +460,7 @@ namespace Content.Client.Lobby.UI
/// </summary> /// </summary>
public void RefreshFlavorText() public void RefreshFlavorText()
{ {
if (_cfgManager.GetCVar(CCVars.FlavorText)) if (_allowFlavorText)
{ {
if (_flavorText != null) if (_flavorText != null)
return; return;

View File

@@ -1,11 +1,13 @@
using System.Numerics; using System.Numerics;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Shared.CCVar;
using Content.Shared.Dataset; using Content.Shared.Dataset;
using Content.Shared.Preferences; using Content.Shared.Preferences;
using Content.Shared.Preferences.Loadouts; using Content.Shared.Preferences.Loadouts;
using Content.Shared.Random.Helpers; using Content.Shared.Random.Helpers;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Random; using Robust.Shared.Random;
@@ -23,12 +25,18 @@ public sealed partial class LoadoutWindow : FancyWindow
public HumanoidCharacterProfile Profile; public HumanoidCharacterProfile Profile;
// CCvar.
private int _maxLoadoutNameLength;
public LoadoutWindow(HumanoidCharacterProfile profile, RoleLoadout loadout, RoleLoadoutPrototype proto, ICommonSession session, IDependencyCollection collection) public LoadoutWindow(HumanoidCharacterProfile profile, RoleLoadout loadout, RoleLoadoutPrototype proto, ICommonSession session, IDependencyCollection collection)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
Profile = profile; Profile = profile;
var protoManager = collection.Resolve<IPrototypeManager>(); var protoManager = collection.Resolve<IPrototypeManager>();
RoleNameEdit.IsValid = text => text.Length <= HumanoidCharacterProfile.MaxLoadoutNameLength; var configManager = collection.Resolve<IConfigurationManager>();
_maxLoadoutNameLength = configManager.GetCVar(CCVars.MaxLoadoutNameLength);
RoleNameEdit.IsValid = text => text.Length <= _maxLoadoutNameLength;
// Hide if we can't edit the name. // Hide if we can't edit the name.
if (!proto.CanCustomizeName) if (!proto.CanCustomizeName)
@@ -45,7 +53,7 @@ public sealed partial class LoadoutWindow : FancyWindow
RoleNameEdit.ToolTip = Loc.GetString( RoleNameEdit.ToolTip = Loc.GetString(
"loadout-name-edit-tooltip", "loadout-name-edit-tooltip",
("max", HumanoidCharacterProfile.MaxLoadoutNameLength)); ("max", _maxLoadoutNameLength));
RoleNameEdit.Text = name ?? string.Empty; RoleNameEdit.Text = name ?? string.Empty;
RoleNameEdit.OnTextChanged += args => OnNameChanged?.Invoke(args.Text); RoleNameEdit.OnTextChanged += args => OnNameChanged?.Invoke(args.Text);
} }

View File

@@ -1,19 +1,25 @@
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Shared.CCVar;
using Content.Shared.Pinpointer; using Content.Shared.Pinpointer;
using Content.Shared.Preferences; using Content.Shared.Preferences;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
namespace Content.Client.Pinpointer.UI; namespace Content.Client.Pinpointer.UI;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class NavMapBeaconWindow : FancyWindow public sealed partial class NavMapBeaconWindow : FancyWindow
{ {
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
private string? _defaultLabel; private string? _defaultLabel;
private bool _defaultEnabled; private bool _defaultEnabled;
private Color _defaultColor; private Color _defaultColor;
// CCVar.
private int _maxNameLength;
public event Action<string?, bool, Color>? OnApplyButtonPressed; public event Action<string?, bool, Color>? OnApplyButtonPressed;
public NavMapBeaconWindow() public NavMapBeaconWindow()
@@ -21,6 +27,7 @@ public sealed partial class NavMapBeaconWindow : FancyWindow
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this); IoCManager.InjectDependencies(this);
_maxNameLength = _cfgManager.GetCVar(CCVars.MaxNameLength);
VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed); VisibleButton.OnPressed += args => UpdateVisibleButton(args.Button.Pressed);
LabelLineEdit.OnTextChanged += OnTextChanged; LabelLineEdit.OnTextChanged += OnTextChanged;
@@ -53,8 +60,8 @@ public sealed partial class NavMapBeaconWindow : FancyWindow
private void OnTextChanged(LineEdit.LineEditEventArgs obj) private void OnTextChanged(LineEdit.LineEditEventArgs obj)
{ {
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);
TryEnableApplyButton(); TryEnableApplyButton();
} }

View File

@@ -1,21 +1,30 @@
using Content.Client.Message; using Content.Client.Message;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Shared.Access.Components; using Content.Shared.Access.Components;
using Content.Shared.CCVar;
using Content.Shared.Security.Components; using Content.Shared.Security.Components;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
namespace Content.Client.Security.Ui; namespace Content.Client.Security.Ui;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class GenpopLockerMenu : FancyWindow public sealed partial class GenpopLockerMenu : FancyWindow
{ {
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
public event Action<string, float, string>? OnConfigurationComplete; public event Action<string, float, string>? OnConfigurationComplete;
// CCVar.
private int _maxIdJobLength;
public GenpopLockerMenu(EntityUid owner, IEntityManager entMan) public GenpopLockerMenu(EntityUid owner, IEntityManager entMan)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
_maxIdJobLength = _cfgManager.GetCVar(CCVars.MaxIdJobLength);
Title = entMan.GetComponent<MetaDataComponent>(owner).EntityName; Title = entMan.GetComponent<MetaDataComponent>(owner).EntityName;
NameLabel.SetMarkup(Loc.GetString("genpop-locker-ui-label-name")); NameLabel.SetMarkup(Loc.GetString("genpop-locker-ui-label-name"));
@@ -25,7 +34,7 @@ public sealed partial class GenpopLockerMenu : FancyWindow
SentenceEdit.Text = "5"; SentenceEdit.Text = "5";
CrimeEdit.Text = Loc.GetString("genpop-prisoner-id-crime-default"); 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; SentenceEdit.IsValid = val => float.TryParse(val, out var f) && f >= 0;
CrimeEdit.IsValid = val => !string.IsNullOrWhiteSpace(val) && val.Length <= GenpopLockerComponent.MaxCrimeLength; CrimeEdit.IsValid = val => !string.IsNullOrWhiteSpace(val) && val.Length <= GenpopLockerComponent.MaxCrimeLength;

View File

@@ -1,5 +1,6 @@
using Content.Client.Stylesheets; using Content.Client.Stylesheets;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Content.Shared.CCVar;
using Content.Shared.NameIdentifier; using Content.Shared.NameIdentifier;
using Content.Shared.NameModifier.EntitySystems; using Content.Shared.NameModifier.EntitySystems;
using Content.Shared.Preferences; using Content.Shared.Preferences;
@@ -8,6 +9,7 @@ using Content.Shared.Silicons.Borgs.Components;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Timing; using Robust.Shared.Timing;
namespace Content.Client.Silicons.Borgs; namespace Content.Client.Silicons.Borgs;
@@ -15,6 +17,7 @@ namespace Content.Client.Silicons.Borgs;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class BorgMenu : FancyWindow public sealed partial class BorgMenu : FancyWindow
{ {
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
[Dependency] private readonly IEntityManager _entity = default!; [Dependency] private readonly IEntityManager _entity = default!;
private readonly NameModifierSystem _nameModifier; private readonly NameModifierSystem _nameModifier;
@@ -27,6 +30,9 @@ public sealed partial class BorgMenu : FancyWindow
private string _lastValidName; private string _lastValidName;
private List<EntityUid> _modules = new(); private List<EntityUid> _modules = new();
// CCVar.
private int _maxNameLength;
public EntityUid Entity; public EntityUid Entity;
public BorgMenu() public BorgMenu()
@@ -36,6 +42,8 @@ public sealed partial class BorgMenu : FancyWindow
_nameModifier = _entity.System<NameModifierSystem>(); _nameModifier = _entity.System<NameModifierSystem>();
_maxNameLength = _cfgManager.GetCVar(CCVars.MaxNameLength);
_lastValidName = NameLineEdit.Text; _lastValidName = NameLineEdit.Text;
EjectBatteryButton.OnPressed += _ => EjectBatteryButtonPressed?.Invoke(); EjectBatteryButton.OnPressed += _ => EjectBatteryButtonPressed?.Invoke();
@@ -153,9 +161,9 @@ public sealed partial class BorgMenu : FancyWindow
return; 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; _lastValidName = obj.Control.Text;
@@ -169,7 +177,7 @@ public sealed partial class BorgMenu : FancyWindow
private void OnNameFocusExit(LineEdit.LineEditEventArgs obj) private void OnNameFocusExit(LineEdit.LineEditEventArgs obj)
{ {
if (obj.Text.Length > HumanoidCharacterProfile.MaxNameLength || if (obj.Text.Length > _maxNameLength ||
obj.Text.Length == 0 || obj.Text.Length == 0 ||
string.IsNullOrWhiteSpace(obj.Text) || string.IsNullOrWhiteSpace(obj.Text) ||
string.IsNullOrEmpty(obj.Text)) string.IsNullOrEmpty(obj.Text))

View File

@@ -2,7 +2,9 @@ using System.Diagnostics.CodeAnalysis;
using Content.Server.Administration; using Content.Server.Administration;
using Content.Shared.Access.Components; using Content.Shared.Access.Components;
using Content.Shared.Administration; using Content.Shared.Administration;
using Content.Shared.CCVar;
using Robust.Server.Player; using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Console; using Robust.Shared.Console;
namespace Content.Server.Mind.Commands; namespace Content.Server.Mind.Commands;
@@ -10,6 +12,7 @@ namespace Content.Server.Mind.Commands;
[AdminCommand(AdminFlags.VarEdit)] [AdminCommand(AdminFlags.VarEdit)]
public sealed class RenameCommand : LocalizedEntityCommands public sealed class RenameCommand : LocalizedEntityCommands
{ {
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
[Dependency] private readonly IEntityManager _entManager = default!; [Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly MetaDataSystem _metaSystem = default!; [Dependency] private readonly MetaDataSystem _metaSystem = default!;
@@ -25,7 +28,7 @@ public sealed class RenameCommand : LocalizedEntityCommands
} }
var name = args[1]; var name = args[1];
if (name.Length > IdCardConsoleComponent.MaxFullNameLength) if (name.Length > _cfgManager.GetCVar(CCVars.MaxNameLength))
{ {
shell.WriteLine(Loc.GetString("cmd-rename-too-long")); shell.WriteLine(Loc.GetString("cmd-rename-too-long"));
return; return;

View File

@@ -1,17 +1,22 @@
using System.Linq; using System.Linq;
using Content.Shared.UserInterface; using Content.Shared.UserInterface;
using Content.Shared.CCVar;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.NameIdentifier; using Content.Shared.NameIdentifier;
using Content.Shared.PowerCell.Components; using Content.Shared.PowerCell.Components;
using Content.Shared.Preferences; using Content.Shared.Preferences;
using Content.Shared.Silicons.Borgs; using Content.Shared.Silicons.Borgs;
using Content.Shared.Silicons.Borgs.Components; using Content.Shared.Silicons.Borgs.Components;
using Robust.Shared.Configuration;
namespace Content.Server.Silicons.Borgs; namespace Content.Server.Silicons.Borgs;
/// <inheritdoc/> /// <inheritdoc/>
public sealed partial class BorgSystem public sealed partial class BorgSystem
{ {
// CCvar.
private int _maxNameLength;
public void InitializeUI() public void InitializeUI()
{ {
SubscribeLocalEvent<BorgChassisComponent, BeforeActivatableUIOpenEvent>(OnBeforeBorgUiOpen); SubscribeLocalEvent<BorgChassisComponent, BeforeActivatableUIOpenEvent>(OnBeforeBorgUiOpen);
@@ -19,6 +24,8 @@ public sealed partial class BorgSystem
SubscribeLocalEvent<BorgChassisComponent, BorgEjectBatteryBuiMessage>(OnEjectBatteryBuiMessage); SubscribeLocalEvent<BorgChassisComponent, BorgEjectBatteryBuiMessage>(OnEjectBatteryBuiMessage);
SubscribeLocalEvent<BorgChassisComponent, BorgSetNameBuiMessage>(OnSetNameBuiMessage); SubscribeLocalEvent<BorgChassisComponent, BorgSetNameBuiMessage>(OnSetNameBuiMessage);
SubscribeLocalEvent<BorgChassisComponent, BorgRemoveModuleBuiMessage>(OnRemoveModuleBuiMessage); SubscribeLocalEvent<BorgChassisComponent, BorgRemoveModuleBuiMessage>(OnRemoveModuleBuiMessage);
Subs.CVar(_cfgManager, CCVars.MaxNameLength, value => _maxNameLength = value, true);
} }
private void OnBeforeBorgUiOpen(EntityUid uid, BorgChassisComponent component, BeforeActivatableUIOpenEvent args) 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) private void OnSetNameBuiMessage(EntityUid uid, BorgChassisComponent component, BorgSetNameBuiMessage args)
{ {
if (args.Name.Length > HumanoidCharacterProfile.MaxNameLength || if (args.Name.Length > _maxNameLength ||
args.Name.Length == 0 || args.Name.Length == 0 ||
string.IsNullOrWhiteSpace(args.Name) || string.IsNullOrWhiteSpace(args.Name) ||
string.IsNullOrEmpty(args.Name)) string.IsNullOrEmpty(args.Name))

View File

@@ -27,6 +27,7 @@ using Content.Shared.Throwing;
using Content.Shared.Whitelist; using Content.Shared.Whitelist;
using Content.Shared.Wires; using Content.Shared.Wires;
using Robust.Server.GameObjects; using Robust.Server.GameObjects;
using Robust.Shared.Configuration;
using Robust.Shared.Containers; using Robust.Shared.Containers;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Random; using Robust.Shared.Random;
@@ -41,6 +42,7 @@ public sealed partial class BorgSystem : SharedBorgSystem
{ {
[Dependency] private readonly IAdminLogManager _adminLog = default!; [Dependency] private readonly IAdminLogManager _adminLog = default!;
[Dependency] private readonly IBanManager _banManager = default!; [Dependency] private readonly IBanManager _banManager = default!;
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly IRobustRandom _random = default!; [Dependency] private readonly IRobustRandom _random = default!;
[Dependency] private readonly ActionsSystem _actions = default!; [Dependency] private readonly ActionsSystem _actions = default!;

View File

@@ -1,5 +1,6 @@
using Content.Shared.Actions; using Content.Shared.Actions;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
using Content.Shared.CCVar;
using Content.Shared.Chat; using Content.Shared.Chat;
using Content.Shared.Clothing; using Content.Shared.Clothing;
using Content.Shared.Database; using Content.Shared.Database;
@@ -8,6 +9,7 @@ using Content.Shared.Popups;
using Content.Shared.Preferences; using Content.Shared.Preferences;
using Content.Shared.Speech; using Content.Shared.Speech;
using Content.Shared.VoiceMask; using Content.Shared.VoiceMask;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
namespace Content.Server.VoiceMask; namespace Content.Server.VoiceMask;
@@ -16,10 +18,14 @@ public sealed partial class VoiceMaskSystem : EntitySystem
{ {
[Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!; [Dependency] private readonly SharedUserInterfaceSystem _uiSystem = default!;
[Dependency] private readonly SharedPopupSystem _popupSystem = default!; [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly IPrototypeManager _proto = default!; [Dependency] private readonly IPrototypeManager _proto = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!; [Dependency] private readonly SharedActionsSystem _actions = default!;
// CCVar.
private int _maxNameLength;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -28,6 +34,8 @@ public sealed partial class VoiceMaskSystem : EntitySystem
SubscribeLocalEvent<VoiceMaskComponent, VoiceMaskChangeVerbMessage>(OnChangeVerb); SubscribeLocalEvent<VoiceMaskComponent, VoiceMaskChangeVerbMessage>(OnChangeVerb);
SubscribeLocalEvent<VoiceMaskComponent, ClothingGotEquippedEvent>(OnEquip); SubscribeLocalEvent<VoiceMaskComponent, ClothingGotEquippedEvent>(OnEquip);
SubscribeLocalEvent<VoiceMaskSetNameEvent>(OpenUI); SubscribeLocalEvent<VoiceMaskSetNameEvent>(OpenUI);
Subs.CVar(_cfgManager, CCVars.MaxNameLength, value => _maxNameLength = value, true);
} }
private void OnTransformSpeakerName(Entity<VoiceMaskComponent> entity, ref InventoryRelayedEvent<TransformSpeakerNameEvent> args) private void OnTransformSpeakerName(Entity<VoiceMaskComponent> entity, ref InventoryRelayedEvent<TransformSpeakerNameEvent> args)
@@ -52,7 +60,7 @@ public sealed partial class VoiceMaskSystem : EntitySystem
private void OnChangeName(Entity<VoiceMaskComponent> entity, ref VoiceMaskChangeNameMessage message) private void OnChangeName(Entity<VoiceMaskComponent> 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); _popupSystem.PopupEntity(Loc.GetString("voice-mask-popup-failure"), entity, message.Actor, PopupType.SmallCaution);
return; return;

View File

@@ -10,9 +10,6 @@ namespace Content.Shared.Access.Components;
[Access(typeof(SharedIdCardConsoleSystem))] [Access(typeof(SharedIdCardConsoleSystem))]
public sealed partial class IdCardConsoleComponent : Component 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 PrivilegedIdCardSlotId = "IdCardConsole-privilegedId";
public static string TargetIdCardSlotId = "IdCardConsole-targetId"; public static string TargetIdCardSlotId = "IdCardConsole-targetId";

View File

@@ -1,6 +1,7 @@
using System.Globalization; using System.Globalization;
using Content.Shared.Access.Components; using Content.Shared.Access.Components;
using Content.Shared.Administration.Logs; using Content.Shared.Administration.Logs;
using Content.Shared.CCVar;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Hands.Components; using Content.Shared.Hands.Components;
using Content.Shared.IdentityManagement; using Content.Shared.IdentityManagement;
@@ -8,6 +9,7 @@ using Content.Shared.Inventory;
using Content.Shared.PDA; using Content.Shared.PDA;
using Content.Shared.Roles; using Content.Shared.Roles;
using Content.Shared.StatusIcon; using Content.Shared.StatusIcon;
using Robust.Shared.Configuration;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Timing; using Robust.Shared.Timing;
@@ -15,6 +17,7 @@ namespace Content.Shared.Access.Systems;
public abstract class SharedIdCardSystem : EntitySystem public abstract class SharedIdCardSystem : EntitySystem
{ {
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!; [Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly IGameTiming _timing = default!; [Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly SharedAccessSystem _access = 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 MetaDataSystem _metaSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
// CCVar.
private int _maxNameLength;
private int _maxIdJobLength;
public override void Initialize() public override void Initialize()
{ {
base.Initialize(); base.Initialize();
@@ -29,6 +36,9 @@ public abstract class SharedIdCardSystem : EntitySystem
SubscribeLocalEvent<IdCardComponent, MapInitEvent>(OnMapInit); SubscribeLocalEvent<IdCardComponent, MapInitEvent>(OnMapInit);
SubscribeLocalEvent<TryGetIdentityShortInfoEvent>(OnTryGetIdentityShortInfo); SubscribeLocalEvent<TryGetIdentityShortInfoEvent>(OnTryGetIdentityShortInfo);
SubscribeLocalEvent<EntityRenamedEvent>(OnRename); SubscribeLocalEvent<EntityRenamedEvent>(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) private void OnRename(ref EntityRenamedEvent ev)
@@ -131,8 +141,8 @@ public abstract class SharedIdCardSystem : EntitySystem
{ {
jobTitle = jobTitle.Trim(); jobTitle = jobTitle.Trim();
if (jobTitle.Length > IdCardConsoleComponent.MaxJobTitleLength) if (jobTitle.Length > _maxIdJobLength)
jobTitle = jobTitle[..IdCardConsoleComponent.MaxJobTitleLength]; jobTitle = jobTitle[.._maxIdJobLength];
} }
else else
{ {
@@ -209,8 +219,8 @@ public abstract class SharedIdCardSystem : EntitySystem
if (!string.IsNullOrWhiteSpace(fullName)) if (!string.IsNullOrWhiteSpace(fullName))
{ {
fullName = fullName.Trim(); fullName = fullName.Trim();
if (fullName.Length > IdCardConsoleComponent.MaxFullNameLength) if (fullName.Length > _maxNameLength)
fullName = fullName[..IdCardConsoleComponent.MaxFullNameLength]; fullName = fullName[.._maxNameLength];
} }
else else
{ {

View File

@@ -11,11 +11,35 @@ public sealed partial class CCVars
CVarDef.Create("ic.restricted_names", true, CVar.SERVER | CVar.REPLICATED); CVarDef.Create("ic.restricted_names", true, CVar.SERVER | CVar.REPLICATED);
/// <summary> /// <summary>
/// Allows flavor text (character descriptions) /// Sets the maximum IC name length.
/// </summary>
public static readonly CVarDef<int> MaxNameLength =
CVarDef.Create("ic.name_length", 32, CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Sets the maximum name length for a loadout name (e.g. cyborg name).
/// </summary>
public static readonly CVarDef<int> MaxLoadoutNameLength =
CVarDef.Create("ic.loadout_name_length", 32, CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Allows flavor text (character descriptions).
/// </summary> /// </summary>
public static readonly CVarDef<bool> FlavorText = public static readonly CVarDef<bool> FlavorText =
CVarDef.Create("ic.flavor_text", false, CVar.SERVER | CVar.REPLICATED); CVarDef.Create("ic.flavor_text", false, CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Sets the maximum length for flavor text (character descriptions).
/// </summary>
public static readonly CVarDef<int> MaxFlavorTextLength =
CVarDef.Create("ic.flavor_text_length", 512, CVar.SERVER | CVar.REPLICATED);
/// <summary>
/// Sets the maximum character length of a job on an ID.
/// </summary>
public static readonly CVarDef<int> MaxIdJobLength =
CVarDef.Create("ic.id_job_length", 30, CVar.SERVER | CVar.REPLICATED);
/// <summary> /// <summary>
/// Adds a period at the end of a sentence if the sentence ends in a letter. /// Adds a period at the end of a sentence if the sentence ends in a letter.
/// </summary> /// </summary>

View File

@@ -28,10 +28,6 @@ namespace Content.Shared.Preferences
private static readonly Regex RestrictedNameRegex = new(@"[^A-Za-z0-9 '\-]"); private static readonly Regex RestrictedNameRegex = new(@"[^A-Za-z0-9 '\-]");
private static readonly Regex ICNameCaseRegex = new(@"^(?<word>\w)|\b(?<word>\w)(?=\w*$)"); private static readonly Regex ICNameCaseRegex = new(@"^(?<word>\w)|\b(?<word>\w)(?=\w*$)");
public const int MaxNameLength = 32;
public const int MaxLoadoutNameLength = 32;
public const int MaxDescLength = 512;
/// <summary> /// <summary>
/// Job preferences for initial spawn. /// Job preferences for initial spawn.
/// </summary> /// </summary>
@@ -508,13 +504,14 @@ namespace Content.Shared.Preferences
}; };
string name; string name;
var maxNameLength = configManager.GetCVar(CCVars.MaxNameLength);
if (string.IsNullOrEmpty(Name)) if (string.IsNullOrEmpty(Name))
{ {
name = GetName(Species, gender); name = GetName(Species, gender);
} }
else if (Name.Length > MaxNameLength) else if (Name.Length > maxNameLength)
{ {
name = Name[..MaxNameLength]; name = Name[..maxNameLength];
} }
else else
{ {
@@ -540,9 +537,10 @@ namespace Content.Shared.Preferences
} }
string flavortext; 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 else
{ {

View File

@@ -1,8 +1,10 @@
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Content.Shared.CCVar;
using Content.Shared.Humanoid.Prototypes; using Content.Shared.Humanoid.Prototypes;
using Content.Shared.Random; using Content.Shared.Random;
using Robust.Shared.Collections; using Robust.Shared.Collections;
using Robust.Shared.Configuration;
using Robust.Shared.Player; using Robust.Shared.Player;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization; using Robust.Shared.Serialization;
@@ -59,6 +61,7 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
{ {
var groupRemove = new ValueList<string>(); var groupRemove = new ValueList<string>();
var protoManager = collection.Resolve<IPrototypeManager>(); var protoManager = collection.Resolve<IPrototypeManager>();
var configManager = collection.Resolve<IConfigurationManager>();
if (!protoManager.TryIndex(Role, out var roleProto)) if (!protoManager.TryIndex(Role, out var roleProto))
{ {
@@ -78,10 +81,11 @@ public sealed partial class RoleLoadout : IEquatable<RoleLoadout>
if (EntityName != null) if (EntityName != null)
{ {
var name = EntityName.Trim(); 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) if (name.Length == 0)

View File

@@ -1,5 +1,6 @@
using Content.Shared.Access.Components; using Content.Shared.Access.Components;
using Content.Shared.Access.Systems; using Content.Shared.Access.Systems;
using Content.Shared.CCVar;
using Content.Shared.Database; using Content.Shared.Database;
using Content.Shared.Examine; using Content.Shared.Examine;
using Content.Shared.Lock; using Content.Shared.Lock;
@@ -8,12 +9,14 @@ using Content.Shared.Security.Components;
using Content.Shared.Storage.Components; using Content.Shared.Storage.Components;
using Content.Shared.Storage.EntitySystems; using Content.Shared.Storage.EntitySystems;
using Content.Shared.Verbs; using Content.Shared.Verbs;
using Robust.Shared.Configuration;
using Robust.Shared.Timing; using Robust.Shared.Timing;
namespace Content.Shared.Security.Systems; namespace Content.Shared.Security.Systems;
public abstract class SharedGenpopSystem : EntitySystem public abstract class SharedGenpopSystem : EntitySystem
{ {
[Dependency] private readonly IConfigurationManager _cfgManager = default!;
[Dependency] protected readonly IGameTiming Timing = default!; [Dependency] protected readonly IGameTiming Timing = default!;
[Dependency] private readonly AccessReaderSystem _accessReader = default!; [Dependency] private readonly AccessReaderSystem _accessReader = default!;
[Dependency] private readonly SharedEntityStorageSystem _entityStorage = 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 SharedPopupSystem _popup = default!;
[Dependency] private readonly SharedUserInterfaceSystem _userInterface = default!; [Dependency] private readonly SharedUserInterfaceSystem _userInterface = default!;
// CCvar.
private int _maxIdJobLength;
/// <inheritdoc/> /// <inheritdoc/>
public override void Initialize() public override void Initialize()
@@ -33,12 +38,14 @@ public abstract class SharedGenpopSystem : EntitySystem
SubscribeLocalEvent<GenpopLockerComponent, LockToggledEvent>(OnLockToggled); SubscribeLocalEvent<GenpopLockerComponent, LockToggledEvent>(OnLockToggled);
SubscribeLocalEvent<GenpopLockerComponent, GetVerbsEvent<Verb>>(OnGetVerbs); SubscribeLocalEvent<GenpopLockerComponent, GetVerbsEvent<Verb>>(OnGetVerbs);
SubscribeLocalEvent<GenpopIdCardComponent, ExaminedEvent>(OnExamine); SubscribeLocalEvent<GenpopIdCardComponent, ExaminedEvent>(OnExamine);
Subs.CVar(_cfgManager, CCVars.MaxIdJobLength, value => _maxIdJobLength = value, true);
} }
private void OnIdConfigured(Entity<GenpopLockerComponent> ent, ref GenpopLockerIdConfiguredMessage args) private void OnIdConfigured(Entity<GenpopLockerComponent> ent, ref GenpopLockerIdConfiguredMessage args)
{ {
// validation. // validation.
if (string.IsNullOrWhiteSpace(args.Name) || args.Name.Length > IdCardConsoleComponent.MaxFullNameLength || if (string.IsNullOrWhiteSpace(args.Name) || args.Name.Length > _maxIdJobLength ||
args.Sentence < 0 || args.Sentence < 0 ||
string.IsNullOrWhiteSpace(args.Crime) || args.Crime.Length > GenpopLockerComponent.MaxCrimeLength) string.IsNullOrWhiteSpace(args.Crime) || args.Crime.Length > GenpopLockerComponent.MaxCrimeLength)
{ {