From 09bff17fc2e97e1e5846c58cc2234e4744be9f4e Mon Sep 17 00:00:00 2001 From: ORelio Date: Sun, 4 May 2014 11:25:51 +0200 Subject: [PATCH] Allow AutoRelog to relog on server login failed - Add some explanations for adding a custom bot in the app - Remove debug code in ConsoleIO (see previous commit) --- MinecraftClient/Bots.cs | 12 +++++++++++- MinecraftClient/ConsoleIO.cs | 7 ------- MinecraftClient/McTcpClient.cs | 4 ++-- MinecraftClient/MinecraftCom.cs | 4 ++-- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/MinecraftClient/Bots.cs b/MinecraftClient/Bots.cs index 44769dbd..3739f479 100644 --- a/MinecraftClient/Bots.cs +++ b/MinecraftClient/Bots.cs @@ -9,7 +9,17 @@ namespace MinecraftClient /// Welcome to the Bot API file ! /// The virtual class "ChatBot" contains anything you need for creating chat bots /// Inherit from this class while adding your bot class to the namespace "Bots", below. - /// Once your bot is created, simply edit the switch in Program.cs to add the corresponding command-line argument! + /// Once your bot is created, read the explanations below to start using it in the MinecraftClient app. + /// + /// Pieces of code to add in other parts of the program for your bot. Line numbers are approximative. + /// Program.cs:166 | if (Settings.YourBot_Enabled){ handler.BotLoad(new Bots.YourBot()); } + /// Settings.cs:73 | public static bool YourBot_Enabled = false; + /// Settings.cs:74 | private enum ParseMode { /* [...] */, YourBot }; + /// Settings.cs:106| case "yourbot": pMode = ParseMode.YourBot; break; + /// Settings.cs:197| case ParseMode.YourBot: switch (argName.ToLower()) { case "enabled": YourBot_Enabled = str2bool(argValue); break; } break; + /// Settings.cs:267| + "[YourBot]\r\n" + "enabled=false\r\n" + /// Here your are. Now you will have a setting in MinecraftClient.ini for enabling your brand new bot. + /// Delete MinecraftClient.ini to re-generate it or add the lines [YourBot] and enabled=true to the existing one. /// /// diff --git a/MinecraftClient/ConsoleIO.cs b/MinecraftClient/ConsoleIO.cs index 78b2c0b2..86059ebc 100644 --- a/MinecraftClient/ConsoleIO.cs +++ b/MinecraftClient/ConsoleIO.cs @@ -164,13 +164,6 @@ namespace MinecraftClient default: if (k.KeyChar != 0) AddChar(k.KeyChar); - /* - reading_lock = false; - WriteLine("CHAR: " + ((int)k.KeyChar)); - if (!System.IO.File.Exists("debug-chars.txt")) { System.IO.File.Create("debug-chars.txt"); } - System.IO.File.AppendAllText("debug-chars.txt", "'" + k.KeyChar + "' " + ((int)k.KeyChar) + "\r\n"); - reading_lock = true; - */ break; } } diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index d70ccac4..6f1a3adf 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -119,7 +119,7 @@ namespace MinecraftClient else { Console.WriteLine("Login failed."); - if (!singlecommand) { Program.ReadLineReconnect(); } + if (!singlecommand && !handler.OnConnectionLost(ChatBot.DisconnectReason.LoginRejected, "Login failed.")) { Program.ReadLineReconnect(); } } } catch (SocketException) @@ -235,7 +235,7 @@ namespace MinecraftClient if (!handler.HasBeenKicked) { ConsoleIO.WriteLine("Connection has been lost."); - if (!handler.OnConnectionLost() && !Program.ReadLineReconnect()) { t_sender.Abort(); } + if (!handler.OnConnectionLost(ChatBot.DisconnectReason.ConnectionLost, "Connection has been lost.") && !Program.ReadLineReconnect()) { t_sender.Abort(); } } else if (Program.ReadLineReconnect()) { t_sender.Abort(); } } diff --git a/MinecraftClient/MinecraftCom.cs b/MinecraftClient/MinecraftCom.cs index c400af27..0cf79112 100644 --- a/MinecraftClient/MinecraftCom.cs +++ b/MinecraftClient/MinecraftCom.cs @@ -183,14 +183,14 @@ namespace MinecraftClient System.IO.File.WriteAllText("debug.txt", dump); System.Diagnostics.Process.Start("debug.txt"); } - public bool OnConnectionLost() + public bool OnConnectionLost(ChatBot.DisconnectReason reason, string reason_message) { if (!connectionlost) { connectionlost = true; for (int i = 0; i < bots.Count; i++) { - if (bots[i].OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Connection has been lost.")) + if (bots[i].OnDisconnect(reason, reason_message)) { return true; //The client is about to restart }