Fix aghost crashes (#8556)
There's still some oddity around MobObserver / AdminObserver where if you move after suicide then aghost you return to your original body, but at least you won't spawn a billion AdminObservers anymore or crash if you controlmob one.
This commit is contained in:
@@ -264,6 +264,13 @@ namespace Content.Server.Mind
|
|||||||
/// </exception>
|
/// </exception>
|
||||||
public void TransferTo(EntityUid? entity, bool ghostCheckOverride = false)
|
public void TransferTo(EntityUid? entity, bool ghostCheckOverride = false)
|
||||||
{
|
{
|
||||||
|
// Looks like caller just wants us to go back to normal.
|
||||||
|
if (entity == OwnedEntity)
|
||||||
|
{
|
||||||
|
UnVisit();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||||
|
|
||||||
MindComponent? component = null;
|
MindComponent? component = null;
|
||||||
@@ -306,11 +313,11 @@ namespace Content.Server.Mind
|
|||||||
|| !entMan.TryGetComponent(VisitingEntity!, out GhostComponent? ghostComponent) // visiting entity is not a Ghost
|
|| !entMan.TryGetComponent(VisitingEntity!, out GhostComponent? ghostComponent) // visiting entity is not a Ghost
|
||||||
|| !ghostComponent.CanReturnToBody)) // it is a ghost, but cannot return to body anyway, so it's okay
|
|| !ghostComponent.CanReturnToBody)) // it is a ghost, but cannot return to body anyway, so it's okay
|
||||||
{
|
{
|
||||||
VisitingEntity = default;
|
RemoveVisitingEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Player is CURRENTLY connected.
|
// Player is CURRENTLY connected.
|
||||||
if (Session != null && !alreadyAttached && VisitingEntity == default)
|
if (Session != null && !alreadyAttached && VisitingEntity == null)
|
||||||
{
|
{
|
||||||
Session.AttachToEntity(entity);
|
Session.AttachToEntity(entity);
|
||||||
Logger.Info($"Session {Session.Name} transferred to entity {entity}.");
|
Logger.Info($"Session {Session.Name} transferred to entity {entity}.");
|
||||||
@@ -370,17 +377,26 @@ namespace Content.Server.Mind
|
|||||||
Logger.Info($"Session {Session?.Name} visiting entity {entity}.");
|
Logger.Info($"Session {Session?.Name} visiting entity {entity}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Returns the mind to its original entity.
|
||||||
|
/// </summary>
|
||||||
public void UnVisit()
|
public void UnVisit()
|
||||||
{
|
{
|
||||||
if (VisitingEntity == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Session?.AttachToEntity(OwnedEntity);
|
Session?.AttachToEntity(OwnedEntity);
|
||||||
|
RemoveVisitingEntity();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Cleans up the VisitingEntity.
|
||||||
|
/// </summary>
|
||||||
|
private void RemoveVisitingEntity()
|
||||||
|
{
|
||||||
|
if (VisitingEntity == null)
|
||||||
|
return;
|
||||||
|
|
||||||
var oldVisitingEnt = VisitingEntity.Value;
|
var oldVisitingEnt = VisitingEntity.Value;
|
||||||
// Null this before removing the component to avoid any infinite loops.
|
// Null this before removing the component to avoid any infinite loops.
|
||||||
VisitingEntity = default;
|
VisitingEntity = null;
|
||||||
|
|
||||||
DebugTools.AssertNotNull(oldVisitingEnt);
|
DebugTools.AssertNotNull(oldVisitingEnt);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user