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:
@@ -461,5 +461,15 @@ namespace Content.Shared.CCVar
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly CVarDef<float> AfkTime =
|
public static readonly CVarDef<float> AfkTime =
|
||||||
CVarDef.Create("afk.time", 60f, CVar.SERVERONLY);
|
CVarDef.Create("afk.time", 60f, CVar.SERVERONLY);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* IC
|
||||||
|
*/
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restricts IC character names to alphanumeric chars.
|
||||||
|
/// </summary>
|
||||||
|
public static readonly CVarDef<bool> RestrictedNames =
|
||||||
|
CVarDef.Create("ic.restricted_names", true, CVar.SERVER | CVar.REPLICATED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
using Content.Shared.CCVar;
|
||||||
using Content.Shared.CharacterAppearance;
|
using Content.Shared.CharacterAppearance;
|
||||||
using Content.Shared.Dataset;
|
using Content.Shared.Dataset;
|
||||||
using Content.Shared.GameTicking;
|
using Content.Shared.GameTicking;
|
||||||
using Content.Shared.Random.Helpers;
|
using Content.Shared.Random.Helpers;
|
||||||
using Content.Shared.Roles;
|
using Content.Shared.Roles;
|
||||||
|
using Robust.Shared.Configuration;
|
||||||
using Robust.Shared.Enums;
|
using Robust.Shared.Enums;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Localization;
|
using Robust.Shared.Localization;
|
||||||
@@ -261,7 +264,7 @@ namespace Content.Shared.Preferences
|
|||||||
string name;
|
string name;
|
||||||
if (string.IsNullOrEmpty(Name))
|
if (string.IsNullOrEmpty(Name))
|
||||||
{
|
{
|
||||||
name = "Urist McHands";
|
name = RandomName();
|
||||||
}
|
}
|
||||||
else if (Name.Length > MaxNameLength)
|
else if (Name.Length > MaxNameLength)
|
||||||
{
|
{
|
||||||
@@ -272,12 +275,18 @@ namespace Content.Shared.Preferences
|
|||||||
name = Name;
|
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();
|
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 appearance = HumanoidCharacterAppearance.EnsureValid(Appearance);
|
||||||
|
|
||||||
var prefsUnavailableMode = PreferenceUnavailable switch
|
var prefsUnavailableMode = PreferenceUnavailable switch
|
||||||
@@ -337,6 +346,16 @@ namespace Content.Shared.Preferences
|
|||||||
|
|
||||||
_antagPreferences.Clear();
|
_antagPreferences.Clear();
|
||||||
_antagPreferences.AddRange(antags);
|
_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)
|
public override bool Equals(object? obj)
|
||||||
|
|||||||
Reference in New Issue
Block a user