diff --git a/MinecraftClient/ChatBots/AutoRelog.cs b/MinecraftClient/ChatBots/AutoRelog.cs index 329f4610..9622a50b 100644 --- a/MinecraftClient/ChatBots/AutoRelog.cs +++ b/MinecraftClient/ChatBots/AutoRelog.cs @@ -8,7 +8,6 @@ namespace MinecraftClient.ChatBots /// /// This bot automatically re-join the server if kick message contains predefined string (Server is restarting ...) /// - public class AutoRelog : ChatBot { private string[] dictionary = new string[0]; @@ -20,7 +19,6 @@ namespace MinecraftClient.ChatBots /// /// Delay before re-joining the server (in seconds) /// Number of retries if connection fails (-1 = infinite) - public AutoRelog(int DelayBeforeRelog, int retries) { attempts = retries; @@ -28,6 +26,8 @@ namespace MinecraftClient.ChatBots McTcpClient.ReconnectionAttemptsLeft = attempts; delay = DelayBeforeRelog; if (delay < 1) { delay = 1; } + if (Settings.DebugMessages) + LogToConsole("Launching with " + attempts + " reconnection attempts"); } public override void Initialize() @@ -35,24 +35,41 @@ namespace MinecraftClient.ChatBots McTcpClient.ReconnectionAttemptsLeft = attempts; if (System.IO.File.Exists(Settings.AutoRelog_KickMessagesFile)) { + if (Settings.DebugMessages) + LogToConsole("Loading messages from file: " + Settings.AutoRelog_KickMessagesFile); + dictionary = System.IO.File.ReadAllLines(Settings.AutoRelog_KickMessagesFile); for (int i = 0; i < dictionary.Length; i++) { + LogToConsole(" Loaded message: " + dictionary[i]); dictionary[i] = dictionary[i].ToLower(); } } - else LogToConsole("File not found: " + Settings.AutoRelog_KickMessagesFile); + else + { + LogToConsole("File not found: " + Settings.AutoRelog_KickMessagesFile); + + if (Settings.DebugMessages) + LogToConsole(" Current directory was: " + System.IO.Directory.GetCurrentDirectory()); + } } public override bool OnDisconnect(DisconnectReason reason, string message) { message = GetVerbatim(message); string comp = message.ToLower(); + + if (Settings.DebugMessages) + LogToConsole("Got disconnected with message: " + message); + foreach (string msg in dictionary) { if (comp.Contains(msg)) { + if (Settings.DebugMessages) + LogToConsole("Message contains '" + msg + "'. Reconnecting."); + LogToConsole("Waiting " + delay + " seconds before reconnecting..."); System.Threading.Thread.Sleep(delay * 1000); McTcpClient.ReconnectionAttemptsLeft = attempts; @@ -60,6 +77,10 @@ namespace MinecraftClient.ChatBots return true; } } + + if (Settings.DebugMessages) + LogToConsole("Message not containing any defined keywords. Ignoring."); + return false; } diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index eef13a1d..31c6a451 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -189,7 +189,9 @@ namespace MinecraftClient if (ReconnectionAttemptsLeft > 0) { ConsoleIO.WriteLogLine("Waiting 5 seconds (" + ReconnectionAttemptsLeft + " attempts left)..."); - Thread.Sleep(5000); ReconnectionAttemptsLeft--; Program.Restart(); + Thread.Sleep(5000); + ReconnectionAttemptsLeft--; + Program.Restart(); } else if (!singlecommand && Settings.interactiveMode) {