Fixed exception in commands crashing the server
Removed Tools.WriteError using Log.Error instead.
This commit is contained in:
parent
8d13023dac
commit
1ea6d2e955
5 changed files with 31 additions and 34 deletions
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
|||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// Sets up the configuration file for all variables, and creates any missing files.
|
||||
/// </summary>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles exceptions that we didn't catch or that Red fucked up
|
||||
/// </summary>
|
||||
|
|
@ -195,6 +210,11 @@ namespace TShockAPI
|
|||
Log.Error(e.ExceptionObject.ToString());
|
||||
}
|
||||
|
||||
/*
|
||||
* Hooks:
|
||||
*
|
||||
*/
|
||||
|
||||
/// <summary>
|
||||
/// When a server command is run.
|
||||
/// </summary>
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -341,7 +341,7 @@ namespace TShockAPI
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FileTools.WriteError(e.Message);
|
||||
Log.Error(e.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ namespace TShockAPI
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FileTools.WriteError(e.Message);
|
||||
Log.Error(e.ToString());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue