From 40f4e946130326240ab560d537b8383cacc3fbb3 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Wed, 25 Jul 2018 17:00:31 +0300 Subject: [PATCH] Fixed incorrect debug info when receiving a message with an invalid object header. The method wrote the bytes/bits read SINCE the previous object (= just one byte, the invalid object header) instead of what was read in the previous object. The error message also ignored empty entity events. --- .../BarotraumaClient/Source/Networking/GameClient.cs | 11 +++++++++-- .../NetEntityEvent/ClientEntityEventManager.cs | 6 ++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs index adbc146eb..c794bd446 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/GameClient.cs @@ -986,6 +986,9 @@ namespace Barotrauma.Networking long prevBitPos = 0; long prevBytePos = 0; + long prevBitLength = 0; + long prevByteLength = 0; + ServerNetObject objHeader; while ((objHeader = (ServerNetObject)inc.ReadByte()) != ServerNetObject.END_OF_MESSAGE) { @@ -1023,8 +1026,9 @@ namespace Barotrauma.Networking List errorLines = new List { "Error while reading update from server (unknown object header \"" + objHeader + "\"!)", + "Message length: " + inc.LengthBits + " (" + inc.LengthBytes + " bytes)", prevObjHeader != null ? "Previous object type: " + prevObjHeader.ToString() : "Error occurred on the very first object!", - "Previous object was " + (inc.Position - prevBitPos) + " bits long (" + (inc.PositionInBytes - prevBytePos) + " bytes)" + "Previous object was " + (prevBitLength) + " bits long (" + (prevByteLength) + " bytes)" }; if (prevObjHeader == ServerNetObject.ENTITY_EVENT || prevObjHeader == ServerNetObject.ENTITY_EVENT_INITIAL) { @@ -1051,13 +1055,16 @@ namespace Barotrauma.Networking 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.Write(inc.Data, (int)(prevBytePos - prevByteLength), (int)(prevByteLength)); sw.Close(); fl.Close(); throw new Exception("Error while reading update from server: please send us \"crashreport_object.bin\"!"); } + prevBitLength = inc.Position - prevBitPos; + prevByteLength = inc.PositionInBytes - prevByteLength; + prevObjHeader = objHeader; prevBitPos = inc.Position; prevBytePos = inc.PositionInBytes; diff --git a/Barotrauma/BarotraumaClient/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs b/Barotrauma/BarotraumaClient/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs index cd4c92164..f8cec2fe5 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs @@ -140,7 +140,13 @@ namespace Barotrauma.Networking if (entityID == 0) { + if (GameSettings.VerboseLogging) + { + DebugConsole.NewMessage("received msg " + thisEventID + " (null entity)", + Microsoft.Xna.Framework.Color.Orange); + } msg.ReadPadBits(); + entities.Add(null); if (thisEventID == (UInt16)(lastReceivedID + 1)) lastReceivedID++; continue; }