From 224af2af0eefce38d2ab1c3e87b01fbe6d913b20 Mon Sep 17 00:00:00 2001 From: Nemanja <98561806+EmoGarbage404@users.noreply.github.com> Date: Mon, 27 May 2024 11:50:05 -0400 Subject: [PATCH] fix mirror server crashes (#28318) --- .../MagicMirror/SharedMagicMirrorSystem.cs | 25 +++++++++++++------ .../Entities/Structures/Wallmounts/mirror.yml | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs b/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs index ea96d504c6..789b484cfd 100644 --- a/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs +++ b/Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs @@ -4,7 +4,6 @@ using Content.Shared.Humanoid.Markings; using Content.Shared.Interaction; using Content.Shared.UserInterface; using Robust.Shared.Serialization; -using Robust.Shared.Utility; namespace Content.Shared.MagicMirror; @@ -18,6 +17,7 @@ public abstract class SharedMagicMirrorSystem : EntitySystem base.Initialize(); SubscribeLocalEvent(OnMagicMirrorInteract); SubscribeLocalEvent(OnBeforeUIOpen); + SubscribeLocalEvent(OnAttemptOpenUI); SubscribeLocalEvent(OnMirrorRangeCheck); } @@ -26,10 +26,8 @@ public abstract class SharedMagicMirrorSystem : EntitySystem if (!args.CanReach || args.Target == null) return; - if (!UISystem.TryOpenUi(mirror.Owner, MagicMirrorUiKey.Key, args.User)) - return; - UpdateInterface(mirror, args.Target.Value, mirror); + UISystem.TryOpenUi(mirror.Owner, MagicMirrorUiKey.Key, args.User); } private void OnMirrorRangeCheck(EntityUid uid, MagicMirrorComponent component, ref BoundUserInterfaceCheckRangeEvent args) @@ -37,17 +35,27 @@ public abstract class SharedMagicMirrorSystem : EntitySystem if (args.Result == BoundUserInterfaceRangeResult.Fail) return; - DebugTools.Assert(component.Target != null && Exists(component.Target)); + if (component.Target == null || !Exists(component.Target)) + { + component.Target = null; + args.Result = BoundUserInterfaceRangeResult.Fail; + return; + } if (!_interaction.InRangeUnobstructed(uid, component.Target.Value)) args.Result = BoundUserInterfaceRangeResult.Fail; } - private void OnBeforeUIOpen(Entity ent, ref BeforeActivatableUIOpenEvent args) + private void OnAttemptOpenUI(EntityUid uid, MagicMirrorComponent component, ref ActivatableUIOpenAttemptEvent args) { - if (args.User != ent.Comp.Target && ent.Comp.Target != null) - return; + var user = component.Target ?? args.User; + if (!HasComp(user)) + args.Cancel(); + } + + private void OnBeforeUIOpen(Entity ent, ref BeforeActivatableUIOpenEvent args) + { UpdateInterface(ent, args.User, ent); } @@ -55,6 +63,7 @@ public abstract class SharedMagicMirrorSystem : EntitySystem { if (!TryComp(targetUid, out var humanoid)) return; + component.Target ??= targetUid; var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings) diff --git a/Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml b/Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml index 1fe3318ef5..27b8390add 100644 --- a/Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml +++ b/Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml @@ -19,6 +19,7 @@ changeSlotTime: 0 - type: ActivatableUI key: enum.MagicMirrorUiKey.Key + singleUser: true - type: UserInterface interfaces: enum.MagicMirrorUiKey.Key: -- 2.51.2