From 219f9588138cfc4d924050ce1451152e8202bfc9 Mon Sep 17 00:00:00 2001 From: Debug <49997488+DebugOk@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:21:54 +0200 Subject: [PATCH 1/5] Add job whitelists --- .../JobRequirementsManager.Whitelist.cs | 30 +++++++++++++++++ .../JobRequirementsManager.cs | 29 +++++++++++------ .../GameTicking/GameTicker.Player.cs | 2 ++ .../PlayTimeTrackingManager.Whitelist.cs | 32 +++++++++++++++++++ .../PlayTimeTrackingManager.cs | 3 +- .../PlayTimeTrackingSystem.cs | 12 +++++-- Content.Server/Whitelist/WhitelistCommands.cs | 24 ++++++++++++++ Content.Shared/CCVar/CCVars.cs | 6 ++++ .../Players/PlayTimeTracking/MsgWhitelist.cs | 25 +++++++++++++++ Content.Shared/Players/PlayerData.cs | 6 ++++ Content.Shared/Roles/JobPrototype.cs | 6 ++++ .../en-US/players/play-time/whitelist.ftl | 1 + .../Prototypes/Roles/Jobs/Command/captain.yml | 1 + .../Roles/Jobs/Security/head_of_security.yml | 3 +- 14 files changed, 167 insertions(+), 13 deletions(-) create mode 100644 Content.Client/Nyanotrasen/Players/PlayTimeTracking/JobRequirementsManager.Whitelist.cs create mode 100644 Content.Server/Nyanotrasen/Players/PlayTimeTracking/PlayTimeTrackingManager.Whitelist.cs create mode 100644 Content.Shared/Nyanotrasen/Players/PlayTimeTracking/MsgWhitelist.cs create mode 100644 Resources/Locale/en-US/players/play-time/whitelist.ftl diff --git a/Content.Client/Nyanotrasen/Players/PlayTimeTracking/JobRequirementsManager.Whitelist.cs b/Content.Client/Nyanotrasen/Players/PlayTimeTracking/JobRequirementsManager.Whitelist.cs new file mode 100644 index 00000000000..985ac27a734 --- /dev/null +++ b/Content.Client/Nyanotrasen/Players/PlayTimeTracking/JobRequirementsManager.Whitelist.cs @@ -0,0 +1,30 @@ +using System.Diagnostics.CodeAnalysis; +using Content.Shared.CCVar; +using Content.Shared.Players.PlayTimeTracking; +using Content.Shared.Roles; +using Robust.Shared.Utility; + +namespace Content.Client.Players.PlayTimeTracking; + +public sealed partial class JobRequirementsManager +{ + private bool _whitelisted = false; + + private bool CheckWhitelist(JobPrototype job, [NotNullWhen(false)] out FormattedMessage? reason) + { + reason = null; + + if (!job.WhitelistRequired || !_cfg.GetCVar(CCVars.GameWhitelistJobs)) + return true; + + if (job.WhitelistRequired && _cfg.GetCVar(CCVars.GameWhitelistJobs) && !_whitelisted) + reason = FormattedMessage.FromMarkup(Loc.GetString("playtime-deny-reason-not-whitelisted")); + + return reason == null; + } + + private void RxWhitelist(MsgWhitelist message) + { + _whitelisted = message.Whitelisted; + } +} diff --git a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs index c67c759dfdd..357a6cf9169 100644 --- a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs +++ b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs @@ -14,7 +14,7 @@ namespace Content.Client.Players.PlayTimeTracking; -public sealed class JobRequirementsManager +public sealed partial class JobRequirementsManager { [Dependency] private readonly IBaseClient _client = default!; [Dependency] private readonly IClientNetManager _net = default!; @@ -37,6 +37,7 @@ public void Initialize() // Yeah the client manager handles role bans and playtime but the server ones are separate DEAL. _net.RegisterNetMessage(RxRoleBans); _net.RegisterNetMessage(RxPlayTime); + _net.RegisterNetMessage(RxWhitelist); _client.RunLevelChanged += ClientOnRunLevelChanged; } @@ -90,24 +91,34 @@ public bool IsAllowed(JobPrototype job, [NotNullWhen(false)] out FormattedMessag return false; } - if (job.Requirements == null || - !_cfg.GetCVar(CCVars.GameRoleTimers)) - { - return true; - } - var player = _playerManager.LocalPlayer?.Session; if (player == null) return true; - return CheckRoleTime(job.Requirements, out reason); + var roleCheck = CheckRoleTime(job.Requirements, out var roleReason); + var whitelistCheck = CheckWhitelist(job, out var whitelistReason); + + if (!roleCheck || !whitelistCheck) + { + reason = new FormattedMessage(); + if (!roleCheck && roleReason != null) + reason.AddMessage(roleReason); + if (!whitelistCheck && whitelistReason != null) + { + if (!reason.IsEmpty) + reason.PushNewline(); + reason.AddMessage(whitelistReason); + } + } + + return reason == null; } public bool CheckRoleTime(HashSet? requirements, [NotNullWhen(false)] out FormattedMessage? reason) { reason = null; - if (requirements == null) + if (requirements == null || !_cfg.GetCVar(CCVars.GameRoleTimers)) return true; var reasons = new List(); diff --git a/Content.Server/GameTicking/GameTicker.Player.cs b/Content.Server/GameTicking/GameTicker.Player.cs index f6402589b2e..447130e9997 100644 --- a/Content.Server/GameTicking/GameTicker.Player.cs +++ b/Content.Server/GameTicking/GameTicker.Player.cs @@ -122,6 +122,8 @@ async void SpawnWaitDb() { await _userDb.WaitLoadComplete(session); + session.ContentData()!.Whitelisted = await _db.GetWhitelistStatusAsync(session.UserId); // Nyanotrasen - Whitelist + SpawnPlayer(session, EntityUid.Invalid); } diff --git a/Content.Server/Nyanotrasen/Players/PlayTimeTracking/PlayTimeTrackingManager.Whitelist.cs b/Content.Server/Nyanotrasen/Players/PlayTimeTracking/PlayTimeTrackingManager.Whitelist.cs new file mode 100644 index 00000000000..587b829c9fd --- /dev/null +++ b/Content.Server/Nyanotrasen/Players/PlayTimeTracking/PlayTimeTrackingManager.Whitelist.cs @@ -0,0 +1,32 @@ +using Content.Server.Players; +using Content.Shared.Players.PlayTimeTracking; +using Robust.Server.Player; + +namespace Content.Server.Players.PlayTimeTracking; + +public sealed partial class PlayTimeTrackingManager +{ + public async void SendWhitelist(IPlayerSession playerSession) + { + var whitelist = await _db.GetWhitelistStatusAsync(playerSession.UserId); + + var msg = new MsgWhitelist + { + Whitelisted = whitelist + }; + + _net.ServerSendMessage(msg, playerSession.ConnectedClient); + } + + public void SendWhitelistCached(IPlayerSession playerSession) + { + var whitelist = playerSession.ContentData()?.Whitelisted ?? false; + + var msg = new MsgWhitelist + { + Whitelisted = whitelist + }; + + _net.ServerSendMessage(msg, playerSession.ConnectedClient); + } +} diff --git a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingManager.cs b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingManager.cs index 50c64e718c3..8708bb69c47 100644 --- a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingManager.cs +++ b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingManager.cs @@ -54,7 +54,7 @@ namespace Content.Server.Players.PlayTimeTracking; /// Operations like refreshing and sending play time info to clients are deferred until the next frame (note: not tick). /// /// -public sealed class PlayTimeTrackingManager +public sealed partial class PlayTimeTrackingManager { [Dependency] private readonly IServerDbManager _db = default!; [Dependency] private readonly IServerNetManager _net = default!; @@ -85,6 +85,7 @@ public void Initialize() _sawmill = Logger.GetSawmill("play_time"); _net.RegisterNetMessage(); + _net.RegisterNetMessage(); // Nyanotrasen - Whitelist status _cfg.OnValueChanged(CCVars.PlayTimeSaveInterval, f => _saveInterval = TimeSpan.FromSeconds(f), true); } diff --git a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs index 13d0794dd5e..86853de662f 100644 --- a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs +++ b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs @@ -158,8 +158,16 @@ private void OnPlayerJoinedLobby(PlayerJoinedLobbyEvent ev) public bool IsAllowed(IPlayerSession player, string role) { - if (!_prototypes.TryIndex(role, out var job) || - job.Requirements == null || + if (!_prototypes.TryIndex(role, out var job)) // Nyanotrasen - separate job requirements check + return true; + + // Nyanotrasen - Require whitelist for certain roles + if (_cfg.GetCVar(CCVars.GameWhitelistJobs) && + job.WhitelistRequired && + !player.ContentData()!.Whitelisted) + return false; + + if (job.Requirements == null || // Nyanotrasen - separate job requirements check so whitelist check gets ran !_cfg.GetCVar(CCVars.GameRoleTimers)) return true; diff --git a/Content.Server/Whitelist/WhitelistCommands.cs b/Content.Server/Whitelist/WhitelistCommands.cs index 59b576e7ca4..67d9645414c 100644 --- a/Content.Server/Whitelist/WhitelistCommands.cs +++ b/Content.Server/Whitelist/WhitelistCommands.cs @@ -1,7 +1,9 @@ using Content.Server.Administration; using Content.Server.Database; +using Content.Server.Players.PlayTimeTracking; using Content.Shared.Administration; using Content.Shared.CCVar; +using Content.Shared.Players; using Robust.Server.Player; using Robust.Shared.Configuration; using Robust.Shared.Console; @@ -22,6 +24,8 @@ public async void Execute(IConsoleShell shell, string argStr, string[] args) var db = IoCManager.Resolve(); var loc = IoCManager.Resolve(); + var player = IoCManager.Resolve(); + var playtime = IoCManager.Resolve(); var name = args[0]; var data = await loc.LookupIdByNameAsync(name); @@ -37,6 +41,15 @@ public async void Execute(IConsoleShell shell, string argStr, string[] args) } await db.AddToWhitelistAsync(guid); + + // Nyanotrasen - Update whitelist status in player data. + if (player.TryGetPlayerDataByUsername(name, out var playerData) && + player.TryGetSessionByUsername(name, out var session)) + { + playerData.ContentData()!.Whitelisted = true; + playtime.SendWhitelistCached(session); + } + shell.WriteLine(Loc.GetString("command-whitelistadd-added", ("username", data.Username))); return; } @@ -58,6 +71,8 @@ public async void Execute(IConsoleShell shell, string argStr, string[] args) var db = IoCManager.Resolve(); var loc = IoCManager.Resolve(); + var player = IoCManager.Resolve(); + var playtime = IoCManager.Resolve(); var name = args[0]; var data = await loc.LookupIdByNameAsync(name); @@ -73,6 +88,15 @@ public async void Execute(IConsoleShell shell, string argStr, string[] args) } await db.RemoveFromWhitelistAsync(guid); + + // Nyanotrasen - Update whitelist status in player data. + if (player.TryGetPlayerDataByUsername(name, out var playerData) && + player.TryGetSessionByUsername(name, out var session)) + { + playerData.ContentData()!.Whitelisted = false; + playtime.SendWhitelistCached(session); + } + shell.WriteLine(Loc.GetString("command-whitelistremove-removed", ("username", data.Username))); return; } diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 1b4d7579c37..849ef1ed66c 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -211,6 +211,12 @@ public static readonly CVarDef public static readonly CVarDef GameRoleTimers = CVarDef.Create("game.role_timers", true, CVar.SERVER | CVar.REPLICATED); + /// + /// Nyanotrasen - Require whitelist for certain jobs + /// + public static readonly CVarDef + GameWhitelistJobs = CVarDef.Create("game.whitelist_jobs", true, CVar.SERVER | CVar.REPLICATED); + /// /// Whether a random position offset will be applied to the station on roundstart. /// diff --git a/Content.Shared/Nyanotrasen/Players/PlayTimeTracking/MsgWhitelist.cs b/Content.Shared/Nyanotrasen/Players/PlayTimeTracking/MsgWhitelist.cs new file mode 100644 index 00000000000..d930828f327 --- /dev/null +++ b/Content.Shared/Nyanotrasen/Players/PlayTimeTracking/MsgWhitelist.cs @@ -0,0 +1,25 @@ +using Lidgren.Network; +using Robust.Shared.Network; +using Robust.Shared.Serialization; + +namespace Content.Shared.Players.PlayTimeTracking; + +/// +/// Sent server -> client to inform the client of their whitelist status. +/// +public sealed class MsgWhitelist : NetMessage +{ + public override MsgGroups MsgGroup => MsgGroups.EntityEvent; + + public bool Whitelisted = false; + + public override void ReadFromBuffer(NetIncomingMessage buffer, IRobustSerializer serializer) + { + Whitelisted = buffer.ReadBoolean(); + } + + public override void WriteToBuffer(NetOutgoingMessage buffer, IRobustSerializer serializer) + { + buffer.Write(Whitelisted); + } +} diff --git a/Content.Shared/Players/PlayerData.cs b/Content.Shared/Players/PlayerData.cs index c6274c950bd..d94bef2e387 100644 --- a/Content.Shared/Players/PlayerData.cs +++ b/Content.Shared/Players/PlayerData.cs @@ -38,6 +38,12 @@ public sealed class PlayerData /// public bool ExplicitlyDeadminned { get; set; } + /// + /// Nyanotrasen - Are they whitelisted? Lets us avoid async. + /// + [ViewVariables] + public bool Whitelisted { get; set; } + public PlayerData(NetUserId userId, string name) { UserId = userId; diff --git a/Content.Shared/Roles/JobPrototype.cs b/Content.Shared/Roles/JobPrototype.cs index b4733d0679f..287fe69e3ae 100644 --- a/Content.Shared/Roles/JobPrototype.cs +++ b/Content.Shared/Roles/JobPrototype.cs @@ -47,6 +47,12 @@ public sealed class JobPrototype : IPrototype [DataField("joinNotifyCrew")] public bool JoinNotifyCrew { get; private set; } = false; + /// + /// Nyanotrasen - If true, require whitelist for the job. + /// + [DataField("whitelistRequired")] + public bool WhitelistRequired = false; + [DataField("requireAdminNotify")] public bool RequireAdminNotify { get; private set; } = false; diff --git a/Resources/Locale/en-US/players/play-time/whitelist.ftl b/Resources/Locale/en-US/players/play-time/whitelist.ftl new file mode 100644 index 00000000000..c6a5a9e07a8 --- /dev/null +++ b/Resources/Locale/en-US/players/play-time/whitelist.ftl @@ -0,0 +1 @@ +playtime-deny-reason-not-whitelisted = You need to be whitelisted. diff --git a/Resources/Prototypes/Roles/Jobs/Command/captain.yml b/Resources/Prototypes/Roles/Jobs/Command/captain.yml index ac036c513d0..b536402713b 100644 --- a/Resources/Prototypes/Roles/Jobs/Command/captain.yml +++ b/Resources/Prototypes/Roles/Jobs/Command/captain.yml @@ -30,6 +30,7 @@ requireAdminNotify: true joinNotifyCrew: true supervisors: job-supervisors-centcom + whitelistRequired: true # DeltaV - Whitelist required canBeAntag: false accessGroups: - AllAccess diff --git a/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml b/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml index 0e143c0d2b8..c79e299f1c2 100644 --- a/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml +++ b/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml @@ -20,6 +20,7 @@ icon: "JobIconHeadOfSecurity" requireAdminNotify: true supervisors: job-supervisors-captain + whitelistRequired: true # DeltaV - Whitelist required canBeAntag: false access: - HeadOfSecurity @@ -41,7 +42,7 @@ components: - type: PsionicBonusChance #Nyano - Summary: makes it more likely to become psionic. flatBonus: 0.025 - + - type: startingGear id: HoSGear equipment: From baaa560725f64b615ed16ce153a3ec6f3051e2f0 Mon Sep 17 00:00:00 2001 From: Debug Date: Tue, 17 Oct 2023 16:34:18 +0200 Subject: [PATCH 2/5] Redo whitelist system with jobrequirements --- .../JobRequirementsManager.Whitelist.cs | 16 +++-------- .../JobRequirementsManager.cs | 28 ++++++------------- .../UI/HumanoidProfileEditor.xaml.cs | 1 + .../PlayTimeTrackingSystem.cs | 24 ++++++++-------- Content.Shared/CCVar/CCVars.cs | 6 ---- .../DeltaV/Roles/JobRequirements.Whitelist.cs | 11 ++++++++ Content.Shared/Roles/JobPrototype.cs | 6 ---- Content.Shared/Roles/JobRequirements.cs | 18 ++++++++++-- Resources/Prototypes/Roles/Antags/nukeops.yml | 1 + .../Prototypes/Roles/Jobs/Command/captain.yml | 3 +- 10 files changed, 54 insertions(+), 60 deletions(-) create mode 100644 Content.Shared/DeltaV/Roles/JobRequirements.Whitelist.cs diff --git a/Content.Client/Nyanotrasen/Players/PlayTimeTracking/JobRequirementsManager.Whitelist.cs b/Content.Client/Nyanotrasen/Players/PlayTimeTracking/JobRequirementsManager.Whitelist.cs index 985ac27a734..9b1f2d203f4 100644 --- a/Content.Client/Nyanotrasen/Players/PlayTimeTracking/JobRequirementsManager.Whitelist.cs +++ b/Content.Client/Nyanotrasen/Players/PlayTimeTracking/JobRequirementsManager.Whitelist.cs @@ -10,21 +10,13 @@ public sealed partial class JobRequirementsManager { private bool _whitelisted = false; - private bool CheckWhitelist(JobPrototype job, [NotNullWhen(false)] out FormattedMessage? reason) + private void RxWhitelist(MsgWhitelist message) { - reason = null; - - if (!job.WhitelistRequired || !_cfg.GetCVar(CCVars.GameWhitelistJobs)) - return true; - - if (job.WhitelistRequired && _cfg.GetCVar(CCVars.GameWhitelistJobs) && !_whitelisted) - reason = FormattedMessage.FromMarkup(Loc.GetString("playtime-deny-reason-not-whitelisted")); - - return reason == null; + _whitelisted = message.Whitelisted; } - private void RxWhitelist(MsgWhitelist message) + public bool IsWhitelisted() { - _whitelisted = message.Whitelisted; + return _whitelisted; } } diff --git a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs index 357a6cf9169..0e559d0f8c8 100644 --- a/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs +++ b/Content.Client/Players/PlayTimeTracking/JobRequirementsManager.cs @@ -91,40 +91,30 @@ public bool IsAllowed(JobPrototype job, [NotNullWhen(false)] out FormattedMessag return false; } + if (job.Requirements == null || + !_cfg.GetCVar(CCVars.GameRoleTimers)) + { + return true; + } + var player = _playerManager.LocalPlayer?.Session; if (player == null) return true; - var roleCheck = CheckRoleTime(job.Requirements, out var roleReason); - var whitelistCheck = CheckWhitelist(job, out var whitelistReason); - - if (!roleCheck || !whitelistCheck) - { - reason = new FormattedMessage(); - if (!roleCheck && roleReason != null) - reason.AddMessage(roleReason); - if (!whitelistCheck && whitelistReason != null) - { - if (!reason.IsEmpty) - reason.PushNewline(); - reason.AddMessage(whitelistReason); - } - } - - return reason == null; + return CheckRoleTime(job.Requirements, out reason); } public bool CheckRoleTime(HashSet? requirements, [NotNullWhen(false)] out FormattedMessage? reason) { reason = null; - if (requirements == null || !_cfg.GetCVar(CCVars.GameRoleTimers)) + if (requirements == null) return true; var reasons = new List(); foreach (var requirement in requirements) { - if (JobRequirements.TryRequirementMet(requirement, _roles, out var jobReason, _entManager, _prototypes)) + if (JobRequirements.TryRequirementMet(requirement, _roles, out var jobReason, _entManager, _prototypes, _whitelisted)) continue; reasons.Add(jobReason.ToMarkup()); diff --git a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs index c9a64eb0973..10db3359388 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs @@ -1327,6 +1327,7 @@ public AntagPreferenceSelector(AntagPrototype proto) // immediately lock requirements if they arent met. // another function checks Disabled after creating the selector so this has to be done now var requirements = IoCManager.Resolve(); + if (proto.Requirements != null && !requirements.CheckRoleTime(proto.Requirements, out var reason)) { LockRequirements(reason); diff --git a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs index 86853de662f..201f80ddad6 100644 --- a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs +++ b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs @@ -1,6 +1,7 @@ using System.Linq; using Content.Server.Afk; using Content.Server.Afk.Events; +using Content.Server.Database; using Content.Server.GameTicking; using Content.Server.Mind; using Content.Shared.CCVar; @@ -158,22 +159,16 @@ private void OnPlayerJoinedLobby(PlayerJoinedLobbyEvent ev) public bool IsAllowed(IPlayerSession player, string role) { - if (!_prototypes.TryIndex(role, out var job)) // Nyanotrasen - separate job requirements check - return true; - - // Nyanotrasen - Require whitelist for certain roles - if (_cfg.GetCVar(CCVars.GameWhitelistJobs) && - job.WhitelistRequired && - !player.ContentData()!.Whitelisted) - return false; - - if (job.Requirements == null || // Nyanotrasen - separate job requirements check so whitelist check gets ran + if (!_prototypes.TryIndex(role, out var job) || + job.Requirements == null || !_cfg.GetCVar(CCVars.GameRoleTimers)) return true; var playTimes = _tracking.GetTrackerTimes(player); - return JobRequirements.TryRequirementsMet(job, playTimes, out _, EntityManager, _prototypes); + var isWhitelisted = player.ContentData()?.Whitelisted ?? false; // DeltaV - Whitelist requirement + + return JobRequirements.TryRequirementsMet(job, playTimes, out _, EntityManager, _prototypes, isWhitelisted); } public HashSet GetDisallowedJobs(IPlayerSession player) @@ -183,6 +178,7 @@ public HashSet GetDisallowedJobs(IPlayerSession player) return roles; var playTimes = _tracking.GetTrackerTimes(player); + var isWhitelisted = player.ContentData()?.Whitelisted ?? false; // DeltaV - Whitelist requirement foreach (var job in _prototypes.EnumeratePrototypes()) { @@ -190,7 +186,7 @@ public HashSet GetDisallowedJobs(IPlayerSession player) { foreach (var requirement in job.Requirements) { - if (JobRequirements.TryRequirementMet(requirement, playTimes, out _, EntityManager, _prototypes)) + if (JobRequirements.TryRequirementMet(requirement, playTimes, out _, EntityManager, _prototypes, isWhitelisted)) continue; goto NoRole; @@ -217,6 +213,8 @@ public void RemoveDisallowedJobs(NetUserId userId, ref List jobs) playTimes ??= new Dictionary(); } + var isWhitelisted = player.ContentData()?.Whitelisted ?? false; // DeltaV - Whitelist requirement + for (var i = 0; i < jobs.Count; i++) { var job = jobs[i]; @@ -228,7 +226,7 @@ public void RemoveDisallowedJobs(NetUserId userId, ref List jobs) foreach (var requirement in jobber.Requirements) { - if (JobRequirements.TryRequirementMet(requirement, playTimes, out _, EntityManager, _prototypes)) + if (JobRequirements.TryRequirementMet(requirement, playTimes, out _, EntityManager, _prototypes, isWhitelisted)) continue; jobs.RemoveSwap(i); diff --git a/Content.Shared/CCVar/CCVars.cs b/Content.Shared/CCVar/CCVars.cs index 849ef1ed66c..1b4d7579c37 100644 --- a/Content.Shared/CCVar/CCVars.cs +++ b/Content.Shared/CCVar/CCVars.cs @@ -211,12 +211,6 @@ public static readonly CVarDef public static readonly CVarDef GameRoleTimers = CVarDef.Create("game.role_timers", true, CVar.SERVER | CVar.REPLICATED); - /// - /// Nyanotrasen - Require whitelist for certain jobs - /// - public static readonly CVarDef - GameWhitelistJobs = CVarDef.Create("game.whitelist_jobs", true, CVar.SERVER | CVar.REPLICATED); - /// /// Whether a random position offset will be applied to the station on roundstart. /// diff --git a/Content.Shared/DeltaV/Roles/JobRequirements.Whitelist.cs b/Content.Shared/DeltaV/Roles/JobRequirements.Whitelist.cs new file mode 100644 index 00000000000..a6e352991e9 --- /dev/null +++ b/Content.Shared/DeltaV/Roles/JobRequirements.Whitelist.cs @@ -0,0 +1,11 @@ +using JetBrains.Annotations; +using Robust.Shared.Serialization; + +namespace Content.Shared.Roles +{ + [UsedImplicitly] + [Serializable, NetSerializable] + public sealed partial class WhitelistRequirement : JobRequirement + { + } +} diff --git a/Content.Shared/Roles/JobPrototype.cs b/Content.Shared/Roles/JobPrototype.cs index 287fe69e3ae..b4733d0679f 100644 --- a/Content.Shared/Roles/JobPrototype.cs +++ b/Content.Shared/Roles/JobPrototype.cs @@ -47,12 +47,6 @@ public sealed class JobPrototype : IPrototype [DataField("joinNotifyCrew")] public bool JoinNotifyCrew { get; private set; } = false; - /// - /// Nyanotrasen - If true, require whitelist for the job. - /// - [DataField("whitelistRequired")] - public bool WhitelistRequired = false; - [DataField("requireAdminNotify")] public bool RequireAdminNotify { get; private set; } = false; diff --git a/Content.Shared/Roles/JobRequirements.cs b/Content.Shared/Roles/JobRequirements.cs index fc3b759a9c2..2785e988bcd 100644 --- a/Content.Shared/Roles/JobRequirements.cs +++ b/Content.Shared/Roles/JobRequirements.cs @@ -2,6 +2,7 @@ using Content.Shared.Players.PlayTimeTracking; using Content.Shared.Roles.Jobs; using JetBrains.Annotations; +using Robust.Shared.Players; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; @@ -76,7 +77,8 @@ public static bool TryRequirementsMet( Dictionary playTimes, [NotNullWhen(false)] out FormattedMessage? reason, IEntityManager entManager, - IPrototypeManager prototypes) + IPrototypeManager prototypes, + bool isWhitelisted) { reason = null; if (job.Requirements == null) @@ -84,7 +86,7 @@ public static bool TryRequirementsMet( foreach (var requirement in job.Requirements) { - if (!TryRequirementMet(requirement, playTimes, out reason, entManager, prototypes)) + if (!TryRequirementMet(requirement, playTimes, out reason, entManager, prototypes, isWhitelisted)) return false; } @@ -99,7 +101,8 @@ public static bool TryRequirementMet( Dictionary playTimes, [NotNullWhen(false)] out FormattedMessage? reason, IEntityManager entManager, - IPrototypeManager prototypes) + IPrototypeManager prototypes, + bool isWhitelisted) { reason = null; @@ -216,6 +219,15 @@ public static bool TryRequirementMet( return true; } + case WhitelistRequirement _: // DeltaV - Whitelist requirement + if (isWhitelisted == null) + throw new ArgumentNullException(nameof(isWhitelisted), "isWhitelisted cannot be null."); + + if (isWhitelisted) + return true; + + reason = FormattedMessage.FromMarkup(Loc.GetString("playtime-deny-reason-not-whitelisted")); + return false; default: throw new NotImplementedException(); } diff --git a/Resources/Prototypes/Roles/Antags/nukeops.yml b/Resources/Prototypes/Roles/Antags/nukeops.yml index bd625e6d81a..f4fae1a8b17 100644 --- a/Resources/Prototypes/Roles/Antags/nukeops.yml +++ b/Resources/Prototypes/Roles/Antags/nukeops.yml @@ -33,4 +33,5 @@ - !type:DepartmentTimeRequirement department: Security time: 18000 # 5h + - !type:WhitelistRequirement # DeltaV - Commander is an "hrp" role # should be changed to nukie playtime when thats tracked (wyci) diff --git a/Resources/Prototypes/Roles/Jobs/Command/captain.yml b/Resources/Prototypes/Roles/Jobs/Command/captain.yml index b536402713b..d97cd535be7 100644 --- a/Resources/Prototypes/Roles/Jobs/Command/captain.yml +++ b/Resources/Prototypes/Roles/Jobs/Command/captain.yml @@ -24,13 +24,14 @@ time: 108000 # DeltaV - 30 hours - !type:OverallPlaytimeRequirement # DeltaV - Playtime requirement time: 108000 # 30 hours + - !type:WhitelistRequirement # DeltaV - Whitelist requirement weight: 20 startingGear: CaptainGear icon: "JobIconCaptain" requireAdminNotify: true joinNotifyCrew: true supervisors: job-supervisors-centcom - whitelistRequired: true # DeltaV - Whitelist required + #whitelistRequired: true # DeltaV - Whitelist required canBeAntag: false accessGroups: - AllAccess From 34b14cac42b98b7c6b31ed45c9d224b82e5c740e Mon Sep 17 00:00:00 2001 From: Debug Date: Tue, 17 Oct 2023 16:45:27 +0200 Subject: [PATCH 3/5] Remove unused function --- .../PlayTimeTrackingManager.Whitelist.cs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/Content.Server/Nyanotrasen/Players/PlayTimeTracking/PlayTimeTrackingManager.Whitelist.cs b/Content.Server/Nyanotrasen/Players/PlayTimeTracking/PlayTimeTrackingManager.Whitelist.cs index 587b829c9fd..335384934ca 100644 --- a/Content.Server/Nyanotrasen/Players/PlayTimeTracking/PlayTimeTrackingManager.Whitelist.cs +++ b/Content.Server/Nyanotrasen/Players/PlayTimeTracking/PlayTimeTrackingManager.Whitelist.cs @@ -6,18 +6,6 @@ namespace Content.Server.Players.PlayTimeTracking; public sealed partial class PlayTimeTrackingManager { - public async void SendWhitelist(IPlayerSession playerSession) - { - var whitelist = await _db.GetWhitelistStatusAsync(playerSession.UserId); - - var msg = new MsgWhitelist - { - Whitelisted = whitelist - }; - - _net.ServerSendMessage(msg, playerSession.ConnectedClient); - } - public void SendWhitelistCached(IPlayerSession playerSession) { var whitelist = playerSession.ContentData()?.Whitelisted ?? false; From 9623240d26459779e39d03bd2a0552812bc32a85 Mon Sep 17 00:00:00 2001 From: Debug Date: Tue, 17 Oct 2023 16:45:36 +0200 Subject: [PATCH 4/5] Fix linter errors --- Resources/Prototypes/Roles/Jobs/Command/captain.yml | 1 - Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Resources/Prototypes/Roles/Jobs/Command/captain.yml b/Resources/Prototypes/Roles/Jobs/Command/captain.yml index d97cd535be7..5d97b24620d 100644 --- a/Resources/Prototypes/Roles/Jobs/Command/captain.yml +++ b/Resources/Prototypes/Roles/Jobs/Command/captain.yml @@ -31,7 +31,6 @@ requireAdminNotify: true joinNotifyCrew: true supervisors: job-supervisors-centcom - #whitelistRequired: true # DeltaV - Whitelist required canBeAntag: false accessGroups: - AllAccess diff --git a/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml b/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml index c79e299f1c2..0e18aa63a7e 100644 --- a/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml +++ b/Resources/Prototypes/Roles/Jobs/Security/head_of_security.yml @@ -15,12 +15,12 @@ time: 36000 # 10 hours - !type:OverallPlaytimeRequirement time: 90000 # DeltaV - 25 hours + - !type:WhitelistRequirement # DeltaV - Whitelist requirement weight: 10 startingGear: HoSGear icon: "JobIconHeadOfSecurity" requireAdminNotify: true supervisors: job-supervisors-captain - whitelistRequired: true # DeltaV - Whitelist required canBeAntag: false access: - HeadOfSecurity From 7f337622b2b0a3b776d327981de3332873eae3ee Mon Sep 17 00:00:00 2001 From: Debug <49997488+DebugOk@users.noreply.github.com> Date: Wed, 18 Oct 2023 22:04:31 +0200 Subject: [PATCH 5/5] Remove unused dependency and whitespace --- Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs | 1 - .../Players/PlayTimeTracking/PlayTimeTrackingSystem.cs | 1 - 2 files changed, 2 deletions(-) diff --git a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs index 10db3359388..c9a64eb0973 100644 --- a/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs +++ b/Content.Client/Preferences/UI/HumanoidProfileEditor.xaml.cs @@ -1327,7 +1327,6 @@ public AntagPreferenceSelector(AntagPrototype proto) // immediately lock requirements if they arent met. // another function checks Disabled after creating the selector so this has to be done now var requirements = IoCManager.Resolve(); - if (proto.Requirements != null && !requirements.CheckRoleTime(proto.Requirements, out var reason)) { LockRequirements(reason); diff --git a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs index 201f80ddad6..7d62c54fc26 100644 --- a/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs +++ b/Content.Server/Players/PlayTimeTracking/PlayTimeTrackingSystem.cs @@ -1,7 +1,6 @@ using System.Linq; using Content.Server.Afk; using Content.Server.Afk.Events; -using Content.Server.Database; using Content.Server.GameTicking; using Content.Server.Mind; using Content.Shared.CCVar;