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:
@@ -84,6 +84,11 @@ namespace Barotrauma
|
|||||||
|
|
||||||
public bool isSynced = false;
|
public bool isSynced = false;
|
||||||
|
|
||||||
|
public string OwnerClientIP;
|
||||||
|
public string OwnerClientName;
|
||||||
|
public bool ClientDisconnected;
|
||||||
|
public float KillDisconnectedTimer;
|
||||||
|
|
||||||
public List<CharacterStateInfo> MemState
|
public List<CharacterStateInfo> MemState
|
||||||
{
|
{
|
||||||
get { return memState; }
|
get { return memState; }
|
||||||
|
|||||||
@@ -368,6 +368,28 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
entityEventManager.Update(connectedClients);
|
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 =
|
bool isCrewDead =
|
||||||
connectedClients.All(c => c.Character == null || c.Character.IsDead || c.Character.IsUnconscious) &&
|
connectedClients.All(c => c.Character == null || c.Character.IsDead || c.Character.IsUnconscious) &&
|
||||||
(myCharacter == null || myCharacter.IsDead || myCharacter.IsUnconscious);
|
(myCharacter == null || myCharacter.IsDead || myCharacter.IsUnconscious);
|
||||||
@@ -1313,6 +1335,8 @@ namespace Barotrauma.Networking
|
|||||||
spawnedCharacter.GiveJobItems(assignedWayPoints[i]);
|
spawnedCharacter.GiveJobItems(assignedWayPoints[i]);
|
||||||
|
|
||||||
teamClients[i].Character = spawnedCharacter;
|
teamClients[i].Character = spawnedCharacter;
|
||||||
|
spawnedCharacter.OwnerClientIP = teamClients[i].Connection.RemoteEndPoint.Address.ToString();
|
||||||
|
spawnedCharacter.OwnerClientName = teamClients[i].Name;
|
||||||
|
|
||||||
#if CLIENT
|
#if CLIENT
|
||||||
GameMain.GameSession.CrewManager.AddCharacter(spawnedCharacter);
|
GameMain.GameSession.CrewManager.AddCharacter(spawnedCharacter);
|
||||||
@@ -1610,8 +1634,8 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
if (gameStarted && client.Character != null)
|
if (gameStarted && client.Character != null)
|
||||||
{
|
{
|
||||||
|
client.Character.ClientDisconnected = true;
|
||||||
client.Character.ClearInputs();
|
client.Character.ClearInputs();
|
||||||
client.Character.Kill(CauseOfDeath.Disconnected, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
client.Character = null;
|
client.Character = null;
|
||||||
@@ -2006,6 +2030,8 @@ namespace Barotrauma.Networking
|
|||||||
if (client.Character != null)
|
if (client.Character != null)
|
||||||
{
|
{
|
||||||
client.Character.IsRemotePlayer = false;
|
client.Character.IsRemotePlayer = false;
|
||||||
|
client.Character.OwnerClientIP = null;
|
||||||
|
client.Character.OwnerClientName = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newCharacter == null)
|
if (newCharacter == null)
|
||||||
@@ -2015,16 +2041,19 @@ namespace Barotrauma.Networking
|
|||||||
CreateEntityEvent(client.Character, new object[] { NetEntityEvent.Type.Control, null });
|
CreateEntityEvent(client.Character, new object[] { NetEntityEvent.Type.Control, null });
|
||||||
client.Character = null;
|
client.Character = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else //taking control of a new character
|
else //taking control of a new character
|
||||||
{
|
{
|
||||||
|
newCharacter.ClientDisconnected = false;
|
||||||
|
newCharacter.KillDisconnectedTimer = 0.0f;
|
||||||
newCharacter.ResetNetState();
|
newCharacter.ResetNetState();
|
||||||
if (client.Character != null)
|
if (client.Character != null)
|
||||||
{
|
{
|
||||||
newCharacter.LastNetworkUpdateID = client.Character.LastNetworkUpdateID;
|
newCharacter.LastNetworkUpdateID = client.Character.LastNetworkUpdateID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newCharacter.OwnerClientIP = client.Connection.RemoteEndPoint.Address.ToString();
|
||||||
|
newCharacter.OwnerClientName = client.Name;
|
||||||
newCharacter.IsRemotePlayer = true;
|
newCharacter.IsRemotePlayer = true;
|
||||||
newCharacter.Enabled = true;
|
newCharacter.Enabled = true;
|
||||||
client.Character = newCharacter;
|
client.Character = newCharacter;
|
||||||
|
|||||||
@@ -219,6 +219,13 @@ namespace Barotrauma.Networking
|
|||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serialize(30.0f, true)]
|
||||||
|
public bool KillDisconnectedTime
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
private set;
|
||||||
|
}
|
||||||
|
|
||||||
[Serialize(true, true)]
|
[Serialize(true, true)]
|
||||||
public bool TraitorUseRatio
|
public bool TraitorUseRatio
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user