Added try/catch statements.

This commit is contained in:
Deathmax 2011-06-04 11:46:52 +08:00
parent 0155156367
commit ab67d9f137

View file

@ -137,6 +137,8 @@ namespace TShockAPI
NetHooks.OnPreGetData -= GetData;
NetHooks.OnGreetPlayer -= new NetHooks.GreetPlayerD(OnGreetPlayer);
NpcHooks.OnStrikeNpc -= new NpcHooks.StrikeNpcD(NpcHooks_OnStrikeNpc);
ConfigurationManager.WriteJsonConfiguration();
Log.Info("Shutting down...");
}
/*
@ -144,6 +146,8 @@ namespace TShockAPI
* */
void NpcHooks_OnStrikeNpc(NpcStrikeEventArgs e)
{
try
{
if (ConfigurationManager.infiniteInvasion)
{
@ -154,8 +158,15 @@ namespace TShockAPI
}
}
}
catch (Exception ex)
{
FileTools.WriteError(ex.ToString());
}
}
void GetData(GetDataEventArgs e)
{
try
{
if (Main.netMode != 2) { return; }
if (e.MsgID == 17)
@ -302,8 +313,15 @@ namespace TShockAPI
}
}
}
catch (Exception ex)
{
FileTools.WriteError(ex.ToString());
}
}
void OnGreetPlayer(int who, HandledEventArgs e)
{
try
{
if (Main.netMode != 2) { return; }
int plr = who; //legacy support
@ -324,8 +342,15 @@ namespace TShockAPI
ShowUpdateReminder(who);
e.Handled = true;
}
catch (Exception ex)
{
FileTools.WriteError(ex.ToString());
}
}
void OnChat(int ply, string msg, HandledEventArgs handler)
{
try
{
if (Main.netMode != 2) { return; }
int x = (int)Main.player[ply].position.X;
@ -340,21 +365,35 @@ namespace TShockAPI
Commands.CommandDelegate command;
if (commands.TryGetValue(msg.Split(' ')[0].TrimStart('/'), out command))
{
Log.Info(Tools.FindPlayer(ply) + " executed " + msg);
command.Invoke(args);
}
else
{
Log.Info(Tools.FindPlayer(ply) + " tried to execute " + msg);
Tools.SendMessage(ply, "Invalid command or no permissions! Try /help.", new float[] { 255f, 0f, 0f });
}
handler.Handled = true;
}
}
catch (Exception ex)
{
FileTools.WriteError(ex.ToString());
}
}
void OnJoin(int ply, AllowEventArgs handler)
{
try
{
if (Main.netMode != 2) { return; }
string ip = Tools.GetRealIP((Convert.ToString(Netplay.serverSock[ply].tcpClient.Client.RemoteEndPoint)));
if (FileTools.CheckBanned(ip))
{
Tools.Kick(ply, "You are banned.");
} else if (FileTools.CheckCheat(ip))
}
else if (FileTools.CheckCheat(ip))
{
Tools.Kick(ply, "You were flagged for cheating.");
}
@ -368,21 +407,35 @@ namespace TShockAPI
}
players[ply] = new TSPlayer(ply);
}
catch (Exception ex)
{
FileTools.WriteError(ex.ToString());
}
}
void OnLoadContent(Microsoft.Xna.Framework.Content.ContentManager obj)
{
}
void OnPreInit()
{
try
{
FileTools.SetupConfig();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
void OnPostInit()
{
}
void OnUpdate(GameTime time)
{
try
{
if (Main.netMode != 2) { return; }
for (uint i = 0; i < Main.maxPlayers; i++)
@ -408,6 +461,11 @@ namespace TShockAPI
}
}
}
catch (Exception ex)
{
FileTools.WriteError(ex.ToString());
}
}
/*
* Useful stuff: