diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 8716ffe3..ebf99e75 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -149,7 +149,10 @@ namespace MinecraftClient ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)..."); Thread.Sleep(5000); AttemptsLeft--; Program.Restart(); } - else if (!singlecommand) { Console.ReadLine(); } + else if (!singlecommand && Settings.interactiveMode) + { + Program.OfflineCommandPrompt(); + } } } diff --git a/MinecraftClient/Program.cs b/MinecraftClient/Program.cs index 4ad3ae27..1cfdfa60 100644 --- a/MinecraftClient/Program.cs +++ b/MinecraftClient/Program.cs @@ -20,6 +20,7 @@ namespace MinecraftClient public static string[] startupargs; public const string Version = "1.8.2"; private static Thread offlinePrompt = null; + private static bool useMcVersionOnce = false; /// /// The main entry point of Minecraft Console Client @@ -148,11 +149,18 @@ namespace MinecraftClient if (Settings.ServerVersion != "" && Settings.ServerVersion.ToLower() != "auto") { protocolversion = Protocol.ProtocolHandler.MCVer2ProtocolVersion(Settings.ServerVersion); + if (protocolversion != 0) { ConsoleIO.WriteLineFormatted("§8Using Minecraft version " + Settings.ServerVersion + " (protocol v" + protocolversion + ')'); } else ConsoleIO.WriteLineFormatted("§8Unknown or not supported MC version '" + Settings.ServerVersion + "'.\nSwitching to autodetection mode."); + + if (useMcVersionOnce) + { + useMcVersionOnce = false; + Settings.ServerVersion = ""; + } } if (protocolversion == 0) @@ -166,7 +174,18 @@ namespace MinecraftClient ChatBots.AutoRelog bot = new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries); if (!bot.OnDisconnect(ChatBot.DisconnectReason.ConnectionLost, "Failed to ping this IP.")) { OfflineCommandPrompt(); } } - else OfflineCommandPrompt(); + else + { + if (Settings.interactiveMode) + { + if (MinecraftVersionPrompt()) + { + Restart(); + return; + } + OfflineCommandPrompt(); + } + } return; } } @@ -191,7 +210,11 @@ namespace MinecraftClient else { Console.WriteLine("Failed to determine server version."); - OfflineCommandPrompt(); + if (Settings.interactiveMode && MinecraftVersionPrompt()) + { + Restart(); + return; + } } } else @@ -256,7 +279,7 @@ namespace MinecraftClient public static void OfflineCommandPrompt() { - if (!Settings.exitOnFailure && offlinePrompt == null) + if (Settings.interactiveMode && offlinePrompt == null) { offlinePrompt = new Thread(new ThreadStart(delegate { @@ -269,31 +292,33 @@ namespace MinecraftClient command = Console.ReadLine().Trim(); if (command.Length > 0) { - if (Settings.internalCmdChar != ' ' && command[0] == Settings.internalCmdChar) - { - string message = ""; + string message = ""; + + if (Settings.internalCmdChar != ' ' + && command[0] == Settings.internalCmdChar) command = command.Substring(1); - if (command.StartsWith("reco")) - { - message = new Commands.Reco().Run(null, Settings.expandVars(command)); - } - else if (command.StartsWith("connect")) - { - message = new Commands.Connect().Run(null, Settings.expandVars(command)); - } - else if (command.StartsWith("exit") || command.StartsWith("quit")) - { - message = new Commands.Exit().Run(null, Settings.expandVars(command)); - } - else if (command.StartsWith("help")) - { - ConsoleIO.WriteLineFormatted("§8MCC: " + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + new Commands.Reco().CMDDesc); - ConsoleIO.WriteLineFormatted("§8MCC: " + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + new Commands.Connect().CMDDesc); - } - else ConsoleIO.WriteLineFormatted("§8Unknown command '" + command.Split(' ')[0] + "'."); - if (message != "") { ConsoleIO.WriteLineFormatted("§8MCC: " + message); } + + if (command.StartsWith("reco")) + { + message = new Commands.Reco().Run(null, Settings.expandVars(command)); } - else ConsoleIO.WriteLineFormatted("§8Please type a command or press Enter to exit."); + else if (command.StartsWith("connect")) + { + message = new Commands.Connect().Run(null, Settings.expandVars(command)); + } + else if (command.StartsWith("exit") || command.StartsWith("quit")) + { + message = new Commands.Exit().Run(null, Settings.expandVars(command)); + } + else if (command.StartsWith("help")) + { + ConsoleIO.WriteLineFormatted("§8MCC: " + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + new Commands.Reco().CMDDesc); + ConsoleIO.WriteLineFormatted("§8MCC: " + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + new Commands.Connect().CMDDesc); + } + else ConsoleIO.WriteLineFormatted("§8Unknown command '" + command.Split(' ')[0] + "'."); + + if (message != "") + ConsoleIO.WriteLineFormatted("§8MCC: " + message); } } })); @@ -301,6 +326,26 @@ namespace MinecraftClient } } + /// + /// + /// + /// + + public static bool MinecraftVersionPrompt() + { + if (Settings.interactiveMode) + { + Console.Write("Server version : "); + Settings.ServerVersion = Console.ReadLine(); + if (Settings.ServerVersion != "") + { + useMcVersionOnce = true; + return true; + } + } + return false; + } + /// /// Detect if the user is running Minecraft Console Client through Mono /// diff --git a/MinecraftClient/Protocol/ProtocolHandler.cs b/MinecraftClient/Protocol/ProtocolHandler.cs index 10a0aa02..5141d16e 100644 --- a/MinecraftClient/Protocol/ProtocolHandler.cs +++ b/MinecraftClient/Protocol/ProtocolHandler.cs @@ -124,7 +124,7 @@ namespace MinecraftClient.Protocol } catch { - return -1; + return 0; } } } diff --git a/MinecraftClient/Settings.cs b/MinecraftClient/Settings.cs index 09e508f1..8746eae2 100644 --- a/MinecraftClient/Settings.cs +++ b/MinecraftClient/Settings.cs @@ -40,7 +40,7 @@ namespace MinecraftClient public static List Bots_Owners = new List(); public static string Language = "en_GB"; public static bool chatTimeStamps = false; - public static bool exitOnFailure = false; + public static bool interactiveMode = true; public static char internalCmdChar = '/'; public static bool playerHeadAsIcon = false; public static string chatbotLogFile = ""; @@ -148,7 +148,7 @@ namespace MinecraftClient case "language": Language = argValue; break; case "consoletitle": ConsoleTitle = argValue; break; case "timestamps": chatTimeStamps = str2bool(argValue); break; - case "exitonfailure": exitOnFailure = str2bool(argValue); break; + case "exitonfailure": interactiveMode = !str2bool(argValue); break; case "playerheadicon": playerHeadAsIcon = str2bool(argValue); break; case "chatbotlogfile": chatbotLogFile = argValue; break; case "mcversion": ServerVersion = argValue; break;