EntityEvents are written and sent even if the entity has been removed at the time of writing. Otherwise the clients may not receive some important events, e.g. when an item applies a statuseffect to something or triggers an explosion and is removed immediately afterwards. I'm not 100% confident that this won't cause any additional issues, so it still needs more testing. See #839

This commit is contained in:
Joonas Rikkonen
2018-10-29 20:37:25 +02:00
parent 9d92b696f0
commit 224e9238db
4 changed files with 26 additions and 6 deletions
@@ -46,6 +46,17 @@ namespace Barotrauma.Networking
return;
}
if (((Entity)entity).Removed)
{
DebugConsole.ThrowError("Can't create an entity event for " + entity + " - the entity has been removed.\n" + Environment.StackTrace);
return;
}
if (((Entity)entity).IdFreed)
{
DebugConsole.ThrowError("Can't create an entity event for " + entity + " - the ID of the entity has been freed.\n" + Environment.StackTrace);
return;
}
ID++;
var newEvent = new ClientEntityEvent(entity, ID);
newEvent.CharacterStateID = GameMain.Client.Character.LastNetworkUpdateID;
@@ -387,7 +387,7 @@ namespace Barotrauma
{
fireSources.Add(fireSource);
if (GameMain.Server != null) GameMain.Server.CreateEntityEvent(this);
if (GameMain.Server != null && !IdFreed) GameMain.Server.CreateEntityEvent(this);
}
public override void Update(float deltaTime, Camera cam)
@@ -56,22 +56,20 @@ namespace Barotrauma.Networking
GameAnalyticsSDK.Net.EGAErrorSeverity.Error,
"Too much data in network event for entity \"" + e.Entity.ToString() + "\" (" + tempEventBuffer.LengthBytes + " bytes");
//write an empty event breaking the event syncing
//write an empty event to prevent breaking the event syncing
tempBuffer.Write((UInt16)0);
tempBuffer.WritePadBits();
eventCount++;
continue;
}
//the ID has been taken by another entity (the original entity has been removed) -> write an empty event
else if (Entity.FindEntityByID(e.Entity.ID) != e.Entity || e.Entity.IdFreed)
/*else if (Entity.FindEntityByID(e.Entity.ID) != e.Entity || e.Entity.IdFreed)
{
//technically the clients don't have any use for these, but removing events and shifting the IDs of all
//consecutive ones is so error-prone that I think this is a safer option
tempBuffer.Write((UInt16)0);
tempBuffer.WritePadBits();
}
}*/
else
{
tempBuffer.Write((UInt16)e.Entity.ID);
@@ -75,6 +75,17 @@ namespace Barotrauma.Networking
return;
}
if (((Entity)entity).Removed)
{
DebugConsole.ThrowError("Can't create an entity event for " + entity + " - the entity has been removed.\n"+Environment.StackTrace);
return;
}
if (((Entity)entity).IdFreed)
{
DebugConsole.ThrowError("Can't create an entity event for " + entity + " - the ID of the entity has been freed.\n"+Environment.StackTrace);
return;
}
var newEvent = new ServerEntityEvent(entity, (UInt16)(ID + 1));
if (extraData != null) newEvent.SetData(extraData);