From 1ea6d2e95587cb9aa237462e74a01091c280fee3 Mon Sep 17 00:00:00 2001 From: ricky Date: Wed, 15 Jun 2011 20:54:32 +1000 Subject: [PATCH] Fixed exception in commands crashing the server Removed Tools.WriteError using Log.Error instead. --- TShockAPI/Commands.cs | 10 +++++++++- TShockAPI/FileTools.cs | 12 ------------ TShockAPI/TShock.cs | 39 +++++++++++++++++++------------------- TShockAPI/Tools.cs | 2 +- TShockAPI/UpdateManager.cs | 2 +- 5 files changed, 31 insertions(+), 34 deletions(-) diff --git a/TShockAPI/Commands.cs b/TShockAPI/Commands.cs index 9f799060..4057f6e3 100755 --- a/TShockAPI/Commands.cs +++ b/TShockAPI/Commands.cs @@ -74,7 +74,15 @@ namespace TShockAPI if (!ply.Group.HasPermission(permission)) return false; - command(new CommandArgs(msg, ply, parms)); + try + { + command(new CommandArgs(msg, ply, parms)); + } + catch (Exception e) + { + Log.Error(e.ToString()); + } + return true; } diff --git a/TShockAPI/FileTools.cs b/TShockAPI/FileTools.cs index 3a41efb0..d82ad069 100644 --- a/TShockAPI/FileTools.cs +++ b/TShockAPI/FileTools.cs @@ -22,7 +22,6 @@ namespace TShockAPI { internal class FileTools { - public static readonly string ErrorsPath = Path.Combine(TShock.SavePath, "errors.txt"); public static readonly string RulesPath = Path.Combine(TShock.SavePath, "rules.txt"); public static readonly string MotdPath = Path.Combine(TShock.SavePath, "motd.txt"); public static readonly string BansPath = Path.Combine(TShock.SavePath, "bans.txt"); @@ -44,17 +43,6 @@ namespace TShockAPI } } - /// - /// Writes an error message to errors.txt - /// - /// string message - public static void WriteError(string err) - { - TextWriter tw = new StreamWriter(ErrorsPath, true); - tw.WriteLine(err); - tw.Close(); - } - /// /// Sets up the configuration file for all variables, and creates any missing files. /// diff --git a/TShockAPI/TShock.cs b/TShockAPI/TShock.cs index 2103f061..203ed518 100755 --- a/TShockAPI/TShock.cs +++ b/TShockAPI/TShock.cs @@ -176,6 +176,21 @@ namespace TShockAPI HandleCommandLine(Environment.GetCommandLineArgs()); } + public override void DeInitialize() + { + Bans.SaveBans(); + ConfigurationManager.WriteJsonConfiguration(); + GameHooks.PostInitialize -= OnPostInit; + GameHooks.Update -= OnUpdate; + ServerHooks.Chat -= OnChat; + ServerHooks.Join -= OnJoin; + ServerHooks.Leave -= OnLeave; + ServerHooks.Command -= ServerHooks_OnCommand; + NetHooks.GetData -= GetData; + NetHooks.GreetPlayer -= OnGreetPlayer; + NpcHooks.StrikeNpc -= NpcHooks_OnStrikeNpc; + } + /// /// Handles exceptions that we didn't catch or that Red fucked up /// @@ -195,6 +210,11 @@ namespace TShockAPI Log.Error(e.ExceptionObject.ToString()); } + /* + * Hooks: + * + */ + /// /// When a server command is run. /// @@ -254,25 +274,6 @@ namespace TShockAPI Log.Info(string.Format("Server said: {0}", text.Remove(0, 4))); } - public override void DeInitialize() - { - Bans.SaveBans(); - ConfigurationManager.WriteJsonConfiguration(); - GameHooks.PostInitialize -= OnPostInit; - GameHooks.Update -= OnUpdate; - ServerHooks.Chat -= OnChat; - ServerHooks.Join -= OnJoin; - ServerHooks.Leave -= OnLeave; - ServerHooks.Command -= ServerHooks_OnCommand; - NetHooks.GetData -= GetData; - NetHooks.GreetPlayer -= OnGreetPlayer; - NpcHooks.StrikeNpc -= NpcHooks_OnStrikeNpc; - } - - /* - * Hooks: - * */ - private void NpcHooks_OnStrikeNpc(NpcStrikeEventArgs e) { if (ConfigurationManager.InfiniteInvasion) diff --git a/TShockAPI/Tools.cs b/TShockAPI/Tools.cs index 1e16a602..74bf668d 100755 --- a/TShockAPI/Tools.cs +++ b/TShockAPI/Tools.cs @@ -341,7 +341,7 @@ namespace TShockAPI } catch (Exception e) { - FileTools.WriteError(e.Message); + Log.Error(e.ToString()); } } } diff --git a/TShockAPI/UpdateManager.cs b/TShockAPI/UpdateManager.cs index c5772297..64bc3d13 100644 --- a/TShockAPI/UpdateManager.cs +++ b/TShockAPI/UpdateManager.cs @@ -60,7 +60,7 @@ namespace TShockAPI } catch (Exception e) { - FileTools.WriteError(e.Message); + Log.Error(e.ToString()); } return false; }