コード例 #1
0
        /// <summary>
        /// Pause the program, usually when an error or a kick occured, letting the user press Enter to quit OR type /reconnect
        /// </summary>

        public static void OfflineCommandPrompt()
        {
            if (!Settings.exitOnFailure && 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)
                        {
                            if (Settings.internalCmdChar != ' ' && command[0] == Settings.internalCmdChar)
                            {
                                string message = "";
                                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);
                                }
                            }
                            else
                            {
                                ConsoleIO.WriteLineFormatted("§8Please type a command or press Enter to exit.");
                            }
                        }
                    }
                }));
                offlinePrompt.Start();
            }
        }
コード例 #2
0
        /// <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();
            }
        }
コード例 #3
0
        /// <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();
            }
        }
コード例 #4
0
 /// <summary>
 /// Pause the program, usually when an error or a kick occured, letting the user press Enter to quit OR type /reconnect
 /// </summary>
 public static void OfflineCommandPrompt()
 {
     if (!Settings.exitOnFailure && 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)
                 {
                     if (Settings.internalCmdChar != ' ' && command[0] == Settings.internalCmdChar)
                     {
                         string message = "";
                         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); }
                     }
                     else ConsoleIO.WriteLineFormatted("§8Please type a command or press Enter to exit.");
                 }
             }
         }));
         offlinePrompt.Start();
     }
 }
コード例 #5
0
ファイル: Program.cs プロジェクト: savioacp/HtBot
        /// <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;
            }
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: gdianaty/MinechatPC
        /// <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("ZORK! Not connected to a server. Use '" + (Settings.internalCmdChar == ' ' ? "" : "" + Settings.internalCmdChar) + "help' for help.");
                        ConsoleIO.WriteLineFormatted("Or press Enter to exit, but i'll miss u.");
                        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("§8ZORK! Unknown command '" + command.Split(' ')[0] + "'.");

                                if (message != "")
                                    ConsoleIO.WriteLineFormatted("§8MCC: " + message);
                            }
                        }
                    }));
                    offlinePrompt.Start();
                }
            }
        }