From 18e52d1a25d012f42e9e0f294db2960a0f843053 Mon Sep 17 00:00:00 2001 From: stevenh Date: Tue, 28 Feb 2012 10:58:40 +0000 Subject: [PATCH 1/2] Added protection against downstream exceptions when saving the world --- TShockAPI/SaveManager.cs | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/TShockAPI/SaveManager.cs b/TShockAPI/SaveManager.cs index dca8628e..f411a2ef 100644 --- a/TShockAPI/SaveManager.cs +++ b/TShockAPI/SaveManager.cs @@ -31,7 +31,17 @@ namespace TShockAPI /// public void OnSaveWorld(bool resettime = false, HandledEventArgs e = null) { - TShock.Utils.Broadcast("Saving world. Momentary lag might result from this.", Color.Red); + // Protect against internal errors causing save failures + // These can be caused by an unexpected error such as a bad or out of date plugin + try + { + TShock.Utils.Broadcast("Saving world. Momentary lag might result from this.", Color.Red); + } + catch (Exception ex) + { + Log.Error("World saved notification failed"); + Log.Error(ex.ToString()); + } } /// @@ -88,15 +98,25 @@ namespace TShockAPI return; else { - if (task.direct) + // Ensure that save handler errors don't bubble up and cause a recursive call + // These can be caused by an unexpected error such as a bad or out of date plugin + try { - OnSaveWorld(); - WorldGen.realsaveWorld(task.resetTime); + if (task.direct) + { + OnSaveWorld(); + WorldGen.realsaveWorld(task.resetTime); + } + else + WorldGen.saveWorld(task.resetTime); + TShock.Utils.Broadcast("World saved.", Color.Yellow); + Log.Info(string.Format("World saved at ({0})", Main.worldPathName)); + } + catch (Exception e) + { + Log.Error("World saved failed"); + Log.Error(e.ToString()); } - else - WorldGen.saveWorld(task.resetTime); - TShock.Utils.Broadcast("World saved.", Color.Yellow); - Log.Info(string.Format("World saved at ({0})", Main.worldPathName)); } } } From dbda83b8e7eab771b26f30bedd4842eb3cf54cb4 Mon Sep 17 00:00:00 2001 From: stevenh Date: Tue, 28 Feb 2012 10:57:05 +0000 Subject: [PATCH 2/2] Corrected compat ForceKick method signature --- TShockAPI/Utils.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/TShockAPI/Utils.cs b/TShockAPI/Utils.cs index 5fa73d26..f6ead281 100644 --- a/TShockAPI/Utils.cs +++ b/TShockAPI/Utils.cs @@ -532,9 +532,9 @@ namespace TShockAPI #if COMPAT_SIGS [Obsolete("This method is for signature compatibility for external code only")] - public bool ForceKick(TSPlayer player, string reason) + public void ForceKick(TSPlayer player, string reason) { - return Kick(player, reason, true, false, string.Empty); + Kick(player, reason, true, false, string.Empty); } #endif /// @@ -801,4 +801,4 @@ namespace TShockAPI return new string(returnstr); } } -} \ No newline at end of file +}