diff --git a/Content.Server/Preferences/ServerPreferencesManager.cs b/Content.Server/Preferences/ServerPreferencesManager.cs index a17bdbbb45..96a0cf2d8c 100644 --- a/Content.Server/Preferences/ServerPreferencesManager.cs +++ b/Content.Server/Preferences/ServerPreferencesManager.cs @@ -7,6 +7,7 @@ using Content.Server.Interfaces; using Content.Shared; using Content.Shared.Network.NetMessages; using Content.Shared.Preferences; +using Content.Shared.Roles; using Robust.Server.Interfaces.Player; using Robust.Shared.Interfaces.Configuration; using Robust.Shared.Interfaces.Network; @@ -250,7 +251,36 @@ namespace Content.Server.Preferences return await _db.InitPrefsAsync(userId, HumanoidCharacterProfile.Default()); } - return prefs; + return SanitizePreferences(prefs); + } + + private PlayerPreferences SanitizePreferences(PlayerPreferences prefs) + { + // Clean up preferences in case of changes to the game, + // such as removed jobs still being selected. + + return new PlayerPreferences(prefs.Characters.Select(p => + { + ICharacterProfile newProf; + switch (p.Value) + { + case HumanoidCharacterProfile hp: + { + newProf = hp + .WithJobPriorities( + hp.JobPriorities.Where(job => + _protos.HasIndex(job.Key))) + .WithAntagPreferences( + hp.AntagPreferences.Where(antag => + _protos.HasIndex(antag))); + break; + } + default: + throw new NotSupportedException(); + } + + return new KeyValuePair(p.Key, newProf); + }), prefs.SelectedCharacterIndex); } public IEnumerable> GetSelectedProfilesForPlayers( diff --git a/Content.Shared/Preferences/HumanoidCharacterProfile.cs b/Content.Shared/Preferences/HumanoidCharacterProfile.cs index a2b1104730..371d30d429 100644 --- a/Content.Shared/Preferences/HumanoidCharacterProfile.cs +++ b/Content.Shared/Preferences/HumanoidCharacterProfile.cs @@ -106,7 +106,7 @@ namespace Content.Shared.Preferences return new(Name, Age, Sex, appearance, _jobPriorities, PreferenceUnavailable, _antagPreferences); } - public HumanoidCharacterProfile WithJobPriorities(IReadOnlyDictionary jobPriorities) + public HumanoidCharacterProfile WithJobPriorities(IEnumerable> jobPriorities) { return new( Name, @@ -138,7 +138,7 @@ namespace Content.Shared.Preferences return new(Name, Age, Sex, Appearance, _jobPriorities, mode, _antagPreferences); } - public HumanoidCharacterProfile WithAntagPreferences(IReadOnlyList antagPreferences) + public HumanoidCharacterProfile WithAntagPreferences(IEnumerable antagPreferences) { return new( Name,