From cea26891c8f87b4366c92904b676d17b132ad54b Mon Sep 17 00:00:00 2001 From: Morb0 <14136326+Morb0@users.noreply.github.com> Date: Mon, 26 Feb 2024 16:11:35 +0300 Subject: [PATCH] Fix sponsors prototypes --- .../Preferences/ClientPreferencesManager.cs | 2 +- .../Managers/ServerPreferencesManager.cs | 15 +++++++++------ .../Preferences/HumanoidCharacterProfile.cs | 4 ++-- Content.Shared/Preferences/ICharacterProfile.cs | 2 +- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Content.Client/Preferences/ClientPreferencesManager.cs b/Content.Client/Preferences/ClientPreferencesManager.cs index 3e71c97d1e7..18b855e3cb5 100644 --- a/Content.Client/Preferences/ClientPreferencesManager.cs +++ b/Content.Client/Preferences/ClientPreferencesManager.cs @@ -68,7 +68,7 @@ public void SelectCharacter(int slot) public void UpdateCharacter(ICharacterProfile profile, int slot) { // Corvax-Sponsors-Start - var sponsorPrototypes = _sponsorsManager?.Prototypes.ToArray() ?? new string[]{}; + var sponsorPrototypes = _sponsorsManager?.Prototypes.ToArray() ?? []; profile.EnsureValid(_cfg, _prototypes, sponsorPrototypes); // Corvax-Sponsors-End var characters = new Dictionary(Preferences.Characters) {[slot] = profile}; diff --git a/Content.Server/Preferences/Managers/ServerPreferencesManager.cs b/Content.Server/Preferences/Managers/ServerPreferencesManager.cs index cd800e21b2a..04942bb3eb7 100644 --- a/Content.Server/Preferences/Managers/ServerPreferencesManager.cs +++ b/Content.Server/Preferences/Managers/ServerPreferencesManager.cs @@ -106,7 +106,7 @@ private async void HandleUpdateCharacterMessage(MsgUpdateCharacter message) // WARN! It's not removing markings from DB! var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(message.MsgChannel.UserId, out var prototypes) ? prototypes.ToArray() - : new string[]{}; + : []; profile.EnsureValid(_cfg, _protos, sponsorPrototypes); // Corvax-Sponsors-End var profiles = new Dictionary(curPrefs.Characters) @@ -206,8 +206,8 @@ async Task LoadPrefs() { var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(session.UserId, out var prototypes) ? prototypes.ToArray() - : new string[]{}; - profile.EnsureValid(sponsorPrototypes); + : []; + profile.EnsureValid(_cfg, _protos, sponsorPrototypes); } // Corvax-Sponsors-End prefsData.Prefs = prefs; @@ -285,17 +285,20 @@ private async Task GetOrCreatePreferencesAsync(NetUserId user return await _db.InitPrefsAsync(userId, HumanoidCharacterProfile.Random()); } - return SanitizePreferences(prefs); + // Corvax-Sponsors-Start + var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(userId, out var prototypes) ? prototypes.ToArray() : []; // Corvax-Sponsors + return SanitizePreferences(prefs, sponsorPrototypes); + // Corvax-Sponsors-End } - private PlayerPreferences SanitizePreferences(PlayerPreferences prefs) + private PlayerPreferences SanitizePreferences(PlayerPreferences prefs, string[] sponsorPrototypes) { // Clean up preferences in case of changes to the game, // such as removed jobs still being selected. return new PlayerPreferences(prefs.Characters.Select(p => { - return new KeyValuePair(p.Key, p.Value.Validated(_cfg, _protos)); + return new KeyValuePair(p.Key, p.Value.Validated(_cfg, _protos, sponsorPrototypes)); }), prefs.SelectedCharacterIndex, prefs.AdminOOCColor); } diff --git a/Content.Shared/Preferences/HumanoidCharacterProfile.cs b/Content.Shared/Preferences/HumanoidCharacterProfile.cs index d5fc702037a..087e69aa78d 100644 --- a/Content.Shared/Preferences/HumanoidCharacterProfile.cs +++ b/Content.Shared/Preferences/HumanoidCharacterProfile.cs @@ -564,10 +564,10 @@ public static bool CanHaveVoice(TTSVoicePrototype voice, Sex sex) } // Corvax-TTS-End - public ICharacterProfile Validated(IConfigurationManager configManager, IPrototypeManager prototypeManager) + public ICharacterProfile Validated(IConfigurationManager configManager, IPrototypeManager prototypeManager, string[] sponsorPrototypes) { var profile = new HumanoidCharacterProfile(this); - profile.EnsureValid(configManager, prototypeManager); + profile.EnsureValid(configManager, prototypeManager, sponsorPrototypes); // Corvax-Sponsors return profile; } diff --git a/Content.Shared/Preferences/ICharacterProfile.cs b/Content.Shared/Preferences/ICharacterProfile.cs index bdbdd66498d..0cfef50c01f 100644 --- a/Content.Shared/Preferences/ICharacterProfile.cs +++ b/Content.Shared/Preferences/ICharacterProfile.cs @@ -20,6 +20,6 @@ public interface ICharacterProfile /// /// Gets a copy of this profile that has applied, i.e. no invalid data. /// - ICharacterProfile Validated(IConfigurationManager configManager, IPrototypeManager prototypeManager); + ICharacterProfile Validated(IConfigurationManager configManager, IPrototypeManager prototypeManager, string[] sponsorPrototypes); } }