From 96c425414c03aa23d2c8797dcb76721a01fd2d93 Mon Sep 17 00:00:00 2001 From: Regalis Date: Sat, 3 Jun 2017 19:01:39 +0300 Subject: [PATCH] Server and EntityEventManager debug logging can be enabled in release builds by enabling verbose logging, DebugConsole.ThrowError logs stacktraces --- Subsurface/Source/DebugConsole.cs | 7 ++- Subsurface/Source/Networking/GameServer.cs | 19 +++---- .../ClientEntityEventManager.cs | 55 ++++++++++++------- .../ServerEntityEventManager.cs | 33 ++++++----- 4 files changed, 66 insertions(+), 48 deletions(-) diff --git a/Subsurface/Source/DebugConsole.cs b/Subsurface/Source/DebugConsole.cs index 9e117a51d..03036e087 100644 --- a/Subsurface/Source/DebugConsole.cs +++ b/Subsurface/Source/DebugConsole.cs @@ -933,8 +933,11 @@ namespace Barotrauma } public static void ThrowError(string error, Exception e = null) - { - if (e != null) error += " {" + e.Message + "}"; + { + if (e != null) + { + error += " {" + e.Message + "}\n" + e.StackTrace; + } System.Diagnostics.Debug.WriteLine(error); NewMessage(error, Color.Red); isOpen = true; diff --git a/Subsurface/Source/Networking/GameServer.cs b/Subsurface/Source/Networking/GameServer.cs index 88131ded2..53249abc2 100644 --- a/Subsurface/Source/Networking/GameServer.cs +++ b/Subsurface/Source/Networking/GameServer.cs @@ -173,7 +173,7 @@ namespace Barotrauma.Networking fileSender = new FileSender(this); fileSender.OnEnded += FileTransferChanged; fileSender.OnStarted += FileTransferChanged; - + server.Start(); } catch (Exception e) @@ -513,11 +513,10 @@ namespace Barotrauma.Networking catch (Exception e) { -#if DEBUG - DebugConsole.ThrowError("Failed to read incoming message", e); -#endif - - continue; + if (GameSettings.VerboseLogging) + { + DebugConsole.ThrowError("Failed to read an incoming message. {" + e + "}\n" + e.StackTrace); + } } } @@ -723,28 +722,24 @@ namespace Barotrauma.Networking { c.lastRecvChatMsgID = lastRecvChatMsgID; } -#if DEBUG - else if (lastRecvChatMsgID != c.lastRecvChatMsgID) + else if (lastRecvChatMsgID != c.lastRecvChatMsgID && GameSettings.VerboseLogging) { DebugConsole.ThrowError( "Invalid lastRecvChatMsgID " + lastRecvChatMsgID + " (previous: " + c.lastChatMsgQueueID + ", latest: "+c.lastChatMsgQueueID+")"); } -#endif if (NetIdUtils.IdMoreRecent(lastRecvEntityEventID, c.lastRecvEntityEventID) && !NetIdUtils.IdMoreRecent(lastRecvEntityEventID, lastEntityEventID)) { c.lastRecvEntityEventID = lastRecvEntityEventID; } -#if DEBUG - else if (lastRecvEntityEventID != c.lastRecvEntityEventID) + else if (lastRecvEntityEventID != c.lastRecvEntityEventID && GameSettings.VerboseLogging) { DebugConsole.ThrowError( "Invalid lastRecvEntityEventID " + lastRecvEntityEventID + " (previous: " + c.lastRecvEntityEventID + ", latest: " + lastEntityEventID + ")"); } -#endif break; case ClientNetObject.CHAT_MESSAGE: ChatMessage.ServerRead(inc, c); diff --git a/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs b/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs index 3c168e98a..1153e0b1a 100644 --- a/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs +++ b/Subsurface/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs @@ -112,15 +112,20 @@ namespace Barotrauma.Networking unreceivedEntityEventCount = msg.ReadUInt16(); firstNewID = msg.ReadUInt16(); -#if DEBUG - DebugConsole.NewMessage("received midround syncing msg, unreceived: "+unreceivedEntityEventCount+", first new ID: "+firstNewID, Microsoft.Xna.Framework.Color.Yellow); -#endif + if (GameSettings.VerboseLogging) + { + DebugConsole.NewMessage( + "received midround syncing msg, unreceived: " + unreceivedEntityEventCount + + ", first new ID: " + firstNewID, Microsoft.Xna.Framework.Color.Yellow); + } } else if (firstNewID != null) { -#if DEBUG - DebugConsole.NewMessage("midround syncing complete, switching to ID "+ (UInt16)(firstNewID - 1), Microsoft.Xna.Framework.Color.Yellow); -#endif + if (GameSettings.VerboseLogging) + { + DebugConsole.NewMessage("midround syncing complete, switching to ID " + (UInt16) (firstNewID - 1), + Microsoft.Xna.Framework.Color.Yellow); + } lastReceivedID = (UInt16)(firstNewID - 1); firstNewID = null; @@ -148,24 +153,33 @@ namespace Barotrauma.Networking //skip the event if we've already received it or if the entity isn't found if (thisEventID != (UInt16)(lastReceivedID + 1) || entity == null) { -#if DEBUG - if (thisEventID != (UInt16)(lastReceivedID + 1)) + if (GameSettings.VerboseLogging) { - DebugConsole.NewMessage("received msg " + thisEventID + " (waiting for "+ (lastReceivedID+1) + ")", thisEventID