Fix ghosts having empty names under certain conditions.

Fixes #4731
This commit is contained in:
Vera Aguilera Puerto 2021-10-06 11:56:16 +02:00
parent 94a29978b5
commit 1f72435263
4 changed files with 18 additions and 7 deletions

View File

@ -47,7 +47,12 @@ namespace Content.Server.Administration.Commands
if (canReturn)
{
ghost.Name = mind.CharacterName ?? string.Empty;
// TODO: Remove duplication between all this and "GamePreset.OnGhostAttempt()"...
if(!string.IsNullOrWhiteSpace(mind.CharacterName))
ghost.Name = mind.CharacterName;
else if (!string.IsNullOrWhiteSpace(mind.Session?.Name))
ghost.Name = mind.Session.Name;
mind.Visit(ghost);
}
else

View File

@ -73,7 +73,14 @@ namespace Content.Server.GameTicking.Presets
var entityManager = IoCManager.Resolve<IEntityManager>();
var ghost = entityManager.SpawnEntity("MobObserver", position.ToMap(entityManager));
ghost.Name = mind.CharacterName ?? string.Empty;
// Try setting the ghost entity name to either the character name or the player name.
// If all else fails, it'll default to the default entity prototype name, "observer".
// However, that should rarely happen.
if(!string.IsNullOrWhiteSpace(mind.CharacterName))
ghost.Name = mind.CharacterName;
else if (!string.IsNullOrWhiteSpace(mind.Session?.Name))
ghost.Name = mind.Session.Name;
var ghostComponent = ghost.GetComponent<GhostComponent>();
EntitySystem.Get<SharedGhostSystem>().SetCanReturnToBody(ghostComponent, canReturn);

View File

@ -7,11 +7,6 @@ namespace Content.Shared.Ghost
{
public abstract class SharedGhostSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
}
public void SetCanReturnToBody(SharedGhostComponent component, bool canReturn)
{
if (component.CanReturnToBody == canReturn)

View File

@ -0,0 +1,4 @@
author: Zumorica
changes:
- type: Fix # One of the following: Add, Remove, Tweak, Fix
message: Fix ghosts having empty names under certain conditions.