From be5f168b76bf0ff7ad4634045231eda2c4aab6c9 Mon Sep 17 00:00:00 2001 From: Joonas Rikkonen Date: Mon, 23 Jul 2018 21:16:57 +0300 Subject: [PATCH] Sending error messages during EntityEvent writing/reading and entity removal to GameAnalytics --- .../ClientEntityEventManager.cs | 6 +-- .../BarotraumaShared/Source/Map/Entity.cs | 48 ++++++++++++++----- .../ServerEntityEventManager.cs | 6 ++- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Barotrauma/BarotraumaClient/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs b/Barotrauma/BarotraumaClient/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs index 4beda97e2..cd4c92164 100644 --- a/Barotrauma/BarotraumaClient/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs +++ b/Barotrauma/BarotraumaClient/Source/Networking/NetEntityEvent/ClientEntityEventManager.cs @@ -191,10 +191,10 @@ namespace Barotrauma.Networking if (GameSettings.VerboseLogging) { DebugConsole.ThrowError("Failed to read event for entity \"" + entity.ToString() + "\"!", e); - GameAnalyticsManager.AddErrorEventOnce("ClientEntityEventManager.Read:ReadFailed" + entity.ToString(), - GameAnalyticsSDK.Net.EGAErrorSeverity.Error, - "Failed to read event for entity \"" + entity.ToString() + "\"!\n" + e.StackTrace); } + GameAnalyticsManager.AddErrorEventOnce("ClientEntityEventManager.Read:ReadFailed" + entity.ToString(), + GameAnalyticsSDK.Net.EGAErrorSeverity.Error, + "Failed to read event for entity \"" + entity.ToString() + "\"!\n" + e.StackTrace); msg.Position = msgPosition + msgLength * 8; } } diff --git a/Barotrauma/BarotraumaShared/Source/Map/Entity.cs b/Barotrauma/BarotraumaShared/Source/Map/Entity.cs index ac0046d75..8546ff782 100644 --- a/Barotrauma/BarotraumaShared/Source/Map/Entity.cs +++ b/Barotrauma/BarotraumaShared/Source/Map/Entity.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; namespace Barotrauma { @@ -126,22 +127,27 @@ namespace Barotrauma catch (Exception exception) { DebugConsole.ThrowError("Error while removing entity \"" + e.ToString() + "\"", exception); + GameAnalyticsManager.AddErrorEventOnce( + "Entity.RemoveAll:Exception" + e.ToString(), + GameAnalyticsSDK.Net.EGAErrorSeverity.Error, + "Error while removing entity \"" + e.ToString() + "\"" + exception.Message); } } + StringBuilder errorMsg = new StringBuilder(); if (dictionary.Count > 0) { - DebugConsole.ThrowError("Some entities were not removed in Entity.RemoveAll:"); + errorMsg.AppendLine("Some entities were not removed in Entity.RemoveAll:"); foreach (Entity e in dictionary.Values) { - DebugConsole.ThrowError(" - " + e.ToString() + "(ID " + e.id + ")"); + errorMsg.AppendLine(" - " + e.ToString() + "(ID " + e.id + ")"); } } if (Item.ItemList.Count > 0) { - DebugConsole.ThrowError("Some items were not removed in Entity.RemoveAll:"); + errorMsg.AppendLine("Some items were not removed in Entity.RemoveAll:"); foreach (Item item in Item.ItemList) { - DebugConsole.ThrowError(" - " + item.Name + "(ID " + item.id + ")"); + errorMsg.AppendLine(" - " + item.Name + "(ID " + item.id + ")"); } var items = new List(Item.ItemList); @@ -153,17 +159,17 @@ namespace Barotrauma } catch (Exception exception) { - DebugConsole.ThrowError("Error while removing entity \"" + item.ToString() + "\"", exception); + DebugConsole.ThrowError("Error while removing item \"" + item.ToString() + "\"", exception); } } Item.ItemList.Clear(); } if (Character.CharacterList.Count > 0) { - DebugConsole.ThrowError("Some characters were not removed in Entity.RemoveAll:"); + errorMsg.AppendLine("Some characters were not removed in Entity.RemoveAll:"); foreach (Character character in Character.CharacterList) { - DebugConsole.ThrowError(" - " + character.Name + "(ID " + character.id + ")"); + errorMsg.AppendLine(" - " + character.Name + "(ID " + character.id + ")"); } var characters = new List(Character.CharacterList); @@ -175,26 +181,42 @@ namespace Barotrauma } catch (Exception exception) { - DebugConsole.ThrowError("Error while removing entity \"" + character.ToString() + "\"", exception); + DebugConsole.ThrowError("Error while removing character \"" + character.ToString() + "\"", exception); } } Character.CharacterList.Clear(); } + if (!string.IsNullOrEmpty(errorMsg.ToString())) + { + foreach (string errorLine in errorMsg.ToString().Split('\n')) + { + DebugConsole.ThrowError(errorLine); + } + GameAnalyticsManager.AddErrorEventOnce("Entity.RemoveAll", GameAnalyticsSDK.Net.EGAErrorSeverity.Error, errorMsg.ToString()); + } + dictionary.Clear(); } public virtual void Remove() { - DebugConsole.Log("Removing entity " + this.ToString() + " (" + ID + ") from entity dictionary."); - Entity existingEntity; - if (!dictionary.TryGetValue(ID, out existingEntity)) + DebugConsole.Log("Removing entity " + ToString() + " (" + ID + ") from entity dictionary."); + if (!dictionary.TryGetValue(ID, out Entity existingEntity)) { - DebugConsole.Log("Entity " + this.ToString() + " (" + ID + ") not present in entity dictionary."); + DebugConsole.Log("Entity " + ToString() + " (" + ID + ") not present in entity dictionary."); + GameAnalyticsManager.AddErrorEventOnce( + "Entity.Remove:EntityNotFound" + ID, + GameAnalyticsSDK.Net.EGAErrorSeverity.Error, + "Entity " + ToString() + " (" + ID + ") not present in entity dictionary.\n" + Environment.StackTrace); } else if (existingEntity != this) { - DebugConsole.Log("Entity ID mismatch in entity dictionary. Entity " + existingEntity + " had the ID " + ID); + DebugConsole.Log("Entity ID mismatch in entity dictionary. Entity " + existingEntity + " had the ID " + ID + " (expecting " + ToString() + ")"); + GameAnalyticsManager.AddErrorEventOnce("Entity.Remove:EntityMismatch" + ID, + GameAnalyticsSDK.Net.EGAErrorSeverity.Error, + "Entity ID mismatch in entity dictionary. Entity " + existingEntity + " had the ID " + ID + " (expecting " + ToString() + ")"); + foreach (var keyValuePair in dictionary.Where(kvp => kvp.Value == this).ToList()) { dictionary.Remove(keyValuePair.Key); diff --git a/Barotrauma/BarotraumaShared/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs b/Barotrauma/BarotraumaShared/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs index 5c0986cd4..648b28c43 100644 --- a/Barotrauma/BarotraumaShared/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs +++ b/Barotrauma/BarotraumaShared/Source/Networking/NetEntityEvent/ServerEntityEventManager.cs @@ -135,10 +135,14 @@ namespace Barotrauma.Networking catch (Exception e) { + string entityName = bufferedEvent.TargetEntity == null ? "null" : bufferedEvent.TargetEntity.ToString(); if (GameSettings.VerboseLogging) { - DebugConsole.ThrowError("Failed to read event for entity \"" + bufferedEvent.TargetEntity.ToString() + "\"!", e); + DebugConsole.ThrowError("Failed to read server event for entity \"" + entityName + "\"!", e); } + GameAnalyticsManager.AddErrorEventOnce("ServerEntityEventManager.Read:ReadFailed" + entityName, + GameAnalyticsSDK.Net.EGAErrorSeverity.Error, + "Failed to read server event for entity \"" + entityName + "\"!\n" + e.StackTrace); } bufferedEvent.IsProcessed = true;