PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.96k stars 904 forks source link

Try to make proxy connection on mineflayer, but it doesn't work #2018

Closed CrazyWords1 closed 3 years ago

CrazyWords1 commented 3 years ago

Detailed description of a problem

My stupid brain bug, i don't understand how i can do this

What did you try yet?

I try to add proxy support like in FAQ

Your current code

const snekfetch = require("snekfetch")
const config = require("./config.json")
const mc = require('minecraft-protocol');
const SocksClient = require('socks').SocksClient;
let number = 100
setInterval(() => {
number = number + 1
var mineflayer = require('mineflayer');
var bot = mineflayer.createBot({
    connect: (client) => {
        SocksClient.createConnection({
          proxy: {
            host: '194.85.124.150',
            port: 4153,
            type: 4,
            userId: config.crackedusernameprefix + number.toString(),
          },
          command: 'connect',
          destination: {
            host: '135.181.20.179',
            port: 25565
          }
        }, (err, info) => {
          if (err) {
            console.log(err)
            return
          }
          client.setSocket(info.socket)
          client.emit('connect')
        })
      },
    port: config.port,
    username: config.crackedusernameprefix + number.toString(),
    version: config.version,
    plugins: {
        conversions: false,
        furnace: false,
        math: false,
        painting: false,
        scoreboard: false,
        villager: false,
        bed: false,
        book: false,
        boss_bar: false,
        chest: false,
        command_block: false,
        craft: false,
        digging: false,
        dispenser: false,
        enchantment_table: false,
        experience: false,
        rain: false,
        ray_trace: false,
        sound: false,
        tablist: false,
        time: false,
        title: false,
        physics: config.physics,
        blocks: true
    }
});
bot.on('login', () => {
    bot.chat("/login p@ssword123")
    bot.chat("/register p@ssword123 p@ssword123")
    setInterval(() => {
        // bot.chat(config.spammessage)
    }, config.spamintervalms)
    console.log("Logged in " + bot.username)
});
bot.on('error', err => console.log(err))
bot.on('kicked', function(reason) {
    console.log("I got kicked for", reason, "lol");
});
}, config.loginintervalms)

What i do wrong?

u9g commented 3 years ago

why did you disable all the plugins?

CrazyWords1 commented 3 years ago

why did you disable all the plugins?

Because i need very hard spam bot for testing my server load UPD: I'm edit my issue, add all code

u9g commented 3 years ago

is there an error?

CrazyWords1 commented 3 years ago

SocksClientError: read ECONNRESET at SocksClient.closeSocket (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:387:32) at SocksClient.onErrorHandler (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:360:14) at Socket.onError (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:222:38) at Object.onceWrapper (events.js:482:26) at Socket.emit (events.js:375:28) at emitErrorNT (internal/streams/destroy.js:106:8) at emitErrorCloseNT (internal/streams/destroy.js:74:3) at processTicksAndRejections (internal/process/task_queues.js:82:21) { options: { proxy: { host: '194.85.124.150', port: 4153, type: 4, userId: 'lopi120' }, command: 'connect', destination: { host: '135.181.20.179', port: 25565 } } }

CrazyWords1 commented 3 years ago

Not connected to proxy, not socks4 not socks5

CrazyWords1 commented 3 years ago

SocksClientError: Socks4 Proxy rejected connection - (Failed)

u9g commented 3 years ago

do any accounts login? I see two possible problems:

  1. proxy doesn't work
  2. you are logging accounts in too quickly
CrazyWords1 commented 3 years ago

do any accounts login? I see two possible problems:

1. proxy doesn't work

2. you are logging accounts in too quickly

Accounts offline I took a lot of proxies from different sites I login in 10 sec in accounts.

maybe u can test my code? Please :)

IceTank commented 3 years ago

SocksClientError: read ECONNRESET at SocksClient.closeSocket (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:387:32) at SocksClient.onErrorHandler (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:360:14) at Socket.onError (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:222:38) at Object.onceWrapper (events.js:482:26) at Socket.emit (events.js:375:28) at emitErrorNT (internal/streams/destroy.js:106:8) at emitErrorCloseNT (internal/streams/destroy.js:74:3) at processTicksAndRejections (internal/process/task_queues.js:82:21) { options: { proxy: { host: '194.85.124.150', port: 4153, type: 4, userId: 'lopi120' }, command: 'connect', destination: { host: '135.181.20.179', port: 25565 } } }

That error most likely means that the proxy is not working

CrazyWords1 commented 3 years ago

SocksClientError: Socks4 Proxy rejected connection - (Failed) at SocksClient.closeSocket (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:387:32) at SocksClient.handleSocks4FinalHandshakeResponse (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:424:18) at SocksClient.processData (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:318:26) at SocksClient.onDataReceivedHandler (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:304:14) at Socket.onDataReceived (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:220:46) at Socket.emit (events.js:375:28) at addChunk (internal/streams/readable.js:290:12) at readableAddChunk (internal/streams/readable.js:265:9) at Socket.Readable.push (internal/streams/readable.js:204:10) at TCP.onStreamRead (internal/stream_base_commons.js:188:23) { options: { proxy: { host: '109.70.189.51', port: 3629, type: 4 }, command: 'connect', destination: { host: '135.181.20.179', port: 25565 } } }

