Fix mind test issues (#18793)

This commit is contained in:
Leon Friedrich
2023-08-07 15:29:10 +12:00
committed by GitHub
parent 91658a0cd5
commit 6a45d36457
6 changed files with 85 additions and 33 deletions

View File

@@ -31,6 +31,7 @@ public sealed class MindSystem : EntitySystem
[Dependency] private readonly GhostSystem _ghostSystem = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly ActorSystem _actor = default!;
// This is dictionary is required to track the minds of disconnected players that may have had their entity deleted.
private readonly Dictionary<NetUserId, Mind> _userMinds = new();
@@ -584,11 +585,10 @@ public sealed class MindSystem : EntitySystem
}
/// <summary>
/// Sets the Mind's UserId, Session, and updates the player's PlayerData.
/// This should have no direct effect on the entity that any mind is connected to, but it may change a player's attached entity.
/// Sets the Mind's UserId, Session, and updates the player's PlayerData. This should have no direct effect on the
/// entity that any mind is connected to, except as a side effect of the fact that it may change a player's
/// attached entity. E.g., ghosts get deleted.
/// </summary>
/// <param name="mind"></param>
/// <param name="userId"></param>
public void SetUserId(Mind mind, NetUserId? userId)
{
if (mind.UserId == userId)
@@ -602,7 +602,7 @@ public sealed class MindSystem : EntitySystem
if (mind.Session != null)
{
mind.Session.AttachToEntity(null);
_actor.Attach(null, mind.Session);
mind.Session = null;
}
@@ -629,8 +629,11 @@ public sealed class MindSystem : EntitySystem
mind.UserId = userId;
mind.OriginalOwnerUserId ??= userId;
_playerManager.TryGetSessionById(userId.Value, out var ret);
mind.Session = ret;
if (_playerManager.TryGetSessionById(userId.Value, out var ret))
{
mind.Session = ret;
_actor.Attach(mind.CurrentEntity, mind.Session);
}
// session may be null, but user data may still exist for disconnected players.
if (_playerManager.GetPlayerData(userId.Value).ContentData() is { } data)