Equipment verbs & admin inventory access. (#14315)

This commit is contained in:
Leon Friedrich
2023-03-06 06:12:08 +13:00
committed by GitHub
parent a9b268af49
commit b148bebd60
29 changed files with 499 additions and 141 deletions

View File

@@ -1,7 +1,9 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.ActionBlocker;
using Content.Shared.Administration;
using Content.Shared.Administration.Logs;
using Content.Shared.Administration.Managers;
using Content.Shared.CombatMode;
using Content.Shared.Database;
using Content.Shared.Ghost;
@@ -9,6 +11,7 @@ using Content.Shared.Hands.Components;
using Content.Shared.Input;
using Content.Shared.Interaction.Components;
using Content.Shared.Interaction.Events;
using Content.Shared.Inventory;
using Content.Shared.Item;
using Content.Shared.Movement.Components;
using Content.Shared.Physics;
@@ -45,6 +48,7 @@ namespace Content.Shared.Interaction
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly ISharedAdminManager _adminManager = default!;
[Dependency] private readonly ISharedAdminLogManager _adminLogger = default!;
[Dependency] private readonly ActionBlockerSystem _actionBlockerSystem = default!;
[Dependency] private readonly RotateToFaceSystem _rotateToFaceSystem = default!;
@@ -55,6 +59,7 @@ namespace Content.Shared.Interaction
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
[Dependency] private readonly UseDelaySystem _useDelay = default!;
[Dependency] private readonly SharedPullingSystem _pullSystem = default!;
[Dependency] private readonly InventorySystem _inventory = default!;
[Dependency] private readonly IRobustRandom _random = default!;
private const CollisionGroup InRangeUnobstructedMask
@@ -104,7 +109,12 @@ namespace Content.Shared.Interaction
return;
}
if (!_containerSystem.IsInSameOrParentContainer(user, ev.Target) && !CanAccessViaStorage(user, ev.Target))
// Check if the bound entity is accessible. Note that we allow admins to ignore this restriction, so that
// they can fiddle with UI's that people can't normally interact with (e.g., placing things directly into
// other people's backpacks).
if (!_containerSystem.IsInSameOrParentContainer(user, ev.Target)
&& !CanAccessViaStorage(user, ev.Target)
&& !_adminManager.HasAdminFlag(user, AdminFlags.Admin))
{
ev.Cancel();
return;
@@ -983,6 +993,32 @@ namespace Content.Shared.Interaction
/// </summary>
public abstract bool CanAccessViaStorage(EntityUid user, EntityUid target);
/// <summary>
/// Checks whether an entity currently equipped by another player is accessible to some user. This shouldn't
/// be used as a general interaction check, as these kinda of interactions should generally trigger a
/// do-after and a warning for the other player.
/// </summary>
public bool CanAccessEquipment(EntityUid user, EntityUid target)
{
if (Deleted(target))
return false;
if (!_containerSystem.TryGetContainingContainer(target, out var container))
return false;
var wearer = container.Owner;
if (!_inventory.TryGetSlot(wearer, container.ID, out var slotDef))
return false;
if (wearer == user)
return true;
if (slotDef.StripHidden)
return false;
return InRangeUnobstructed(user, wearer) && _containerSystem.IsInSameOrParentContainer(user, wearer);
}
protected bool ValidateClientInput(ICommonSession? session, EntityCoordinates coords,
EntityUid uid, [NotNullWhen(true)] out EntityUid? userEntity)
{