diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index 73e79a1e..93f0201d 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -572,6 +572,8 @@ namespace MinecraftClient /// Optional delay, in seconds, before restarting protected void ReconnectToTheServer(int ExtraAttempts = 3, int delaySeconds = 0) { + if (Settings.DebugMessages) + ConsoleIO.WriteLogLine(String.Format("[{0}] Disconnecting and Reconnecting to the Server", this.GetType().Name)); McTcpClient.ReconnectionAttemptsLeft = ExtraAttempts; Program.Restart(delaySeconds); } diff --git a/MinecraftClient/ChatBots/AutoRelog.cs b/MinecraftClient/ChatBots/AutoRelog.cs index b690f13e..d94818a3 100644 --- a/MinecraftClient/ChatBots/AutoRelog.cs +++ b/MinecraftClient/ChatBots/AutoRelog.cs @@ -33,26 +33,34 @@ namespace MinecraftClient.ChatBots public override void Initialize() { McTcpClient.ReconnectionAttemptsLeft = attempts; - if (System.IO.File.Exists(Settings.AutoRelog_KickMessagesFile)) + if (Settings.AutoRelog_IgnoreKickMessage) { if (Settings.DebugMessages) - LogToConsole("Loading messages from file: " + System.IO.Path.GetFullPath(Settings.AutoRelog_KickMessagesFile)); - - dictionary = System.IO.File.ReadAllLines(Settings.AutoRelog_KickMessagesFile); - - for (int i = 0; i < dictionary.Length; i++) - { - if (Settings.DebugMessages) - LogToConsole(" Loaded message: " + dictionary[i]); - dictionary[i] = dictionary[i].ToLower(); - } + LogToConsole("Initializing without a kick message file"); } else { - LogToConsole("File not found: " + System.IO.Path.GetFullPath(Settings.AutoRelog_KickMessagesFile)); + if (System.IO.File.Exists(Settings.AutoRelog_KickMessagesFile)) + { + if (Settings.DebugMessages) + LogToConsole("Loading messages from file: " + System.IO.Path.GetFullPath(Settings.AutoRelog_KickMessagesFile)); - if (Settings.DebugMessages) - LogToConsole(" Current directory was: " + System.IO.Directory.GetCurrentDirectory()); + dictionary = System.IO.File.ReadAllLines(Settings.AutoRelog_KickMessagesFile); + + for (int i = 0; i < dictionary.Length; i++) + { + if (Settings.DebugMessages) + LogToConsole(" Loaded message: " + dictionary[i]); + dictionary[i] = dictionary[i].ToLower(); + } + } + else + { + LogToConsole("File not found: " + System.IO.Path.GetFullPath(Settings.AutoRelog_KickMessagesFile)); + + if (Settings.DebugMessages) + LogToConsole(" Current directory was: " + System.IO.Directory.GetCurrentDirectory()); + } } } @@ -61,7 +69,7 @@ namespace MinecraftClient.ChatBots if (reason == DisconnectReason.UserLogout) { if (Settings.DebugMessages) - LogToConsole("Ignoring disconnection initiated by User or MCC bot"); + LogToConsole("Disconnection initiated by User or MCC bot. Ignoring."); } else { @@ -71,6 +79,14 @@ namespace MinecraftClient.ChatBots if (Settings.DebugMessages) LogToConsole("Got disconnected with message: " + message); + if (Settings.AutoRelog_IgnoreKickMessage) + { + if (Settings.DebugMessages) + LogToConsole("Ignoring kick message, reconnecting anyway."); + ReconnectToTheServer(); + return true; + } + foreach (string msg in dictionary) { if (comp.Contains(msg)) diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index 108dd945..45ce6ac7 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -473,6 +473,10 @@ namespace MinecraftClient.Protocol.Handlers foreach (var item in nbt) { + // Skip NBT root name + if (item.Key == "" && root) + continue; + byte fieldType; byte[] fieldNameLength = GetUShort((ushort)item.Key.Length); byte[] fieldName = Encoding.ASCII.GetBytes(item.Key); diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 0706cf55..50c7ab56 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -130,6 +130,7 @@ namespace MinecraftClient public static bool AutoRelog_Enabled = false; public static int AutoRelog_Delay = 10; public static int AutoRelog_Retries = 3; + public static bool AutoRelog_IgnoreKickMessage = false; public static string AutoRelog_KickMessagesFile = "kickmessages.txt"; //Script Scheduler Settings @@ -363,6 +364,7 @@ namespace MinecraftClient case "enabled": AutoRelog_Enabled = str2bool(argValue); break; case "delay": AutoRelog_Delay = str2int(argValue); break; case "retries": AutoRelog_Retries = str2int(argValue); break; + case "ignorekickmessage": AutoRelog_IgnoreKickMessage = str2bool(argValue); break; case "kickmessagesfile": AutoRelog_KickMessagesFile = argValue; break; } break; @@ -639,6 +641,7 @@ namespace MinecraftClient + "enabled=false\r\n" + "delay=10\r\n" + "retries=3 #-1 = unlimited\r\n" + + "ignorekickmessage=false\r\n" + "kickmessagesfile=kickmessages.txt\r\n" + "\r\n" + "[ChatLog]\r\n" diff --git a/MinecraftClient/config/README.md b/MinecraftClient/config/README.md index c0371f67..6e615444 100644 --- a/MinecraftClient/config/README.md +++ b/MinecraftClient/config/README.md @@ -192,6 +192,7 @@ A kick message "Connection has been lost." is generated by the console itself wh A kick message "Login failed." is generated the same way when it failed to login to the server. A kick message "Failed to ping this IP." is generated when it failed to ping the server. You can use them for reconnecting when connection is lost or the login failed. +If you want to always reconnect, set ignorekickmessage=true in MinecraftClient.ini. Use at own risk! Using the Script Scheduler ------