/// <summary> /// When connection has been lost /// </summary> public void OnConnectionLost(ChatBot.DisconnectReason reason, string message) { bool will_restart = false; switch (reason) { case ChatBot.DisconnectReason.ConnectionLost: message = "§3[Conexão]§c Desconectado do servidor: Conexão perdida!"; ConsoleIO.WriteLineFormatted(message); break; case ChatBot.DisconnectReason.InGameKick: ConsoleIO.WriteLineFormatted("§3[Conexão]§c Desconectado pelo servidor: " + message); break; case ChatBot.DisconnectReason.LoginRejected: ConsoleIO.WriteLineFormatted("§3[Conexão]§c Erro ao conectar: " + message); if (message.StartsWith("[Sistema Anti DC]")) { Program.Restart(7); } break; } if (!message.StartsWith("[Sistema Anti DC]")) { foreach (ChatBot bot in bots) { will_restart |= bot.OnDisconnect(reason, message); } if (!will_restart) { Program.HandleFailure(); } } }
public void OnConnectionLost(DisconnectReason reason, string message) { world.Clear(); bool will_restart = false; switch (reason) { case DisconnectReason.ConnectionLost: message = "Connection has been lost."; ConsoleIO.WriteLine(message); break; case DisconnectReason.InGameKick: ConsoleIO.WriteLine("Disconnected by Server :"); ConsoleIO.WriteLineFormatted(message); break; case DisconnectReason.LoginRejected: ConsoleIO.WriteLine("Login failed :"); ConsoleIO.WriteLineFormatted(message); break; } }
/// <summary> /// Start a new Client /// </summary> private static void InitializeClient() { SessionToken session = new SessionToken(); ProtocolHandler.LoginResult result = ProtocolHandler.LoginResult.LoginRequired; if (Settings.Password == "-") { Translations.WriteLineFormatted("mcc.offline"); result = ProtocolHandler.LoginResult.Success; session.PlayerID = "0"; session.PlayerName = Settings.Login; } else { // Validate cached session or login new session. if (Settings.SessionCaching != CacheType.None && SessionCache.Contains(Settings.Login.ToLower())) { session = SessionCache.Get(Settings.Login.ToLower()); result = ProtocolHandler.GetTokenValidation(session); if (result != ProtocolHandler.LoginResult.Success) { Translations.WriteLineFormatted("mcc.session_invalid"); if (Settings.Password == "") { RequestPassword(); } } else { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.session_valid", session.PlayerName)); } } if (result != ProtocolHandler.LoginResult.Success) { Translations.WriteLine("mcc.connecting"); result = ProtocolHandler.GetLogin(Settings.Login, Settings.Password, out session); if (result == ProtocolHandler.LoginResult.Success && Settings.SessionCaching != CacheType.None) { SessionCache.Store(Settings.Login.ToLower(), session); } } } if (result == ProtocolHandler.LoginResult.Success) { Settings.Username = session.PlayerName; if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } if (Settings.playerHeadAsIcon) { ConsoleIcon.setPlayerIconAsync(Settings.Username); } if (Settings.DebugMessages) { Translations.WriteLine("debug.session_id", session.ID); } //ProtocolHandler.RealmsListWorlds(Settings.Username, PlayerID, sessionID); //TODO REMOVE if (Settings.ServerIP == "") { Translations.Write("mcc.ip"); Settings.SetServerIP(Console.ReadLine()); } //Get server version int protocolversion = 0; ForgeInfo forgeInfo = null; if (Settings.ServerVersion != "" && Settings.ServerVersion.ToLower() != "auto") { protocolversion = Protocol.ProtocolHandler.MCVer2ProtocolVersion(Settings.ServerVersion); if (protocolversion != 0) { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.use_version", Settings.ServerVersion, protocolversion)); } else { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.unknown_version", Settings.ServerVersion)); } if (useMcVersionOnce) { useMcVersionOnce = false; Settings.ServerVersion = ""; } } if (protocolversion == 0 || Settings.ServerMayHaveForge) { if (protocolversion != 0) { Translations.WriteLine("mcc.forge"); } else { Translations.WriteLine("mcc.retrieve"); } if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion, ref forgeInfo)) { HandleFailure(Translations.Get("error.ping"), true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } if (protocolversion != 0) { try { //Start the main TCP client if (Settings.SingleCommand != "") { client = new McClient(session.PlayerName, session.PlayerID, session.ID, Settings.ServerIP, Settings.ServerPort, protocolversion, forgeInfo, Settings.SingleCommand); } else { client = new McClient(session.PlayerName, session.PlayerID, session.ID, protocolversion, forgeInfo, Settings.ServerIP, Settings.ServerPort); } //Update console title if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } } catch (NotSupportedException) { HandleFailure(Translations.Get("error.unsupported"), true); } } else { HandleFailure(Translations.Get("error.determine"), true); } } else { string failureMessage = Translations.Get("error.login"); string failureReason = ""; switch (result) { case ProtocolHandler.LoginResult.AccountMigrated: failureReason = "error.login.migrated"; break; case ProtocolHandler.LoginResult.ServiceUnavailable: failureReason = "error.login.server"; break; case ProtocolHandler.LoginResult.WrongPassword: failureReason = "error.login.blocked"; break; case ProtocolHandler.LoginResult.InvalidResponse: failureReason = "error.login.response"; break; case ProtocolHandler.LoginResult.NotPremium: failureReason = "error.login.premium"; break; case ProtocolHandler.LoginResult.OtherError: failureReason = "error.login.network"; break; case ProtocolHandler.LoginResult.SSLError: failureReason = "error.login.ssl"; break; default: failureReason = "error.login.unknown"; break; } failureMessage += Translations.Get(failureReason); if (result == ProtocolHandler.LoginResult.SSLError && isUsingMono) { Translations.WriteLineFormatted("error.login.ssl_help"); return; } HandleFailure(failureMessage, false, ChatBot.DisconnectReason.LoginRejected); } }
/// <summary> /// Handle fatal errors such as ping failure, login failure, server disconnection, and so on. /// Allows AutoRelog to perform on fatal errors, prompt for server version, and offline commands. /// </summary> /// <param name="errorMessage">Error message to display and optionally pass to AutoRelog bot</param> /// <param name="versionError">Specify if the error is related to an incompatible or unkown server version</param> /// <param name="disconnectReason">If set, the error message will be processed by the AutoRelog bot</param> public static void HandleFailure(string errorMessage = null, bool versionError = false, ChatBots.AutoRelog.DisconnectReason?disconnectReason = null) { if (!String.IsNullOrEmpty(errorMessage)) { ConsoleIO.Reset(); while (Console.KeyAvailable) { Console.ReadKey(true); } Console.WriteLine(errorMessage); if (disconnectReason.HasValue) { if (ChatBots.AutoRelog.OnDisconnectStatic(disconnectReason.Value, errorMessage)) { return; //AutoRelog is triggering a restart of the client } } } if (Settings.interactiveMode) { if (versionError) { Console.Write("Versão do servidor : "); Settings.ServerVersion = Console.ReadLine(); if (Settings.ServerVersion != "") { useMcVersionOnce = true; Restart(); return; } } if (doReconnect) { McTcpClient.ReconnectionAttemptsLeft = 999; Program.Restart(30); vars.loggedIn = false; } else { if (offlinePrompt == null) { offlinePrompt = new Thread(new ThreadStart(delegate { string command = " "; ConsoleIO.WriteLineFormatted("O HtBot está desconectado. Use '" + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + "help' para ajuda."); ConsoleIO.WriteLineFormatted("Ou aperte Enter para fechar."); while (command.Length > 0) { if (!ConsoleIO.BasicIO) { ConsoleIO.Write('>'); } command = Console.ReadLine().Trim(); if (command.Length > 0) { 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("§8Comando desconhecido -> '" + command.Split(' ')[0] + "'."); } if (message != "") { ConsoleIO.WriteLineFormatted("§8MCC: " + message); } } } })); offlinePrompt.Start(); } } } else { McTcpClient.ReconnectionAttemptsLeft = 999; Program.Restart(2); vars.loggedIn = false; } }
/// <summary> /// The main entry point of Minecraft Console Client /// </summary> static void Main(string[] args) { ConsoleIO.WriteLineFormatted("§2[HtBot] §9Inicializando o bot xD"); //Console.WriteLine("Console Client for MC {0} to {1} - v{2} - By ORelio & Contributors", MCLowestVersion, MCHighestVersion, Version); HtBot.Telegram.Start(); //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") { Console.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") { 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.LoadSettings(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.LoadSettings("MinecraftClient.ini"); } else { Settings.WriteDefaultSettings("MinecraftClient.ini"); } Settings.Login = "******"; Settings.Password = "******"; //Other command-line arguments if (args.Length >= 1) { string server = args[0].ToLower(); switch (server) { case "asgard": Settings.SetServerIP("Asgard.craftlandia.com.br"); connectedServer = "Asgard"; break; case "destiny": Settings.SetServerIP("destiny.craftlandia.com.br"); connectedServer = "Destiny"; break; case "propano": Settings.SetServerIP("propano.craftlandia.com.br"); connectedServer = "Propano"; break; default: Settings.SetServerIP("legacy.craftlandia.com.br"); connectedServer = "Asgard"; break; } //Single command? //if (args.Length >= 3) //{ // Settings.SingleCommand = args[2]; //} } else { Settings.SetServerIP("legacy.craftlandia.com.br"); connectedServer = "Legacy"; } if (Settings.ConsoleTitle != "") { Settings.Username = "******"; Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } //Load cached sessions from disk if necessary if (Settings.SessionCaching == CacheType.Disk) { bool cacheLoaded = SessionCache.InitializeDiskCache(); if (Settings.DebugMessages) { ConsoleIO.WriteLineFormatted(cacheLoaded ? "§8Os dados da sessão foram carregados do disco." : "§8Não foram encontradas sessões armazenadas no disco."); } } //Asking the user to type in missing data such as Username and Password if (Settings.Login == "") { Console.Write(ConsoleIO.BasicIO ? "Insira seu nick/email do minecraft \n" : "Login : "******"" && (Settings.SessionCaching == CacheType.None || !SessionCache.Contains(Settings.Login.ToLower()))) { //RequestPassword(); } startupargs = args; InitializeClient(); }
/// <summary> /// Start a new Client /// </summary> private static void InitializeClient() { SessionToken session = new SessionToken(); ProtocolHandler.LoginResult result = ProtocolHandler.LoginResult.LoginRequired; if (Settings.Password == "-") { ConsoleIO.WriteLineFormatted("\n§e[信息]§8 你当前使用离线模式"); result = ProtocolHandler.LoginResult.Success; session.PlayerID = "0"; session.PlayerName = Settings.Login; } else { // Validate cached session or login new session. if (Settings.SessionCaching != CacheType.None && SessionCache.Contains(Settings.Login.ToLower())) { session = SessionCache.Get(Settings.Login.ToLower()); result = ProtocolHandler.GetTokenValidation(session); if (result != ProtocolHandler.LoginResult.Success) { ConsoleIO.WriteLineFormatted("§c[错误]§8 Session 错误或过期."); if (Settings.Password == "") { RequestPassword(); } } else { ConsoleIO.WriteLineFormatted("§c[错误]§8 Session 错误 " + session.PlayerName + '.'); } } if (result != ProtocolHandler.LoginResult.Success) { ConsoleIO.WriteLineFormatted("\n§e[信息]§8 正在连接到验证服务器.."); result = ProtocolHandler.GetLogin(Settings.Login, Settings.Password, out session); if (result == ProtocolHandler.LoginResult.Success && Settings.SessionCaching != CacheType.None) { SessionCache.Store(Settings.Login.ToLower(), session); } } } if (result == ProtocolHandler.LoginResult.Success) { Settings.Username = session.PlayerName; if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } if (Settings.playerHeadAsIcon) { ConsoleIcon.setPlayerIconAsync(Settings.Username); } if (Settings.DebugMessages) { ConsoleIO.WriteLineFormatted("§e[信息]§8 成功! (获取的 session ID: " + session.ID + ')'); } //ProtocolHandler.RealmsListWorlds(Settings.Username, PlayerID, sessionID); //TODO REMOVE if (Settings.ServerIP == "") { Console.Write("服务器 IP : "); Settings.SetServerIP(Console.ReadLine()); } //Get server version int protocolversion = 0; ForgeInfo forgeInfo = null; if (Settings.ServerVersion != "" && Settings.ServerVersion.ToLower() != "auto") { protocolversion = Protocol.ProtocolHandler.MCVer2ProtocolVersion(Settings.ServerVersion); if (protocolversion != 0) { ConsoleIO.WriteLineFormatted("§e[信息]§8 使用MC版本: " + Settings.ServerVersion + " (protocol v" + protocolversion + ')'); } else { ConsoleIO.WriteLineFormatted("§c[错误]§8 未知或不支持的mc版本 '" + Settings.ServerVersion + "'.\n正在自动选择版本."); } if (useMcVersionOnce) { useMcVersionOnce = false; Settings.ServerVersion = ""; } } //Retrieve server info if version is not manually set OR if need to retrieve Forge information if (protocolversion == 0 || Settings.ServerAutodetectForge || (Settings.ServerForceForge && !ProtocolHandler.ProtocolMayForceForge(protocolversion))) { if (protocolversion != 0) { ConsoleIO.WriteLineFormatted("§e[信息]§8 正在检查服务器是否存在 Forge.."); } else { ConsoleIO.WriteLineFormatted("§e[信息]§8 正在检查版本...."); } if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion, ref forgeInfo)) { HandleFailure("无法找到这个服务器!", true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } //Force-enable Forge support? if (Settings.ServerForceForge && forgeInfo == null) { if (ProtocolHandler.ProtocolMayForceForge(protocolversion)) { Translations.WriteLine("mcc.forgeforce"); forgeInfo = ProtocolHandler.ProtocolForceForge(protocolversion); } else { HandleFailure(Translations.Get("error.forgeforce"), true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } //Proceed to server login if (protocolversion != 0) { try { //Start the main TCP client if (Settings.SingleCommand != "") { client = new McClient(session.PlayerName, session.PlayerID, session.ID, Settings.ServerIP, Settings.ServerPort, protocolversion, forgeInfo, Settings.SingleCommand); } else { client = new McClient(session.PlayerName, session.PlayerID, session.ID, protocolversion, forgeInfo, Settings.ServerIP, Settings.ServerPort); } //Update console title if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } } catch (NotSupportedException) { HandleFailure("无法连接到服务器 : 不支持的版本!", true); } } else { HandleFailure("无法获取服务器版本", true); } } else { string failureMessage = "Minecraft 登录失败 : "; switch (result) { case ProtocolHandler.LoginResult.AccountMigrated: failureMessage += "未知邮箱"; break; //什么玩意我怎么触发不了 case ProtocolHandler.LoginResult.ServiceUnavailable: failureMessage += "验证服务器目前离线"; break; //"认证服务器处于宕机状态中。请稍后再试,抱歉!" case ProtocolHandler.LoginResult.WrongPassword: failureMessage += "密码错误或短时间登陆太多次被禁止登录"; break; //老无法判定了 case ProtocolHandler.LoginResult.InvalidResponse: failureMessage += "无法读取返回信息"; break; //分析错误(YES) case ProtocolHandler.LoginResult.NotPremium: failureMessage += "非正版玩家"; break; case ProtocolHandler.LoginResult.OtherError: failureMessage += "网络错误"; break; case ProtocolHandler.LoginResult.SSLError: failureMessage += "SSL证书错误"; break; //完蛋Mojang服务器要没了 default: failureMessage += "未知错误"; break; } if (result == ProtocolHandler.LoginResult.SSLError && isUsingMono) { ConsoleIO.WriteLineFormatted("§8看起来你正在使用 Mono 来运行这个程序。" + '\n' + "第一次,您必须导入 HTTPS 证书使用:" + '\n' + "mozroots --import --ask-remove"); return; } HandleFailure(failureMessage, false, ChatBot.DisconnectReason.LoginRejected); } }
/// <summary> /// The main entry point of Minecraft Console Client /// </summary> static void Main(string[] args) { Console.WriteLine("Console Client for MC {0} to {1} - v{2} - By ORelio & Contributors", MCLowestVersion, MCHighestVersion, Version); //Debug input ? if (args.Length == 1 && args[0] == "--keyboard-debug") { Console.WriteLine("Keyboard debug mode: Press any key to display info"); ConsoleIO.DebugReadInput(); } //Basic Input/Output ? if (args.Length >= 1 && args[args.Length - 1] == "BasicIO") { 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.LoadSettings(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.LoadSettings("MinecraftClient.ini"); } else { Settings.WriteDefaultSettings("MinecraftClient.ini"); } //Other command-line arguments if (args.Length >= 1) { Settings.Login = args[0]; if (args.Length >= 2) { Settings.Password = args[1]; if (args.Length >= 3) { Settings.SetServerIP(args[2]); //Single command? if (args.Length >= 4) { Settings.SingleCommand = args[3]; } } } } if (Settings.ConsoleTitle != "") { Settings.Username = "******"; Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } //Load cached sessions from disk if necessary if (Settings.SessionCaching == CacheType.Disk) { bool cacheLoaded = SessionCache.InitializeDiskCache(); if (Settings.DebugMessages) { ConsoleIO.WriteLineFormatted(cacheLoaded ? "§8Session cache has been successfully loaded from disk." : "§8Cached sessions could not be loaded from disk"); } } //Asking the user to type in missing data such as Username and Password if (Settings.Login == "") { Console.Write(ConsoleIO.basicIO ? "Please type the username or email of your choice.\n" : "Login : "******"" && (Settings.SessionCaching == CacheType.None || !SessionCache.Contains(Settings.Login.ToLower()))) { RequestPassword(); } startupargs = args; InitializeClient(); }
/// <summary> /// Handle fatal errors such as ping failure, login failure, server disconnection, and so on. /// Allows AutoRelog to perform on fatal errors, prompt for server version, and offline commands. /// </summary> /// <param name="errorMessage">Error message to display and optionally pass to AutoRelog bot</param> /// <param name="versionError">Specify if the error is related to an incompatible or unkown server version</param> /// <param name="disconnectReason">If set, the error message will be processed by the AutoRelog bot</param> public static void HandleFailure(string errorMessage = null, bool versionError = false, ChatBots.AutoRelog.DisconnectReason?disconnectReason = null) { if (!String.IsNullOrEmpty(errorMessage)) { ConsoleIO.Reset(); while (Console.KeyAvailable) { Console.ReadKey(true); } Console.WriteLine(errorMessage); if (disconnectReason.HasValue) { if (ChatBots.AutoRelog.OnDisconnectStatic(disconnectReason.Value, errorMessage)) { return; //AutoRelog is triggering a restart of the client } } } if (Settings.interactiveMode) { if (versionError) { Translations.Write("mcc.server_version"); Settings.ServerVersion = Console.ReadLine(); if (Settings.ServerVersion != "") { useMcVersionOnce = true; Restart(); return; } } if (offlinePrompt == null) { offlinePrompt = new Thread(new ThreadStart(delegate { string command = " "; ConsoleIO.WriteLineFormatted(Translations.Get("mcc.disconnected", (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar))); Translations.WriteLineFormatted("mcc.press_exit"); while (command.Length > 0) { if (!ConsoleIO.BasicIO) { ConsoleIO.Write('>'); } command = Console.ReadLine().Trim(); if (command.Length > 0) { 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), null); } else if (command.StartsWith("connect")) { message = new Commands.Connect().Run(null, Settings.ExpandVars(command), null); } else if (command.StartsWith("exit") || command.StartsWith("quit")) { message = new Commands.Exit().Run(null, Settings.ExpandVars(command), null); } else if (command.StartsWith("help")) { ConsoleIO.WriteLineFormatted("§8MCC: " + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + new Commands.Reco().GetCmdDescTranslated()); ConsoleIO.WriteLineFormatted("§8MCC: " + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + new Commands.Connect().GetCmdDescTranslated()); } else { ConsoleIO.WriteLineFormatted(Translations.Get("icmd.unknown", command.Split(' ')[0])); } if (message != "") { ConsoleIO.WriteLineFormatted("§8MCC: " + message); } } } })); offlinePrompt.Start(); } } else { // Not in interactive mode, just exit and let the calling script handle the failure if (disconnectReason.HasValue) { // Return distinct exit codes for known failures. if (disconnectReason.Value == ChatBot.DisconnectReason.UserLogout) { Exit(1); } if (disconnectReason.Value == ChatBot.DisconnectReason.InGameKick) { Exit(2); } if (disconnectReason.Value == ChatBot.DisconnectReason.ConnectionLost) { Exit(3); } if (disconnectReason.Value == ChatBot.DisconnectReason.LoginRejected) { Exit(4); } } Exit(); } }
/// <summary> /// Start a new Client /// </summary> private static void InitializeClient() { SessionToken session = new SessionToken(); ProtocolHandler.LoginResult result = ProtocolHandler.LoginResult.LoginRequired; if (Settings.Password == "-") { Translations.WriteLineFormatted("mcc.offline"); result = ProtocolHandler.LoginResult.Success; session.PlayerID = "0"; session.PlayerName = Settings.Login; } else { // Validate cached session or login new session. if (Settings.SessionCaching != CacheType.None && SessionCache.Contains(Settings.Login.ToLower())) { session = SessionCache.Get(Settings.Login.ToLower()); result = ProtocolHandler.GetTokenValidation(session); if (result != ProtocolHandler.LoginResult.Success) { Translations.WriteLineFormatted("mcc.session_invalid"); if (Settings.Password == "") { RequestPassword(); } } else { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.session_valid", session.PlayerName)); } } if (result != ProtocolHandler.LoginResult.Success) { Translations.WriteLine("mcc.connecting", Settings.AccountType == ProtocolHandler.AccountType.Mojang ? "Minecraft.net" : "Microsoft"); result = ProtocolHandler.GetLogin(Settings.Login, Settings.Password, Settings.AccountType, out session); if (result == ProtocolHandler.LoginResult.Success && Settings.SessionCaching != CacheType.None) { SessionCache.Store(Settings.Login.ToLower(), session); } } } if (result == ProtocolHandler.LoginResult.Success) { Settings.Username = session.PlayerName; bool isRealms = false; if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } if (Settings.playerHeadAsIcon) { ConsoleIcon.setPlayerIconAsync(Settings.Username); } if (Settings.DebugMessages) { Translations.WriteLine("debug.session_id", session.ID); } List <string> availableWorlds = new List <string>(); if (Settings.MinecraftRealmsEnabled && !String.IsNullOrEmpty(session.ID)) { availableWorlds = ProtocolHandler.RealmsListWorlds(Settings.Username, session.PlayerID, session.ID); } if (Settings.ServerIP == "") { Translations.Write("mcc.ip"); string addressInput = Console.ReadLine(); if (addressInput.StartsWith("realms:")) { if (Settings.MinecraftRealmsEnabled) { if (availableWorlds.Count == 0) { HandleFailure(Translations.Get("error.realms.access_denied"), false, ChatBot.DisconnectReason.LoginRejected); return; } int worldIndex = 0; string worldId = addressInput.Split(':')[1]; if (!availableWorlds.Contains(worldId) && int.TryParse(worldId, out worldIndex) && worldIndex < availableWorlds.Count) { worldId = availableWorlds[worldIndex]; } if (availableWorlds.Contains(worldId)) { string RealmsAddress = ProtocolHandler.GetRealmsWorldServerAddress(worldId, Settings.Username, session.PlayerID, session.ID); if (RealmsAddress != "") { addressInput = RealmsAddress; isRealms = true; Settings.ServerVersion = MCHighestVersion; } else { HandleFailure(Translations.Get("error.realms.server_unavailable"), false, ChatBot.DisconnectReason.LoginRejected); return; } } else { HandleFailure(Translations.Get("error.realms.server_id"), false, ChatBot.DisconnectReason.LoginRejected); return; } } else { HandleFailure(Translations.Get("error.realms.disabled"), false, null); return; } } Settings.SetServerIP(addressInput); } //Get server version int protocolversion = 0; ForgeInfo forgeInfo = null; if (Settings.ServerVersion != "" && Settings.ServerVersion.ToLower() != "auto") { protocolversion = Protocol.ProtocolHandler.MCVer2ProtocolVersion(Settings.ServerVersion); if (protocolversion != 0) { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.use_version", Settings.ServerVersion, protocolversion)); } else { ConsoleIO.WriteLineFormatted(Translations.Get("mcc.unknown_version", Settings.ServerVersion)); } if (useMcVersionOnce) { useMcVersionOnce = false; Settings.ServerVersion = ""; } } //Retrieve server info if version is not manually set OR if need to retrieve Forge information if (!isRealms && (protocolversion == 0 || Settings.ServerAutodetectForge || (Settings.ServerForceForge && !ProtocolHandler.ProtocolMayForceForge(protocolversion)))) { if (protocolversion != 0) { Translations.WriteLine("mcc.forge"); } else { Translations.WriteLine("mcc.retrieve"); } if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion, ref forgeInfo)) { HandleFailure(Translations.Get("error.ping"), true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } //Force-enable Forge support? if (!isRealms && Settings.ServerForceForge && forgeInfo == null) { if (ProtocolHandler.ProtocolMayForceForge(protocolversion)) { Translations.WriteLine("mcc.forgeforce"); forgeInfo = ProtocolHandler.ProtocolForceForge(protocolversion); } else { HandleFailure(Translations.Get("error.forgeforce"), true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } //Proceed to server login if (protocolversion != 0) { try { //Start the main TCP client if (Settings.SingleCommand != "") { client = new McClient(session.PlayerName, session.PlayerID, session.ID, Settings.ServerIP, Settings.ServerPort, protocolversion, forgeInfo, Settings.SingleCommand); } else { client = new McClient(session.PlayerName, session.PlayerID, session.ID, protocolversion, forgeInfo, Settings.ServerIP, Settings.ServerPort); } //Update console title if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } } catch (NotSupportedException) { HandleFailure(Translations.Get("error.unsupported"), true); } } else { HandleFailure(Translations.Get("error.determine"), true); } } else { string failureMessage = Translations.Get("error.login"); string failureReason = ""; switch (result) { case ProtocolHandler.LoginResult.AccountMigrated: failureReason = "error.login.migrated"; break; case ProtocolHandler.LoginResult.ServiceUnavailable: failureReason = "error.login.server"; break; case ProtocolHandler.LoginResult.WrongPassword: failureReason = "error.login.blocked"; break; case ProtocolHandler.LoginResult.InvalidResponse: failureReason = "error.login.response"; break; case ProtocolHandler.LoginResult.NotPremium: failureReason = "error.login.premium"; break; case ProtocolHandler.LoginResult.OtherError: failureReason = "error.login.network"; break; case ProtocolHandler.LoginResult.SSLError: failureReason = "error.login.ssl"; break; case ProtocolHandler.LoginResult.UserCancel: failureReason = "error.login.cancel"; break; default: failureReason = "error.login.unknown"; break; } failureMessage += Translations.Get(failureReason); if (result == ProtocolHandler.LoginResult.SSLError && isUsingMono) { Translations.WriteLineFormatted("error.login.ssl_help"); return; } HandleFailure(failureMessage, false, ChatBot.DisconnectReason.LoginRejected); } }
/// <summary> /// The main entry point of Minecraft Console Client /// </summary> static void Main(string[] args) { Console.WriteLine("Console Client for MC {0} to {1} - v{2} - By ORelio & Contributors", MCLowestVersion, MCHighestVersion, Version); //BIOS if (args.Length >= 1 && args[args.Length - 1] == "BasicIO") { ConsoleIO.basicIO = true; Console.OutputEncoding = Console.InputEncoding = Encoding.GetEncoding(System.Globalization.CultureInfo.CurrentCulture.TextInfo.ANSICodePage); args = args.Where(o => !Object.ReferenceEquals(o, args[args.Length - 1])).ToArray(); } //设置ini设置文件 if (args.Length >= 1 && System.IO.File.Exists(args[0]) && System.IO.Path.GetExtension(args[0]).ToLower() == ".ini") { Settings.LoadSettings(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.LoadSettings("MinecraftClient.ini"); } else { Settings.WriteDefaultSettings("MinecraftClient.ini"); } //其他命令行参数 if (args.Length >= 1) { Settings.Login = args[0]; if (args.Length >= 2) { Settings.Password = args[1]; if (args.Length >= 3) { Settings.SetServerIP(args[2]); //Single command? if (args.Length >= 4) { Settings.SingleCommand = args[3]; } } } } if (Settings.ConsoleTitle != "") { Settings.Username = "******"; Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } //有必要的话启用本地cache if (Settings.SessionCaching == CacheType.Disk) { bool cacheLoaded = SessionCache.InitializeDiskCache(); if (Settings.DebugMessages) { ConsoleIO.WriteLineFormatted(cacheLoaded ? "§8Session cache has been successfully loaded from disk." : "§8Cached sessions could not be loaded from disk"); } } //Asking the user to type in missing data such as Username and Password if (Settings.Login == "") { Console.Write(ConsoleIO.basicIO ? "Please type the username or email of your choice.\n" : "Login : "******"" && (Settings.SessionCaching == CacheType.None || !SessionCache.Contains(Settings.Login.ToLower()))) { RequestPassword(); } startupargs = args; InitializeClient(); }
/// <summary> /// Starts the main chat client, wich will login to the server using the MinecraftCom class. /// </summary> /// <param name="user">The chosen username of a premium Minecraft Account</param> /// <param name="sessionID">A valid sessionID obtained with MinecraftCom.GetLogin()</param> /// <param name="server_ip">The server IP</param> /// <param name="port">The server port to use</param> /// <param name="protocolversion">Minecraft protocol version to use</param> /// <param name="uuid">The player's UUID for online-mode authentication</param> /// <param name="singlecommand">If set to true, the client will send a single command and then disconnect from the server</param> /// <param name="command">The text or command to send. Will only be sent if singlecommand is set to true.</param> private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, bool singlecommand, string command) { this.sessionid = sessionID; this.uuid = uuid; this.username = user; this.host = server_ip; this.port = port; if (!singlecommand) { if (Settings.AntiAFK_Enabled) { BotLoad(new ChatBots.AntiAFK(Settings.AntiAFK_Delay)); } if (Settings.Hangman_Enabled) { BotLoad(new ChatBots.HangmanGame(Settings.Hangman_English)); } if (Settings.Alerts_Enabled) { BotLoad(new ChatBots.Alerts()); } if (Settings.ChatLog_Enabled) { BotLoad(new ChatBots.ChatLog(Settings.expandVars(Settings.ChatLog_File), Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); } if (Settings.PlayerLog_Enabled) { BotLoad(new ChatBots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.expandVars(Settings.PlayerLog_File))); } if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); } if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.expandVars(Settings.ScriptScheduler_TasksFile))); } if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); } } try { client = ProxyHandler.newTcpClient(host, port); client.ReceiveBufferSize = 1024 * 1024; handler = Protocol.ProtocolHandler.getProtocolHandler(client, protocolversion, this); Console.WriteLine("Version is supported.\nLogging in..."); if (handler.Login()) { if (singlecommand) { handler.SendChatMessage(command); ConsoleIO.WriteLineFormatted("§7Command §8" + command + "§7 sent."); Thread.Sleep(5000); handler.Disconnect(); Thread.Sleep(1000); } else { foreach (ChatBot bot in scripts_on_hold) { bot.SetHandler(this); } bots.AddRange(scripts_on_hold); scripts_on_hold.Clear(); Console.WriteLine("Server was successfully joined.\nType '" + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + "quit' to leave the server."); cmdprompt = new Thread(new ThreadStart(CommandPrompt)); cmdprompt.Name = "MCC Command prompt"; cmdprompt.Start(); } } } catch (SocketException) { Console.WriteLine("Failed to connect to this IP."); if (AttemptsLeft > 0) { ChatBot.LogToConsole("Waiting 5 seconds (" + AttemptsLeft + " attempts left)..."); Thread.Sleep(5000); AttemptsLeft--; Program.Restart(); } else if (!singlecommand) { Console.ReadLine(); } } }
private void Log(string msg, params object[] args) { ConsoleIO.WriteLineFormatted(string.Format(msg, args)); }
private void Log(string msg) { ConsoleIO.WriteLineFormatted(msg); }
private void Log(object msg) { ConsoleIO.WriteLineFormatted(msg.ToString()); }
/// <summary> /// The main entry point of Minecraft Console Client /// </summary> static void Main(string[] args) { Console.WriteLine("Console Client for MC {0} to {1} - v{2} - By ORelio & Contributors", MCLowestVersion, MCHighestVersion, Version); ConsoleIO.WriteLineFormatted("§dMCC §e汉化 By XIAYM §f& §eWindowX"); //WindowX:劳资的名字捏!!!! //XIAYM:好吧给你改了 //Build information to facilitate processing of bug reports if (BuildInfo != null) { ConsoleIO.WriteLineFormatted("§e" + BuildInfo); } //已被禁用的信息(2020.10.6 17:30 启用) //Debug input ? if (args.Length == 1 && args[0] == "--keyboard-debug") { ConsoleIO.WriteLine("按下任意键显示 Debug 信息..."); ConsoleIO.DebugReadInput(); } //Setup ConsoleIO ConsoleIO.LogPrefix = "§e[信息]§8 "; 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.LoadSettings(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.LoadSettings("MinecraftClient.ini"); } else { Settings.WriteDefaultSettings("MinecraftClient.ini"); } //Other command-line arguments if (args.Length >= 1) { Settings.Login = args[0]; if (args.Length >= 2) { Settings.Password = args[1]; if (args.Length >= 3) { Settings.SetServerIP(args[2]); //Single command? if (args.Length >= 4) { Settings.SingleCommand = args[3]; } } } } if (Settings.ConsoleTitle != "") { Settings.Username = "******"; Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } //Test line to troubleshoot invisible colors if (Settings.DebugMessages) { ConsoleIO.WriteLineFormatted("§e[调试]§8 颜色测试: 您应该显示为: [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) { ConsoleIO.WriteLineFormatted(cacheLoaded ? "§e[信息]§8 Session 数据已从硬盘加载!" : "§e[信息]§8没有 Session 数据从硬盘加载!"); } } //Asking the user to type in missing data such as Username and Password if (Settings.Login == "") { Console.Write(ConsoleIO.BasicIO ? "请输入用户名或邮箱\n" : "账户 : "); Settings.Login = Console.ReadLine(); } if (Settings.Password == "" && (Settings.SessionCaching == CacheType.None || !SessionCache.Contains(Settings.Login.ToLower()))) { RequestPassword(); } startupargs = args; InitializeClient(); }
/// <summary> /// The main entry point of Minecraft Console Client /// </summary> static void Main(string[] args) { Console.WriteLine("Console Client for MC {0} to {1} - v{2} - By ORelio & Contributors", MCLowestVersion, MCHighestVersion, Version); //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.LoadSettings(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.LoadSettings("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) { Settings.Login = args[0]; if (args.Length >= 2) { Settings.Password = args[1]; if (args.Length >= 3) { Settings.SetServerIP(args[2]); //Single command? if (args.Length >= 4) { Settings.SingleCommand = args[3]; } } } } if (Settings.ConsoleTitle != "") { Settings.Username = "******"; Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } //Test line to troubleshoot invisible colors if (Settings.DebugMessages) { Translations.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 if (Settings.Login == "") { 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()))) { RequestPassword(); } startupargs = args; InitializeClient(); }
/// <summary> /// Starts the main chat client, wich will login to the server using the MinecraftCom class. /// </summary> /// <param name="user">The chosen username of a premium Minecraft Account</param> /// <param name="sessionID">A valid sessionID obtained with MinecraftCom.GetLogin()</param> /// <param name="server_ip">The server IP</param> /// <param name="port">The server port to use</param> /// <param name="protocolversion">Minecraft protocol version to use</param> /// <param name="uuid">The player's UUID for online-mode authentication</param> /// <param name="singlecommand">If set to true, the client will send a single command and then disconnect from the server</param> /// <param name="command">The text or command to send. Will only be sent if singlecommand is set to true.</param> private void StartClient(string user, string uuid, string sessionID, string server_ip, ushort port, int protocolversion, ForgeInfo forgeInfo, bool singlecommand, string command) { terrainAndMovementsEnabled = Settings.TerrainAndMovements; bool retry = false; this.sessionid = sessionID; this.uuid = uuid; this.username = user; this.host = server_ip; this.port = port; if (!singlecommand) { if (botsOnHold.Count == 0) { if (Settings.AntiAFK_Enabled) { BotLoad(new ChatBots.AntiAFK(Settings.AntiAFK_Delay)); } if (Settings.Hangman_Enabled) { BotLoad(new ChatBots.HangmanGame(Settings.Hangman_English)); } if (Settings.Alerts_Enabled) { BotLoad(new ChatBots.Alerts()); } if (Settings.ChatLog_Enabled) { BotLoad(new ChatBots.ChatLog(Settings.ExpandVars(Settings.ChatLog_File), Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); } if (Settings.PlayerLog_Enabled) { BotLoad(new ChatBots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.ExpandVars(Settings.PlayerLog_File))); } if (Settings.AutoRelog_Enabled) { BotLoad(new ChatBots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); } if (Settings.ScriptScheduler_Enabled) { BotLoad(new ChatBots.ScriptScheduler(Settings.ExpandVars(Settings.ScriptScheduler_TasksFile))); } if (Settings.RemoteCtrl_Enabled) { BotLoad(new ChatBots.RemoteControl()); } if (Settings.AutoRespond_Enabled) { BotLoad(new ChatBots.AutoRespond(Settings.AutoRespond_Matches)); } //Add your ChatBot here by uncommenting and adapting //BotLoad(new ChatBots.YourBot()); } } try { client = ProxyHandler.newTcpClient(host, port); client.ReceiveBufferSize = 1024 * 1024; handler = Protocol.ProtocolHandler.GetProtocolHandler(client, protocolversion, forgeInfo, this); Console.WriteLine("Version is supported.\nLogging in..."); try { if (handler.Login()) { if (singlecommand) { handler.SendChatMessage(command); ConsoleIO.WriteLineFormatted("§7Command §8" + command + "§7 sent."); Thread.Sleep(5000); handler.Disconnect(); Thread.Sleep(1000); } else { foreach (ChatBot bot in botsOnHold) { BotLoad(bot, false); } botsOnHold.Clear(); Console.WriteLine("Server was successfully joined.\nType '" + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + "quit' to leave the server."); cmdprompt = new Thread(new ThreadStart(CommandPrompt)); cmdprompt.Name = "MCC Command prompt"; cmdprompt.Start(); } } } catch (Exception e) { ConsoleIO.WriteLineFormatted("§8" + e.Message); Console.WriteLine("Failed to join this server."); retry = true; } } catch (SocketException e) { ConsoleIO.WriteLineFormatted("§8" + e.Message); Console.WriteLine("Failed to connect to this IP."); retry = true; } if (retry) { if (ReconnectionAttemptsLeft > 0) { ConsoleIO.WriteLogLine("Waiting 5 seconds (" + ReconnectionAttemptsLeft + " attempts left)..."); Thread.Sleep(5000); ReconnectionAttemptsLeft--; Program.Restart(); } else if (!singlecommand && Settings.interactiveMode) { Program.HandleFailure(); } } }
/// <summary> /// Start a new Client /// </summary> private static void InitializeClient() { ProtocolHandler.LoginResult result; Settings.Username = Settings.Login; string sessionID = ""; string UUID = ""; if (Settings.Password == "-") { ConsoleIO.WriteLineFormatted("§8You chose to run in offline mode."); result = ProtocolHandler.LoginResult.Success; sessionID = "0"; } else { Console.WriteLine("Connecting to Minecraft.net..."); result = ProtocolHandler.GetLogin(ref Settings.Username, Settings.Password, ref sessionID, ref UUID); } if (result == ProtocolHandler.LoginResult.Success) { if (Settings.ConsoleTitle != "") { Console.Title = Settings.expandVars(Settings.ConsoleTitle); } if (Settings.playerHeadAsIcon) { ConsoleIcon.setPlayerIconAsync(Settings.Username); } Console.WriteLine("Success. (session ID: " + sessionID + ')'); if (Settings.ServerIP == "") { Console.Write("Server IP : "); Settings.setServerIP(Console.ReadLine()); } //Get server version int protocolversion = 0; 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 (protocolversion == 0) { Console.WriteLine("Retrieving Server Info..."); if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion)) { Console.WriteLine("Failed to ping this IP."); if (Settings.AutoRelog_Enabled) { 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(); } return; } } if (protocolversion != 0) { try { //Start the main TCP client if (Settings.SingleCommand != "") { Client = new McTcpClient(Settings.Username, UUID, sessionID, Settings.ServerIP, Settings.ServerPort, protocolversion, Settings.SingleCommand); } else { Client = new McTcpClient(Settings.Username, UUID, sessionID, protocolversion, Settings.ServerIP, Settings.ServerPort); } } catch (NotSupportedException) { Console.WriteLine("Cannot connect to the server : This version is not supported !"); OfflineCommandPrompt(); } } else { Console.WriteLine("Failed to determine server version."); OfflineCommandPrompt(); } } else { Console.ForegroundColor = ConsoleColor.Gray; Console.Write("Connection failed : "); switch (result) { case ProtocolHandler.LoginResult.AccountMigrated: Console.WriteLine("Account migrated, use e-mail as username."); break; case ProtocolHandler.LoginResult.ServiceUnavailable: Console.WriteLine("Login servers are unavailable. Please try again later."); break; case ProtocolHandler.LoginResult.WrongPassword: Console.WriteLine("Incorrect password."); break; case ProtocolHandler.LoginResult.NotPremium: Console.WriteLine("User not premium."); break; case ProtocolHandler.LoginResult.OtherError: Console.WriteLine("Network error."); break; case ProtocolHandler.LoginResult.SSLError: Console.WriteLine("SSL Error."); if (isUsingMono) { ConsoleIO.WriteLineFormatted("§8It appears that you are using Mono to run this program." + '\n' + "The first time, you have to import HTTPS certificates using:" + '\n' + "mozroots --import --ask-remove"); return; } break; } while (Console.KeyAvailable) { Console.ReadKey(false); } if (Settings.SingleCommand == "") { OfflineCommandPrompt(); } } }
/// <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(); }
/// <summary> /// The main entry point of Minecraft Console Client /// </summary> static void Main(string[] args) { ConsoleIO.WriteLineFormatted("§cSyrax Client§8 (by Emperio) » §bBETA-0.2"); ConsoleIO.WriteLine(""); ConsoleIO.WriteLineFormatted("§bFetching Updates & News..."); string code = ""; using (WebClient client = new WebClient()) { string htmlCode = client.DownloadString("https://emperio.me/syraxupdates.html"); code = htmlCode; } ConsoleIO.WriteLineFormatted("§dRecent News : "); ConsoleIO.WriteLineFormatted("§5" + code); //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") { Console.WriteLine("Keyboard debug mode: Press any key to display info"); ConsoleIO.DebugReadInput(); } //Setup ConsoleIO ConsoleIO.LogPrefix = "§8 [»Syrax«] "; if (args.Length >= 1 && args[args.Length - 1] == "BasicIO") { 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.LoadSettings(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.LoadSettings("MinecraftClient.ini"); } else { Settings.WriteDefaultSettings("MinecraftClient.ini"); } //Other command-line arguments if (args.Length >= 1) { Settings.Login = args[0]; if (args.Length >= 2) { Settings.Password = args[1]; if (args.Length >= 3) { Settings.SetServerIP(args[2]); //Single command? if (args.Length >= 4) { Settings.SingleCommand = args[3]; } } } } if (Settings.ConsoleTitle != "") { Settings.Username = "******"; Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } //Load cached sessions from disk if necessary if (Settings.SessionCaching == CacheType.Disk) { bool cacheLoaded = SessionCache.InitializeDiskCache(); if (Settings.DebugMessages) { ConsoleIO.WriteLineFormatted(cacheLoaded ? "§8Session data loaded" : "§8No sessions could be loaded."); } } //Asking the user to type in missing data such as Username and Password if (Settings.Login == "") { Console.Write(ConsoleIO.BasicIO ? "Enter Minecraft Username or Password\n" : "Login » "); Settings.Login = Console.ReadLine(); } if (Settings.Password == "" && (Settings.SessionCaching == CacheType.None || !SessionCache.Contains(Settings.Login.ToLower()))) { RequestPassword(); } startupargs = args; InitializeClient(); }
/// <summary> /// Start a new Client /// </summary> private static void InitializeClient() { SessionToken session = new SessionToken(); ProtocolHandler.LoginResult result = ProtocolHandler.LoginResult.LoginRequired; if (Settings.Password == "-") { ConsoleIO.WriteLineFormatted("§8You chose to run in offline mode."); result = ProtocolHandler.LoginResult.Success; session.PlayerID = "0"; session.PlayerName = Settings.Login; } else { // Validate cached session or login new session. if (Settings.SessionCaching != CacheType.None && SessionCache.Contains(Settings.Login.ToLower())) { session = SessionCache.Get(Settings.Login.ToLower()); result = ProtocolHandler.GetTokenValidation(session); if (result != ProtocolHandler.LoginResult.Success) { ConsoleIO.WriteLineFormatted("§8Cached session is invalid or expired."); if (Settings.Password == "") { RequestPassword(); } } else { ConsoleIO.WriteLineFormatted("§8Cached session is still valid for " + session.PlayerName + '.'); } } if (result != ProtocolHandler.LoginResult.Success) { Console.WriteLine("Connecting to Minecraft.net..."); result = ProtocolHandler.GetLogin(Settings.Login, Settings.Password, out session); if (result == ProtocolHandler.LoginResult.Success && Settings.SessionCaching != CacheType.None) { SessionCache.Store(Settings.Login.ToLower(), session); } } } if (result == ProtocolHandler.LoginResult.Success) { Settings.Username = session.PlayerName; if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } if (Settings.playerHeadAsIcon) { ConsoleIcon.setPlayerIconAsync(Settings.Username); } if (Settings.DebugMessages) { Console.WriteLine("Success. (session ID: " + session.ID + ')'); } //ProtocolHandler.RealmsListWorlds(Settings.Username, PlayerID, sessionID); //TODO REMOVE if (Settings.ServerIP == "") { Console.Write("Server IP : "); Settings.SetServerIP(Console.ReadLine()); } //Get server version int protocolversion = 0; ForgeInfo forgeInfo = null; 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) { Console.WriteLine("Retrieving Server Info..."); if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion, ref forgeInfo)) { HandleFailure("Failed to ping this IP.", true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } if (protocolversion != 0) { try { //Start the main TCP client if (Settings.SingleCommand != "") { Client = new McTcpClient(session.PlayerName, session.PlayerID, session.ID, Settings.ServerIP, Settings.ServerPort, protocolversion, forgeInfo, Settings.SingleCommand); } else { Client = new McTcpClient(session.PlayerName, session.PlayerID, session.ID, protocolversion, forgeInfo, Settings.ServerIP, Settings.ServerPort); } //Update console title if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } } catch (NotSupportedException) { HandleFailure("Cannot connect to the server : This version is not supported !", true); } } else { HandleFailure("Failed to determine server version.", true); } } else { Console.ForegroundColor = ConsoleColor.Gray; string failureMessage = "Minecraft Login failed : "; switch (result) { case ProtocolHandler.LoginResult.AccountMigrated: failureMessage += "Account migrated, use e-mail as username."; break; case ProtocolHandler.LoginResult.ServiceUnavailable: failureMessage += "Login servers are unavailable. Please try again later."; break; case ProtocolHandler.LoginResult.WrongPassword: failureMessage += "Incorrect password."; break; case ProtocolHandler.LoginResult.NotPremium: failureMessage += "User not premium."; break; case ProtocolHandler.LoginResult.OtherError: failureMessage += "Network error."; break; case ProtocolHandler.LoginResult.SSLError: failureMessage += "SSL Error."; break; default: failureMessage += "Unknown Error."; break; } if (result == ProtocolHandler.LoginResult.SSLError && isUsingMono) { ConsoleIO.WriteLineFormatted("§8It appears that you are using Mono to run this program." + '\n' + "The first time, you have to import HTTPS certificates using:" + '\n' + "mozroots --import --ask-remove"); return; } HandleFailure(failureMessage, false, ChatBot.DisconnectReason.LoginRejected); } }
/// <summary> /// Start a new Client /// </summary> private static void InitializeClient() { vars.logInTimestamp = Telegram.data.getTimestamp() + 60; SessionToken session = new SessionToken(); ProtocolHandler.LoginResult result = ProtocolHandler.LoginResult.LoginRequired; if (Settings.Password == "-") { //ConsoleIO.WriteLineFormatted("§8Iniciando no modo OffLine."); result = ProtocolHandler.LoginResult.Success; session.PlayerID = "0"; session.PlayerName = Settings.Login; } else { // Validate cached session or login new session. if (Settings.SessionCaching != CacheType.None && SessionCache.Contains(Settings.Login.ToLower())) { session = SessionCache.Get(Settings.Login.ToLower()); result = ProtocolHandler.GetTokenValidation(session); if (result != ProtocolHandler.LoginResult.Success) { ConsoleIO.WriteLineFormatted("§8Cached session is invalid or expired."); if (Settings.Password == "") { RequestPassword(); } } else { ConsoleIO.WriteLineFormatted("§8Cached session is still valid for " + session.PlayerName + '.'); } } if (result != ProtocolHandler.LoginResult.Success) { Console.WriteLine("Connecting to Minecraft.net..."); result = ProtocolHandler.GetLogin(Settings.Login, Settings.Password, out session); if (result == ProtocolHandler.LoginResult.Success && Settings.SessionCaching != CacheType.None) { SessionCache.Store(Settings.Login.ToLower(), session); } } } if (result == ProtocolHandler.LoginResult.Success) { Settings.Username = "******"; if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } if (Settings.playerHeadAsIcon) { ConsoleIcon.setPlayerIconAsync(Settings.Username); } if (Settings.DebugMessages) { Console.WriteLine("Success. (session ID: " + session.ID + ')'); } //ProtocolHandler.RealmsListWorlds(Settings.Username, PlayerID, sessionID); //TODO REMOVE if (Settings.ServerIP == "") { Console.Write("Server IP : "); Settings.SetServerIP(Console.ReadLine()); } //Get server version int protocolversion = 0; ForgeInfo forgeInfo = null; //if (Settings.ServerVersion != "" && Settings.ServerVersion.ToLower() != "auto") if (true) { //protocolversion = Protocol.ProtocolHandler.MCVer2ProtocolVersion(Settings.ServerVersion); protocolversion = Protocol.ProtocolHandler.MCVer2ProtocolVersion("1.8"); if (protocolversion != 0) { ConsoleIO.WriteLineFormatted("§8Usando a versão " + Settings.ServerVersion + " (protocolo v" + protocolversion + ')'); } else { ConsoleIO.WriteLineFormatted("§8A versão '" + Settings.ServerVersion + "' é desconhecida ou não suportada :/\nDetectando versão compativel automaticamente!"); } if (useMcVersionOnce) { useMcVersionOnce = false; Settings.ServerVersion = ""; } } if (protocolversion == 0) { //Console.WriteLine("Obtendo informações do servidor..."); if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion, ref forgeInfo)) { //HandleFailure("Falha ao conectar :/", true, ChatBots.AutoRelog.DisconnectReason.ConnectionLost); return; } } if (protocolversion != 0) { try { //Start the main TCP client if (Settings.SingleCommand != "") { Client = new McTcpClient(session.PlayerName, session.PlayerID, session.ID, Settings.ServerIP, Settings.ServerPort, protocolversion, forgeInfo, Settings.SingleCommand); } else { Client = new McTcpClient(session.PlayerName, session.PlayerID, session.ID, protocolversion, forgeInfo, Settings.ServerIP, Settings.ServerPort); } //Update console title if (Settings.ConsoleTitle != "") { Console.Title = Settings.ExpandVars(Settings.ConsoleTitle); } } catch (NotSupportedException) { HandleFailure("Não foi possivel conectar-se ao servidor : Versão nao suportada !", true); } } else { HandleFailure("Falha ao determinar a versão do servidor.", true); } } else { string failureMessage = "Minecraft Login failed : "; switch (result) { case ProtocolHandler.LoginResult.AccountMigrated: failureMessage += "Account migrated, use e-mail as username."; break; case ProtocolHandler.LoginResult.ServiceUnavailable: failureMessage += "Login servers are unavailable. Please try again later."; break; case ProtocolHandler.LoginResult.WrongPassword: failureMessage += "Incorrect password, blacklisted IP or too many logins."; break; case ProtocolHandler.LoginResult.InvalidResponse: failureMessage += "Invalid server response."; break; case ProtocolHandler.LoginResult.NotPremium: failureMessage += "User not premium."; break; case ProtocolHandler.LoginResult.OtherError: failureMessage += "Network error."; break; case ProtocolHandler.LoginResult.SSLError: failureMessage += "SSL Error."; break; default: failureMessage += "Unknown Error."; break; } if (result == ProtocolHandler.LoginResult.SSLError && isUsingMono) { ConsoleIO.WriteLineFormatted("§8It appears that you are using Mono to run this program." + '\n' + "The first time, you have to import HTTPS certificates using:" + '\n' + "mozroots --import --ask-remove"); return; } HandleFailure(failureMessage, false, ChatBot.DisconnectReason.LoginRejected); } }
/// <summary> /// Handle fatal errors such as ping failure, login failure, server disconnection, and so on. /// Allows AutoRelog to perform on fatal errors, prompt for server version, and offline commands. /// </summary> /// <param name="errorMessage">Error message to display and optionally pass to AutoRelog bot</param> /// <param name="versionError">Specify if the error is related to an incompatible or unkown server version</param> /// <param name="disconnectReason">If set, the error message will be processed by the AutoRelog bot</param> public static void HandleFailure(string errorMessage = null, bool versionError = false, ChatBots.AutoRelog.DisconnectReason?disconnectReason = null) { if (!String.IsNullOrEmpty(errorMessage)) { ConsoleIO.Reset(); while (Console.KeyAvailable) { Console.ReadKey(true); } Console.WriteLine(errorMessage); if (disconnectReason.HasValue) { if (ChatBots.AutoRelog.OnDisconnectStatic(disconnectReason.Value, errorMessage)) { return; //AutoRelog is triggering a restart of the client } } } if (Settings.interactiveMode) { if (versionError) { Console.Write("Server version : "); Settings.ServerVersion = Console.ReadLine(); if (Settings.ServerVersion != "") { useMcVersionOnce = true; Restart(); return; } } if (offlinePrompt == null) { offlinePrompt = new Thread(new ThreadStart(delegate { string command = " "; ConsoleIO.WriteLineFormatted("Not connected to any server. Use '" + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + "help' for help."); ConsoleIO.WriteLineFormatted("Or press Enter to exit Minecraft Console Client."); while (command.Length > 0) { if (!ConsoleIO.basicIO) { ConsoleIO.Write('>'); } command = Console.ReadLine().Trim(); if (command.Length > 0) { 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); } } } })); offlinePrompt.Start(); } } else { Exit(); } }
/// <summary> /// Translate the key and write a Minecraft-Like formatted string to the standard output, using §c color codes /// See minecraft.gamepedia.com/Classic_server_protocol#Color_Codes for more info /// </summary> /// <param name="key">Translation key</param> /// <param name="acceptnewlines">If false, space are printed instead of newlines</param> /// <param name="displayTimestamp"> /// If false, no timestamp is prepended. /// If true, "hh-mm-ss" timestamp will be prepended. /// If unspecified, value is retrieved from EnableTimestamps. /// </param> public static void WriteLineFormatted(string key, bool acceptnewlines = true, bool?displayTimestamp = null) { ConsoleIO.WriteLineFormatted(Get(key), acceptnewlines, displayTimestamp); }