Server and EntityEventManager debug logging can be enabled in release builds by enabling verbose logging, DebugConsole.ThrowError logs stacktraces

This commit is contained in:
Regalis
2017-06-03 19:01:39 +03:00
parent 1f8460e8ad
commit 96c425414c
4 changed files with 66 additions and 48 deletions
+4 -1
View File
@@ -934,7 +934,10 @@ namespace Barotrauma
public static void ThrowError(string error, Exception e = null) 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); System.Diagnostics.Debug.WriteLine(error);
NewMessage(error, Color.Red); NewMessage(error, Color.Red);
isOpen = true; isOpen = true;
+6 -11
View File
@@ -513,11 +513,10 @@ namespace Barotrauma.Networking
catch (Exception e) catch (Exception e)
{ {
#if DEBUG if (GameSettings.VerboseLogging)
DebugConsole.ThrowError("Failed to read incoming message", e); {
#endif DebugConsole.ThrowError("Failed to read an incoming message. {" + e + "}\n" + e.StackTrace);
}
continue;
} }
} }
@@ -723,28 +722,24 @@ namespace Barotrauma.Networking
{ {
c.lastRecvChatMsgID = lastRecvChatMsgID; c.lastRecvChatMsgID = lastRecvChatMsgID;
} }
#if DEBUG else if (lastRecvChatMsgID != c.lastRecvChatMsgID && GameSettings.VerboseLogging)
else if (lastRecvChatMsgID != c.lastRecvChatMsgID)
{ {
DebugConsole.ThrowError( DebugConsole.ThrowError(
"Invalid lastRecvChatMsgID " + lastRecvChatMsgID + "Invalid lastRecvChatMsgID " + lastRecvChatMsgID +
" (previous: " + c.lastChatMsgQueueID + ", latest: "+c.lastChatMsgQueueID+")"); " (previous: " + c.lastChatMsgQueueID + ", latest: "+c.lastChatMsgQueueID+")");
} }
#endif
if (NetIdUtils.IdMoreRecent(lastRecvEntityEventID, c.lastRecvEntityEventID) && if (NetIdUtils.IdMoreRecent(lastRecvEntityEventID, c.lastRecvEntityEventID) &&
!NetIdUtils.IdMoreRecent(lastRecvEntityEventID, lastEntityEventID)) !NetIdUtils.IdMoreRecent(lastRecvEntityEventID, lastEntityEventID))
{ {
c.lastRecvEntityEventID = lastRecvEntityEventID; c.lastRecvEntityEventID = lastRecvEntityEventID;
} }
#if DEBUG else if (lastRecvEntityEventID != c.lastRecvEntityEventID && GameSettings.VerboseLogging)
else if (lastRecvEntityEventID != c.lastRecvEntityEventID)
{ {
DebugConsole.ThrowError( DebugConsole.ThrowError(
"Invalid lastRecvEntityEventID " + lastRecvEntityEventID + "Invalid lastRecvEntityEventID " + lastRecvEntityEventID +
" (previous: " + c.lastRecvEntityEventID + ", latest: " + lastEntityEventID + ")"); " (previous: " + c.lastRecvEntityEventID + ", latest: " + lastEntityEventID + ")");
} }
#endif
break; break;
case ClientNetObject.CHAT_MESSAGE: case ClientNetObject.CHAT_MESSAGE:
ChatMessage.ServerRead(inc, c); ChatMessage.ServerRead(inc, c);
@@ -112,15 +112,20 @@ namespace Barotrauma.Networking
unreceivedEntityEventCount = msg.ReadUInt16(); unreceivedEntityEventCount = msg.ReadUInt16();
firstNewID = msg.ReadUInt16(); firstNewID = msg.ReadUInt16();
#if DEBUG if (GameSettings.VerboseLogging)
DebugConsole.NewMessage("received midround syncing msg, unreceived: "+unreceivedEntityEventCount+", first new ID: "+firstNewID, Microsoft.Xna.Framework.Color.Yellow); {
#endif DebugConsole.NewMessage(
"received midround syncing msg, unreceived: " + unreceivedEntityEventCount +
", first new ID: " + firstNewID, Microsoft.Xna.Framework.Color.Yellow);
}
} }
else if (firstNewID != null) else if (firstNewID != null)
{ {
#if DEBUG if (GameSettings.VerboseLogging)
DebugConsole.NewMessage("midround syncing complete, switching to ID "+ (UInt16)(firstNewID - 1), Microsoft.Xna.Framework.Color.Yellow); {
#endif DebugConsole.NewMessage("midround syncing complete, switching to ID " + (UInt16) (firstNewID - 1),
Microsoft.Xna.Framework.Color.Yellow);
}
lastReceivedID = (UInt16)(firstNewID - 1); lastReceivedID = (UInt16)(firstNewID - 1);
firstNewID = null; 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 //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)
{ {
#if DEBUG if (GameSettings.VerboseLogging)
if (thisEventID != (UInt16)(lastReceivedID + 1))
{ {
DebugConsole.NewMessage("received msg " + thisEventID + " (waiting for "+ (lastReceivedID+1) + ")", thisEventID<lastReceivedID+1 ? Microsoft.Xna.Framework.Color.Yellow : Microsoft.Xna.Framework.Color.Red); if (thisEventID != (UInt16) (lastReceivedID + 1))
{
DebugConsole.NewMessage(
"received msg " + thisEventID + " (waiting for " + (lastReceivedID + 1) + ")",
thisEventID < lastReceivedID + 1
? Microsoft.Xna.Framework.Color.Yellow
: Microsoft.Xna.Framework.Color.Red);
}
else if (entity == null)
{
DebugConsole.NewMessage(
"received msg " + thisEventID + ", entity " + entityID + " not found",
Microsoft.Xna.Framework.Color.Red);
}
} }
else if (entity == null)
{
DebugConsole.NewMessage("received msg " + thisEventID + ", entity " + entityID + " not found", Microsoft.Xna.Framework.Color.Red);
}
#endif
msg.Position += msgLength * 8; msg.Position += msgLength * 8;
} }
else else
{ {
long msgPosition = msg.Position; long msgPosition = msg.Position;
#if DEBUG if (GameSettings.VerboseLogging)
DebugConsole.NewMessage("received msg " + thisEventID + " (" + entity.ToString() + ")", Microsoft.Xna.Framework.Color.Green); {
#endif DebugConsole.NewMessage("received msg " + thisEventID + " (" + entity.ToString() + ")",
Microsoft.Xna.Framework.Color.Green);
}
lastReceivedID++; lastReceivedID++;
try try
{ {
@@ -174,9 +188,10 @@ namespace Barotrauma.Networking
catch (Exception e) catch (Exception e)
{ {
#if DEBUG if (GameSettings.VerboseLogging)
DebugConsole.ThrowError("Failed to read event for entity \"" + entity.ToString() + "\"!", e); {
#endif DebugConsole.ThrowError("Failed to read event for entity \"" + entity.ToString() + "!", e);
}
msg.Position = msgPosition + msgLength * 8; msg.Position = msgPosition + msgLength * 8;
} }
} }
@@ -135,9 +135,10 @@ namespace Barotrauma.Networking
catch (Exception e) catch (Exception e)
{ {
#if DEBUG if (GameSettings.VerboseLogging)
DebugConsole.ThrowError("Failed to read event for entity \"" + bufferedEvent.TargetEntity.ToString() + "\"!", e); {
#endif DebugConsole.ThrowError("Failed to read event for entity \"" + bufferedEvent.TargetEntity.ToString() + "!", e);
}
} }
bufferedEvent.IsProcessed = true; bufferedEvent.IsProcessed = true;
@@ -326,23 +327,27 @@ namespace Barotrauma.Networking
//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)(sender.lastSentEntityEventID + 1) || entity == null) if (thisEventID != (UInt16)(sender.lastSentEntityEventID + 1) || entity == null)
{ {
#if DEBUG if (GameSettings.VerboseLogging)
if (thisEventID != (UInt16)(sender.lastSentEntityEventID + 1))
{ {
DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Red); if (thisEventID != (UInt16) (sender.lastSentEntityEventID + 1))
{
DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Red);
}
else if (entity == null)
{
DebugConsole.NewMessage(
"received msg " + thisEventID + ", entity " + entityID + " not found",
Microsoft.Xna.Framework.Color.Red);
}
} }
else if (entity == null)
{
DebugConsole.NewMessage("received msg " + thisEventID + ", entity " + entityID + " not found", Microsoft.Xna.Framework.Color.Red);
}
#endif
msg.Position += msgLength * 8; msg.Position += msgLength * 8;
} }
else else
{ {
#if DEBUG if (GameSettings.VerboseLogging)
DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Green); {
#endif DebugConsole.NewMessage("received msg " + thisEventID, Microsoft.Xna.Framework.Color.Green);
}
UInt16 characterStateID = msg.ReadUInt16(); UInt16 characterStateID = msg.ReadUInt16();