Character profile sanitization improvements (#25579)
Validate that job and antag prototypes can actually be set in character profiles, rather than just checking if the prototype exists. Make preferences system just call existing validation code when loading prototype from database, instead of some hacked-together stuff. Also I made the character profile validation logic take dependencies in via parameter because fuck resolves.
This commit is contained in:
committed by
GitHub
parent
90279b3357
commit
8d244f7b76
@@ -99,7 +99,7 @@ namespace Content.Server.Preferences.Managers
|
||||
|
||||
var curPrefs = prefsData.Prefs!;
|
||||
|
||||
profile.EnsureValid();
|
||||
profile.EnsureValid(_cfg, _protos);
|
||||
|
||||
var profiles = new Dictionary<int, ICharacterProfile>(curPrefs.Characters)
|
||||
{
|
||||
@@ -270,34 +270,7 @@ namespace Content.Server.Preferences.Managers
|
||||
|
||||
return new PlayerPreferences(prefs.Characters.Select(p =>
|
||||
{
|
||||
ICharacterProfile newProf;
|
||||
switch (p.Value)
|
||||
{
|
||||
case HumanoidCharacterProfile hp:
|
||||
{
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
var selectedSpecies = HumanoidAppearanceSystem.DefaultSpecies;
|
||||
|
||||
if (prototypeManager.TryIndex<SpeciesPrototype>(hp.Species, out var species) && species.RoundStart)
|
||||
{
|
||||
selectedSpecies = hp.Species;
|
||||
}
|
||||
|
||||
newProf = hp
|
||||
.WithJobPriorities(
|
||||
hp.JobPriorities.Where(job =>
|
||||
_protos.HasIndex<JobPrototype>(job.Key)))
|
||||
.WithAntagPreferences(
|
||||
hp.AntagPreferences.Where(antag =>
|
||||
_protos.HasIndex<AntagPrototype>(antag)))
|
||||
.WithSpecies(selectedSpecies);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
return new KeyValuePair<int, ICharacterProfile>(p.Key, newProf);
|
||||
return new KeyValuePair<int, ICharacterProfile>(p.Key, p.Value.Validated(_cfg, _protos));
|
||||
}), prefs.SelectedCharacterIndex, prefs.AdminOOCColor);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user