From d05cb8addd7c2d46ab50791168394694d099e6d9 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Fri, 10 May 2024 08:13:48 +0100 Subject: [PATCH 01/20] prevent borgs from using locks --- Content.Shared/Lock/LockSystem.cs | 1 + Content.Shared/Silicons/Borgs/SharedBorgSystem.cs | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/Content.Shared/Lock/LockSystem.cs b/Content.Shared/Lock/LockSystem.cs index 54f5d801ea0c..e620f5541219 100644 --- a/Content.Shared/Lock/LockSystem.cs +++ b/Content.Shared/Lock/LockSystem.cs @@ -224,6 +224,7 @@ public bool CanToggleLock(EntityUid uid, EntityUid user, bool quiet = true) var ev = new LockToggleAttemptEvent(user, quiet); RaiseLocalEvent(uid, ref ev, true); + RaiseLocalEvent(user, ref ev, true); return !ev.Cancelled; } diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index 0431d95a42f8..7cda5d34e1af 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -30,6 +30,7 @@ public override void Initialize() SubscribeLocalEvent(OnInserted); SubscribeLocalEvent(OnRemoved); SubscribeLocalEvent(OnRefreshMovementSpeedModifiers); + SubscribeLocalEvent(OnLockToggleAttempt); InitializeRelay(); } @@ -96,4 +97,11 @@ private void OnRefreshMovementSpeedModifiers(EntityUid uid, BorgChassisComponent var sprintDif = movement.BaseWalkSpeed / movement.BaseSprintSpeed; args.ModifySpeed(1f, sprintDif); } + + private void OnLockToggleAttempt(Entity ent, ref LockToggleAttempt args) + { + // prevent cyborgs unlocking things, even though they have HandsComponent + if (args.User == ent) + args.Cancelled = true; + } } From 412628ca3f4758854414e53715e4a694e023a053 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Fri, 10 May 2024 09:58:48 +0100 Subject: [PATCH 02/20] e --- Content.Shared/Silicons/Borgs/SharedBorgSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index 7cda5d34e1af..8217f949bc82 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -30,7 +30,7 @@ public override void Initialize() SubscribeLocalEvent(OnInserted); SubscribeLocalEvent(OnRemoved); SubscribeLocalEvent(OnRefreshMovementSpeedModifiers); - SubscribeLocalEvent(OnLockToggleAttempt); + SubscribeLocalEvent(OnLockToggleAttempt); InitializeRelay(); } From 21af7ae712351d569ec2151f100fb8f673cb5d00 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Fri, 10 May 2024 14:07:33 +0100 Subject: [PATCH 03/20] bru --- Content.Shared/Silicons/Borgs/SharedBorgSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index 8217f949bc82..49812dab478c 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -98,7 +98,7 @@ private void OnRefreshMovementSpeedModifiers(EntityUid uid, BorgChassisComponent args.ModifySpeed(1f, sprintDif); } - private void OnLockToggleAttempt(Entity ent, ref LockToggleAttempt args) + private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) { // prevent cyborgs unlocking things, even though they have HandsComponent if (args.User == ent) From dca5dde88ab6b90d9daa4a05f696419771c9de18 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Fri, 10 May 2024 14:16:11 +0100 Subject: [PATCH 04/20] a --- Content.Shared/Silicons/Borgs/SharedBorgSystem.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index 49812dab478c..865b03390e1b 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -1,5 +1,6 @@ using Content.Shared.Access.Components; using Content.Shared.Containers.ItemSlots; +using Content.Shared.Lock; using Content.Shared.Movement.Components; using Content.Shared.Movement.Systems; using Content.Shared.Popups; @@ -101,7 +102,7 @@ private void OnRefreshMovementSpeedModifiers(EntityUid uid, BorgChassisComponent private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) { // prevent cyborgs unlocking things, even though they have HandsComponent - if (args.User == ent) + if (args.User == ent.Owner) args.Cancelled = true; } } From c45612d69d8522c88a13c990d9d4c67c0ce1c04c Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Fri, 10 May 2024 16:21:26 +0100 Subject: [PATCH 05/20] blacklist borgs and robotics console --- .../Silicons/Borgs/Components/BorgChassisComponent.cs | 6 ++++++ Content.Shared/Silicons/Borgs/SharedBorgSystem.cs | 5 +++-- .../Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Content.Shared/Silicons/Borgs/Components/BorgChassisComponent.cs b/Content.Shared/Silicons/Borgs/Components/BorgChassisComponent.cs index 71d3a7bd166c..9cf968cb1fa5 100644 --- a/Content.Shared/Silicons/Borgs/Components/BorgChassisComponent.cs +++ b/Content.Shared/Silicons/Borgs/Components/BorgChassisComponent.cs @@ -19,6 +19,12 @@ public sealed partial class BorgChassisComponent : Component [DataField("activated"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] public bool Activated; + /// + /// Things the borg is not allowed to lock or unlock. + /// + [DataField] + public EntityWhitelist? LockBlacklist; + #region Brain /// /// A whitelist for which entities count as valid brains diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index 865b03390e1b..8e834d014785 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -19,6 +19,7 @@ public abstract partial class SharedBorgSystem : EntitySystem [Dependency] protected readonly SharedContainerSystem Container = default!; [Dependency] protected readonly ItemSlotsSystem ItemSlots = default!; [Dependency] protected readonly SharedPopupSystem Popup = default!; + [Dependency] private readonly EntityWhitelistSystem _whitelist = default!; /// public override void Initialize() @@ -101,8 +102,8 @@ private void OnRefreshMovementSpeedModifiers(EntityUid uid, BorgChassisComponent private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) { - // prevent cyborgs unlocking things, even though they have HandsComponent - if (args.User == ent.Owner) + // prevent locking blacklist things when borg is the one doing the locking + if (args.User == ent.Owner && _whitelist.IsValid(ent.Comp.LockBlacklist, ent) == true) args.Cancelled = true; } } diff --git a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml index 187aeae2650a..d85b4de4e399 100644 --- a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml +++ b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml @@ -100,6 +100,10 @@ doAfterDelay: 10 allowSelfRepair: false - type: BorgChassis + lockBlacklist: + components: + - BorgChassis + - RoboticsConsole - type: WiresPanel - type: ActivatableUIRequiresPanel - type: NameIdentifier From e701d5faa9400c15758729efd70f76bf316b7d5e Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Fri, 10 May 2024 16:24:22 +0100 Subject: [PATCH 06/20] frogro --- Content.Shared/Silicons/Borgs/SharedBorgSystem.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index 8e834d014785..406fbc187cd5 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -6,6 +6,7 @@ using Content.Shared.Popups; using Content.Shared.PowerCell.Components; using Content.Shared.Silicons.Borgs.Components; +using Content.Shared.Whitelist; using Content.Shared.Wires; using Robust.Shared.Containers; From eb843cd6827c78533f7e380e6a33a64dc2e0a5ec Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Fri, 10 May 2024 16:44:21 +0100 Subject: [PATCH 07/20] add IsAllowed to EntityWhitelistSystem --- .../Whitelist/EntityWhitelistSystem.cs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Content.Shared/Whitelist/EntityWhitelistSystem.cs b/Content.Shared/Whitelist/EntityWhitelistSystem.cs index d73646b7e99e..7c654cd33a07 100644 --- a/Content.Shared/Whitelist/EntityWhitelistSystem.cs +++ b/Content.Shared/Whitelist/EntityWhitelistSystem.cs @@ -23,6 +23,42 @@ public bool IsValid(EntityWhitelist list, [NotNullWhen(true)] EntityUid? uid) return uid != null && IsValid(list, uid.Value); } + /// + /// Checks whether a given entity satisfies a whitelist. + /// If the whitelist is null it returns null. + /// + public bool? Match(EntityWhitelist? list, [NotNullWhen(true)] EntityUid? uid) + { + if (list == null) + return null; + + return IsValid(list, uid); + } + + /// + /// Checks whether a given entity is allowed by a whitelist and not blocked by a blacklist. + /// If a blacklist is provided and it matches then this returns false. + /// If a whitelist is provided and it does not match then this returns false. + /// If either list is null it does not get checked. + /// + public bool IsAllowed([NotNullWhen(true)] EntityUid? uid, EntityWhitelist? blacklist = null, EntityWhitelist? whitelist = null) + { + if (uid == null) + return false; + + return Match(blacklist, uid) != true + && Match(whitelist, uid) != false; + } + + /// + /// Checks whether a given entity is on a blacklist. + /// If the blacklist is null it cannot be on it, so it returns false. + /// + public bool IsBlacklisted(EntityWhitelist? list, EntityUid? uid) + { + return Match(list, uid) != true; + } + /// /// Checks whether a given entity satisfies a whitelist. /// From aec924490053a6fbdb67eb816e7e2ad6d54956a0 Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Fri, 10 May 2024 16:44:26 +0100 Subject: [PATCH 08/20] use IsAllowed --- Content.Shared/Silicons/Borgs/SharedBorgSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index 406fbc187cd5..c9e3b7a048b3 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -104,7 +104,7 @@ private void OnRefreshMovementSpeedModifiers(EntityUid uid, BorgChassisComponent private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) { // prevent locking blacklist things when borg is the one doing the locking - if (args.User == ent.Owner && _whitelist.IsValid(ent.Comp.LockBlacklist, ent) == true) + if (args.User == ent.Owner && !_whitelist.IsAllowed(ent, blacklist: ent.Comp.LockBlacklist)) args.Cancelled = true; } } From 9e8f106e4f61471e3f54327432968541c27dc87f Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Fri, 10 May 2024 17:39:05 +0100 Subject: [PATCH 09/20] move thing to new LockingWhitelistSystem --- .../Lock/LockingWhitelistComponent.cs | 16 ++++++++++++++ Content.Shared/Lock/LockingWhitelistSystem.cs | 21 +++++++++++++++++++ .../Silicons/Borgs/SharedBorgSystem.cs | 10 --------- .../Mobs/Cyborgs/base_borg_chassis.yml | 3 ++- 4 files changed, 39 insertions(+), 11 deletions(-) create mode 100644 Content.Shared/Lock/LockingWhitelistComponent.cs create mode 100644 Content.Shared/Lock/LockingWhitelistSystem.cs diff --git a/Content.Shared/Lock/LockingWhitelistComponent.cs b/Content.Shared/Lock/LockingWhitelistComponent.cs new file mode 100644 index 000000000000..205ce2873ab1 --- /dev/null +++ b/Content.Shared/Lock/LockingWhitelistComponent.cs @@ -0,0 +1,16 @@ +using Content.Shared.Whitelist; + +namespace Content.Shared.Lock; + +/// +/// Adds whitelist and blacklist for this mob to lock things. +/// +[RegisterComponent, NetworkedComponent, Access(typeof(LockingWhitelistSystem))] +public sealed partial class LockingWhitelistComponent : Component +{ + [DataField] + public EntityWhitelist? Whitelist; + + [DataField] + public EntityWhitelist? Blacklist; +} diff --git a/Content.Shared/Lock/LockingWhitelistSystem.cs b/Content.Shared/Lock/LockingWhitelistSystem.cs new file mode 100644 index 000000000000..2ca430422ef4 --- /dev/null +++ b/Content.Shared/Lock/LockingWhitelistSystem.cs @@ -0,0 +1,21 @@ +using Content.Shared.Whitelist; + +namespace Content.Shared.Lock; + +public sealed class LockingWhitelistSystem : EntitySystem +{ + [Dependency] private readonly EntityWhitelistSystem _whitelist = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent(OnLockToggleAttempt); + } + + private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) + { + if (args.User == ent.Owner && !_whitelist.IsAllowed(ent, ent.Comp.Blacklist, ent.Comp.Whitelist)) + args.Cancelled = true; + } +} diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index c9e3b7a048b3..5ed5fb62b4db 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -6,7 +6,6 @@ using Content.Shared.Popups; using Content.Shared.PowerCell.Components; using Content.Shared.Silicons.Borgs.Components; -using Content.Shared.Whitelist; using Content.Shared.Wires; using Robust.Shared.Containers; @@ -20,7 +19,6 @@ public abstract partial class SharedBorgSystem : EntitySystem [Dependency] protected readonly SharedContainerSystem Container = default!; [Dependency] protected readonly ItemSlotsSystem ItemSlots = default!; [Dependency] protected readonly SharedPopupSystem Popup = default!; - [Dependency] private readonly EntityWhitelistSystem _whitelist = default!; /// public override void Initialize() @@ -33,7 +31,6 @@ public override void Initialize() SubscribeLocalEvent(OnInserted); SubscribeLocalEvent(OnRemoved); SubscribeLocalEvent(OnRefreshMovementSpeedModifiers); - SubscribeLocalEvent(OnLockToggleAttempt); InitializeRelay(); } @@ -100,11 +97,4 @@ private void OnRefreshMovementSpeedModifiers(EntityUid uid, BorgChassisComponent var sprintDif = movement.BaseWalkSpeed / movement.BaseSprintSpeed; args.ModifySpeed(1f, sprintDif); } - - private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) - { - // prevent locking blacklist things when borg is the one doing the locking - if (args.User == ent.Owner && !_whitelist.IsAllowed(ent, blacklist: ent.Comp.LockBlacklist)) - args.Cancelled = true; - } } diff --git a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml index d85b4de4e399..174e5125ce97 100644 --- a/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml +++ b/Resources/Prototypes/Entities/Mobs/Cyborgs/base_borg_chassis.yml @@ -100,7 +100,8 @@ doAfterDelay: 10 allowSelfRepair: false - type: BorgChassis - lockBlacklist: + - type: LockingWhitelist + blacklist: components: - BorgChassis - RoboticsConsole From d36490e9a9665ad16ed9044be8aa8aae5057a97d Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 11 May 2024 08:49:06 +0100 Subject: [PATCH 10/20] :trollface: --- Content.Shared/Lock/LockingWhitelistComponent.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Content.Shared/Lock/LockingWhitelistComponent.cs b/Content.Shared/Lock/LockingWhitelistComponent.cs index 205ce2873ab1..57f623d8d157 100644 --- a/Content.Shared/Lock/LockingWhitelistComponent.cs +++ b/Content.Shared/Lock/LockingWhitelistComponent.cs @@ -1,4 +1,5 @@ using Content.Shared.Whitelist; +using Robust.Shared.GameStates; namespace Content.Shared.Lock; From fea83be8dfb02948825dc73c65c173a89cc4e02e Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 11 May 2024 16:08:34 +0100 Subject: [PATCH 11/20] review --- .../Whitelist/EntityWhitelistSystem.cs | 27 +++---------------- 1 file changed, 4 insertions(+), 23 deletions(-) diff --git a/Content.Shared/Whitelist/EntityWhitelistSystem.cs b/Content.Shared/Whitelist/EntityWhitelistSystem.cs index 7c654cd33a07..d45557895896 100644 --- a/Content.Shared/Whitelist/EntityWhitelistSystem.cs +++ b/Content.Shared/Whitelist/EntityWhitelistSystem.cs @@ -23,40 +23,21 @@ public bool IsValid(EntityWhitelist list, [NotNullWhen(true)] EntityUid? uid) return uid != null && IsValid(list, uid.Value); } - /// - /// Checks whether a given entity satisfies a whitelist. - /// If the whitelist is null it returns null. - /// - public bool? Match(EntityWhitelist? list, [NotNullWhen(true)] EntityUid? uid) - { - if (list == null) - return null; - - return IsValid(list, uid); - } - /// /// Checks whether a given entity is allowed by a whitelist and not blocked by a blacklist. /// If a blacklist is provided and it matches then this returns false. /// If a whitelist is provided and it does not match then this returns false. /// If either list is null it does not get checked. /// - public bool IsAllowed([NotNullWhen(true)] EntityUid? uid, EntityWhitelist? blacklist = null, EntityWhitelist? whitelist = null) + public bool CheckBoth([NotNullWhen(true)] EntityUid? uid, EntityWhitelist? blacklist = null, EntityWhitelist? whitelist = null) { if (uid == null) return false; - return Match(blacklist, uid) != true - && Match(whitelist, uid) != false; - } + if (blacklist != null && IsValid(blacklist, uid)) + return false; - /// - /// Checks whether a given entity is on a blacklist. - /// If the blacklist is null it cannot be on it, so it returns false. - /// - public bool IsBlacklisted(EntityWhitelist? list, EntityUid? uid) - { - return Match(list, uid) != true; + return whitelist == null || IsValid(whitelist, uid); } /// From f5d90b3a7e577db85095f3e68d644761663d4dee Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 11 May 2024 16:09:12 +0100 Subject: [PATCH 12/20] use renamed CheckBoth in locking whitelist --- Content.Shared/Lock/LockingWhitelistSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Lock/LockingWhitelistSystem.cs b/Content.Shared/Lock/LockingWhitelistSystem.cs index 2ca430422ef4..83986a009994 100644 --- a/Content.Shared/Lock/LockingWhitelistSystem.cs +++ b/Content.Shared/Lock/LockingWhitelistSystem.cs @@ -15,7 +15,7 @@ public override void Initialize() private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) { - if (args.User == ent.Owner && !_whitelist.IsAllowed(ent, ent.Comp.Blacklist, ent.Comp.Whitelist)) + if (args.User == ent.Owner && !_whitelist.CheckBoth(ent, ent.Comp.Blacklist, ent.Comp.Whitelist)) args.Cancelled = true; } } From c36bf43e57fd1395c8eb6fc2de62c1d85c55b6fe Mon Sep 17 00:00:00 2001 From: deltanedas <@deltanedas:kde.org> Date: Sat, 11 May 2024 16:26:38 +0100 Subject: [PATCH 13/20] remove unused stuff and add more to doc --- Content.Shared/Lock/LockingWhitelistComponent.cs | 1 + .../Silicons/Borgs/Components/BorgChassisComponent.cs | 6 ------ Content.Shared/Silicons/Borgs/SharedBorgSystem.cs | 1 - 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/Content.Shared/Lock/LockingWhitelistComponent.cs b/Content.Shared/Lock/LockingWhitelistComponent.cs index 57f623d8d157..4ac832e43843 100644 --- a/Content.Shared/Lock/LockingWhitelistComponent.cs +++ b/Content.Shared/Lock/LockingWhitelistComponent.cs @@ -5,6 +5,7 @@ namespace Content.Shared.Lock; /// /// Adds whitelist and blacklist for this mob to lock things. +/// The whitelist and blacklist are checked against the object being locked, not the mob. /// [RegisterComponent, NetworkedComponent, Access(typeof(LockingWhitelistSystem))] public sealed partial class LockingWhitelistComponent : Component diff --git a/Content.Shared/Silicons/Borgs/Components/BorgChassisComponent.cs b/Content.Shared/Silicons/Borgs/Components/BorgChassisComponent.cs index 9cf968cb1fa5..71d3a7bd166c 100644 --- a/Content.Shared/Silicons/Borgs/Components/BorgChassisComponent.cs +++ b/Content.Shared/Silicons/Borgs/Components/BorgChassisComponent.cs @@ -19,12 +19,6 @@ public sealed partial class BorgChassisComponent : Component [DataField("activated"), ViewVariables(VVAccess.ReadWrite), AutoNetworkedField] public bool Activated; - /// - /// Things the borg is not allowed to lock or unlock. - /// - [DataField] - public EntityWhitelist? LockBlacklist; - #region Brain /// /// A whitelist for which entities count as valid brains diff --git a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs index 5ed5fb62b4db..0431d95a42f8 100644 --- a/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs +++ b/Content.Shared/Silicons/Borgs/SharedBorgSystem.cs @@ -1,6 +1,5 @@ using Content.Shared.Access.Components; using Content.Shared.Containers.ItemSlots; -using Content.Shared.Lock; using Content.Shared.Movement.Components; using Content.Shared.Movement.Systems; using Content.Shared.Popups; From 64b5a316dc321de8f2e14a9652883047ee4606ae Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 13:20:58 -0700 Subject: [PATCH 14/20] Use target entity instead to remove self check --- Content.Shared/Lock/LockComponent.cs | 2 +- Content.Shared/Lock/LockSystem.cs | 3 +-- Content.Shared/Lock/LockingWhitelistSystem.cs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Content.Shared/Lock/LockComponent.cs b/Content.Shared/Lock/LockComponent.cs index e3e2bc6df133..bb060362111e 100644 --- a/Content.Shared/Lock/LockComponent.cs +++ b/Content.Shared/Lock/LockComponent.cs @@ -84,7 +84,7 @@ public sealed partial class LockComponent : Component /// Can be cancelled to prevent it. /// [ByRefEvent] -public record struct LockToggleAttemptEvent(EntityUid User, bool Silent = false, bool Cancelled = false); +public record struct LockToggleAttemptEvent(EntityUid User, EntityUid Target, bool Silent = false, bool Cancelled = false); /// /// Event raised on a lock after it has been toggled. diff --git a/Content.Shared/Lock/LockSystem.cs b/Content.Shared/Lock/LockSystem.cs index 4fca4d68f20d..95c376355441 100644 --- a/Content.Shared/Lock/LockSystem.cs +++ b/Content.Shared/Lock/LockSystem.cs @@ -230,7 +230,7 @@ public bool CanToggleLock(EntityUid uid, EntityUid user, bool quiet = true) if (!HasComp(user)) return false; - var ev = new LockToggleAttemptEvent(user, quiet); + var ev = new LockToggleAttemptEvent(user, uid, quiet); RaiseLocalEvent(uid, ref ev, true); RaiseLocalEvent(user, ref ev, true); return !ev.Cancelled; @@ -377,4 +377,3 @@ private void LockToggled(EntityUid uid, ActivatableUIRequiresLockComponent compo _activatableUI.CloseAll(uid); } } - diff --git a/Content.Shared/Lock/LockingWhitelistSystem.cs b/Content.Shared/Lock/LockingWhitelistSystem.cs index 83986a009994..2edb05ae15e2 100644 --- a/Content.Shared/Lock/LockingWhitelistSystem.cs +++ b/Content.Shared/Lock/LockingWhitelistSystem.cs @@ -15,7 +15,7 @@ public override void Initialize() private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) { - if (args.User == ent.Owner && !_whitelist.CheckBoth(ent, ent.Comp.Blacklist, ent.Comp.Whitelist)) + if (!_whitelist.CheckBoth(args.Target, ent.Comp.Blacklist, ent.Comp.Whitelist)) args.Cancelled = true; } } From 12e7c834c6ec0b1fb3166b1a768d3c3bd4d60d61 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 13:21:43 -0700 Subject: [PATCH 15/20] Rename to _whitelistSystem --- Content.Shared/Lock/LockingWhitelistSystem.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Content.Shared/Lock/LockingWhitelistSystem.cs b/Content.Shared/Lock/LockingWhitelistSystem.cs index 2edb05ae15e2..8fe53e6a2a0b 100644 --- a/Content.Shared/Lock/LockingWhitelistSystem.cs +++ b/Content.Shared/Lock/LockingWhitelistSystem.cs @@ -4,7 +4,7 @@ namespace Content.Shared.Lock; public sealed class LockingWhitelistSystem : EntitySystem { - [Dependency] private readonly EntityWhitelistSystem _whitelist = default!; + [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; public override void Initialize() { @@ -15,7 +15,7 @@ public override void Initialize() private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) { - if (!_whitelist.CheckBoth(args.Target, ent.Comp.Blacklist, ent.Comp.Whitelist)) + if (!_whitelistSystem.CheckBoth(args.Target, ent.Comp.Blacklist, ent.Comp.Whitelist)) args.Cancelled = true; } } From 97aeac7ebf52c79cf21638fa9b7c28ec51747efe Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 13:26:45 -0700 Subject: [PATCH 16/20] Add deny lock toggle popup --- Content.Shared/Lock/LockingWhitelistSystem.cs | 11 +++++++++-- .../Locale/en-US/lock/locking-whitelist-component.ftl | 1 + 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 Resources/Locale/en-US/lock/locking-whitelist-component.ftl diff --git a/Content.Shared/Lock/LockingWhitelistSystem.cs b/Content.Shared/Lock/LockingWhitelistSystem.cs index 8fe53e6a2a0b..f74bbe439185 100644 --- a/Content.Shared/Lock/LockingWhitelistSystem.cs +++ b/Content.Shared/Lock/LockingWhitelistSystem.cs @@ -1,3 +1,4 @@ +using Content.Shared.Popups; using Content.Shared.Whitelist; namespace Content.Shared.Lock; @@ -5,6 +6,7 @@ namespace Content.Shared.Lock; public sealed class LockingWhitelistSystem : EntitySystem { [Dependency] private readonly EntityWhitelistSystem _whitelistSystem = default!; + [Dependency] private readonly SharedPopupSystem _popupSystem = default!; public override void Initialize() { @@ -15,7 +17,12 @@ public override void Initialize() private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) { - if (!_whitelistSystem.CheckBoth(args.Target, ent.Comp.Blacklist, ent.Comp.Whitelist)) - args.Cancelled = true; + if (_whitelistSystem.CheckBoth(args.Target, ent.Comp.Blacklist, ent.Comp.Whitelist)) + return; + + if (!args.Silent) + _popupSystem.PopupClient(Loc.GetString("locking-whitelist-component-lock-toggle-deny"), ent.Owner); + + args.Cancelled = true; } } diff --git a/Resources/Locale/en-US/lock/locking-whitelist-component.ftl b/Resources/Locale/en-US/lock/locking-whitelist-component.ftl new file mode 100644 index 000000000000..182814c2c56d --- /dev/null +++ b/Resources/Locale/en-US/lock/locking-whitelist-component.ftl @@ -0,0 +1 @@ +locking-whitelist-component-lock-toggle-deny = You can't toggle the lock. From 53b9c9e498bc4b5e5492f308569818b7993a4af4 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 13:27:12 -0700 Subject: [PATCH 17/20] Prevent duplicate checks and popups --- Content.Shared/Lock/LockSystem.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Content.Shared/Lock/LockSystem.cs b/Content.Shared/Lock/LockSystem.cs index 95c376355441..17b26c6e8eb2 100644 --- a/Content.Shared/Lock/LockSystem.cs +++ b/Content.Shared/Lock/LockSystem.cs @@ -232,6 +232,8 @@ public bool CanToggleLock(EntityUid uid, EntityUid user, bool quiet = true) var ev = new LockToggleAttemptEvent(user, uid, quiet); RaiseLocalEvent(uid, ref ev, true); + if (ev.Cancelled) + return false; RaiseLocalEvent(user, ref ev, true); return !ev.Cancelled; } From 6a962ace79098778625454e7d52fdb5911ec2618 Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 14:15:38 -0700 Subject: [PATCH 18/20] Fix wrong entity in popup when toggling another borg --- Content.Shared/Lock/LockingWhitelistSystem.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Lock/LockingWhitelistSystem.cs b/Content.Shared/Lock/LockingWhitelistSystem.cs index f74bbe439185..b49f87c6853a 100644 --- a/Content.Shared/Lock/LockingWhitelistSystem.cs +++ b/Content.Shared/Lock/LockingWhitelistSystem.cs @@ -21,7 +21,7 @@ private void OnLockToggleAttempt(Entity ent, ref Lock return; if (!args.Silent) - _popupSystem.PopupClient(Loc.GetString("locking-whitelist-component-lock-toggle-deny"), ent.Owner); + _popupSystem.PopupClient(Loc.GetString("locking-whitelist-component-lock-toggle-deny"), args.User); args.Cancelled = true; } From d26d799ed8ac60905c46e483382ebb2300ce48ee Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 14:39:47 -0700 Subject: [PATCH 19/20] Make new event --- Content.Shared/Lock/LockComponent.cs | 9 ++++++++- Content.Shared/Lock/LockSystem.cs | 8 +++++--- Content.Shared/Lock/LockingWhitelistSystem.cs | 6 +++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Content.Shared/Lock/LockComponent.cs b/Content.Shared/Lock/LockComponent.cs index bb060362111e..bdfc546dc870 100644 --- a/Content.Shared/Lock/LockComponent.cs +++ b/Content.Shared/Lock/LockComponent.cs @@ -84,7 +84,14 @@ public sealed partial class LockComponent : Component /// Can be cancelled to prevent it. /// [ByRefEvent] -public record struct LockToggleAttemptEvent(EntityUid User, EntityUid Target, bool Silent = false, bool Cancelled = false); +public record struct LockToggleAttemptEvent(EntityUid User, bool Silent = false, bool Cancelled = false); + +/// +/// Event raised on the lock when a toggle is attempted. +/// Can be cancelled to prevent it. +/// +[ByRefEvent] +public record struct UserLockToggleAttemptEvent(EntityUid Target, bool Silent = false, bool Cancelled = false); /// /// Event raised on a lock after it has been toggled. diff --git a/Content.Shared/Lock/LockSystem.cs b/Content.Shared/Lock/LockSystem.cs index 17b26c6e8eb2..d767cb2eda89 100644 --- a/Content.Shared/Lock/LockSystem.cs +++ b/Content.Shared/Lock/LockSystem.cs @@ -230,12 +230,14 @@ public bool CanToggleLock(EntityUid uid, EntityUid user, bool quiet = true) if (!HasComp(user)) return false; - var ev = new LockToggleAttemptEvent(user, uid, quiet); + var ev = new LockToggleAttemptEvent(user, quiet); RaiseLocalEvent(uid, ref ev, true); if (ev.Cancelled) return false; - RaiseLocalEvent(user, ref ev, true); - return !ev.Cancelled; + + var userEv = new UserLockToggleAttemptEvent(uid, quiet); + RaiseLocalEvent(user, ref userEv, true); + return !userEv.Cancelled; } private bool HasUserAccess(EntityUid uid, EntityUid user, AccessReaderComponent? reader = null, bool quiet = true) diff --git a/Content.Shared/Lock/LockingWhitelistSystem.cs b/Content.Shared/Lock/LockingWhitelistSystem.cs index b49f87c6853a..ba495fba905f 100644 --- a/Content.Shared/Lock/LockingWhitelistSystem.cs +++ b/Content.Shared/Lock/LockingWhitelistSystem.cs @@ -12,16 +12,16 @@ public override void Initialize() { base.Initialize(); - SubscribeLocalEvent(OnLockToggleAttempt); + SubscribeLocalEvent(OnUserLockToggleAttempt); } - private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) + private void OnUserLockToggleAttempt(Entity ent, ref UserLockToggleAttemptEvent args) { if (_whitelistSystem.CheckBoth(args.Target, ent.Comp.Blacklist, ent.Comp.Whitelist)) return; if (!args.Silent) - _popupSystem.PopupClient(Loc.GetString("locking-whitelist-component-lock-toggle-deny"), args.User); + _popupSystem.PopupClient(Loc.GetString("locking-whitelist-component-lock-toggle-deny"), ent.Owner); args.Cancelled = true; } From 8b45b0579822f007f49f6c75acc58461672abade Mon Sep 17 00:00:00 2001 From: ShadowCommander <10494922+ShadowCommander@users.noreply.github.com> Date: Wed, 29 May 2024 15:02:56 -0700 Subject: [PATCH 20/20] Update comment to user for new event --- Content.Shared/Lock/LockComponent.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Content.Shared/Lock/LockComponent.cs b/Content.Shared/Lock/LockComponent.cs index bdfc546dc870..070d5801c1c8 100644 --- a/Content.Shared/Lock/LockComponent.cs +++ b/Content.Shared/Lock/LockComponent.cs @@ -87,7 +87,7 @@ public sealed partial class LockComponent : Component public record struct LockToggleAttemptEvent(EntityUid User, bool Silent = false, bool Cancelled = false); /// -/// Event raised on the lock when a toggle is attempted. +/// Event raised on the user when a toggle is attempted. /// Can be cancelled to prevent it. /// [ByRefEvent]