diff --git a/Content.Shared/Interaction/Components/BypassInteractionChecksComponent.cs b/Content.Shared/Interaction/Components/BypassInteractionChecksComponent.cs new file mode 100644 index 000000000000..ca0ff963151a --- /dev/null +++ b/Content.Shared/Interaction/Components/BypassInteractionChecksComponent.cs @@ -0,0 +1,6 @@ +using Robust.Shared.GameStates; + +namespace Content.Shared.Interaction.Components; + +[RegisterComponent, NetworkedComponent] +public sealed partial class BypassInteractionChecksComponent : Component; diff --git a/Content.Shared/Inventory/InventorySystem.Slots.cs b/Content.Shared/Inventory/InventorySystem.Slots.cs index 19831278b0a5..228b788722ec 100644 --- a/Content.Shared/Inventory/InventorySystem.Slots.cs +++ b/Content.Shared/Inventory/InventorySystem.Slots.cs @@ -75,7 +75,7 @@ private void OnOpenSlotStorage(OpenSlotStorageNetworkMessage ev, EntitySessionEv if (TryGetSlotEntity(uid, ev.Slot, out var entityUid) && TryComp(entityUid, out var storageComponent)) { - _storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent); + _storageSystem.OpenStorageUI(entityUid.Value, uid, storageComponent, false); } } diff --git a/Content.Shared/Lock/LockSystem.cs b/Content.Shared/Lock/LockSystem.cs index 54f5d801ea0c..4115358d9d78 100644 --- a/Content.Shared/Lock/LockSystem.cs +++ b/Content.Shared/Lock/LockSystem.cs @@ -8,6 +8,7 @@ using Content.Shared.IdentityManagement; using Content.Shared.Interaction; using Content.Shared.Popups; +using Content.Shared.Storage; using Content.Shared.Storage.Components; using Content.Shared.Verbs; using Content.Shared.Wires; @@ -42,11 +43,13 @@ public override void Initialize() SubscribeLocalEvent(OnEmagged); SubscribeLocalEvent(OnDoAfterLock); SubscribeLocalEvent(OnDoAfterUnlock); + SubscribeLocalEvent(OnStorageInteractAttempt); SubscribeLocalEvent(OnLockToggleAttempt); SubscribeLocalEvent(OnAttemptChangePanel); SubscribeLocalEvent(OnUnanchorAttempt); } + private void OnStartup(EntityUid uid, LockComponent lockComp, ComponentStartup args) { _appearanceSystem.SetData(uid, LockVisuals.Locked, lockComp.Locked); @@ -293,6 +296,12 @@ private void OnDoAfterUnlock(EntityUid uid, LockComponent component, UnlockDoAft TryUnlock(uid, args.User, skipDoAfter: true); } + private void OnStorageInteractAttempt(Entity ent, ref StorageInteractAttemptEvent args) + { + if (ent.Comp.Locked) + args.Cancelled = true; + } + private void OnLockToggleAttempt(Entity ent, ref LockToggleAttemptEvent args) { if (args.Cancelled) diff --git a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs index 6dd7f9d41844..ea0c9632f0ec 100644 --- a/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs +++ b/Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs @@ -2,17 +2,15 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using Content.Shared.ActionBlocker; -using Content.Shared.Administration; -using Content.Shared.Administration.Managers; using Content.Shared.Containers.ItemSlots; using Content.Shared.Destructible; using Content.Shared.DoAfter; -using Content.Shared.Ghost; using Content.Shared.Hands.Components; using Content.Shared.Hands.EntitySystems; using Content.Shared.Implants.Components; using Content.Shared.Input; using Content.Shared.Interaction; +using Content.Shared.Interaction.Components; using Content.Shared.Inventory; using Content.Shared.Item; using Content.Shared.Lock; @@ -40,7 +38,6 @@ public abstract class SharedStorageSystem : EntitySystem { [Dependency] private readonly IPrototypeManager _prototype = default!; [Dependency] protected readonly IRobustRandom Random = default!; - [Dependency] private readonly ISharedAdminManager _admin = default!; [Dependency] protected readonly ActionBlockerSystem ActionBlocker = default!; [Dependency] private readonly EntityLookupSystem _entityLookupSystem = default!; [Dependency] private readonly SharedAppearanceSystem _appearance = default!; @@ -249,17 +246,8 @@ private void OnBoundUIClosed(EntityUid uid, StorageComponent storageComp, BoundU private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent args) { - var silent = false; - if (!args.CanAccess || !args.CanInteract || TryComp(uid, out var lockComponent) && lockComponent.Locked) - { - // we allow admins to open the storage anyways - if (!_admin.HasAdminFlag(args.User, AdminFlags.Admin)) - return; - - silent = true; - } - - silent |= HasComp(args.User); + if (!CanInteract(args.User, (uid, component), args.CanAccess && args.CanInteract)) + return; // Does this player currently have the storage UI open? var uiOpen = _ui.IsUiOpen(uid, StorageComponent.StorageUiKey.Key, args.User); @@ -274,7 +262,7 @@ private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent< } else { - OpenStorageUI(uid, args.User, component, silent); + OpenStorageUI(uid, args.User, component); } } }; @@ -298,13 +286,16 @@ private void AddUiVerb(EntityUid uid, StorageComponent component, GetVerbsEvent< /// Opens the storage UI for an entity /// /// The entity to open the UI for - public void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = false) + public void OpenStorageUI(EntityUid uid, EntityUid entity, StorageComponent? storageComp = null, bool silent = true) { if (!Resolve(uid, ref storageComp, false)) return; // prevent spamming bag open / honkerton honk sound silent |= TryComp(uid, out var useDelay) && UseDelay.IsDelayed((uid, useDelay)); + if (!CanInteract(entity, (uid, storageComp), silent: silent)) + return; + if (!silent) { if (!_ui.IsUiOpen(uid, StorageComponent.StorageUiKey.Key)) @@ -326,7 +317,7 @@ private void AddTransferVerbs(EntityUid uid, StorageComponent component, GetVerb var entities = component.Container.ContainedEntities; - if (entities.Count == 0 || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked) + if (entities.Count == 0 || !CanInteract(args.User, (uid, component))) return; // if the target is storage, add a verb to transfer storage. @@ -337,7 +328,7 @@ private void AddTransferVerbs(EntityUid uid, StorageComponent component, GetVerb { Text = Loc.GetString("storage-component-transfer-verb"), IconEntity = GetNetEntity(args.Using), - Act = () => TransferEntities(uid, args.Target, args.User, component, lockComponent, targetStorage, targetLock) + Act = () => TransferEntities(uid, args.Target, args.User, component, null, targetStorage, targetLock) }; args.Verbs.Add(verb); @@ -350,7 +341,7 @@ private void AddTransferVerbs(EntityUid uid, StorageComponent component, GetVerb /// true if inserted, false otherwise private void OnInteractUsing(EntityUid uid, StorageComponent storageComp, InteractUsingEvent args) { - if (args.Handled || !storageComp.ClickInsert || TryComp(uid, out LockComponent? lockComponent) && lockComponent.Locked) + if (args.Handled || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert, false)) return; if (HasComp(uid)) @@ -368,7 +359,7 @@ private void OnInteractUsing(EntityUid uid, StorageComponent storageComp, Intera /// private void OnActivate(EntityUid uid, StorageComponent storageComp, ActivateInWorldEvent args) { - if (args.Handled || TryComp(uid, out var lockComponent) && lockComponent.Locked) + if (args.Handled || !CanInteract(args.User, (uid, storageComp), storageComp.ClickInsert)) return; // Toggle @@ -378,7 +369,7 @@ private void OnActivate(EntityUid uid, StorageComponent storageComp, ActivateInW } else { - OpenStorageUI(uid, args.User, storageComp); + OpenStorageUI(uid, args.User, storageComp, false); } args.Handled = true; @@ -392,7 +383,7 @@ private void OnImplantActivate(EntityUid uid, StorageComponent storageComp, Open if (args.Handled) return; - OpenStorageUI(uid, args.Performer, storageComp); + OpenStorageUI(uid, args.Performer, storageComp, false); args.Handled = true; } @@ -1403,7 +1394,7 @@ public ItemSizePrototype GetMaxItemSize(Entity uid) } /// - /// Checks if a storage's UI is open by anyone when locked, and closes it unless they're an admin. + /// Checks if a storage's UI is open by anyone when locked, and closes it. /// private void OnLockToggled(EntityUid uid, StorageComponent component, ref LockToggledEvent args) { @@ -1413,11 +1404,8 @@ private void OnLockToggled(EntityUid uid, StorageComponent component, ref LockTo // Gets everyone looking at the UI foreach (var actor in _ui.GetActors(uid, StorageComponent.StorageUiKey.Key).ToList()) { - if (_admin.HasAdminFlag(actor, AdminFlags.Admin)) - continue; - - // And closes it unless they're an admin - _ui.CloseUi(uid, StorageComponent.StorageUiKey.Key, actor); + if (!CanInteract(actor, (uid, component))) + _ui.CloseUi(uid, StorageComponent.StorageUiKey.Key, actor); } } @@ -1457,7 +1445,7 @@ private void HandleToggleSlotUI(ICommonSession? session, string slot) if (!_ui.IsUiOpen(storageEnt.Value, StorageComponent.StorageUiKey.Key, playerEnt)) { - OpenStorageUI(storageEnt.Value, playerEnt); + OpenStorageUI(storageEnt.Value, playerEnt, silent: false); } else { @@ -1472,6 +1460,20 @@ protected void ClearCantFillReasons() #endif } + private bool CanInteract(EntityUid user, Entity storage, bool canInteract = true, bool silent = true) + { + if (HasComp(user)) + return true; + + if (!canInteract) + return false; + + var ev = new StorageInteractAttemptEvent(silent); + RaiseLocalEvent(storage, ref ev); + + return !ev.Cancelled; + } + /// /// Plays a clientside pickup animation for the specified uid. /// diff --git a/Content.Shared/Storage/StorageComponent.cs b/Content.Shared/Storage/StorageComponent.cs index ef682dd4f94c..2860f8dacfe8 100644 --- a/Content.Shared/Storage/StorageComponent.cs +++ b/Content.Shared/Storage/StorageComponent.cs @@ -5,7 +5,6 @@ using Robust.Shared.Containers; using Robust.Shared.GameStates; using Robust.Shared.Map; -using Robust.Shared.Player; using Robust.Shared.Prototypes; using Robust.Shared.Serialization; @@ -228,6 +227,9 @@ public AnimateInsertingEntitiesEvent(NetEntity storage, List storedEn } } + [ByRefEvent] + public record struct StorageInteractAttemptEvent(bool Silent, bool Cancelled = false); + [NetSerializable] [Serializable] public enum StorageVisuals : byte diff --git a/Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml b/Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml index 8171ec0053ca..b294729e07a4 100644 --- a/Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml +++ b/Resources/Prototypes/Entities/Mobs/Player/admin_ghost.yml @@ -90,6 +90,7 @@ - type: InventorySlots - type: Loadout prototypes: [ MobAghostGear ] + - type: BypassInteractionChecks - type: entity id: ActionAGhostShowSolar