Unknown object headers will now crash the game with a copy of the previous object to be read
This commit is contained in:
@@ -974,8 +974,14 @@ namespace Barotrauma.Networking
|
|||||||
|
|
||||||
private void ReadIngameUpdate(NetIncomingMessage inc)
|
private void ReadIngameUpdate(NetIncomingMessage inc)
|
||||||
{
|
{
|
||||||
|
List<IServerSerializable> entities = new List<IServerSerializable>();
|
||||||
|
|
||||||
float sendingTime = inc.ReadFloat() - inc.SenderConnection.RemoteTimeOffset;
|
float sendingTime = inc.ReadFloat() - inc.SenderConnection.RemoteTimeOffset;
|
||||||
|
|
||||||
|
ServerNetObject? prevObjHeader = null;
|
||||||
|
long prevBitPos = 0;
|
||||||
|
long prevBytePos = 0;
|
||||||
|
|
||||||
ServerNetObject objHeader;
|
ServerNetObject objHeader;
|
||||||
while ((objHeader = (ServerNetObject)inc.ReadByte()) != ServerNetObject.END_OF_MESSAGE)
|
while ((objHeader = (ServerNetObject)inc.ReadByte()) != ServerNetObject.END_OF_MESSAGE)
|
||||||
{
|
{
|
||||||
@@ -1004,15 +1010,51 @@ namespace Barotrauma.Networking
|
|||||||
break;
|
break;
|
||||||
case ServerNetObject.ENTITY_EVENT:
|
case ServerNetObject.ENTITY_EVENT:
|
||||||
case ServerNetObject.ENTITY_EVENT_INITIAL:
|
case ServerNetObject.ENTITY_EVENT_INITIAL:
|
||||||
entityEventManager.Read(objHeader, inc, sendingTime);
|
entityEventManager.Read(objHeader, inc, sendingTime, entities);
|
||||||
break;
|
break;
|
||||||
case ServerNetObject.CHAT_MESSAGE:
|
case ServerNetObject.CHAT_MESSAGE:
|
||||||
ChatMessage.ClientRead(inc);
|
ChatMessage.ClientRead(inc);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
DebugConsole.ThrowError("Error while reading update from server (unknown object header \""+objHeader+"\"!)");
|
DebugConsole.ThrowError("Error while reading update from server (unknown object header \""+objHeader+"\"!)");
|
||||||
|
if (prevObjHeader != null)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Previous object type: " + prevObjHeader.ToString());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError("Error occurred on the very first object!");
|
||||||
|
}
|
||||||
|
DebugConsole.ThrowError("Previous object was " + (inc.Position - prevBitPos) + " bits long (" + (inc.PositionInBytes - prevBytePos) + " bytes)");
|
||||||
|
if (prevObjHeader == ServerNetObject.ENTITY_EVENT || prevObjHeader == ServerNetObject.ENTITY_EVENT_INITIAL)
|
||||||
|
{
|
||||||
|
foreach (IServerSerializable ent in entities)
|
||||||
|
{
|
||||||
|
if (ent == null)
|
||||||
|
{
|
||||||
|
DebugConsole.ThrowError(" - NULL");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Entity e = ent as Entity;
|
||||||
|
DebugConsole.ThrowError(" - "+e.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DebugConsole.ThrowError("Writing object data to \"crashreport_object.bin\", please send this file to us at http://github.com/Regalis11/Barotrauma/issues");
|
||||||
|
|
||||||
|
FileStream fl = File.Open("crashreport_object.bin", FileMode.Create);
|
||||||
|
BinaryWriter sw = new BinaryWriter(fl);
|
||||||
|
|
||||||
|
sw.Write(inc.Data, (int)prevBytePos, (int)(inc.LengthBytes - prevBytePos));
|
||||||
|
|
||||||
|
sw.Close();
|
||||||
|
fl.Close();
|
||||||
|
|
||||||
|
throw new Exception("Error while reading update from server: please send us \"crashreport_object.bin\"!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
prevObjHeader = objHeader;
|
||||||
|
prevBitPos = inc.Position;
|
||||||
|
prevBytePos = inc.PositionInBytes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+4
-1
@@ -100,7 +100,7 @@ namespace Barotrauma.Networking
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read the events from the message, ignoring ones we've already received
|
/// Read the events from the message, ignoring ones we've already received
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Read(ServerNetObject type, NetIncomingMessage msg, float sendingTime)
|
public void Read(ServerNetObject type, NetIncomingMessage msg, float sendingTime, List<IServerSerializable> entities)
|
||||||
{
|
{
|
||||||
UInt16 unreceivedEntityEventCount = 0;
|
UInt16 unreceivedEntityEventCount = 0;
|
||||||
|
|
||||||
@@ -128,6 +128,8 @@ namespace Barotrauma.Networking
|
|||||||
firstNewID = null;
|
firstNewID = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
entities.Clear();
|
||||||
|
|
||||||
UInt16 firstEventID = msg.ReadUInt16();
|
UInt16 firstEventID = msg.ReadUInt16();
|
||||||
int eventCount = msg.ReadByte();
|
int eventCount = msg.ReadByte();
|
||||||
|
|
||||||
@@ -146,6 +148,7 @@ namespace Barotrauma.Networking
|
|||||||
byte msgLength = msg.ReadByte();
|
byte msgLength = msg.ReadByte();
|
||||||
|
|
||||||
IServerSerializable entity = Entity.FindEntityByID(entityID) as IServerSerializable;
|
IServerSerializable entity = Entity.FindEntityByID(entityID) as IServerSerializable;
|
||||||
|
entities.Add(entity);
|
||||||
|
|
||||||
//skip the event if we've already received it or if the entity isn't found
|
//skip the event if we've already received it or if the entity isn't found
|
||||||
if (thisEventID != (UInt16)(lastReceivedID + 1) || entity == null)
|
if (thisEventID != (UInt16)(lastReceivedID + 1) || entity == null)
|
||||||
|
|||||||
Reference in New Issue
Block a user