]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
fix mirror server crashes (#28318)
authorNemanja <98561806+EmoGarbage404@users.noreply.github.com>
Mon, 27 May 2024 15:50:05 +0000 (11:50 -0400)
committerGitHub <noreply@github.com>
Mon, 27 May 2024 15:50:05 +0000 (17:50 +0200)
Content.Shared/MagicMirror/SharedMagicMirrorSystem.cs
Resources/Prototypes/Entities/Structures/Wallmounts/mirror.yml

index ea96d504c6e6f1bd3d1adc40d70c72433b07b0fc..789b484cfd3e6efb50cffcae2e8c7a81459374b0 100644 (file)
@@ -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<MagicMirrorComponent, AfterInteractEvent>(OnMagicMirrorInteract);
         SubscribeLocalEvent<MagicMirrorComponent, BeforeActivatableUIOpenEvent>(OnBeforeUIOpen);
+        SubscribeLocalEvent<MagicMirrorComponent, ActivatableUIOpenAttemptEvent>(OnAttemptOpenUI);
         SubscribeLocalEvent<MagicMirrorComponent, BoundUserInterfaceCheckRangeEvent>(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<MagicMirrorComponent> 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<HumanoidAppearanceComponent>(user))
+            args.Cancel();
+    }
+
+    private void OnBeforeUIOpen(Entity<MagicMirrorComponent> ent, ref BeforeActivatableUIOpenEvent args)
+    {
         UpdateInterface(ent, args.User, ent);
     }
 
@@ -55,6 +63,7 @@ public abstract class SharedMagicMirrorSystem : EntitySystem
     {
         if (!TryComp<HumanoidAppearanceComponent>(targetUid, out var humanoid))
             return;
+
         component.Target ??= targetUid;
 
         var hair = humanoid.MarkingSet.TryGetCategory(MarkingCategories.Hair, out var hairMarkings)
index 1fe3318ef5581014fccb2aa4eb87cd1aa8ec39e5..27b8390add29bce63433fed146bbae4110a8f52f 100644 (file)
@@ -19,6 +19,7 @@
     changeSlotTime: 0
   - type: ActivatableUI
     key: enum.MagicMirrorUiKey.Key
+    singleUser: true
   - type: UserInterface
     interfaces:
       enum.MagicMirrorUiKey.Key: