diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 063b55fd02..0dbad615ae 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -461,5 +461,15 @@ namespace Content.Shared.CCVar /// public static readonly CVarDef AfkTime = CVarDef.Create("afk.time", 60f, CVar.SERVERONLY); + + /* + * IC + */ + + /// + /// Restricts IC character names to alphanumeric chars. + /// + public static readonly CVarDef RestrictedNames = + CVarDef.Create("ic.restricted_names", true, CVar.SERVER | CVar.REPLICATED); } } diff --git a/Content.Shared/Preferences/HumanoidCharacterProfile.cs b/Content.Shared/Preferences/HumanoidCharacterProfile.cs index 5b44b715b5..9ee15f22e2 100644 --- a/Content.Shared/Preferences/HumanoidCharacterProfile.cs +++ b/Content.Shared/Preferences/HumanoidCharacterProfile.cs @@ -1,11 +1,14 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text.RegularExpressions; +using Content.Shared.CCVar; using Content.Shared.CharacterAppearance; using Content.Shared.Dataset; using Content.Shared.GameTicking; using Content.Shared.Random.Helpers; using Content.Shared.Roles; +using Robust.Shared.Configuration; using Robust.Shared.Enums; using Robust.Shared.IoC; using Robust.Shared.Localization; @@ -261,7 +264,7 @@ namespace Content.Shared.Preferences string name; if (string.IsNullOrEmpty(Name)) { - name = "Urist McHands"; + name = RandomName(); } else if (Name.Length > MaxNameLength) { @@ -272,12 +275,18 @@ namespace Content.Shared.Preferences name = Name; } - // TODO: Avoid Z̨͇̙͉͎̭͔̼̿͋A͚̖̞̗̞͈̓̾̀ͩͩ̔L̟ͮ̈͝G̙O͍͎̗̺̺ͫ̀̽͊̓͝ͅ tier shenanigans. - // And other stuff like RTL overrides and such. - // Probably also emojis... - name = name.Trim(); + if (IoCManager.Resolve().GetCVar(CCVars.RestrictedNames)) + { + name = Regex.Replace(name, @"[^A-Z,a-z,0-9, -]", string.Empty); + } + + if (string.IsNullOrEmpty(name)) + { + name = RandomName(); + } + var appearance = HumanoidCharacterAppearance.EnsureValid(Appearance); var prefsUnavailableMode = PreferenceUnavailable switch @@ -337,6 +346,16 @@ namespace Content.Shared.Preferences _antagPreferences.Clear(); _antagPreferences.AddRange(antags); + + string RandomName() + { + if (Sex == null) return "Urist McHands"; // This shouldn't happen + var random = IoCManager.Resolve(); + var protoMan = IoCManager.Resolve(); + var firstName = random.Pick(Sex.FirstNames(protoMan).Values); + var lastName = random.Pick(protoMan.Index("names_last")); + return $"{firstName} {lastName}"; + } } public override bool Equals(object? obj)