From 318f82ab302a2a00bf875ca35b0ded2444c9e4b6 Mon Sep 17 00:00:00 2001 From: Vera Aguilera Puerto Date: Sat, 2 Jan 2021 22:11:39 +0100 Subject: [PATCH] Fixes aghost spam creating many admin ghosts. - Also gives aghosts their character/player name --- .../Administration/Commands/AGhost.cs | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Content.Server/Administration/Commands/AGhost.cs b/Content.Server/Administration/Commands/AGhost.cs index 89c71d0346..eddc879dde 100644 --- a/Content.Server/Administration/Commands/AGhost.cs +++ b/Content.Server/Administration/Commands/AGhost.cs @@ -1,4 +1,6 @@ -using Content.Server.GameObjects.Components.Observer; +using Content.Server.Commands.Observer; +using Content.Server.GameObjects.Components.Observer; +using Content.Server.Interfaces.GameTicking; using Content.Server.Players; using Content.Shared.Administration; using Robust.Server.Interfaces.Console; @@ -23,14 +25,15 @@ namespace Content.Server.Administration.Commands return; } - var mind = player.ContentData().Mind; + var mind = player.ContentData()?.Mind; + if (mind == null) { shell.SendText(player, "You can't ghost here!"); return; } - if (mind.VisitingEntity != null && mind.VisitingEntity.Prototype.ID == "AdminObserver") + if (mind.VisitingEntity != null && mind.VisitingEntity.Prototype?.ID == "AdminObserver") { var visiting = mind.VisitingEntity; mind.UnVisit(); @@ -38,13 +41,22 @@ namespace Content.Server.Administration.Commands } else { - var canReturn = mind.CurrentEntity != null && !mind.CurrentEntity.HasComponent(); - var entityManager = IoCManager.Resolve(); - var ghost = entityManager.SpawnEntity("AdminObserver", player.AttachedEntity.Transform.MapPosition); - if(canReturn) + var canReturn = mind.CurrentEntity != null; + var ghost = IoCManager.Resolve() + .SpawnEntity("AdminObserver", player.AttachedEntity?.Transform.Coordinates + ?? IoCManager.Resolve().GetObserverSpawnPoint()); + + if (canReturn) + { + ghost.Name = mind.CharacterName; mind.Visit(ghost); + } else + { + ghost.Name = player.Name; mind.TransferTo(ghost); + } + ghost.GetComponent().CanReturnToBody = canReturn; } }