/// <summary> /// Disconnect the current client from the server and exit the app /// </summary> public static void Exit(int exitcode = 0) { new Thread(new ThreadStart(delegate { if (client != null) { client.Disconnect(); ConsoleIO.Reset(); } if (offlinePrompt != null) { offlinePrompt.Abort(); offlinePrompt = null; ConsoleIO.Reset(); } if (Settings.playerHeadAsIcon) { ConsoleIcon.revertToMCCIcon(); } Environment.Exit(exitcode); })).Start(); }
/// <summary> /// The main entry point of Minecraft Console Client /// </summary> static void Main(string[] args) { Console.WriteLine("Minecraft Console Client v{0} - for MC {1} to {2} - Github.com/MCCTeam", Version, MCLowestVersion, MCHighestVersion); //Build information to facilitate processing of bug reports if (BuildInfo != null) { ConsoleIO.WriteLineFormatted("§8" + BuildInfo); } //Debug input ? if (args.Length == 1 && args[0] == "--keyboard-debug") { ConsoleIO.WriteLine("Keyboard debug mode: Press any key to display info"); ConsoleIO.DebugReadInput(); } //Setup ConsoleIO ConsoleIO.LogPrefix = "§8[MCC] "; if (args.Length >= 1 && args[args.Length - 1] == "BasicIO" || args.Length >= 1 && args[args.Length - 1] == "BasicIO-NoColor") { if (args.Length >= 1 && args[args.Length - 1] == "BasicIO-NoColor") { ConsoleIO.BasicIO_NoColor = true; } ConsoleIO.BasicIO = true; args = args.Where(o => !Object.ReferenceEquals(o, args[args.Length - 1])).ToArray(); } //Take advantage of Windows 10 / Mac / Linux UTF-8 console if (isUsingMono || WindowsVersion.WinMajorVersion >= 10) { Console.OutputEncoding = Console.InputEncoding = Encoding.UTF8; } //Process ini configuration file if (args.Length >= 1 && System.IO.File.Exists(args[0]) && System.IO.Path.GetExtension(args[0]).ToLower() == ".ini") { Settings.LoadFile(args[0]); //remove ini configuration file from arguments array List <string> args_tmp = args.ToList <string>(); args_tmp.RemoveAt(0); args = args_tmp.ToArray(); } else if (System.IO.File.Exists("MinecraftClient.ini")) { Settings.LoadFile("MinecraftClient.ini"); } else { Settings.WriteDefaultSettings("MinecraftClient.ini"); } //Load external translation file. Should be called AFTER settings loaded Translations.LoadExternalTranslationFile(Settings.Language); //Other command-line arguments if (args.Length >= 1) { if (args.Contains("--help")) { Console.WriteLine("Command-Line Help:"); Console.WriteLine("MinecraftClient.exe <username> <password> <server>"); Console.WriteLine("MinecraftClient.exe <username> <password> <server> \"/mycommand\""); Console.WriteLine("MinecraftClient.exe --setting=value [--other settings]"); Console.WriteLine("MinecraftClient.exe --section.setting=value [--other settings]"); Console.WriteLine("MinecraftClient.exe <settings-file.ini> [--other settings]"); return; } try { Settings.LoadArguments(args); } catch (ArgumentException e) { Settings.interactiveMode = false; HandleFailure(e.Message); return; } } if (Settings.ConsoleTitle != "") { Settings.Username = "******"; Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } //Test line to troubleshoot invisible colors if (Settings.DebugMessages) { ConsoleIO.WriteLineFormatted(Translations.Get("debug.color_test", "[0123456789ABCDEF]: [§00§11§22§33§44§55§66§77§88§99§aA§bB§cC§dD§eE§fF§r]")); } //Load cached sessions from disk if necessary if (Settings.SessionCaching == CacheType.Disk) { bool cacheLoaded = SessionCache.InitializeDiskCache(); if (Settings.DebugMessages) { Translations.WriteLineFormatted(cacheLoaded ? "debug.session_cache_ok" : "debug.session_cache_fail"); } } //Asking the user to type in missing data such as Username and Password bool useBrowser = Settings.AccountType == ProtocolHandler.AccountType.Microsoft && Settings.LoginMethod == "browser"; if (Settings.Login == "") { if (useBrowser) { ConsoleIO.WriteLine("Press Enter to skip session cache checking and continue sign-in with browser"); } Console.Write(ConsoleIO.BasicIO ? Translations.Get("mcc.login_basic_io") + "\n" : Translations.Get("mcc.login")); Settings.Login = Console.ReadLine(); } if (Settings.Password == "" && (Settings.SessionCaching == CacheType.None || !SessionCache.Contains(Settings.Login.ToLower())) && !useBrowser) { RequestPassword(); } // Setup exit cleaning code ExitCleanUp.Add(delegate() { // Do NOT use Program.Exit() as creating new Thread cause program to freeze if (client != null) { client.Disconnect(); ConsoleIO.Reset(); } if (offlinePrompt != null) { offlinePrompt.Abort(); offlinePrompt = null; ConsoleIO.Reset(); } if (Settings.playerHeadAsIcon) { ConsoleIcon.revertToMCCIcon(); } }); startupargs = args; InitializeClient(); }