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:
+11
@@ -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)
|
||||
|
||||
+3
-5
@@ -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);
|
||||
|
||||
+11
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user