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