Restrict character names to alphanumerics via cvar (#4947)
* Restrict character names to ASCII via cvar * Alphanumerics is better * name randomization Co-authored-by: ike709 <ike709@github.com>
This commit is contained in:
@@ -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<IConfigurationManager>().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<IRobustRandom>();
|
||||
var protoMan = IoCManager.Resolve<IPrototypeManager>();
|
||||
var firstName = random.Pick(Sex.FirstNames(protoMan).Values);
|
||||
var lastName = random.Pick(protoMan.Index<DatasetPrototype>("names_last"));
|
||||
return $"{firstName} {lastName}";
|
||||
}
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
|
||||
Reference in New Issue
Block a user