[ByRefEvent]
public record struct LockToggleAttemptEvent(EntityUid User, bool Silent = false, bool Cancelled = false);
+/// <summary>
+/// Event raised on the user when a toggle is attempted.
+/// Can be cancelled to prevent it.
+/// </summary>
+[ByRefEvent]
+public record struct UserLockToggleAttemptEvent(EntityUid Target, bool Silent = false, bool Cancelled = false);
+
/// <summary>
/// Event raised on a lock after it has been toggled.
/// </summary>
var ev = new LockToggleAttemptEvent(user, quiet);
RaiseLocalEvent(uid, ref ev, true);
- return !ev.Cancelled;
+ if (ev.Cancelled)
+ return false;
+
+ var userEv = new UserLockToggleAttemptEvent(uid, quiet);
+ RaiseLocalEvent(user, ref userEv, true);
+ return !userEv.Cancelled;
}
// TODO: this should be a helper on AccessReaderSystem since so many systems copy paste it
_activatableUI.CloseAll(uid);
}
}
-
--- /dev/null
+using Content.Shared.Whitelist;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Lock;
+
+/// <summary>
+/// Adds whitelist and blacklist for this mob to lock things.
+/// The whitelist and blacklist are checked against the object being locked, not the mob.
+/// </summary>
+[RegisterComponent, NetworkedComponent, Access(typeof(LockingWhitelistSystem))]
+public sealed partial class LockingWhitelistComponent : Component
+{
+ [DataField]
+ public EntityWhitelist? Whitelist;
+
+ [DataField]
+ public EntityWhitelist? Blacklist;
+}
--- /dev/null
+using Content.Shared.Popups;
+using Content.Shared.Whitelist;
+
+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()
+ {
+ base.Initialize();
+
+ SubscribeLocalEvent<LockingWhitelistComponent, UserLockToggleAttemptEvent>(OnUserLockToggleAttempt);
+ }
+
+ private void OnUserLockToggleAttempt(Entity<LockingWhitelistComponent> 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"), ent.Owner);
+
+ args.Cancelled = true;
+ }
+}
return uid != null && IsValid(list, uid.Value);
}
+ /// <summary>
+ /// 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.
+ /// </summary>
+ public bool CheckBoth([NotNullWhen(true)] EntityUid? uid, EntityWhitelist? blacklist = null, EntityWhitelist? whitelist = null)
+ {
+ if (uid == null)
+ return false;
+
+ if (blacklist != null && IsValid(blacklist, uid))
+ return false;
+
+ return whitelist == null || IsValid(whitelist, uid);
+ }
+
/// <summary>
/// Checks whether a given entity satisfies a whitelist.
/// </summary>
--- /dev/null
+locking-whitelist-component-lock-toggle-deny = You can't toggle the lock.
doAfterDelay: 10
allowSelfRepair: false
- type: BorgChassis
+ - type: LockingWhitelist
+ blacklist:
+ components:
+ - BorgChassis
+ - RoboticsConsole
- type: WiresPanel
- type: ActivatableUIRequiresPanel
- type: NameIdentifier