Fixed exception in commands crashing the server

Removed Tools.WriteError using Log.Error instead.
This commit is contained in:
ricky 2011-06-15 20:54:32 +10:00
parent 8d13023dac
commit 1ea6d2e955
5 changed files with 31 additions and 34 deletions

View file

@ -74,7 +74,15 @@ namespace TShockAPI
if (!ply.Group.HasPermission(permission)) if (!ply.Group.HasPermission(permission))
return false; return false;
command(new CommandArgs(msg, ply, parms)); try
{
command(new CommandArgs(msg, ply, parms));
}
catch (Exception e)
{
Log.Error(e.ToString());
}
return true; return true;
} }

View file

@ -22,7 +22,6 @@ namespace TShockAPI
{ {
internal class FileTools 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 RulesPath = Path.Combine(TShock.SavePath, "rules.txt");
public static readonly string MotdPath = Path.Combine(TShock.SavePath, "motd.txt"); public static readonly string MotdPath = Path.Combine(TShock.SavePath, "motd.txt");
public static readonly string BansPath = Path.Combine(TShock.SavePath, "bans.txt"); public static readonly string BansPath = Path.Combine(TShock.SavePath, "bans.txt");
@ -44,17 +43,6 @@ namespace TShockAPI
} }
} }
/// <summary>
/// Writes an error message to errors.txt
/// </summary>
/// <param name="err">string message</param>
public static void WriteError(string err)
{
TextWriter tw = new StreamWriter(ErrorsPath, true);
tw.WriteLine(err);
tw.Close();
}
/// <summary> /// <summary>
/// Sets up the configuration file for all variables, and creates any missing files. /// Sets up the configuration file for all variables, and creates any missing files.
/// </summary> /// </summary>

View file

@ -176,6 +176,21 @@ namespace TShockAPI
HandleCommandLine(Environment.GetCommandLineArgs()); 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;
}
/// <summary> /// <summary>
/// Handles exceptions that we didn't catch or that Red fucked up /// Handles exceptions that we didn't catch or that Red fucked up
/// </summary> /// </summary>
@ -195,6 +210,11 @@ namespace TShockAPI
Log.Error(e.ExceptionObject.ToString()); Log.Error(e.ExceptionObject.ToString());
} }
/*
* Hooks:
*
*/
/// <summary> /// <summary>
/// When a server command is run. /// When a server command is run.
/// </summary> /// </summary>
@ -254,25 +274,6 @@ namespace TShockAPI
Log.Info(string.Format("Server said: {0}", text.Remove(0, 4))); 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) private void NpcHooks_OnStrikeNpc(NpcStrikeEventArgs e)
{ {
if (ConfigurationManager.InfiniteInvasion) if (ConfigurationManager.InfiniteInvasion)

View file

@ -341,7 +341,7 @@ namespace TShockAPI
} }
catch (Exception e) catch (Exception e)
{ {
FileTools.WriteError(e.Message); Log.Error(e.ToString());
} }
} }
} }

View file

@ -60,7 +60,7 @@ namespace TShockAPI
} }
catch (Exception e) catch (Exception e)
{ {
FileTools.WriteError(e.Message); Log.Error(e.ToString());
} }
return false; return false;
} }