A fix to occasional "unknown object header" errors.

If an entity had been removed and it's ID taken by some other entity, clients who hadn't received a message about the removal and the new entity would end up reading ENTITY_POSITION messages for the new entity incorrectly. Reading an incorrect number of bits from the message would also prevent the clients from reading the rest of the data in the packet properly.

Now the server doesn't send position updates to clients during midround syncing (because there's no guarantee they know about the entity yet). Clients also force the read position to the correct place after reading a position update in case something goes wrong when reading the msg.
This commit is contained in:
Regalis
2017-04-09 19:00:33 +03:00
parent 4ee96e4fbe
commit 0301457a8f
3 changed files with 47 additions and 44 deletions

View File

@@ -921,18 +921,17 @@ namespace Barotrauma.Networking
UInt16 id = inc.ReadUInt16();
byte msgLength = inc.ReadByte();
long msgEndPos = inc.Position + msgLength * 8;
var entity = Entity.FindEntityByID(id) as IServerSerializable;
if (entity == null)
{
//skip through the rest of the message
inc.Position += msgLength * 8;
}
else
if (entity != null)
{
entity.ClientRead(objHeader, inc, sendingTime);
}
inc.ReadPadBits();
//force to the correct position in case the entity doesn't exist
//or the message wasn't read correctly for whatever reason
inc.Position = msgEndPos;
break;
case ServerNetObject.ENTITY_EVENT:
case ServerNetObject.ENTITY_EVENT_INITIAL: