]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Replace obsolete EntityWhitelist IsValid usages (#28465)
authorPlykiya <58439124+Plykiya@users.noreply.github.com>
Sun, 2 Jun 2024 03:10:24 +0000 (20:10 -0700)
committerGitHub <noreply@github.com>
Sun, 2 Jun 2024 03:10:24 +0000 (23:10 -0400)
* Replace obsolete whitelist is valid with whitelist system

* Consistency

* Fix logic

* Bork

* I figured out how to get whitelists on the client lol

* test fail

* woops

* HELP ME FUNCTIONS

* Fix errors

* simplify

---------

Co-authored-by: plykiya <plykiya@protonmail.com>
31 files changed:
Content.Client/Chat/UI/EmotesMenu.xaml.cs
Content.Client/Construction/UI/ConstructionMenuPresenter.cs
Content.Server/Chat/Systems/ChatSystem.Emote.cs
Content.Server/Chat/Systems/ChatSystem.cs
Content.Server/Gatherable/GatherableSystem.cs
Content.Server/NPC/Systems/NPCImprintingOnSpawnBehaviourSystem.cs
Content.Server/NPC/Systems/NPCUtilitySystem.cs
Content.Server/Power/EntitySystems/ChargerSystem.cs
Content.Server/Revenant/EntitySystems/RevenantSystem.Abilities.cs
Content.Server/Silicons/Borgs/BorgSystem.Modules.cs
Content.Server/Silicons/Borgs/BorgSystem.cs
Content.Server/Storage/EntitySystems/PickRandomSystem.cs
Content.Server/Xenoarchaeology/XenoArtifacts/ArtifactSystem.Nodes.cs
Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs
Content.Shared/Damage/Systems/DamageContactsSystem.cs
Content.Shared/Devour/SharedDevourSystem.cs
Content.Shared/Disposal/SharedDisposalUnitSystem.cs
Content.Shared/Implants/SharedImplanterSystem.cs
Content.Shared/Interaction/SmartEquipSystem.cs
Content.Shared/Materials/SharedMaterialStorageSystem.cs
Content.Shared/Polymorph/Systems/SharedChameleonProjectorSystem.cs
Content.Shared/Salvage/Fulton/SharedFultonSystem.cs
Content.Shared/Shuttles/Systems/SharedShuttleSystem.cs
Content.Shared/Storage/EntitySystems/MagnetPickupSystem.cs
Content.Shared/Storage/EntitySystems/SharedEntityStorageSystem.cs
Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Content.Shared/Weapons/Marker/SharedDamageMarkerSystem.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Ballistic.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.Revolver.cs
Content.Shared/Weapons/Ranged/Systems/SharedGunSystem.cs
Content.Shared/Whitelist/EntityWhitelistSystem.cs

index a26d319920bf66df04c347b4d8b2324831268105..3340755343890b0f5b753341d525c1284520f96c 100644 (file)
@@ -1,7 +1,8 @@
-using System.Numerics;
+using System.Numerics;
 using Content.Client.UserInterface.Controls;
 using Content.Shared.Chat.Prototypes;
 using Content.Shared.Speech;
+using Content.Shared.Whitelist;
 using Robust.Client.AutoGenerated;
 using Robust.Client.GameObjects;
 using Robust.Client.UserInterface.Controls;
@@ -19,6 +20,7 @@ public sealed partial class EmotesMenu : RadialMenu
     [Dependency] private readonly ISharedPlayerManager _playerManager = default!;
 
     private readonly SpriteSystem _spriteSystem;
+    private readonly EntityWhitelistSystem _whitelistSystem;
 
     public event Action<ProtoId<EmotePrototype>>? OnPlayEmote;
 
@@ -28,6 +30,7 @@ public sealed partial class EmotesMenu : RadialMenu
         RobustXamlLoader.Load(this);
 
         _spriteSystem = _entManager.System<SpriteSystem>();
+        _whitelistSystem = _entManager.System<EntityWhitelistSystem>();
 
         var main = FindControl<RadialContainer>("Main");
 
@@ -37,8 +40,8 @@ public sealed partial class EmotesMenu : RadialMenu
             var player = _playerManager.LocalSession?.AttachedEntity;
             if (emote.Category == EmoteCategory.Invalid ||
                 emote.ChatTriggers.Count == 0 ||
-                !(player.HasValue && (emote.Whitelist?.IsValid(player.Value, _entManager) ?? true)) ||
-                (emote.Blacklist?.IsValid(player.Value, _entManager) ?? false))
+                !(player.HasValue && _whitelistSystem.IsWhitelistPassOrNull(emote.Whitelist, player.Value)) ||
+                _whitelistSystem.IsBlacklistPass(emote.Blacklist, player.Value))
                 continue;
 
             if (!emote.Available &&
index 9a09436176652ee659a60b85bb078e660cbc121b..0c7912e0bcd5507837fe95a18645217e02147bf5 100644 (file)
@@ -2,6 +2,7 @@ using System.Linq;
 using Content.Client.UserInterface.Systems.MenuBar.Widgets;
 using Content.Shared.Construction.Prototypes;
 using Content.Shared.Tag;
+using Content.Shared.Whitelist;
 using Robust.Client.GameObjects;
 using Robust.Client.Graphics;
 using Robust.Client.Placement;
@@ -23,6 +24,7 @@ namespace Content.Client.Construction.UI
     /// </summary>
     internal sealed class ConstructionMenuPresenter : IDisposable
     {
+        [Dependency] private readonly EntityManager _entManager = default!;
         [Dependency] private readonly IEntitySystemManager _systemManager = default!;
         [Dependency] private readonly IPrototypeManager _prototypeManager = default!;
         [Dependency] private readonly IPlacementManager _placementManager = default!;
@@ -30,6 +32,7 @@ namespace Content.Client.Construction.UI
         [Dependency] private readonly IPlayerManager _playerManager = default!;
 
         private readonly IConstructionMenuView _constructionView;
+        private readonly EntityWhitelistSystem _whitelistSystem;
 
         private ConstructionSystem? _constructionSystem;
         private ConstructionPrototype? _selected;
@@ -78,6 +81,7 @@ namespace Content.Client.Construction.UI
             // This is a lot easier than a factory
             IoCManager.InjectDependencies(this);
             _constructionView = new ConstructionMenu();
+            _whitelistSystem = _entManager.System<EntityWhitelistSystem>();
 
             // This is required so that if we load after the system is initialized, we can bind to it immediately
             if (_systemManager.TryGetEntitySystem<ConstructionSystem>(out var constructionSystem))
@@ -157,7 +161,7 @@ namespace Content.Client.Construction.UI
 
                 if (_playerManager.LocalSession == null
                 || _playerManager.LocalEntity == null
-                || (recipe.EntityWhitelist != null && !recipe.EntityWhitelist.IsValid(_playerManager.LocalEntity.Value)))
+                || _whitelistSystem.IsWhitelistFail(recipe.EntityWhitelist, _playerManager.LocalEntity.Value))
                     continue;
 
                 if (!string.IsNullOrEmpty(search))
index d120812b8801f405942410f1db0b0d33bbd47001..23e1517d7548264cb939176025e11af9452424a1 100644 (file)
@@ -81,9 +81,7 @@ public partial class ChatSystem
         bool ignoreActionBlocker = false
         )
     {
-        if (!(emote.Whitelist?.IsValid(source, EntityManager) ?? true))
-            return;
-        if (emote.Blacklist?.IsValid(source, EntityManager) ?? false)
+        if (_whitelistSystem.IsWhitelistFailOrNull(emote.Whitelist, source) || _whitelistSystem.IsBlacklistPass(emote.Blacklist, source))
             return;
 
         if (!emote.Available &&
index b79e16a8df9762b51b6a71c3323e322f156f9b0d..0fe9dcbc4d854e64771e4dafcc8c00913973a2f5 100644 (file)
@@ -22,6 +22,7 @@ using Content.Shared.Mobs.Systems;
 using Content.Shared.Players;
 using Content.Shared.Radio;
 using Content.Shared.Speech;
+using Content.Shared.Whitelist;
 using Robust.Server.Player;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
@@ -58,6 +59,7 @@ public sealed partial class ChatSystem : SharedChatSystem
     [Dependency] private readonly SharedAudioSystem _audio = default!;
     [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
     [Dependency] private readonly ReplacementAccentSystem _wordreplacement = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public const int VoiceRange = 10; // how far voice goes in world units
     public const int WhisperClearRange = 2; // how far whisper goes while still being understandable, in world units
index e24b0da593949efa4f2b913a66865de0f4577b8c..d6a3be451b6aa30078ac6fb128ade60242ce4567 100644 (file)
@@ -3,6 +3,7 @@ using Content.Server.Gatherable.Components;
 using Content.Shared.Interaction;
 using Content.Shared.Tag;
 using Content.Shared.Weapons.Melee.Events;
+using Content.Shared.Whitelist;
 using Robust.Server.GameObjects;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Prototypes;
@@ -18,6 +19,7 @@ public sealed partial class GatherableSystem : EntitySystem
     [Dependency] private readonly SharedAudioSystem _audio = default!;
     [Dependency] private readonly TagSystem _tagSystem = default!;
     [Dependency] private readonly TransformSystem _transform = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public override void Initialize()
     {
@@ -30,7 +32,7 @@ public sealed partial class GatherableSystem : EntitySystem
 
     private void OnAttacked(Entity<GatherableComponent> gatherable, ref AttackedEvent args)
     {
-        if (gatherable.Comp.ToolWhitelist?.IsValid(args.Used, EntityManager) != true)
+        if (_whitelistSystem.IsWhitelistFailOrNull(gatherable.Comp.ToolWhitelist, args.Used))
             return;
 
         Gather(gatherable, args.User);
@@ -41,7 +43,7 @@ public sealed partial class GatherableSystem : EntitySystem
         if (args.Handled || !args.Complex)
             return;
 
-        if (gatherable.Comp.ToolWhitelist?.IsValid(args.User, EntityManager) != true)
+        if (_whitelistSystem.IsWhitelistFailOrNull(gatherable.Comp.ToolWhitelist, args.User))
             return;
 
         Gather(gatherable, args.User);
index cfd3b08c61a6b71079c5a1a0ebb3c67befa0194a..c3e0328037d3bf4bf3b5da90916b54cc90c68fb1 100644 (file)
@@ -1,6 +1,7 @@
 using System.Numerics;
 using Content.Shared.NPC.Components;
 using Content.Shared.NPC.Systems;
+using Content.Shared.Whitelist;
 using Robust.Shared.Collections;
 using Robust.Shared.Map;
 using Robust.Shared.Random;
@@ -13,6 +14,7 @@ public sealed partial class NPCImprintingOnSpawnBehaviourSystem : SharedNPCImpri
     [Dependency] private readonly EntityLookupSystem _lookup = default!;
     [Dependency] private readonly NPCSystem _npc = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public override void Initialize()
     {
@@ -27,7 +29,7 @@ public sealed partial class NPCImprintingOnSpawnBehaviourSystem : SharedNPCImpri
 
         foreach (var friend in friends)
         {
-            if (imprinting.Comp.Whitelist?.IsValid(friend) != false)
+            if (_whitelistSystem.IsWhitelistPassOrNull(imprinting.Comp.Whitelist, friend))
             {
                 AddImprintingTarget(imprinting, friend, imprinting.Comp);
             }
index 2e8c628b5030ed1a5a4dc4320cf13c27e2e60a92..ca74d7133574245587b05d465176a8761f20ac06 100644 (file)
@@ -19,6 +19,7 @@ using Content.Shared.Tools.Systems;
 using Content.Shared.Weapons.Melee;
 using Content.Shared.Weapons.Ranged.Components;
 using Content.Shared.Weapons.Ranged.Events;
+using Content.Shared.Whitelist;
 using Microsoft.Extensions.ObjectPool;
 using Robust.Server.Containers;
 using Robust.Shared.Prototypes;
@@ -46,6 +47,7 @@ public sealed class NPCUtilitySystem : EntitySystem
     [Dependency] private readonly SolutionContainerSystem _solutions = default!;
     [Dependency] private readonly WeldableSystem _weldable = default!;
     [Dependency] private readonly ExamineSystemShared _examine = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     private EntityQuery<PuddleComponent> _puddleQuery;
     private EntityQuery<TransformComponent> _xformQuery;
@@ -249,7 +251,7 @@ public sealed class NPCUtilitySystem : EntitySystem
                     return 0f;
                 }
 
-                if (heldGun.Whitelist?.IsValid(targetUid, EntityManager) != true)
+                if (_whitelistSystem.IsWhitelistFailOrNull(heldGun.Whitelist, targetUid))
                 {
                     return 0f;
                 }
index 1ff13a24f2c31463025f79fec3a35f603de08cc9..038295eac1159b42659f47dcf8e285a3f51ec23f 100644 (file)
@@ -10,6 +10,7 @@ using Robust.Shared.Containers;
 using System.Diagnostics.CodeAnalysis;
 using Content.Shared.Storage.Components;
 using Robust.Server.Containers;
+using Content.Shared.Whitelist;
 
 namespace Content.Server.Power.EntitySystems;
 
@@ -20,6 +21,7 @@ internal sealed class ChargerSystem : EntitySystem
     [Dependency] private readonly PowerCellSystem _powerCell = default!;
     [Dependency] private readonly BatterySystem _battery = default!;
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public override void Initialize()
     {
@@ -208,7 +210,7 @@ internal sealed class ChargerSystem : EntitySystem
         if (!receiverComponent.Powered)
             return;
 
-        if (component.Whitelist?.IsValid(targetEntity, EntityManager) == false)
+        if (_whitelistSystem.IsWhitelistFail(component.Whitelist, targetEntity))
             return;
 
         if (!SearchForBattery(targetEntity, out var batteryUid, out var heldBattery))
index 670c64577a480f15b441b17b816976b9973132d3..c889d59f1556385b186a95ea79965b6fb492c03a 100644 (file)
@@ -28,6 +28,7 @@ using Content.Shared.Revenant.Components;
 using Robust.Shared.Physics.Components;
 using Robust.Shared.Utility;
 using Robust.Shared.Map.Components;
+using Content.Shared.Whitelist;
 
 namespace Content.Server.Revenant.EntitySystems;
 
@@ -40,6 +41,7 @@ public sealed partial class RevenantSystem
     [Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
     [Dependency] private readonly GhostSystem _ghost = default!;
     [Dependency] private readonly TileSystem _tile = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     private void InitializeAbilities()
     {
@@ -331,10 +333,8 @@ public sealed partial class RevenantSystem
 
         foreach (var ent in _lookup.GetEntitiesInRange(uid, component.MalfunctionRadius))
         {
-            if (component.MalfunctionWhitelist?.IsValid(ent, EntityManager) == false)
-                continue;
-
-            if (component.MalfunctionBlacklist?.IsValid(ent, EntityManager) == true)
+            if (_whitelistSystem.IsWhitelistFail(component.MalfunctionWhitelist, ent) ||
+                _whitelistSystem.IsBlacklistPass(component.MalfunctionBlacklist, ent))
                 continue;
 
             _emag.DoEmagEffect(uid, ent); //it does not emag itself. adorable.
index cc57c34c4754b1458a68aed9e0077dd97cca148a..5c600be3f6404eb2c4109e70f437f495d0d41850 100644 (file)
@@ -267,7 +267,7 @@ public sealed partial class BorgSystem
             return false;
         }
 
-        if (component.ModuleWhitelist?.IsValid(module, EntityManager) == false)
+        if (_whitelistSystem.IsWhitelistFail(component.ModuleWhitelist, module))
         {
             if (user != null)
                 Popup.PopupEntity(Loc.GetString("borg-module-whitelist-deny"), uid, user.Value);
index 082e38921a2cfae69b683de70148f553368b119d..1ab7f5387f31eb7dd850f1c190d7c15df91c228f 100644 (file)
@@ -22,6 +22,7 @@ using Content.Shared.Roles;
 using Content.Shared.Silicons.Borgs;
 using Content.Shared.Silicons.Borgs.Components;
 using Content.Shared.Throwing;
+using Content.Shared.Whitelist;
 using Content.Shared.Wires;
 using Robust.Server.GameObjects;
 using Robust.Shared.Containers;
@@ -53,6 +54,8 @@ public sealed partial class BorgSystem : SharedBorgSystem
     [Dependency] private readonly ThrowingSystem _throwing = default!;
     [Dependency] private readonly UserInterfaceSystem _ui = default!;
     [Dependency] private readonly SharedContainerSystem _container = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
+
 
     [ValidatePrototypeId<JobPrototype>]
     public const string BorgJobId = "Borg";
@@ -104,9 +107,8 @@ public sealed partial class BorgSystem : SharedBorgSystem
             return;
         }
 
-        if (component.BrainEntity == null &&
-            brain != null &&
-            component.BrainWhitelist?.IsValid(used) != false)
+        if (component.BrainEntity == null && brain != null &&
+            _whitelistSystem.IsWhitelistPassOrNull(component.BrainWhitelist, used))
         {
             if (_mind.TryGetMind(used, out _, out var mind) && mind.Session != null)
             {
index dbbe1dd7785f762d1bd55cdc96a2303da1920627..f0e986e199bf1cd5764a31695d80e6ab00b28937 100644 (file)
@@ -4,6 +4,7 @@ using Content.Shared.Database;
 using Content.Shared.Hands.EntitySystems;
 using Content.Shared.Storage;
 using Content.Shared.Verbs;
+using Content.Shared.Whitelist;
 using Robust.Shared.Containers;
 using Robust.Shared.Random;
 
@@ -15,6 +16,7 @@ public sealed class PickRandomSystem : EntitySystem
     [Dependency] private readonly SharedContainerSystem _container = default!;
     [Dependency] private readonly SharedHandsSystem _hands = default!;
     [Dependency] private readonly IRobustRandom _random = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public override void Initialize()
     {
@@ -30,7 +32,7 @@ public sealed class PickRandomSystem : EntitySystem
 
         var user = args.User;
 
-        var enabled = storage.Container.ContainedEntities.Any(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true);
+        var enabled = storage.Container.ContainedEntities.Any(item => _whitelistSystem.IsWhitelistPassOrNull(comp.Whitelist, item));
 
         // alt-click / alt-z to pick an item
         args.Verbs.Add(new AlternativeVerb
@@ -48,7 +50,7 @@ public sealed class PickRandomSystem : EntitySystem
 
     private void TryPick(EntityUid uid, PickRandomComponent comp, StorageComponent storage, EntityUid user)
     {
-        var entities = storage.Container.ContainedEntities.Where(item => comp.Whitelist?.IsValid(item, EntityManager) ?? true).ToArray();
+        var entities = storage.Container.ContainedEntities.Where(item => _whitelistSystem.IsWhitelistPassOrNull(comp.Whitelist, item)).ToArray();
 
         if (!entities.Any())
             return;
index 895bb0217b3b235cea7ceef9f82b3e16aa98243a..65aaabdf0e957ff392a9ec8a082cb23ea8ce462c 100644 (file)
@@ -1,15 +1,16 @@
 using System.Linq;
 using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
+using Content.Shared.Whitelist;
 using Content.Shared.Xenoarchaeology.XenoArtifacts;
 using JetBrains.Annotations;
-using Robust.Shared.Prototypes;
 using Robust.Shared.Random;
-using Robust.Shared.Serialization.Manager;
 
 namespace Content.Server.Xenoarchaeology.XenoArtifacts;
 
 public sealed partial class ArtifactSystem
 {
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
+
     private const int MaxEdgesPerNode = 4;
 
     private readonly HashSet<int> _usedNodeIds = new();
@@ -81,7 +82,8 @@ public sealed partial class ArtifactSystem
     private string GetRandomTrigger(EntityUid artifact, ref ArtifactNode node)
     {
         var allTriggers = _prototype.EnumeratePrototypes<ArtifactTriggerPrototype>()
-            .Where(x => (x.Whitelist?.IsValid(artifact, EntityManager) ?? true) && (!x.Blacklist?.IsValid(artifact, EntityManager) ?? true)).ToList();
+            .Where(x => _whitelistSystem.IsWhitelistPassOrNull(x.Whitelist, artifact) &&
+            _whitelistSystem.IsBlacklistFailOrNull(x.Blacklist, artifact)).ToList();
         var validDepth = allTriggers.Select(x => x.TargetDepth).Distinct().ToList();
 
         var weights = GetDepthWeights(validDepth, node.Depth);
@@ -95,7 +97,8 @@ public sealed partial class ArtifactSystem
     private string GetRandomEffect(EntityUid artifact, ref ArtifactNode node)
     {
         var allEffects = _prototype.EnumeratePrototypes<ArtifactEffectPrototype>()
-            .Where(x => (x.Whitelist?.IsValid(artifact, EntityManager) ?? true) && (!x.Blacklist?.IsValid(artifact, EntityManager) ?? true)).ToList();
+            .Where(x => _whitelistSystem.IsWhitelistPassOrNull(x.Whitelist, artifact) &&
+            _whitelistSystem.IsBlacklistFailOrNull(x.Blacklist, artifact)).ToList();
         var validDepth = allEffects.Select(x => x.TargetDepth).Distinct().ToList();
 
         var weights = GetDepthWeights(validDepth, node.Depth);
index 2e3f9ed461a33b0f7157174a8ee6b8f453753eaf..48f4f07cbe1ad56708a7801c3775c74772cd7c34 100644 (file)
@@ -9,6 +9,7 @@ using Content.Shared.Interaction;
 using Content.Shared.Interaction.Events;
 using Content.Shared.Popups;
 using Content.Shared.Verbs;
+using Content.Shared.Whitelist;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
 using Robust.Shared.GameStates;
@@ -31,6 +32,7 @@ namespace Content.Shared.Containers.ItemSlots
         [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
         [Dependency] private readonly SharedHandsSystem _handsSystem = default!;
         [Dependency] private readonly SharedAudioSystem _audioSystem = default!;
+        [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
         public override void Initialize()
         {
@@ -266,8 +268,7 @@ namespace Content.Shared.Containers.ItemSlots
             if (slot.ContainerSlot == null)
                 return false;
 
-            if ((!slot.Whitelist?.IsValid(usedUid) ?? false) ||
-                (slot.Blacklist?.IsValid(usedUid) ?? false))
+            if (_whitelistSystem.IsWhitelistFail(slot.Whitelist, usedUid) || _whitelistSystem.IsBlacklistPass(slot.Blacklist, usedUid))
             {
                 if (popup.HasValue && slot.WhitelistFailPopup.HasValue)
                     _popupSystem.PopupClient(Loc.GetString(slot.WhitelistFailPopup), uid, popup.Value);
index aec3d0766ae9740aa635bcca6d0d88baf43bd621..b08ef77fed5eaa4de2d185db0cc03e39800263e0 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Shared.Damage.Components;
+using Content.Shared.Whitelist;
 using Robust.Shared.Physics.Components;
 using Robust.Shared.Physics.Events;
 using Robust.Shared.Physics.Systems;
@@ -11,6 +12,7 @@ public sealed class DamageContactsSystem : EntitySystem
     [Dependency] private readonly IGameTiming _timing = default!;
     [Dependency] private readonly DamageableSystem _damageable = default!;
     [Dependency] private readonly SharedPhysicsSystem _physics = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public override void Initialize()
     {
@@ -63,7 +65,7 @@ public sealed class DamageContactsSystem : EntitySystem
         if (HasComp<DamagedByContactComponent>(otherUid))
             return;
 
-        if (component.IgnoreWhitelist?.IsValid(otherUid) ?? false)
+        if (_whitelistSystem.IsWhitelistFail(component.IgnoreWhitelist, otherUid))
             return;
 
         var damagedByContact = EnsureComp<DamagedByContactComponent>(otherUid);
index 3d73b14dd35631eb3be2bbad1e5ca3ef47cccaf9..14047fba7dd2822920d79a9f57eedd1d46df225a 100644 (file)
@@ -4,6 +4,7 @@ using Content.Shared.DoAfter;
 using Content.Shared.Mobs;
 using Content.Shared.Mobs.Components;
 using Content.Shared.Popups;
+using Content.Shared.Whitelist;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
@@ -18,6 +19,7 @@ public abstract class SharedDevourSystem : EntitySystem
     [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
     [Dependency] private readonly SharedActionsSystem _actionsSystem = default!;
     [Dependency] protected readonly SharedContainerSystem ContainerSystem = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public override void Initialize()
     {
@@ -41,7 +43,7 @@ public abstract class SharedDevourSystem : EntitySystem
     /// </summary>
     protected void OnDevourAction(EntityUid uid, DevourerComponent component, DevourActionEvent args)
     {
-        if (args.Handled || component.Whitelist?.IsValid(args.Target, EntityManager) != true)
+        if (args.Handled || _whitelistSystem.IsWhitelistFailOrNull(component.Whitelist, args.Target))
             return;
 
         args.Handled = true;
index c39139f9a57daba0512ef41553ad307c7c76a271..9fdb4a6a804de1686513f14c55bb7e2bbfba4938 100644 (file)
@@ -6,6 +6,7 @@ using Content.Shared.DragDrop;
 using Content.Shared.Emag.Systems;
 using Content.Shared.Item;
 using Content.Shared.Throwing;
+using Content.Shared.Whitelist;
 using Robust.Shared.Audio;
 using Robust.Shared.Physics.Components;
 using Robust.Shared.Physics.Events;
@@ -25,6 +26,7 @@ public abstract class SharedDisposalUnitSystem : EntitySystem
     [Dependency] protected readonly IGameTiming GameTiming = default!;
     [Dependency] protected readonly MetaDataSystem Metadata = default!;
     [Dependency] protected readonly SharedJointSystem Joints = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     protected static TimeSpan ExitAttemptDelay = TimeSpan.FromSeconds(0.5);
 
@@ -113,10 +115,8 @@ public abstract class SharedDisposalUnitSystem : EntitySystem
         if (!storable && !HasComp<BodyComponent>(entity))
             return false;
 
-        if (component.Blacklist?.IsValid(entity, EntityManager) == true)
-            return false;
-
-        if (component.Whitelist != null && component.Whitelist?.IsValid(entity, EntityManager) != true)
+        if (_whitelistSystem.IsBlacklistPass(component.Blacklist, entity) ||
+            _whitelistSystem.IsWhitelistFail(component.Whitelist, entity))
             return false;
 
         if (TryComp<PhysicsComponent>(entity, out var physics) && (physics.CanCollide) || storable)
index d78522b56ccf8dd75532246467ad7e77f373d2a1..44803e721c0db7a303e965fcdf7bf71b23175d70 100644 (file)
@@ -20,6 +20,7 @@ public abstract class SharedImplanterSystem : EntitySystem
     [Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly SharedPopupSystem _popup = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public override void Initialize()
     {
@@ -105,8 +106,8 @@ public abstract class SharedImplanterSystem : EntitySystem
 
     protected bool CheckTarget(EntityUid target, EntityWhitelist? whitelist, EntityWhitelist? blacklist)
     {
-        return whitelist?.IsValid(target, EntityManager) != false &&
-            blacklist?.IsValid(target, EntityManager) != true;
+        return _whitelistSystem.IsWhitelistPassOrNull(whitelist, target) &&
+            _whitelistSystem.IsBlacklistFailOrNull(blacklist, target);
     }
 
     //Draw the implant out of the target
index fb2bc3c46097ac535203eae1ff33076d7fc7717f..bba294db28d2cb3865bbc4a9ef7bd751e9ce5519 100644 (file)
@@ -1,4 +1,4 @@
-using Content.Shared.ActionBlocker;
+using Content.Shared.ActionBlocker;
 using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Hands.Components;
 using Content.Shared.Hands.EntitySystems;
@@ -7,6 +7,7 @@ using Content.Shared.Inventory;
 using Content.Shared.Popups;
 using Content.Shared.Storage;
 using Content.Shared.Storage.EntitySystems;
+using Content.Shared.Whitelist;
 using Robust.Shared.Containers;
 using Robust.Shared.Input.Binding;
 using Robust.Shared.Player;
@@ -25,6 +26,7 @@ public sealed class SmartEquipSystem : EntitySystem
     [Dependency] private readonly SharedContainerSystem _container = default!;
     [Dependency] private readonly SharedPopupSystem _popup = default!;
     [Dependency] private readonly ActionBlockerSystem _actionBlocker = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     /// <inheritdoc/>
     public override void Initialize()
@@ -182,7 +184,7 @@ public sealed class SmartEquipSystem : EntitySystem
             foreach (var slot in slots.Slots.Values)
             {
                 if (!slot.HasItem
-                    && (slot.Whitelist?.IsValid(handItem.Value, EntityManager) ?? true)
+                    && _whitelistSystem.IsWhitelistPassOrNull(slot.Whitelist, handItem.Value)
                     && slot.Priority > (toInsertTo?.Priority ?? int.MinValue))
                 {
                     toInsertTo = slot;
index b1de77d971a0e4b29a9278ca80ec6ee43344f30b..af815bdb2b7fb6bb95b3294d654b4f4e984085b1 100644 (file)
@@ -2,6 +2,7 @@ using System.Linq;
 using Content.Shared.Interaction;
 using Content.Shared.Interaction.Components;
 using Content.Shared.Stacks;
+using Content.Shared.Whitelist;
 using JetBrains.Annotations;
 using Robust.Shared.Prototypes;
 using Robust.Shared.Timing;
@@ -17,6 +18,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
     [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
     [Dependency] private readonly IGameTiming _timing = default!;
     [Dependency] private readonly IPrototypeManager _prototype = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     /// <summary>
     /// Default volume for a sheet if the material's entity prototype has no material composition.
@@ -121,7 +123,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
         if (!CanTakeVolume(uid, volume, component))
             return false;
 
-        if (component.MaterialWhiteList != null && !component.MaterialWhiteList.Contains(materialId))
+        if (component.MaterialWhiteList == null ? false : component.MaterialWhiteList.Contains(materialId))
             return false;
 
         var amount = component.Storage.GetValueOrDefault(materialId);
@@ -239,7 +241,7 @@ public abstract class SharedMaterialStorageSystem : EntitySystem
         if (!Resolve(toInsert, ref material, ref composition, false))
             return false;
 
-        if (storage.Whitelist?.IsValid(toInsert) == false)
+        if (_whitelistSystem.IsWhitelistFail(storage.Whitelist, toInsert))
             return false;
 
         if (HasComp<UnremoveableComponent>(toInsert))
index c1abfc526f5d2d1fc9ec17004aa8b3e144d83851..00096b7d4094db945eab90397e4735524a939336 100644 (file)
@@ -6,6 +6,7 @@ using Content.Shared.Popups;
 using Robust.Shared.Serialization.Manager;
 using Robust.Shared.Prototypes;
 using System.Diagnostics.CodeAnalysis;
+using Content.Shared.Whitelist;
 
 namespace Content.Shared.Polymorph.Systems;
 
@@ -18,6 +19,7 @@ public abstract class SharedChameleonProjectorSystem : EntitySystem
     [Dependency] private readonly IPrototypeManager _proto = default!;
     [Dependency] private readonly ISerializationManager _serMan = default!;
     [Dependency] private readonly SharedPopupSystem _popup = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public override void Initialize()
     {
@@ -49,8 +51,8 @@ public abstract class SharedChameleonProjectorSystem : EntitySystem
     /// </summary>
     public bool IsInvalid(ChameleonProjectorComponent comp, EntityUid target)
     {
-        return (comp.Whitelist?.IsValid(target, EntityManager) == false)
-            || (comp.Blacklist?.IsValid(target, EntityManager) == true);
+        return _whitelistSystem.IsWhitelistFail(comp.Whitelist, target)
+            || _whitelistSystem.IsBlacklistPass(comp.Blacklist, target);
     }
 
     /// <summary>
index b355ae5873037905bb61b6413a8fc5261bd0ed18..f94558b0b30f384b9fbb26a626baf8a39bdfc0c9 100644 (file)
@@ -6,6 +6,7 @@ using Content.Shared.Interaction;
 using Content.Shared.Popups;
 using Content.Shared.Stacks;
 using Content.Shared.Verbs;
+using Content.Shared.Whitelist;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
@@ -30,6 +31,7 @@ public abstract partial class SharedFultonSystem : EntitySystem
     [Dependency] private   readonly SharedPopupSystem _popup = default!;
     [Dependency] private   readonly SharedStackSystem _stack = default!;
     [Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     [ValidatePrototypeId<EntityPrototype>] public const string EffectProto = "FultonEffect";
     protected static readonly Vector2 EffectOffset = Vector2.Zero;
@@ -176,7 +178,7 @@ public abstract partial class SharedFultonSystem : EntitySystem
         if (!CanFulton(targetUid))
             return false;
 
-        if (component.Whitelist?.IsValid(targetUid, EntityManager) != true)
+        if (_whitelistSystem.IsWhitelistFailOrNull(component.Whitelist, targetUid))
             return false;
 
         return true;
index d859d9f4859093f4c8fa70c3f25590a6a66f4f17..a382e943ff946e8b3b4ce1fd5aec128c22c26539 100644 (file)
@@ -2,6 +2,7 @@ using Content.Shared.Containers.ItemSlots;
 using Content.Shared.Shuttles.BUIStates;
 using Content.Shared.Shuttles.Components;
 using Content.Shared.Shuttles.UI.MapObjects;
+using Content.Shared.Whitelist;
 using Robust.Shared.Map;
 using Robust.Shared.Map.Components;
 using Robust.Shared.Physics.Collision.Shapes;
@@ -15,6 +16,7 @@ public abstract partial class SharedShuttleSystem : EntitySystem
     [Dependency] private readonly ItemSlotsSystem _itemSlots = default!;
     [Dependency] protected readonly SharedMapSystem Maps = default!;
     [Dependency] protected readonly SharedTransformSystem XformSystem = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public const float FTLRange = 512f;
     public const float FTLBufferRange = 8f;
@@ -83,7 +85,7 @@ public abstract partial class SharedShuttleSystem : EntitySystem
         if (HasComp<FTLMapComponent>(mapUid))
             return false;
 
-        return destination.Whitelist?.IsValid(shuttleUid, EntityManager) != false;
+        return _whitelistSystem.IsWhitelistPassOrNull(destination.Whitelist, shuttleUid);
     }
 
     /// <summary>
index 03da2d09b0e1f24ff5e9f502b1164a4850b5bf49..7a8961485d6eaaf7bde03303a2ddd2f2aa9da209 100644 (file)
@@ -1,5 +1,6 @@
 using Content.Server.Storage.Components;
 using Content.Shared.Inventory;
+using Content.Shared.Whitelist;
 using Robust.Shared.Map;
 using Robust.Shared.Physics.Components;
 using Robust.Shared.Timing;
@@ -16,6 +17,8 @@ public sealed class MagnetPickupSystem : EntitySystem
     [Dependency] private readonly InventorySystem _inventory = default!;
     [Dependency] private readonly SharedTransformSystem _transform = default!;
     [Dependency] private readonly SharedStorageSystem _storage = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
+
 
     private static readonly TimeSpan ScanDelay = TimeSpan.FromSeconds(1);
 
@@ -63,7 +66,7 @@ public sealed class MagnetPickupSystem : EntitySystem
 
             foreach (var near in _lookup.GetEntitiesInRange(uid, comp.Range, LookupFlags.Dynamic | LookupFlags.Sundries))
             {
-                if (storage.Whitelist?.IsValid(near, EntityManager) == false)
+                if (_whitelistSystem.IsWhitelistFail(storage.Whitelist, near))
                     continue;
 
                 if (!_physicsQuery.TryGetComponent(near, out var physics) || physics.BodyStatus != BodyStatus.OnGround)
index 0576e46df4a2b3776508ca6c210a55886f0c0173..bb49725e04711184a0f48a1303f7a8a3d0807043 100644 (file)
@@ -15,6 +15,7 @@ using Content.Shared.Storage.Components;
 using Content.Shared.Tools.Systems;
 using Content.Shared.Verbs;
 using Content.Shared.Wall;
+using Content.Shared.Whitelist;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
@@ -45,6 +46,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
     [Dependency] protected readonly SharedPopupSystem Popup = default!;
     [Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
     [Dependency] private   readonly WeldableSystem _weldable = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public const string ContainerName = "entity_storage";
 
@@ -432,7 +434,7 @@ public abstract class SharedEntityStorageSystem : EntitySystem
 
         var targetIsMob = HasComp<BodyComponent>(toInsert);
         var storageIsItem = HasComp<ItemComponent>(container);
-        var allowedToEat = component.Whitelist?.IsValid(toInsert) ?? HasComp<ItemComponent>(toInsert);
+        var allowedToEat = component.Whitelist == null ? HasComp<ItemComponent>(toInsert) : _whitelistSystem.IsValid(component.Whitelist, toInsert);
 
         // BEFORE REPLACING THIS WITH, I.E. A PROPERTY:
         // Make absolutely 100% sure you have worked out how to stop people ending up in backpacks.
index ee087901f3ba278caa1f6953c425fc2b30daa9cb..d87b57bfc8dde7d052c90c8ca30c0b9b756612cd 100644 (file)
@@ -55,6 +55,7 @@ public abstract class SharedStorageSystem : EntitySystem
     [Dependency] protected readonly SharedTransformSystem TransformSystem = default!;
     [Dependency] private   readonly SharedUserInterfaceSystem _ui = default!;
     [Dependency] protected readonly UseDelaySystem UseDelay = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     private EntityQuery<ItemComponent> _itemQuery;
     private EntityQuery<StackComponent> _stackQuery;
@@ -860,13 +861,8 @@ public abstract class SharedStorageSystem : EntitySystem
             return false;
         }
 
-        if (storageComp.Whitelist?.IsValid(insertEnt, EntityManager) == false)
-        {
-            reason = "comp-storage-invalid-container";
-            return false;
-        }
-
-        if (storageComp.Blacklist?.IsValid(insertEnt, EntityManager) == true)
+        if (_whitelistSystem.IsWhitelistFail(storageComp.Whitelist, insertEnt) ||
+            _whitelistSystem.IsBlacklistPass(storageComp.Blacklist, insertEnt))
         {
             reason = "comp-storage-invalid-container";
             return false;
index d1814020e6e32e1ac7cbf30c6e170a10c82f022b..eab638a9fc2ac6c54c17ec19a3e2b6d6019b1cf5 100644 (file)
@@ -1,6 +1,7 @@
 using Content.Shared.Damage;
 using Content.Shared.Projectiles;
 using Content.Shared.Weapons.Melee.Events;
+using Content.Shared.Whitelist;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Network;
@@ -15,6 +16,7 @@ public abstract class SharedDamageMarkerSystem : EntitySystem
     [Dependency] private readonly INetManager _netManager = default!;
     [Dependency] private readonly SharedAudioSystem _audio = default!;
     [Dependency] private readonly DamageableSystem _damageable = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     public override void Initialize()
     {
@@ -58,7 +60,7 @@ public abstract class SharedDamageMarkerSystem : EntitySystem
         if (!args.OtherFixture.Hard ||
             args.OurFixtureId != SharedProjectileSystem.ProjectileFixture ||
             component.Amount <= 0 ||
-            component.Whitelist?.IsValid(args.OtherEntity, EntityManager) == false ||
+            _whitelistSystem.IsWhitelistFail(component.Whitelist, args.OtherEntity) ||
             !TryComp<ProjectileComponent>(uid, out var projectile) ||
             projectile.Weapon == null)
         {
index 784dd0793a89e46314850460cd7d306055a906d4..1f9e6cee76aa342390b3693735a7899a67c0c84f 100644 (file)
@@ -41,7 +41,10 @@ public abstract partial class SharedGunSystem
 
     private void OnBallisticInteractUsing(EntityUid uid, BallisticAmmoProviderComponent component, InteractUsingEvent args)
     {
-        if (args.Handled || component.Whitelist?.IsValid(args.Used, EntityManager) != true)
+        if (args.Handled)
+            return;
+
+        if (_whitelistSystem.IsWhitelistFailOrNull(component.Whitelist, args.Used))
             return;
 
         if (GetBallisticShots(component) >= component.Capacity)
index b8b00799c1b09d9bf5cc9a4178c8ce6f342edd12..14aaff5bf70da9df174feb1e437191fad892a715 100644 (file)
@@ -89,7 +89,7 @@ public partial class SharedGunSystem
 
     public bool TryRevolverInsert(EntityUid revolverUid, RevolverAmmoProviderComponent component, EntityUid uid, EntityUid? user)
     {
-        if (component.Whitelist?.IsValid(uid, EntityManager) == false)
+        if (_whitelistSystem.IsWhitelistFail(component.Whitelist, uid))
             return false;
 
         // If it's a speedloader try to get ammo from it.
index 4debc289be1f2ea845cc7173f2c35bedf2359c76..47648a07ad44c4f458a2d2fbbb15aa99e6744c67 100644 (file)
@@ -21,6 +21,7 @@ using Content.Shared.Weapons.Melee;
 using Content.Shared.Weapons.Melee.Events;
 using Content.Shared.Weapons.Ranged.Components;
 using Content.Shared.Weapons.Ranged.Events;
+using Content.Shared.Whitelist;
 using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 using Robust.Shared.Containers;
@@ -63,6 +64,7 @@ public abstract partial class SharedGunSystem : EntitySystem
     [Dependency] protected readonly TagSystem TagSystem = default!;
     [Dependency] protected readonly ThrowingSystem ThrowingSystem = default!;
     [Dependency] private   readonly UseDelaySystem _useDelay = default!;
+    [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!;
 
     private const float InteractNextFire = 0.3f;
     private const double SafetyNextFire = 0.5;
index d73646b7e99e93b6839ac5ffe84d596956500d9f..f311946cf9873705820469d759fe2ca02129bffe 100644 (file)
@@ -60,6 +60,90 @@ public sealed class EntityWhitelistSystem : EntitySystem
 
         return list.RequireAll;
     }
+    /// The following are a list of "helper functions" that are basically the same as each other
+    /// to help make code that uses EntityWhitelist a bit more readable because at the moment
+    /// it is quite clunky having to write out component.Whitelist == null ? true : _whitelist.IsValid(component.Whitelist, uid)
+    /// several times in a row and makes comparisons easier to read
+
+    /// <summary>
+    /// Helper function to determine if Whitelist is not null and entity is on list
+    /// </summary>
+    public bool IsWhitelistPass(EntityWhitelist? whitelist, EntityUid uid)
+    {
+        if (whitelist == null)
+            return false;
+
+        return IsValid(whitelist, uid);
+    }
+
+    /// <summary>
+    /// Helper function to determine if Whitelist is not null and entity is not on the list
+    /// </summary>
+    public bool IsWhitelistFail(EntityWhitelist? whitelist, EntityUid uid)
+    {
+        if (whitelist == null)
+            return false;
+
+        return !IsValid(whitelist, uid);
+    }
+
+    /// <summary>
+    /// Helper function to determine if Whitelist is either null or the entity is on the list
+    /// </summary>
+    public bool IsWhitelistPassOrNull(EntityWhitelist? whitelist, EntityUid uid)
+    {
+        if (whitelist == null)
+            return true;
+
+        return IsValid(whitelist, uid);
+    }
+
+    /// <summary>
+    /// Helper function to determine if Whitelist is either null or the entity is not on the list
+    /// </summary>
+    public bool IsWhitelistFailOrNull(EntityWhitelist? whitelist, EntityUid uid)
+    {
+        if (whitelist == null)
+            return true;
+
+        return !IsValid(whitelist, uid);
+    }
+
+    /// <summary>
+    /// Helper function to determine if Blacklist is not null and entity is on list
+    /// Duplicate of equivalent Whitelist function
+    /// </summary>
+    public bool IsBlacklistPass(EntityWhitelist? blacklist, EntityUid uid)
+    {
+        return IsWhitelistPass(blacklist, uid);
+    }
+
+    /// <summary>
+    /// Helper function to determine if Blacklist is not null and entity is not on the list
+    /// Duplicate of equivalent Whitelist function
+    /// </summary>
+    public bool IsBlacklistFail(EntityWhitelist? blacklist, EntityUid uid)
+    {
+        return IsWhitelistFail(blacklist, uid);
+    }
+
+    /// <summary>
+    /// Helper function to determine if Blacklist is either null or the entity is on the list
+    /// Duplicate of equivalent Whitelist function
+    /// </summary>
+    public bool IsBlacklistPassOrNull(EntityWhitelist? blacklist, EntityUid uid)
+    {
+        return IsWhitelistPassOrNull(blacklist, uid);
+    }
+
+    /// <summary>                                        
+    /// Helper function to determine if Blacklist is either null or the entity is not on the list
+    /// Duplicate of equivalent Whitelist function
+    /// </summary>
+    public bool IsBlacklistFailOrNull(EntityWhitelist? blacklist, EntityUid uid)
+    {
+        return IsWhitelistFailOrNull(blacklist, uid);
+    }
 
     private void EnsureRegistrations(EntityWhitelist list)
     {