From 80c6ccf4d2cfba923fc0a59cf4c25ab759cce89c Mon Sep 17 00:00:00 2001 From: Morb0 <14136326+Morb0@users.noreply.github.com> Date: Sun, 12 May 2024 23:38:13 +0300 Subject: [PATCH] Use shared sponsors manager --- .../UI/Tabs/PanicBunkerTab/PanicBunkerTab.xaml.cs | 4 ++-- .../Corvax/TTS/HumanoidProfileEditor.TTS.cs | 7 +++---- Content.Client/Humanoid/MarkingPicker.xaml.cs | 6 +++--- .../Humanoid/SingleMarkingPicker.xaml.cs | 6 +++--- .../Preferences/ClientPreferencesManager.cs | 8 +++----- .../Preferences/UI/HumanoidProfileEditor.xaml.cs | 2 +- Content.Server/Chat/Managers/ChatManager.cs | 6 +++--- Content.Server/Connection/ConnectionManager.cs | 6 +++--- .../Managers/ServerPreferencesManager.cs | 15 ++++++--------- .../IClientSponsorsManager.cs | 8 -------- .../IServerSponsorsManager.cs | 14 -------------- .../ISharedSponsorsManager.cs | 15 ++++++++++++++- Secrets | 2 +- 13 files changed, 42 insertions(+), 57 deletions(-) delete mode 100644 Corvax/Content.Corvax.Interfaces.Client/IClientSponsorsManager.cs delete mode 100644 Corvax/Content.Corvax.Interfaces.Server/IServerSponsorsManager.cs diff --git a/Content.Client/Administration/UI/Tabs/PanicBunkerTab/PanicBunkerTab.xaml.cs b/Content.Client/Administration/UI/Tabs/PanicBunkerTab/PanicBunkerTab.xaml.cs index 1d0a4fd886..9b85d38551 100644 --- a/Content.Client/Administration/UI/Tabs/PanicBunkerTab/PanicBunkerTab.xaml.cs +++ b/Content.Client/Administration/UI/Tabs/PanicBunkerTab/PanicBunkerTab.xaml.cs @@ -1,4 +1,4 @@ -using Content.Corvax.Interfaces.Client; +using Content.Corvax.Interfaces.Shared; using Content.Shared.Administration.Events; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface; @@ -30,7 +30,7 @@ public sealed partial class PanicBunkerTab : Control MinOverallHours.OnFocusExit += args => SendMinOverallHours(args.Text); _minOverallHours = MinOverallHours.Text; // Corvax-VPNGuard-Start - var haveSecrets = IoCManager.Instance!.TryResolveType(out _); // TODO: Probably need better way to detect Secrets module + var haveSecrets = IoCManager.Instance!.TryResolveType(out _); // TODO: Probably need better way to detect Secrets module if (haveSecrets) { VPNContainer.Visible = true; diff --git a/Content.Client/Corvax/TTS/HumanoidProfileEditor.TTS.cs b/Content.Client/Corvax/TTS/HumanoidProfileEditor.TTS.cs index 7a75225eaf..851fb9d4ec 100644 --- a/Content.Client/Corvax/TTS/HumanoidProfileEditor.TTS.cs +++ b/Content.Client/Corvax/TTS/HumanoidProfileEditor.TTS.cs @@ -1,15 +1,14 @@ using System.Linq; -using Content.Client.Corvax.TTS; using Content.Client.Lobby; +using Content.Corvax.Interfaces.Shared; using Content.Shared.Corvax.TTS; using Content.Shared.Preferences; -using Content.Corvax.Interfaces.Client; namespace Content.Client.Preferences.UI; public sealed partial class HumanoidProfileEditor { - private IClientSponsorsManager? _sponsorsMgr; + private ISharedSponsorsManager? _sponsorsMgr; private List _voiceList = default!; private void InitializeVoice() @@ -53,7 +52,7 @@ public sealed partial class HumanoidProfileEditor if (_sponsorsMgr is null) continue; if (voice.SponsorOnly && _sponsorsMgr != null && - !_sponsorsMgr.Prototypes.Contains(voice.ID)) + !_sponsorsMgr.GetClientPrototypes().Contains(voice.ID)) { _voiceButton.SetItemDisabled(_voiceButton.GetIdx(i), true); } diff --git a/Content.Client/Humanoid/MarkingPicker.xaml.cs b/Content.Client/Humanoid/MarkingPicker.xaml.cs index 48fcfc0e6a..885403aa56 100644 --- a/Content.Client/Humanoid/MarkingPicker.xaml.cs +++ b/Content.Client/Humanoid/MarkingPicker.xaml.cs @@ -1,5 +1,5 @@ using System.Linq; -using Content.Corvax.Interfaces.Client; +using Content.Corvax.Interfaces.Shared; using Content.Shared.Humanoid; using Content.Shared.Humanoid.Markings; using Content.Shared.Humanoid.Prototypes; @@ -19,7 +19,7 @@ public sealed partial class MarkingPicker : Control { [Dependency] private readonly MarkingManager _markingManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - private IClientSponsorsManager? _sponsorsManager; // Corvax-Sponsors + private ISharedSponsorsManager? _sponsorsManager; // Corvax-Sponsors public Action? OnMarkingAdded; public Action? OnMarkingRemoved; @@ -229,7 +229,7 @@ public sealed partial class MarkingPicker : Control item.Metadata = marking; // Corvax-Sponsors-Start if (marking.SponsorOnly && _sponsorsManager != null) - item.Disabled = !_sponsorsManager.Prototypes.Contains(marking.ID); + item.Disabled = !_sponsorsManager.GetClientPrototypes().Contains(marking.ID); // Corvax-Sponsors-End } diff --git a/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs b/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs index 9e072ea4e0..a742d749f4 100644 --- a/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs +++ b/Content.Client/Humanoid/SingleMarkingPicker.xaml.cs @@ -1,5 +1,5 @@ using System.Linq; -using Content.Corvax.Interfaces.Client; +using Content.Corvax.Interfaces.Shared; using Content.Shared.Humanoid.Markings; using Robust.Client.AutoGenerated; using Robust.Client.UserInterface.Controls; @@ -12,7 +12,7 @@ namespace Content.Client.Humanoid; public sealed partial class SingleMarkingPicker : BoxContainer { [Dependency] private readonly MarkingManager _markingManager = default!; - private IClientSponsorsManager? _sponsorsManager; // Corvax-Sponsors + private ISharedSponsorsManager? _sponsorsManager; // Corvax-Sponsors /// /// What happens if a marking is selected. @@ -195,7 +195,7 @@ public sealed partial class SingleMarkingPicker : BoxContainer item.Metadata = marking.ID; // Corvax-Sponsors-Start if (marking.SponsorOnly && _sponsorsManager != null) - item.Disabled = !_sponsorsManager.Prototypes.Contains(marking.ID); + item.Disabled = !_sponsorsManager.GetClientPrototypes().Contains(marking.ID); // Corvax-Sponsors-End if (_markings[Slot].MarkingId == id) diff --git a/Content.Client/Preferences/ClientPreferencesManager.cs b/Content.Client/Preferences/ClientPreferencesManager.cs index 9a7fdb37cd..16a1f6b259 100644 --- a/Content.Client/Preferences/ClientPreferencesManager.cs +++ b/Content.Client/Preferences/ClientPreferencesManager.cs @@ -1,11 +1,9 @@ using System.Linq; -using Content.Corvax.Interfaces.Client; +using Content.Corvax.Interfaces.Shared; using Content.Shared.Preferences; using Robust.Client; using Robust.Client.Player; -using Robust.Shared.Configuration; using Robust.Shared.Network; -using Robust.Shared.Prototypes; using Robust.Shared.Utility; namespace Content.Client.Preferences @@ -20,7 +18,7 @@ namespace Content.Client.Preferences [Dependency] private readonly IClientNetManager _netManager = default!; [Dependency] private readonly IBaseClient _baseClient = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; - private IClientSponsorsManager? _sponsorsManager; // Corvax-Sponsors + private ISharedSponsorsManager? _sponsorsManager; // Corvax-Sponsors public event Action? OnServerDataLoaded; @@ -66,7 +64,7 @@ namespace Content.Client.Preferences { var collection = IoCManager.Instance!; // Corvax-Sponsors-Start - var sponsorPrototypes = _sponsorsManager?.Prototypes.ToArray() ?? []; + var sponsorPrototypes = _sponsorsManager?.GetClientPrototypes().ToArray() ?? []; profile.EnsureValid(_playerManager.LocalSession!, collection, sponsorPrototypes); // Corvax-Sponsors-End var characters = new Dictionary(Preferences.Characters) {[slot] = profile}; diff --git a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs index 5d96f81b9e..e56997f671 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs @@ -162,7 +162,7 @@ namespace Content.Client.Preferences.UI _speciesList = prototypeManager.EnumeratePrototypes().Where(o => o.RoundStart).ToList(); // Corvax-Sponsors-Start if (_sponsorsMgr != null) - _speciesList = _speciesList.Where(p => !p.SponsorOnly || _sponsorsMgr.Prototypes.Contains(p.ID)).ToList(); + _speciesList = _speciesList.Where(p => !p.SponsorOnly || _sponsorsMgr.GetClientPrototypes().Contains(p.ID)).ToList(); // Corvax-Sponsors-End for (var i = 0; i < _speciesList.Count; i++) { diff --git a/Content.Server/Chat/Managers/ChatManager.cs b/Content.Server/Chat/Managers/ChatManager.cs index cded336d38..0630b7e283 100644 --- a/Content.Server/Chat/Managers/ChatManager.cs +++ b/Content.Server/Chat/Managers/ChatManager.cs @@ -1,7 +1,7 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Runtime.InteropServices; -using Content.Corvax.Interfaces.Server; +using Content.Corvax.Interfaces.Shared; using Content.Server.Administration.Logs; using Content.Server.Administration.Managers; using Content.Server.Administration.Systems; @@ -46,7 +46,7 @@ namespace Content.Server.Chat.Managers [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly IPlayerManager _playerManager = default!; - private IServerSponsorsManager? _sponsorsManager; // Corvax-Sponsors + private ISharedSponsorsManager? _sponsorsManager; // Corvax-Sponsors /// /// The maximum length a player-sent message can be sent @@ -253,7 +253,7 @@ namespace Content.Server.Chat.Managers } // Corvax-Sponsors-Start - if (_sponsorsManager != null && _sponsorsManager.TryGetOocColor(player.UserId, out var oocColor)) + if (_sponsorsManager != null && _sponsorsManager.TryGetServerOocColor(player.UserId, out var oocColor)) { wrappedMessage = Loc.GetString("chat-manager-send-ooc-patron-wrap-message", ("patronColor", oocColor),("playerName", player.Name), ("message", FormattedMessage.EscapeText(message))); } diff --git a/Content.Server/Connection/ConnectionManager.cs b/Content.Server/Connection/ConnectionManager.cs index e7ab8c00c8..4c46324dfb 100644 --- a/Content.Server/Connection/ConnectionManager.cs +++ b/Content.Server/Connection/ConnectionManager.cs @@ -1,8 +1,8 @@ using System.Collections.Immutable; using System.Runtime.InteropServices; -using System.Text.Json.Nodes; using System.Threading.Tasks; using Content.Corvax.Interfaces.Server; +using Content.Corvax.Interfaces.Shared; using Content.Server.Database; using Content.Server.GameTicking; using Content.Server.Preferences.Managers; @@ -50,7 +50,7 @@ namespace Content.Server.Connection [Dependency] private readonly ServerDbEntryManager _serverDbEntry = default!; [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly ILogManager _logManager = default!; - private IServerSponsorsManager? _sponsorsMgr; // Corvax-Sponsors + private ISharedSponsorsManager? _sponsorsMgr; // Corvax-Sponsors private IServerVPNGuardManager? _vpnGuardMgr; // Corvax-VPNGuard private readonly Dictionary _temporaryBypasses = []; @@ -283,7 +283,7 @@ namespace Content.Server.Connection public async Task HavePrivilegedJoin(NetUserId userId) { var adminBypass = _cfg.GetCVar(CCVars.AdminBypassMaxPlayers) && await _dbManager.GetAdminDataForAsync(userId) != null; - var havePriorityJoin = _sponsorsMgr != null && _sponsorsMgr.HavePriorityJoin(userId); // Corvax-Sponsors + var havePriorityJoin = _sponsorsMgr != null && _sponsorsMgr.HaveServerPriorityJoin(userId); // Corvax-Sponsors var wasInGame = EntitySystem.TryGet(out var ticker) && ticker.PlayerGameStatuses.TryGetValue(userId, out var status) && status == PlayerGameStatus.JoinedGame; diff --git a/Content.Server/Preferences/Managers/ServerPreferencesManager.cs b/Content.Server/Preferences/Managers/ServerPreferencesManager.cs index dafb4d0a73..0e884fd60e 100644 --- a/Content.Server/Preferences/Managers/ServerPreferencesManager.cs +++ b/Content.Server/Preferences/Managers/ServerPreferencesManager.cs @@ -2,13 +2,10 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Content.Corvax.Interfaces.Server; +using Content.Corvax.Interfaces.Shared; using Content.Server.Database; -using Content.Server.Humanoid; using Content.Shared.CCVar; -using Content.Shared.Humanoid.Prototypes; using Content.Shared.Preferences; -using Content.Shared.Roles; using Robust.Server.Player; using Robust.Shared.Configuration; using Robust.Shared.Network; @@ -31,7 +28,7 @@ namespace Content.Server.Preferences.Managers [Dependency] private readonly IPlayerManager _playerManager = default!; [Dependency] private readonly IDependencyCollection _dependencies = default!; [Dependency] private readonly IPrototypeManager _protos = default!; - private IServerSponsorsManager? _sponsors; + private ISharedSponsorsManager? _sponsors; // Cache player prefs on the server so we don't need as much async hell related to them. private readonly Dictionary _cachedPlayerPrefs = @@ -108,7 +105,7 @@ namespace Content.Server.Preferences.Managers var session = _playerManager.GetSessionById(userId); // Corvax-Sponsors-Start - var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(session.UserId, out var prototypes) + var sponsorPrototypes = _sponsors != null && _sponsors.TryGetServerPrototypes(session.UserId, out var prototypes) ? prototypes.ToArray() : []; profile.EnsureValid(session, _dependencies, sponsorPrototypes); @@ -210,7 +207,7 @@ namespace Content.Server.Preferences.Managers var collection = IoCManager.Instance!; foreach (var (_, profile) in prefs.Characters) { - var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(session.UserId, out var prototypes) + var sponsorPrototypes = _sponsors != null && _sponsors.TryGetServerPrototypes(session.UserId, out var prototypes) ? prototypes.ToArray() : []; profile.EnsureValid(session, collection, sponsorPrototypes); @@ -255,7 +252,7 @@ namespace Content.Server.Preferences.Managers private int GetMaxUserCharacterSlots(NetUserId userId) { var maxSlots = _cfg.GetCVar(CCVars.GameMaxCharacterSlots); - var extraSlots = _sponsors?.GetExtraCharSlots(userId) ?? 0; + var extraSlots = _sponsors?.GetServerExtraCharSlots(userId) ?? 0; return maxSlots + extraSlots; } // Corvax-Sponsors-End @@ -324,7 +321,7 @@ namespace Content.Server.Preferences.Managers // Clean up preferences in case of changes to the game, // such as removed jobs still being selected. - var sponsorPrototypes = _sponsors != null && _sponsors.TryGetPrototypes(session.UserId, out var prototypes) ? prototypes.ToArray() : []; // Corvax-Sponsors + var sponsorPrototypes = _sponsors != null && _sponsors.TryGetServerPrototypes(session.UserId, out var prototypes) ? prototypes.ToArray() : []; // Corvax-Sponsors return new PlayerPreferences(prefs.Characters.Select(p => { return new KeyValuePair(p.Key, p.Value.Validated(session, collection, sponsorPrototypes)); diff --git a/Corvax/Content.Corvax.Interfaces.Client/IClientSponsorsManager.cs b/Corvax/Content.Corvax.Interfaces.Client/IClientSponsorsManager.cs deleted file mode 100644 index f2814999de..0000000000 --- a/Corvax/Content.Corvax.Interfaces.Client/IClientSponsorsManager.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Content.Corvax.Interfaces.Shared; - -namespace Content.Corvax.Interfaces.Client; - -public interface IClientSponsorsManager : ISharedSponsorsManager -{ - public List Prototypes { get; } -} diff --git a/Corvax/Content.Corvax.Interfaces.Server/IServerSponsorsManager.cs b/Corvax/Content.Corvax.Interfaces.Server/IServerSponsorsManager.cs deleted file mode 100644 index fa5cacc051..0000000000 --- a/Corvax/Content.Corvax.Interfaces.Server/IServerSponsorsManager.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Diagnostics.CodeAnalysis; -using Content.Corvax.Interfaces.Shared; -using Robust.Shared.Maths; -using Robust.Shared.Network; - -namespace Content.Corvax.Interfaces.Server; - -public interface IServerSponsorsManager : ISharedSponsorsManager -{ - public bool TryGetPrototypes(NetUserId userId, [NotNullWhen(true)] out List? prototypes); - public bool TryGetOocColor(NetUserId userId, [NotNullWhen(true)] out Color? color); - public int GetExtraCharSlots(NetUserId userId); - public bool HavePriorityJoin(NetUserId userId); -} diff --git a/Corvax/Content.Corvax.Interfaces.Shared/ISharedSponsorsManager.cs b/Corvax/Content.Corvax.Interfaces.Shared/ISharedSponsorsManager.cs index 475ff481f2..8904204e6c 100644 --- a/Corvax/Content.Corvax.Interfaces.Shared/ISharedSponsorsManager.cs +++ b/Corvax/Content.Corvax.Interfaces.Shared/ISharedSponsorsManager.cs @@ -1,6 +1,19 @@ -namespace Content.Corvax.Interfaces.Shared; +using System.Diagnostics.CodeAnalysis; +using Robust.Shared.Maths; +using Robust.Shared.Network; + +namespace Content.Corvax.Interfaces.Shared; public interface ISharedSponsorsManager { public void Initialize(); + + // Client + public List GetClientPrototypes(); + + // Server + public bool TryGetServerPrototypes(NetUserId userId, [NotNullWhen(true)] out List? prototypes); + public bool TryGetServerOocColor(NetUserId userId, [NotNullWhen(true)] out Color? color); + public int GetServerExtraCharSlots(NetUserId userId); + public bool HaveServerPriorityJoin(NetUserId userId); } diff --git a/Secrets b/Secrets index c6695f3f88..eca67902c2 160000 --- a/Secrets +++ b/Secrets @@ -1 +1 @@ -Subproject commit c6695f3f8863932ddc479541a900bc88360fa8b9 +Subproject commit eca67902c227da4163d619ffb1a382b8a1815d51