Fix ghost respawn bug (#17511)
This commit is contained in:
@@ -27,15 +27,16 @@ namespace Content.Server.GameTicking
|
||||
{
|
||||
var session = args.Session;
|
||||
|
||||
if (_mindSystem.TryGetMind(session.UserId, out var mind))
|
||||
if (_mind.TryGetMind(session.UserId, out var mind))
|
||||
{
|
||||
if (args.OldStatus == SessionStatus.Connecting && args.NewStatus == SessionStatus.Connected)
|
||||
mind.Session = session;
|
||||
|
||||
DebugTools.Assert(mind.Session == session);
|
||||
DebugTools.Assert(session.Data.ContentData()?.Mind is not {} dataMind || dataMind == mind);
|
||||
}
|
||||
|
||||
DebugTools.Assert(session.GetMind() == mind);
|
||||
|
||||
switch (args.NewStatus)
|
||||
{
|
||||
case SessionStatus.Connected:
|
||||
@@ -75,32 +76,32 @@ namespace Content.Server.GameTicking
|
||||
{
|
||||
_userDb.ClientConnected(session);
|
||||
|
||||
var data = session.ContentData();
|
||||
|
||||
DebugTools.AssertNotNull(data);
|
||||
|
||||
if (data!.Mind == null)
|
||||
if (mind == null)
|
||||
{
|
||||
if (LobbyEnabled)
|
||||
{
|
||||
PlayerJoinLobby(session);
|
||||
return;
|
||||
}
|
||||
else
|
||||
SpawnWaitDb();
|
||||
|
||||
SpawnWaitDb();
|
||||
break;
|
||||
}
|
||||
|
||||
if (data.Mind.CurrentEntity == null || Deleted(data.Mind.CurrentEntity))
|
||||
if (mind.CurrentEntity == null || Deleted(mind.CurrentEntity))
|
||||
{
|
||||
DebugTools.Assert(data.Mind.CurrentEntity == null, "a mind's current entity has been deleted");
|
||||
SpawnWaitDb();
|
||||
DebugTools.Assert(mind.CurrentEntity == null, "a mind's current entity was deleted without updating the mind");
|
||||
|
||||
// This player is joining the game with an existing mind, but the mind has no entity.
|
||||
// Their entity was probably deleted sometime while they were disconnected, or they were an observer.
|
||||
// Instead of allowing them to spawn in, we will dump and their existing mind in an observer ghost.
|
||||
SpawnObserverWaitDb();
|
||||
}
|
||||
else
|
||||
{
|
||||
session.AttachToEntity(data.Mind.CurrentEntity);
|
||||
// Simply re-attach to existing entity.
|
||||
session.AttachToEntity(mind.CurrentEntity);
|
||||
PlayerJoinGame(session);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -123,6 +124,12 @@ namespace Content.Server.GameTicking
|
||||
SpawnPlayer(session, EntityUid.Invalid);
|
||||
}
|
||||
|
||||
async void SpawnObserverWaitDb()
|
||||
{
|
||||
await _userDb.WaitLoadComplete(session);
|
||||
JoinAsObserver(session);
|
||||
}
|
||||
|
||||
async void AddPlayerToDb(Guid id)
|
||||
{
|
||||
if (RoundId != 0 && _runLevel != GameRunLevel.PreRoundLobby)
|
||||
|
||||
Reference in New Issue
Block a user