//Will be automatically set on bot loading, don't worry about this
 public void SetHandler(McTcpClient handler) { this.handler = handler; }
 /// <summary>
 /// Perform the command
 /// </summary>
 /// <param name="command">The full command, eg: 'mycommand arg1 arg2'</param>
 /// <param name="localVars">Local variables passed along with the command (may be null)</param>
 /// <returns>A confirmation/error message, or "" if no message</returns>
 public abstract string Run(McTcpClient handler, string command, Dictionary <string, object> localVars);
Beispiel #3
0
 //Handler will be automatically set on bot loading, don't worry about this
 public void SetHandler(McTcpClient handler)
 {
     this._handler = handler;
 }
        /// <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>
        /// 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);
            }
        }
Beispiel #6
0
        /// <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);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Perform the command
        /// </summary>
        /// <param name="command">The full command, eg: 'mycommand arg1 arg2'</param>
        /// <returns>A confirmation/error message, or "" if no message</returns>

        public abstract string Run(McTcpClient handler, string command);
        /// <summary>
        /// Start a new Client
        /// </summary>
        private static void InitializeClient()
        {
            MinecraftCom.LoginResult result;
            string logindata = "";

            if (Settings.Password == "-")
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine("You chose to run in offline mode.");
                Console.ForegroundColor = ConsoleColor.Gray;
                result = MinecraftCom.LoginResult.Success;
                logindata = "0:deprecated:" + Settings.Login + ":0";
            }
            else
            {
                Console.WriteLine("Connecting to Minecraft.net...");
                result = MinecraftCom.GetLogin(Settings.Login, Settings.Password, ref logindata);
            }
            if (result == MinecraftCom.LoginResult.Success)
            {
                Settings.Username = logindata.Split(':')[2];
                string sessionID = logindata.Split(':')[3];
                Console.WriteLine("Success. (session ID: " + sessionID + ')');
                if (Settings.ServerIP == "")
                {
                    Console.Write("Server IP : ");
                    Settings.ServerIP = Console.ReadLine();
                }

                //Get server version
                Console.WriteLine("Retrieving Server Info...");
                byte protocolversion = 0; string version = "";
                if (MinecraftCom.GetServerInfo(Settings.ServerIP, ref protocolversion, ref version))
                {
                    //Supported protocol version ?
                    int[] supportedVersions = { 51, 60, 61, 72, 73, 74 };
                    if (Array.IndexOf(supportedVersions, protocolversion) > -1)
                    {
                        //Minecraft 1.6+ ? Load translations
                        if (protocolversion >= 72) { ChatParser.InitTranslations(); }

                        //Will handle the connection for this client
                        Console.WriteLine("Version is supported.");
                        MinecraftCom handler = new MinecraftCom();
                        ConsoleIO.SetAutoCompleteEngine(handler);
                        handler.setVersion(protocolversion);

                        //Load & initialize bots if needed
                        if (Settings.AntiAFK_Enabled)   { handler.BotLoad(new Bots.AntiAFK(Settings.AntiAFK_Delay)); }
                        if (Settings.Hangman_Enabled)   { handler.BotLoad(new Bots.Pendu(Settings.Hangman_English)); }
                        if (Settings.Alerts_Enabled)    { handler.BotLoad(new Bots.Alerts()); }
                        if (Settings.ChatLog_Enabled)   { handler.BotLoad(new Bots.ChatLog(Settings.ChatLog_File, Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); }
                        if (Settings.PlayerLog_Enabled) { handler.BotLoad(new Bots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.PlayerLog_File)); }
                        if (Settings.AutoRelog_Enabled) { handler.BotLoad(new Bots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
                        if (Settings.xAuth_Enabled)     { handler.BotLoad(new Bots.xAuth(Settings.xAuth_Password)); }
                        if (Settings.Scripting_Enabled) { handler.BotLoad(new Bots.Scripting(Settings.Scripting_ScriptFile)); }

                        //Start the main TCP client
                        if (Settings.SingleCommand != "")
                        {
                            Client = new McTcpClient(Settings.Username, sessionID, Settings.ServerIP, handler, Settings.SingleCommand);
                        }
                        else Client = new McTcpClient(Settings.Username, sessionID, Settings.ServerIP, handler);
                    }
                    else
                    {
                        Console.WriteLine("Cannot connect to the server : This version is not supported !");
                        ReadLineReconnect();
                    }
                }
                else
                {
                    Console.WriteLine("Failed to ping this IP.");
                    ReadLineReconnect();
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write("Connection failed : ");
                switch (result)
                {
                    case MinecraftCom.LoginResult.AccountMigrated: Console.WriteLine("Account migrated, use e-mail as username."); break;
                    case MinecraftCom.LoginResult.Blocked: Console.WriteLine("Too many failed logins. Please try again later."); break;
                    case MinecraftCom.LoginResult.BadRequest: Console.WriteLine("Login attempt rejected: Bad request."); break;
                    case MinecraftCom.LoginResult.WrongPassword: Console.WriteLine("Incorrect password."); break;
                    case MinecraftCom.LoginResult.NotPremium: Console.WriteLine("User not premium."); break;
                    case MinecraftCom.LoginResult.Error: Console.WriteLine("Network error."); break;
                }
                while (Console.KeyAvailable) { Console.ReadKey(false); }
                if (Settings.SingleCommand == "") { ReadLineReconnect(); }
            }
        }
        /// <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>
        /// Start a new Client
        /// </summary>
        private static void InitializeClient()
        {
            MinecraftLoginResult result = MinecraftLoginResult.OtherError;
            Settings.Username = Settings.Login;
            string sessionID = "";
            string UUID = "";

            if (Settings.Password == "-")
            {
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Console.WriteLine("You chose to run in offline mode.");
                Console.ForegroundColor = ConsoleColor.Gray;
                result = MinecraftLoginResult.Success;
                sessionID = "0";
            }
            else
            {
                Console.WriteLine("Connecting to Minecraft.net...");
                try
                {
                    result = MinecraftCom.GetLogin(ref Settings.Username, Settings.Password, ref sessionID, ref UUID);
                } catch(MinecraftAuthException ex) {
                    DisplayError (ex);
                }
            }
            if (result == MinecraftLoginResult.Success)
            {
                if (Settings.ConsoleTitle != "")
                {
                    Console.Title = Settings.ConsoleTitle.Replace("%username%", Settings.Username);
                }

                Console.WriteLine("Success. (session ID: " + sessionID + ')');
                if (Settings.ServerIP == "")
                {
                    Console.Write("Server IP : ");
                    Settings.ServerIP = Console.ReadLine();
                }

                //Get server version
                Console.WriteLine("Retrieving Server Info...");
                int protocolversion = 0; string version = "";
                if (MinecraftCom.GetServerInfo(Settings.ServerIP, ref protocolversion, ref version))
                {
                    //Supported protocol version ?
                    int[] supportedVersions = { 4, 5 };
                    if (Array.IndexOf(supportedVersions, protocolversion) > -1)
                    {
                        //Load translations (Minecraft 1.6+)
                        ChatParser.InitTranslations();

                        //Will handle the connection for this client
                        Console.WriteLine("Version is supported.");
                        MinecraftCom handler = new MinecraftCom();
                        ConsoleIO.SetAutoCompleteEngine(handler);
                        handler.setVersion(protocolversion);

                        //Load & initialize bots if needed
                        if (Settings.AntiAFK_Enabled)         { handler.BotLoad(new Bots.AntiAFK(Settings.AntiAFK_Delay)); }
                        if (Settings.Hangman_Enabled)         { handler.BotLoad(new Bots.Pendu(Settings.Hangman_English)); }
                        if (Settings.Alerts_Enabled)          { handler.BotLoad(new Bots.Alerts()); }
                        if (Settings.ChatLog_Enabled)         { handler.BotLoad(new Bots.ChatLog(Settings.ChatLog_File.Replace("%username%", Settings.Username), Settings.ChatLog_Filter, Settings.ChatLog_DateTime)); }
                        if (Settings.PlayerLog_Enabled)       { handler.BotLoad(new Bots.PlayerListLogger(Settings.PlayerLog_Delay, Settings.PlayerLog_File.Replace("%username%", Settings.Username))); }
                        if (Settings.AutoRelog_Enabled)       { handler.BotLoad(new Bots.AutoRelog(Settings.AutoRelog_Delay, Settings.AutoRelog_Retries)); }
                        if (Settings.ScriptScheduler_Enabled) { handler.BotLoad(new Bots.ScriptScheduler(Settings.ScriptScheduler_TasksFile.Replace("%username%", Settings.Username))); }
                        if (Settings.RemoteCtrl_Enabled)      { handler.BotLoad(new Bots.RemoteControl()); }

                        //Start the main TCP client
                        if (Settings.SingleCommand != "")
                        {
                            Client = new McTcpClient(Settings.Username, UUID, sessionID, Settings.ServerIP, handler, Settings.SingleCommand);
                        }
                        else Client = new McTcpClient(Settings.Username, UUID, sessionID, Settings.ServerIP, handler);
                    }
                    else
                    {
                        Console.WriteLine("Cannot connect to the server : This version is not supported !");
                        ReadLineReconnect();
                    }
                }
                else
                {
                    Console.WriteLine("Failed to ping this IP.");
                    ReadLineReconnect();
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                Console.Write("Connection failed : ");
                switch (result)
                {
                    case MinecraftLoginResult.AccountMigrated: Console.WriteLine("Account migrated, use e-mail as username."); break;
                    case MinecraftLoginResult.Blocked: Console.WriteLine("Too many failed logins. Please try again later."); break;
                    case MinecraftLoginResult.ServiceUnavailable: Console.WriteLine("Login servers are unavailable. Please try again later."); break;
                    case MinecraftLoginResult.WrongPassword: Console.WriteLine("Incorrect password."); break;
                    case MinecraftLoginResult.NotPremium: Console.WriteLine("User not premium."); break;
                    case MinecraftLoginResult.OtherError: Console.WriteLine("Network error."); break;
                    case MinecraftLoginResult.SSLError: Console.WriteLine("SSL Error.");
                        if (isUsingMono)
                        {
                            Console.ForegroundColor = ConsoleColor.DarkGray;
                            Console.WriteLine("It 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");
                            Console.ForegroundColor = ConsoleColor.Gray;
                            return;
                        }
                        break;
                }
                while (Console.KeyAvailable) { Console.ReadKey(false); }
                if (Settings.SingleCommand == "") { ReadLineReconnect(); }
            }
        }
Beispiel #11
0
        /// <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, how strange.");
                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("§8Session expired. Maybe log in again?");
                        if (Settings.Password == "")
                            RequestPassword();
                    }
                    else ConsoleIO.WriteLineFormatted("§8This user is still logged into the app: " + session.PlayerName + '.');
                }

                if (result != ProtocolHandler.LoginResult.Success)
                {
                    Console.WriteLine("Automagically getting minecrafty magics... (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. Keep this session ID safe from the internet! No screencaps of it! (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("Fetchin' server profile...");
                    if (!ProtocolHandler.GetServerInfo(Settings.ServerIP, Settings.ServerPort, ref protocolversion, ref forgeInfo))
                    {
                        HandleFailure("ZORK! Failed to plug this IP! Its derpy!", 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("ZORK! This minecraft server ve", true); }
                }
                else HandleFailure("ZORK! I coulden't tell what version this server was!", true);
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Gray;
                string failureMessage = "ZORK! Log in failed! : ";
                switch (result)
                {
                    case ProtocolHandler.LoginResult.AccountMigrated: failureMessage += "You migrated to mojang! Use your e-mail instead of your username!"; break;
                    case ProtocolHandler.LoginResult.ServiceUnavailable: failureMessage += "Apparently, Moajng's ninjas took their job too seriously. Login servers offline"; break;
                    case ProtocolHandler.LoginResult.WrongPassword: failureMessage += "Incorrect password."; break;
                    case ProtocolHandler.LoginResult.NotPremium: failureMessage += "User not premium. You had the trial! Maybe buy minecraft, is a totally kewl game!"; break;
                    case ProtocolHandler.LoginResult.OtherError: failureMessage += "Your internet let me down. Networking error."; break;
                    case ProtocolHandler.LoginResult.SSLError: failureMessage += "SSL Error."; break;
                    default: failureMessage += "Well, gee bobby. I just can't figure out whats not working right."; break;
                }
                if (result == ProtocolHandler.LoginResult.SSLError && isUsingMono)
                {
                    ConsoleIO.WriteLineFormatted("§8Oh, so I see your using Mono to run this app!."
                        + '\n' + "The first time, you have to import HTTPS certificates using:"
                        + '\n' + "mozroots --import --ask-remove");
                    return;
                }
                HandleFailure(failureMessage, false, ChatBot.DisconnectReason.LoginRejected);
            }
        }
        /// <summary>
        /// Perform the command
        /// </summary>
        /// <param name="command">The full command, eg: 'mycommand arg1 arg2'</param>
        /// <returns>A confirmation/error message, or "" if no message</returns>

        public abstract string Run(McTcpClient handler, string command);