]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Fix cardboard box remote control exploits (#14494)
authorRane <60792108+Elijahrane@users.noreply.github.com>
Fri, 24 Mar 2023 05:09:58 +0000 (01:09 -0400)
committerGitHub <noreply@github.com>
Fri, 24 Mar 2023 05:09:58 +0000 (16:09 +1100)
Content.Server/CardboardBox/CardboardBoxSystem.cs

index 2cfdf126a181eecdeebe004cecef4137f1bff111..890ff0f4e2f20a48a07a96c4b8a0cdde53a55e66 100644 (file)
@@ -32,6 +32,7 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
         SubscribeLocalEvent<CardboardBoxComponent, StorageAfterCloseEvent>(AfterStorageClosed);
         SubscribeLocalEvent<CardboardBoxComponent, InteractedNoHandEvent>(OnNoHandInteracted);
         SubscribeLocalEvent<CardboardBoxComponent, EntInsertedIntoContainerMessage>(OnEntInserted);
+        SubscribeLocalEvent<CardboardBoxComponent, EntRemovedFromContainerMessage>(OnEntRemoved);
 
         SubscribeLocalEvent<CardboardBoxComponent, DamageChangedEvent>(OnDamage);
     }
@@ -50,7 +51,6 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
         //Remove the mover after the box is opened and play the effect if it hasn't been played yet.
         if (component.Mover != null)
         {
-            RemComp<RelayInputMoverComponent>(component.Mover.Value);
             if (_timing.CurTime > component.EffectCooldown)
             {
                 RaiseNetworkEvent(new PlayBoxEffectMessage(component.Owner, component.Mover.Value), Filter.PvsExcept(component.Owner));
@@ -59,8 +59,6 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
             }
         }
 
-        component.Mover = null;
-
         // If this box has a stealth/chameleon effect, disable the stealth effect while the box is open.
         _stealth.SetEnabled(uid, false);
     }
@@ -102,4 +100,17 @@ public sealed class CardboardBoxSystem : SharedCardboardBoxSystem
         _mover.SetRelay(args.Entity, uid, relay);
         component.Mover = args.Entity;
     }
+
+    /// <summary>
+    /// Through e.g. teleporting, it's possible for the mover to exit the box without opening it.
+    /// Handle those situations but don't play the sound.
+    /// </summary>
+    private void OnEntRemoved(EntityUid uid, CardboardBoxComponent component, EntRemovedFromContainerMessage args)
+    {
+        if (args.Entity != component.Mover)
+            return;
+
+        RemComp<RelayInputMoverComponent>(component.Mover.Value);
+        component.Mover = null;
+    }
 }