CrazyWords1 commented 3 years ago

Now i have this error

CrazyWords1 commented 3 years ago

I check all example for proxy client connect, and i have a this error

Proxy ok ip: 192.111.137.37
Proxy Connection closed
SocksClientError: Proxy connection timed out
    at SocksClient.closeSocket (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:387:32)
    at SocksClient.onEstablishedTimeout (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:276:18)
    at Timeout._onTimeout (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:225:45)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  options: {
    proxy: { host: '192.111.137.37', port: 18762, type: 5 },
    command: 'connect',
    destination: { host: 'emeraldix.net', port: 25565 }
  }
}
SocksClientError: Proxy connection timed out
    at SocksClient.closeSocket (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:387:32)
    at SocksClient.onEstablishedTimeout (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:276:18)
    at Timeout._onTimeout (C:\Users\CrazyWords\Desktop\node_modules\socks\build\client\socksclient.js:225:45)
    at listOnTimeout (internal/timers.js:557:17)
    at processTimers (internal/timers.js:500:7) {
  options: {
    proxy: { host: '192.111.137.37', port: 18762, type: 5 },
    command: 'connect',
    destination: { host: 'emeraldix.net', port: 25565 }
  }
}

and if i using ip instead of domain i have this:

Socks5 proxy rejected connection - ConnectionRefused

CrazyWords1 commented 3 years ago

@u9g I bought private proxy, and i get Socks5 proxy rejected connection - ConnectionRefused

u9g commented 3 years ago

Okay, I took a bit to do some research and found in the faq an example for the socks5 proxy, https://github.com/PrismarineJS/mineflayer/blob/master/docs/FAQ.md#how-can-i-use-a-socks5-proxy , I suggest you compare it to your own code, and see that the problem is that you are putting a minecraft username where you should be putting the proxy username, and you should be adding the proxy password there too

Aroxis commented 3 years ago

I based myself of the given example but that didn't work. Upon adding host and port in the root of the options object I managed to get it working ...

bot = mineflayer.createBot({
                           connect: client => {
                                socks.createConnection({
                                    proxy : mcProxy,
                                    command: 'connect',
                                    destination: {
                                        host: currentOperation.serverAddress,
                                        port: parseInt(currentOperation.serverPort)
                                    }
                                }, (err, info) => {
                                    if (err) {
                                        console.log(err)
                                        return
                                    }
                                    client.setSocket(info.socket)
                                    client.emit('connect')
                                })
                            },
                            username: account.username,
                            password: account.password,
                            host: currentOperation.serverAddress, // Without these a Not Permitted error would be thrown
                            port: parseInt(currentOperation.serverPort), // 
                            agent: agent
                        });
Aroxis commented 3 years ago

I based myself of the given example but that didn't work. Upon adding host and port in the root of the options object I managed to get it working ...

bot = mineflayer.createBot({
                           connect: client => {
                                socks.createConnection({
                                    proxy : mcProxy,
                                    command: 'connect',
                                    destination: {
                                        host: currentOperation.serverAddress,
                                        port: parseInt(currentOperation.serverPort)
                                    }
                                }, (err, info) => {
                                    if (err) {
                                        console.log(err)
                                        return
                                    }
                                    client.setSocket(info.socket)
                                    client.emit('connect')
                                })
                            },
                            username: account.username,
                            password: account.password,
                            host: currentOperation.serverAddress, // Without these a Not Permitted error would be thrown
                            port: parseInt(currentOperation.serverPort), // 
                            agent: agent
                        });

Actually I was wrong, adding the host and port will cause the client to connect to the server without using the Proxy. I'm still struggling with this without any progress. I am sure that my proxy is working so ...

Aroxis commented 3 years ago

For those who are trying to use offline accounts with the proxies, don't be like me and don't forget the 'skipValidation': true on the options object. Wasted 5 hours of my life on this.

IceTank commented 3 years ago

I based myself of the given example but that didn't work. Upon adding host and port in the root of the options object I managed to get it working ...

bot = mineflayer.createBot({
                           connect: client => {
                                socks.createConnection({
                                    proxy : mcProxy,
                                    command: 'connect',
                                    destination: {
                                        host: currentOperation.serverAddress,
                                        port: parseInt(currentOperation.serverPort)
                                    }
                                }, (err, info) => {
                                    if (err) {
                                        console.log(err)
                                        return
                                    }
                                    client.setSocket(info.socket)
                                    client.emit('connect')
                                })
                            },
                            username: account.username,
                            password: account.password,
                            host: currentOperation.serverAddress, // Without these a Not Permitted error would be thrown
                            port: parseInt(currentOperation.serverPort), // 
                            agent: agent
                        });

Actually I was wrong, adding the host and port will cause the client to connect to the server without using the Proxy. I'm still struggling with this without any progress. I am sure that my proxy is working so ...

What is the user agent you used for the agent option? This example should work as mineflayer uses minecraft-protocol to connect the bots. https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/examples/client_socks_proxy/client_socks_proxy.js

u9g commented 3 years ago

Come to our discord if you are still confused: https://discord.gg/vYtdBvDgZn