Add job whitelist system (#28085)
* Add job whitelist system * Address reviews * Fix name * Apply suggestions from code review Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com> * cancinium --------- Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
@@ -4,7 +4,9 @@ using Content.Server.Administration.Managers;
|
||||
using Content.Server.Afk;
|
||||
using Content.Server.Afk.Events;
|
||||
using Content.Server.GameTicking;
|
||||
using Content.Server.GameTicking.Events;
|
||||
using Content.Server.Mind;
|
||||
using Content.Server.Station.Events;
|
||||
using Content.Shared.CCVar;
|
||||
using Content.Shared.GameTicking;
|
||||
using Content.Shared.Mobs;
|
||||
@@ -12,7 +14,6 @@ using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Players;
|
||||
using Content.Shared.Players.PlayTimeTracking;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Network;
|
||||
@@ -50,6 +51,9 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
|
||||
SubscribeLocalEvent<UnAFKEvent>(OnUnAFK);
|
||||
SubscribeLocalEvent<MobStateChangedEvent>(OnMobStateChanged);
|
||||
SubscribeLocalEvent<PlayerJoinedLobbyEvent>(OnPlayerJoinedLobby);
|
||||
SubscribeLocalEvent<StationJobsGetCandidatesEvent>(OnStationJobsGetCandidates);
|
||||
SubscribeLocalEvent<IsJobAllowedEvent>(OnIsJobAllowed);
|
||||
SubscribeLocalEvent<GetDisallowedJobsEvent>(OnGetDisallowedJobs);
|
||||
_adminManager.OnPermsChanged += AdminPermsChanged;
|
||||
}
|
||||
|
||||
@@ -174,6 +178,22 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
|
||||
_tracking.QueueSendTimers(ev.PlayerSession);
|
||||
}
|
||||
|
||||
private void OnStationJobsGetCandidates(ref StationJobsGetCandidatesEvent ev)
|
||||
{
|
||||
RemoveDisallowedJobs(ev.Player, ev.Jobs);
|
||||
}
|
||||
|
||||
private void OnIsJobAllowed(ref IsJobAllowedEvent ev)
|
||||
{
|
||||
if (!IsAllowed(ev.Player, ev.JobId))
|
||||
ev.Cancelled = true;
|
||||
}
|
||||
|
||||
private void OnGetDisallowedJobs(ref GetDisallowedJobsEvent ev)
|
||||
{
|
||||
ev.Jobs.UnionWith(GetDisallowedJobs(ev.Player));
|
||||
}
|
||||
|
||||
public bool IsAllowed(ICommonSession player, string role)
|
||||
{
|
||||
if (!_prototypes.TryIndex<JobPrototype>(role, out var job) ||
|
||||
@@ -190,9 +210,9 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
|
||||
return JobRequirements.TryRequirementsMet(job, playTimes, out _, EntityManager, _prototypes);
|
||||
}
|
||||
|
||||
public HashSet<string> GetDisallowedJobs(ICommonSession player)
|
||||
public HashSet<ProtoId<JobPrototype>> GetDisallowedJobs(ICommonSession player)
|
||||
{
|
||||
var roles = new HashSet<string>();
|
||||
var roles = new HashSet<ProtoId<JobPrototype>>();
|
||||
if (!_cfg.GetCVar(CCVars.GameRoleTimers))
|
||||
return roles;
|
||||
|
||||
@@ -222,7 +242,7 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
|
||||
return roles;
|
||||
}
|
||||
|
||||
public void RemoveDisallowedJobs(NetUserId userId, ref List<string> jobs)
|
||||
public void RemoveDisallowedJobs(NetUserId userId, List<ProtoId<JobPrototype>> jobs)
|
||||
{
|
||||
if (!_cfg.GetCVar(CCVars.GameRoleTimers))
|
||||
return;
|
||||
@@ -239,7 +259,7 @@ public sealed class PlayTimeTrackingSystem : EntitySystem
|
||||
{
|
||||
var job = jobs[i];
|
||||
|
||||
if (!_prototypes.TryIndex<JobPrototype>(job, out var jobber) ||
|
||||
if (!_prototypes.TryIndex(job, out var jobber) ||
|
||||
jobber.Requirements == null ||
|
||||
jobber.Requirements.Count == 0)
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user