Clean up stale preferences data on load at the server.
This fixes further bugs with "nonexistant job selected in character preferences" like the client blowing up in the lobby.
This commit is contained in:
@@ -7,6 +7,7 @@ using Content.Server.Interfaces;
|
|||||||
using Content.Shared;
|
using Content.Shared;
|
||||||
using Content.Shared.Network.NetMessages;
|
using Content.Shared.Network.NetMessages;
|
||||||
using Content.Shared.Preferences;
|
using Content.Shared.Preferences;
|
||||||
|
using Content.Shared.Roles;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.Interfaces.Configuration;
|
using Robust.Shared.Interfaces.Configuration;
|
||||||
using Robust.Shared.Interfaces.Network;
|
using Robust.Shared.Interfaces.Network;
|
||||||
@@ -250,7 +251,36 @@ namespace Content.Server.Preferences
|
|||||||
return await _db.InitPrefsAsync(userId, HumanoidCharacterProfile.Default());
|
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<JobPrototype>(job.Key)))
|
||||||
|
.WithAntagPreferences(
|
||||||
|
hp.AntagPreferences.Where(antag =>
|
||||||
|
_protos.HasIndex<AntagPrototype>(antag)));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new NotSupportedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new KeyValuePair<int, ICharacterProfile>(p.Key, newProf);
|
||||||
|
}), prefs.SelectedCharacterIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<KeyValuePair<NetUserId, ICharacterProfile>> GetSelectedProfilesForPlayers(
|
public IEnumerable<KeyValuePair<NetUserId, ICharacterProfile>> GetSelectedProfilesForPlayers(
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ namespace Content.Shared.Preferences
|
|||||||
return new(Name, Age, Sex, appearance, _jobPriorities, PreferenceUnavailable, _antagPreferences);
|
return new(Name, Age, Sex, appearance, _jobPriorities, PreferenceUnavailable, _antagPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HumanoidCharacterProfile WithJobPriorities(IReadOnlyDictionary<string, JobPriority> jobPriorities)
|
public HumanoidCharacterProfile WithJobPriorities(IEnumerable<KeyValuePair<string, JobPriority>> jobPriorities)
|
||||||
{
|
{
|
||||||
return new(
|
return new(
|
||||||
Name,
|
Name,
|
||||||
@@ -138,7 +138,7 @@ namespace Content.Shared.Preferences
|
|||||||
return new(Name, Age, Sex, Appearance, _jobPriorities, mode, _antagPreferences);
|
return new(Name, Age, Sex, Appearance, _jobPriorities, mode, _antagPreferences);
|
||||||
}
|
}
|
||||||
|
|
||||||
public HumanoidCharacterProfile WithAntagPreferences(IReadOnlyList<string> antagPreferences)
|
public HumanoidCharacterProfile WithAntagPreferences(IEnumerable<string> antagPreferences)
|
||||||
{
|
{
|
||||||
return new(
|
return new(
|
||||||
Name,
|
Name,
|
||||||
|
|||||||
Reference in New Issue
Block a user