Skip to content

Commit

Permalink
Replace obsolete EntityWhitelist IsValid usages (#28465)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
Plykiya and plykiya authored Jun 2, 2024
1 parent dce68e4 commit d6ba166
Show file tree
Hide file tree
Showing 31 changed files with 186 additions and 56 deletions.
9 changes: 6 additions & 3 deletions Content.Client/Chat/UI/EmotesMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand All @@ -28,6 +30,7 @@ public EmotesMenu()
RobustXamlLoader.Load(this);

_spriteSystem = _entManager.System<SpriteSystem>();
_whitelistSystem = _entManager.System<EntityWhitelistSystem>();

var main = FindControl<RadialContainer>("Main");

Expand All @@ -37,8 +40,8 @@ public EmotesMenu()
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 &&
Expand Down
6 changes: 5 additions & 1 deletion Content.Client/Construction/UI/ConstructionMenuPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
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;
Expand All @@ -23,13 +24,15 @@ 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!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

private readonly IConstructionMenuView _constructionView;
private readonly EntityWhitelistSystem _whitelistSystem;

private ConstructionSystem? _constructionSystem;
private ConstructionPrototype? _selected;
Expand Down Expand Up @@ -78,6 +81,7 @@ public ConstructionMenuPresenter()
// 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))
Expand Down Expand Up @@ -157,7 +161,7 @@ private void OnViewPopulateRecipes(object? sender, (string search, string catago

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))
Expand Down
4 changes: 1 addition & 3 deletions Content.Server/Chat/Systems/ChatSystem.Emote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ public void TryEmoteWithChat(
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 &&
Expand Down
2 changes: 2 additions & 0 deletions Content.Server/Chat/Systems/ChatSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions Content.Server/Gatherable/GatherableSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand All @@ -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()
{
Expand All @@ -30,7 +32,7 @@ public override void Initialize()

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);
Expand All @@ -41,7 +43,7 @@ private void OnActivate(Entity<GatherableComponent> gatherable, ref ActivateInWo
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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()
{
Expand All @@ -27,7 +29,7 @@ private void OnMapInit(Entity<NPCImprintingOnSpawnBehaviourComponent> imprinting

foreach (var friend in friends)
{
if (imprinting.Comp.Whitelist?.IsValid(friend) != false)
if (_whitelistSystem.IsWhitelistPassOrNull(imprinting.Comp.Whitelist, friend))
{
AddImprintingTarget(imprinting, friend, imprinting.Comp);
}
Expand Down
4 changes: 3 additions & 1 deletion Content.Server/NPC/Systems/NPCUtilitySystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -249,7 +251,7 @@ private float GetScore(NPCBlackboard blackboard, EntityUid targetUid, UtilityCon
return 0f;
}

if (heldGun.Whitelist?.IsValid(targetUid, EntityManager) != true)
if (_whitelistSystem.IsWhitelistFailOrNull(heldGun.Whitelist, targetUid))
{
return 0f;
}
Expand Down
4 changes: 3 additions & 1 deletion Content.Server/Power/EntitySystems/ChargerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System.Diagnostics.CodeAnalysis;
using Content.Shared.Storage.Components;
using Robust.Server.Containers;
using Content.Shared.Whitelist;

namespace Content.Server.Power.EntitySystems;

Expand All @@ -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()
{
Expand Down Expand Up @@ -208,7 +210,7 @@ private void TransferPower(EntityUid uid, EntityUid targetEntity, ChargerCompone
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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using Robust.Shared.Physics.Components;
using Robust.Shared.Utility;
using Robust.Shared.Map.Components;
using Content.Shared.Whitelist;

namespace Content.Server.Revenant.EntitySystems;

Expand All @@ -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()
{
Expand Down Expand Up @@ -331,10 +333,8 @@ private void OnMalfunctionAction(EntityUid uid, RevenantComponent component, Rev

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.
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Silicons/Borgs/BorgSystem.Modules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public bool CanInsertModule(EntityUid uid, EntityUid module, BorgChassisComponen
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);
Expand Down
8 changes: 5 additions & 3 deletions Content.Server/Silicons/Borgs/BorgSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
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;
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -104,9 +107,8 @@ private void OnChassisInteractUsing(EntityUid uid, BorgChassisComponent componen
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)
{
Expand Down
6 changes: 4 additions & 2 deletions Content.Server/Storage/EntitySystems/PickRandomSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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;

Expand All @@ -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()
{
Expand All @@ -30,7 +32,7 @@ private void OnGetAlternativeVerbs(EntityUid uid, PickRandomComponent comp, GetV

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
Expand All @@ -48,7 +50,7 @@ private void OnGetAlternativeVerbs(EntityUid uid, PickRandomComponent comp, GetV

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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -81,7 +82,8 @@ private int GetValidNodeId()
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);
Expand All @@ -95,7 +97,8 @@ private string GetRandomTrigger(EntityUid artifact, ref ArtifactNode node)
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);
Expand Down
5 changes: 3 additions & 2 deletions Content.Shared/Containers/ItemSlot/ItemSlotsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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;
Expand All @@ -31,6 +32,7 @@ public sealed class ItemSlotsSystem : EntitySystem
[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()
{
Expand Down Expand Up @@ -266,8 +268,7 @@ public bool CanInsert(EntityUid uid, EntityUid usedUid, EntityUid? user, ItemSlo
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);
Expand Down
Loading

0 comments on commit d6ba166

Please sign in to comment.