Example #1
0
        internal void newTask(int cooldown = 0)
        {
            MinecraftBot connection;

            try
            {
                while (TaskWorking)
                {
                    if (Bots.Count < threads)
                    {
                        if (proxyip.Count <= 0)
                        {
                            ConsoleIO.AddMsgSeq("正在获取代理...", "Proxy");
                            HttpReq.getips_(proxyip);
                        }
                        connection          = new MinecraftBot(Info.ServerIP, Info.ServerPort, username, protocol, Info.ForgeInfo, this);
                        connection.Chatlist = Chat;
                        connection.AddPlayer();

                        Thread.Sleep(cooldown);
                    }
                    else
                    {
                        Clear();
                    }
                }
            }
            catch (Exception e)
            {
                ConsoleIO.AddMsgSeq(e.Message, "Error");
            }
        }
Example #2
0
 public void OnConnectionLost(BotUtils.DisconnectReason type, string msg)
 {
     if (type == BotUtils.DisconnectReason.InGameKick)
     {
         ConsoleIO.AddMsgSeq(string.Format("{0}连接丢失:{1}", playername, Helper.ParseMsg(msg)), "Connection");
         if (Setting.t_rejoin > 0)
         {
             ReJoin();
         }
         else
         {
             Dispose();
         }
     }
     else if (type == BotUtils.DisconnectReason.LoginRejected)
     {
         ConsoleIO.AddMsgSeq(string.Format("{0}拒绝连接:{1}", playername, Helper.ParseMsg(msg)), "Connection");
         if (Setting.t_rejoin > 0)
         {
             ReJoin();
         }
         else
         {
             Dispose();
         }
     }
     else if (type == BotUtils.DisconnectReason.ConnectionLost)
     {
         Dispose();
     }
 }
Example #3
0
 internal void AddPlayer()
 {
     mainThread = new Thread(new ThreadStart(() =>
     {
         try
         {
             bots.Bots.Add(this);
             if (Setting.sendmotd)
             {
                 Tcp = getProxyClient();
                 SendMotd(Tcp);
                 Thread.Sleep(300);
             }
             Tcp = getProxyClient();
             Tcp.ReceiveTimeout = 10000;
             Tcp.SendTimeout    = 10000;
             client             = new MinecraftProtocol(Tcp, ProtocolVersion, this, forgeInfo);
             if (client.Login(Host, Port, playername))
             {
                 if (Setting.t_tabcomplete > 0)
                 {
                     TabComplete();
                 }
                 ConsoleIO.AddMsgSeq(playername + " Join the game", "Player");
                 client.StartUpdating(false);
             }
         }
         catch
         {
             Dispose();
         }
     }));
     mainThread.Start();
 }
        public bool Login(string host, int port, string username)
        {
            byte[] protocol_version  = getVarInt(protocolversion);
            byte[] server_adress_val = Encoding.UTF8.GetBytes(host + (forgeInfo != null ? "\0FML\0" : ""));
            byte[] server_adress_len = getVarInt(server_adress_val.Length);
            byte[] server_port       = BitConverter.GetBytes((ushort)port); Array.Reverse(server_port);
            byte[] next_state        = getVarInt(2);
            byte[] handshake_packet  = concatBytes(protocol_version, server_adress_len, server_adress_val, server_port, next_state);

            SendPacket(0x00, handshake_packet);
            byte[] username_val = Encoding.UTF8.GetBytes(username);
            byte[] username_len = getVarInt(username_val.Length);
            byte[] login_packet = concatBytes(username_len, username_val);
            SendPacket(0x00, login_packet);
            int         packetID   = -1;
            List <byte> packetData = new List <byte>();

            while (true)
            {
                readNextPacket(ref packetID, packetData);
                if (packetID == 0x00) //Login rejected
                {
                    handler.OnConnectionLost(BotUtils.DisconnectReason.LoginRejected, readNextString(packetData));
                    return(false);
                }
                else if (packetID == 0x01) //Encryption request
                {
                    ConsoleIO.AddMsgSeq(username + "This Server is in online mode.", "Connection");
                    return(false);
                }
                else if (packetID == 0x02) //Login successful
                {
                    login_phase = false;
                    if (forgeInfo != null)
                    {
                        // Do the forge handshake.
                        if (!CompleteForgeHandshake())
                        {
                            return(false);
                        }
                    }

                    //StartUpdating();
                    return(true); //No need to check session or start encryption
                }
                else
                {
                    handlePacket(packetID, packetData);
                }
            }
        }
