Fix user interface interaction validation (#36480)

This commit is contained in:
Leon Friedrich
2025-04-14 02:09:56 +10:00
committed by GitHub
parent b619d4fae1
commit 6af4a4d9b8

View File

@@ -106,7 +106,9 @@ namespace Content.Shared.Interaction
_uiQuery = GetEntityQuery<ActivatableUIComponent>();
SubscribeLocalEvent<BoundUserInterfaceCheckRangeEvent>(HandleUserInterfaceRangeCheck);
SubscribeLocalEvent<ActivatableUIComponent, BoundUserInterfaceMessageAttempt>(OnBoundInterfaceInteractAttempt);
// TODO make this a broadcast event subscription again when engine has updated.
SubscribeLocalEvent<UserInterfaceComponent, BoundUserInterfaceMessageAttempt>(OnBoundInterfaceInteractAttempt);
SubscribeAllEvent<InteractInventorySlotEvent>(HandleInteractInventorySlotEvent);
@@ -151,12 +153,15 @@ namespace Content.Shared.Interaction
/// <summary>
/// Check that the user that is interacting with the BUI is capable of interacting and can access the entity.
/// </summary>
private void OnBoundInterfaceInteractAttempt(Entity<ActivatableUIComponent> ent, ref BoundUserInterfaceMessageAttempt ev)
private void OnBoundInterfaceInteractAttempt(Entity<UserInterfaceComponent> ent, ref BoundUserInterfaceMessageAttempt ev)
{
_uiQuery.TryComp(ev.Target, out var aUiComp);
if (!_actionBlockerSystem.CanInteract(ev.Actor, ev.Target))
{
// We permit ghosts to open uis unless explicitly blocked
if (ev.Message is not OpenBoundInterfaceMessage || !HasComp<GhostComponent>(ev.Actor) || ent.Comp.BlockSpectators)
if (ev.Message is not OpenBoundInterfaceMessage
|| !HasComp<GhostComponent>(ev.Actor)
|| aUiComp?.BlockSpectators == true)
{
ev.Cancel();
return;
@@ -174,14 +179,16 @@ namespace Content.Shared.Interaction
return;
}
if (aUiComp == null)
return;
if (ent.Comp.SingleUser && ent.Comp.CurrentSingleUser != null && ent.Comp.CurrentSingleUser != ev.Actor)
if (aUiComp.SingleUser && aUiComp.CurrentSingleUser != null && aUiComp.CurrentSingleUser != ev.Actor)
{
ev.Cancel();
return;
}
if (ent.Comp.RequiresComplex && !_actionBlockerSystem.CanComplexInteract(ev.Actor))
if (aUiComp.RequiresComplex && !_actionBlockerSystem.CanComplexInteract(ev.Actor))
ev.Cancel();
}