From 683d45f00c36b14ddc2d02395c55abefda078b9d Mon Sep 17 00:00:00 2001 From: high Date: Sun, 5 Jun 2011 15:15:37 -0400 Subject: [PATCH] Added unhandled exception logging. Also if server crashes from an unhandled exception it will save the world with .crash appended. --- TShockAPI/TShock.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 0b505b2f..22a40338 100644 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -126,14 +126,26 @@ namespace TShockAPI NetHooks.OnGreetPlayer += new NetHooks.GreetPlayerD(OnGreetPlayer); NpcHooks.OnStrikeNpc += new NpcHooks.StrikeNpcD(NpcHooks_OnStrikeNpc); ServerHooks.OnCommand += new ServerHooks.CommandD(ServerHooks_OnCommand); + + AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; + Log.Info("Hooks initialized"); Commands.InitCommands(); Log.Info("Commands initialized"); } + void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + if (Main.worldPathName != null) + { + Main.worldPathName += ".crash"; + WorldGen.saveWorld(); + } + Log.Error(e.ExceptionObject.ToString()); + } + void ServerHooks_OnCommand(string cmd, HandledEventArgs e) { - } public override void DeInitialize() @@ -762,6 +774,7 @@ namespace TShockAPI { public float X; public float Y; + public Position(float x, float y) { X = x; Y = y; } }