Commit fc10fcec authored by mercury233's avatar mercury233

remove safe mode eventually

"catch when" was included in C#6.0, which shouldn't be neccessary
parent c626f14f
...@@ -11,13 +11,6 @@ namespace WindBot ...@@ -11,13 +11,6 @@ namespace WindBot
{ {
public class Program public class Program
{ {
// In safe mode, all errors will be catched instead of causing the program to crash.
#if DEBUG
public static bool SafeMode = false;
#else
public static bool SafeMode = true;
#endif
internal static Random Rand; internal static Random Rand;
internal static void Main(string[] args) internal static void Main(string[] args)
...@@ -89,8 +82,10 @@ namespace WindBot ...@@ -89,8 +82,10 @@ namespace WindBot
Logger.WriteLine("HTTP GET http://127.0.0.1:" + ServerPort + "/?name=WindBot&host=127.0.0.1&port=7911 to call the bot."); Logger.WriteLine("HTTP GET http://127.0.0.1:" + ServerPort + "/?name=WindBot&host=127.0.0.1&port=7911 to call the bot.");
while (true) while (true)
{ {
#if !DEBUG
try try
{ {
#endif
HttpListenerContext ctx = MainServer.GetContext(); HttpListenerContext ctx = MainServer.GetContext();
WindBotInfo Info = new WindBotInfo(); WindBotInfo Info = new WindBotInfo();
...@@ -121,53 +116,68 @@ namespace WindBot ...@@ -121,53 +116,68 @@ namespace WindBot
} }
else else
{ {
#if !DEBUG
try try
{ {
#endif
Thread workThread = new Thread(new ParameterizedThreadStart(Run)); Thread workThread = new Thread(new ParameterizedThreadStart(Run));
workThread.Start(Info); workThread.Start(Info);
#if !DEBUG
} }
catch (Exception ex) when (SafeMode) catch (Exception ex)
{ {
Logger.WriteErrorLine("Start Thread Error: " + ex); Logger.WriteErrorLine("Start Thread Error: " + ex);
} }
#endif
ctx.Response.StatusCode = 200; ctx.Response.StatusCode = 200;
ctx.Response.Close(); ctx.Response.Close();
} }
#if !DEBUG
} }
catch (Exception ex) when (SafeMode) catch (Exception ex)
{ {
Logger.WriteErrorLine("Parse Http Request Error: " + ex); Logger.WriteErrorLine("Parse Http Request Error: " + ex);
} }
#endif
} }
} }
} }
private static void Run(object o) private static void Run(object o)
{ {
#if !DEBUG
try try
{ {
//all errors will be catched instead of causing the program to crash.
#endif
WindBotInfo Info = (WindBotInfo)o; WindBotInfo Info = (WindBotInfo)o;
GameClient client = new GameClient(Info); GameClient client = new GameClient(Info);
client.Start(); client.Start();
Logger.DebugWriteLine(client.Username + " started."); Logger.DebugWriteLine(client.Username + " started.");
while (client.Connection.IsConnected) while (client.Connection.IsConnected)
{ {
#if !DEBUG
try try
{ {
#endif
client.Tick(); client.Tick();
Thread.Sleep(30); Thread.Sleep(30);
#if !DEBUG
} }
catch (Exception ex) when (SafeMode) catch (Exception ex)
{ {
Logger.WriteErrorLine("Tick Error: " + ex); Logger.WriteErrorLine("Tick Error: " + ex);
} }
#endif
} }
Logger.DebugWriteLine(client.Username + " end."); Logger.DebugWriteLine(client.Username + " end.");
#if !DEBUG
} }
catch (Exception ex) when (SafeMode) catch (Exception ex)
{ {
Logger.WriteErrorLine("Run Error: " + ex); Logger.WriteErrorLine("Run Error: " + ex);
} }
#endif
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment