Characters stay alive for 30 seconds after a client disconnects, and if the client rejoins during that time they regain control of the character. Closes #42

This commit is contained in:
Joonas Rikkonen
2018-08-06 13:38:39 +03:00
parent af3fa80011
commit 4ebe3d715e
3 changed files with 45 additions and 4 deletions

View File

@@ -79,11 +79,16 @@ namespace Barotrauma
private List<CharacterStateInfo> memState = new List<CharacterStateInfo>();
private List<CharacterStateInfo> memLocalState = new List<CharacterStateInfo>();
private bool networkUpdateSent;
public bool isSynced = false;
public string OwnerClientIP;
public string OwnerClientName;
public bool ClientDisconnected;
public float KillDisconnectedTimer;
public List<CharacterStateInfo> MemState
{
get { return memState; }

View File

@@ -368,6 +368,28 @@ namespace Barotrauma.Networking
entityEventManager.Update(connectedClients);
foreach (Character character in Character.CharacterList)
{
if (character.IsDead || !character.ClientDisconnected) continue;
character.KillDisconnectedTimer += deltaTime;
character.SetStun(1.0f);
if (character.KillDisconnectedTimer > KillDisconnectedTime)
{
character.Kill(CauseOfDeath.Disconnected);
continue;
}
Client owner = connectedClients.Find(c =>
c.InGame && !c.NeedsMidRoundSync &&
c.Name == character.OwnerClientName &&
c.Connection.RemoteEndPoint.Address.ToString() == character.OwnerClientIP);
if (owner != null)
{
SetClientCharacter(owner, character);
}
}
bool isCrewDead =
connectedClients.All(c => c.Character == null || c.Character.IsDead || c.Character.IsUnconscious) &&
(myCharacter == null || myCharacter.IsDead || myCharacter.IsUnconscious);
@@ -1313,6 +1335,8 @@ namespace Barotrauma.Networking
spawnedCharacter.GiveJobItems(assignedWayPoints[i]);
teamClients[i].Character = spawnedCharacter;
spawnedCharacter.OwnerClientIP = teamClients[i].Connection.RemoteEndPoint.Address.ToString();
spawnedCharacter.OwnerClientName = teamClients[i].Name;
#if CLIENT
GameMain.GameSession.CrewManager.AddCharacter(spawnedCharacter);
@@ -1610,8 +1634,8 @@ namespace Barotrauma.Networking
if (gameStarted && client.Character != null)
{
client.Character.ClientDisconnected = true;
client.Character.ClearInputs();
client.Character.Kill(CauseOfDeath.Disconnected, true);
}
client.Character = null;
@@ -2006,6 +2030,8 @@ namespace Barotrauma.Networking
if (client.Character != null)
{
client.Character.IsRemotePlayer = false;
client.Character.OwnerClientIP = null;
client.Character.OwnerClientName = null;
}
if (newCharacter == null)
@@ -2015,16 +2041,19 @@ namespace Barotrauma.Networking
CreateEntityEvent(client.Character, new object[] { NetEntityEvent.Type.Control, null });
client.Character = null;
}
}
else //taking control of a new character
{
newCharacter.ClientDisconnected = false;
newCharacter.KillDisconnectedTimer = 0.0f;
newCharacter.ResetNetState();
if (client.Character != null)
{
newCharacter.LastNetworkUpdateID = client.Character.LastNetworkUpdateID;
}
newCharacter.OwnerClientIP = client.Connection.RemoteEndPoint.Address.ToString();
newCharacter.OwnerClientName = client.Name;
newCharacter.IsRemotePlayer = true;
newCharacter.Enabled = true;
client.Character = newCharacter;

View File

@@ -219,6 +219,13 @@ namespace Barotrauma.Networking
private set;
}
[Serialize(30.0f, true)]
public bool KillDisconnectedTime
{
get;
private set;
}
[Serialize(true, true)]
public bool TraitorUseRatio
{