Example #5
0
        private void Clear()
        {
            Thread.Sleep(Setting.t_clear);
            int l     = 0;
            int clear = 0;

            for (; l < Bots.Count; l++)
            {
                TimeSpan ts = DateTime.Now.Subtract(Bots[l].alivetime);
                if (ts.Seconds > 15)
                {
                    Bots[l].Dispose();
                    clear++;
                }
            }
            ConsoleIO.AddMsgSeq("清理线程数目:" + clear, "Thread");
            ConsoleIO.AddMsgSeq("当前运行线程:" + Bots.Count, "Thread");
            ConsoleIO.AddMsgSeq("代理数量:" + proxyip.Count, "Thread");
            GC.Collect();
        }
        private bool CompleteForgeHandshake()
        {
            int         packetID   = -1;
            List <byte> packetData = new List <byte>();

            while (fmlHandshakeState != FMLHandshakeClientState.DONE)
            {
                readNextPacket(ref packetID, packetData);

                if (packetID == 0x40) // Disconnect
                {
                    ConsoleIO.AddMsgSeq("[FML] Connection Lost.");
                    return(false);
                }
                else
                {
                    handlePacket(packetID, packetData);
                }
            }

            return(true);
        }
Example #7
0
 public void OnGameJoin()
 {
     ConsoleIO.AddMsgSeq(playername + " Join the game", "Player");
     if (Setting.sendsetting)
     {
         client.SendClientSettings("en_US", 9, 0, 0, false, 65, 0);
     }
     alivetime = DateTime.Now;
     chatMsg   = new Thread(new ThreadStart(() =>
     {
         while (Tcp != null && Tcp.Connected)
         {
             for (int l = 0; l < Chatlist.Count; l++)
             {
                 Thread.Sleep(2000);
                 client.SendChatMessage(Chatlist[l].ToString());
             }
         }
     }));
     chatMsg.IsBackground = true;
     chatMsg.Start();
 }
        public static void getips_(List <string> list)//89ipAPI Get
        {
            string          api = Setting.proxy_url;
            HttpWebResponse wr  = null;
            HttpWebRequest  req = (HttpWebRequest)HttpWebRequest.Create(api);

            try
            {
                req.UserAgent       = "Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0";
                req.CookieContainer = GetCookiesByHeader(Setting.proxy_cookie, ".89ip.cn");
                req.Method          = "GET";
                wr = (HttpWebResponse)req.GetResponse();
                StreamReader    stream = new StreamReader(wr.GetResponseStream());
                MatchCollection match  = Regex.Matches(stream.ReadToEnd(), Setting.proxy_regex);
                foreach (Match ip in match)
                {
                    list.Add(ip.Value);
                }
                ConsoleIO.AddMsgSeq("#2_Get Success:" + match.Count, "Proxy");
            }
            catch (WebException e)
            {
                wr = (HttpWebResponse)e.Response;
                if (Convert.ToInt32(wr.StatusCode) == 521)
                {
                    ConsoleIO.AddMsgSeq("#2_SetCookie\r\n" + e.Message, "Proxy");
                    if (wr.Headers["Set-Cookie"] != null)
                    {
                        Setting.proxy_cookie = wr.Headers["Set-Cookie"];
                    }
                    Setting.IniWriteValue("Proxy", "cookie", Setting.proxy_cookie);
                }
                getips__(list);
            }catch (Exception e)
            {
                ConsoleIO.AddMsgSeq("#2_Failed\r\n" + e.Message, "Proxy");
            }
        }
Example #9
0
        internal void newTask(int cooldown = 0)
        {
            MinecraftBot client;
            Thread       socksThread = new Thread(getProxys);

            socksThread.Start();
            new Thread(new ThreadStart(Clear)).Start();
            new Thread(new ThreadStart(() =>
            {
                try
                {
                    while (TaskWorking)
                    {
                        while (Bots.Count < threads)
                        {
                            if (socks_pool.Count > 0)
                            {
                                client = new MinecraftBot(socks_pool[0], Info.ServerIP, Info.ServerPort, protocol, Info.ForgeInfo, this);
                                Bots.Add(client);
                                client.Chatlist = Chat;
                                client.AddPlayer(username);
                                socks_pool.RemoveAt(0);
                                Thread.Sleep(cooldown);
                            }
                            else
                            {
                                Thread.Sleep(1000);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    ConsoleIO.AddMsgSeq(e.Message, "Error");
                }
            })).Start();
        }