public MinecraftProtocol(TcpClient tcp, int protocolver, IMinecraftCom Handler, ForgeInfo forge)
 {
     client          = tcp;
     protocolversion = protocolver;
     forgeInfo       = forge;
     handler         = Handler;
 }
        private void StartClient(string user, string uuid, string sessionID, int protocolversion, string server_ip, ushort port, ForgeInfo forgeInfo)
        {
            this.sessionid = sessionID;
            this.host      = server_ip;
            this.port      = port;
            player         = new Player(world, user, uuid);

            try
            {
                packetClient = new PacketClient();
                if (!packetClient.Connect(new ServerConnectionInfo(server_ip, port), player, protocolversion, forgeInfo, this))
                {
                    return;
                }

                handler = packetClient.communicationHandler;
                player.SetHandler(handler);

                Console.WriteLine("Server was successfully joined.\nType '" + Settings.internalCmdChar + "quit' to leave the server.");
            }
            catch (SocketException e)
            {
                ConsoleIO.WriteLineFormatted("§8" + e.Message);
                Console.WriteLine("Failed to connect to this IP.");
            }
        }
예제 #3
0
        public bool Connect(ServerConnectionInfo serverInfo, Player player, int protocolVersion, ForgeInfo forgeInfo, IMinecraftComHandler minecraftComHandler)
        {
            client = ProxyHandler.startNewTcpClient(serverInfo.ServerIP, serverInfo.ServerPort);
            //client.Connect(serverInfo.ServerIP, serverInfo.ServerPort);
            client.ReceiveBufferSize = 1024 * 1024;

            communicationHandler = ProtocolHandler.GetProtocolHandler(client, protocolVersion, forgeInfo, minecraftComHandler, player);

            return(login());
            //send login packets
        }
예제 #4
0
 public void SetHandler(IMinecraftCom handler)
 {
     this.handler = handler;
 }
예제 #5
0
        /// <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();
                }
            }
        }
예제 #6
0
        /// <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();
                }
            }
        }
        /// <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(); }
            }
        }