diff --git a/Content.Server/Mobs/Mind.cs b/Content.Server/Mobs/Mind.cs index 2b11bf8474..e931b80fbc 100644 --- a/Content.Server/Mobs/Mind.cs +++ b/Content.Server/Mobs/Mind.cs @@ -1,7 +1,8 @@ -using System; +using System; using System.Collections.Generic; using Content.Server.GameObjects.Components.Mobs; using Content.Server.Players; +using Robust.Server.Interfaces.GameObjects; using Robust.Server.Interfaces.Player; using Robust.Shared.Interfaces.GameObjects; using Robust.Shared.IoC; @@ -142,6 +143,7 @@ namespace Content.Server.Mobs public void TransferTo(IEntity entity) { MindComponent component = null; + bool alreadyAttached = false; if (entity != null) { if (!entity.TryGetComponent(out component)) @@ -153,6 +155,17 @@ namespace Content.Server.Mobs // TODO: Kick them out, maybe? throw new ArgumentException("That entity already has a mind.", nameof(entity)); } + + if (entity.TryGetComponent(out IActorComponent actor)) + { + // Happens when transferring to your currently visited entity. + if (actor.playerSession != Session) + { + throw new ArgumentException("Visit target already has a session.", nameof(entity)); + } + + alreadyAttached = true; + } } OwnedMob?.InternalEjectMind(); @@ -160,7 +173,7 @@ namespace Content.Server.Mobs OwnedMob?.InternalAssignMind(this); // Player is CURRENTLY connected. - if (Session != null && OwnedMob != null) + if (Session != null && OwnedMob != null && !alreadyAttached) { Session.AttachToEntity(entity); }