Advertisement
thevipershowita

BotStress

Aug 12th, 2019
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const readline = require('readline')
  2. const color = require('ansi-color').set
  3. const mc = require('minecraft-protocol')
  4. const states = mc.states
  5. const util = require('util')
  6. const SocksClient = require('socks').SocksClient;
  7.  
  8. const colors = {
  9.     black: 'black+white_bg',
  10.     dark_blue: 'blue',
  11.     dark_green: 'green',
  12.     dark_aqua: 'cyan',
  13.     dark_red: 'red',
  14.     dark_purple: 'magenta',
  15.     gold: 'yellow',
  16.     gray: 'black+white_bg',
  17.     dark_gray: 'black+white_bg',
  18.     blue: 'blue',
  19.     green: 'green',
  20.     aqua: 'cyan',
  21.     red: 'red',
  22.     light_purple: 'magenta',
  23.     yellow: 'yellow',
  24.     white: 'white',
  25.     obfuscated: 'blink',
  26.     bold: 'bold',
  27.     strikethrough: '',
  28.     underlined: 'underlined',
  29.     italic: '',
  30.     reset: 'white+black_bg'
  31. }
  32.  
  33. const dictionary = {
  34.     'chat.stream.emote': '(%s) * %s %s',
  35.     'chat.stream.text': '(%s) <%s> %s',
  36.     'chat.type.achievement': '%s has just earned the achievement %s',
  37.     'chat.type.admin': '[%s: %s]',
  38.     'chat.type.announcement': '[%s] %s',
  39.     'chat.type.emote': '* %s %s',
  40.     'chat.type.text': '<%s> %s'
  41. }
  42.  
  43. const rl = readline.createInterface({
  44.     input: process.stdin,
  45.     output: process.stdout,
  46.     terminal: false
  47. })
  48.  
  49. function printHelp () {
  50.     console.log('usage: node main.js <server hostname> <server port> <SOCKS v4 proxy host> <SOCKS port> <user> [<password>]')
  51. }
  52.  
  53. if (process.argv.length < 6) {
  54.     console.log('Too few arguments!')
  55.     printHelp()
  56.     process.exit(1)
  57. }
  58. let phost = process.argv[4]
  59. let pport = parseInt(process.argv[5])
  60.  
  61. process.argv.forEach(function (val) {
  62.     if (val === '-h') {
  63.         printHelp()
  64.         process.exit(0)
  65.     }
  66. })
  67.  
  68. let host = process.argv[2]
  69. let port = parseInt(process.argv[3])
  70.  
  71. function randStr(len) {
  72.     let s = '';
  73.     while (s.length < len) s += Math.random().toString(36).substr(2, len - s.length);
  74.     return s;
  75. }
  76.  
  77. const passwd = process.argv[7]
  78. const options = {
  79.     proxy: {
  80.         host: phost, // ipv4 or ipv6 or hostname
  81.         port: parseInt(pport),
  82.         type: 4 // Proxy version (4 or 5)
  83.     },
  84.  
  85.     command: 'connect', // SOCKS command (createConnection factory function only supports the connect command)
  86.  
  87.     destination: {
  88.         host: host, // github.com (hostname lookups are supported with SOCKS v4a and 5)
  89.         port: port
  90.     }
  91. };
  92. if (host.indexOf(':') !== -1) {
  93.     port = host.substring(host.indexOf(':') + 1)
  94.     host = host.substring(0, host.indexOf(':'))
  95. }
  96.  
  97. console.log('connecting to ' + host + ':' + port)
  98. console.log('user: ' + randStr(14))
  99.  
  100.  
  101. for(k=0;k<125;k++) {
  102.     const client = mc.createClient({
  103.  
  104.         connect: client => {
  105.             console.log("Using SOCKS proxy: " + options.proxy.host + ":" + options.proxy.port)
  106.             SocksClient.createConnection(options, function (err, socket) {
  107.                 if (err) {
  108.                     console.log(err)
  109.                     return
  110.                 }
  111.  
  112.                 client.setSocket(socket)
  113.                 client.emit('connect')
  114.             })
  115.         },
  116.         host: host,
  117.         port: port,
  118.         username: randStr(14),
  119.         password: passwd
  120.     })
  121.  
  122.     client.on('kick_disconnect', function (packet) {
  123.         console.info(color('Kicked for ' + packet.reason, 'blink+red'))
  124.         process.exit(1)
  125.     })
  126.  
  127.     const chats = []
  128.  
  129.     client.on('connect', function () {
  130.         console.info(color('Successfully connected to ' + host + ':' + port, 'blink+green'))
  131.     })
  132.  
  133.     client.on('disconnect', function (packet) {
  134.         console.log('disconnected!!!: ' + packet.reason)
  135.     })
  136.  
  137.     client.on('end', function () {
  138.         console.log('Connection lost')
  139.         process.exit()
  140.     })
  141.  
  142.     client.on('error', function (err) {
  143.         console.log('Error occured')
  144.         console.log(err)
  145.         process.exit(1)
  146.     })
  147.  
  148.     client.on('state', function (newState) {
  149.         if (newState === states.PLAY) {
  150.             chats.forEach(function (chat) {
  151.                 client.write('chat', {message: chat})
  152.             })
  153.         }
  154.     })
  155.  
  156.     rl.on('line', function (line) {
  157.         if (line === '') {
  158.             return
  159.         } else if (line === '/quit') {
  160.             console.info('Disconnected from ' + host + ':' + port)
  161.             client.end()
  162.             return
  163.         } else if (line === '/end') {
  164.             console.info('Forcibly ended client')
  165.             process.exit(0)
  166.         }
  167.         if (!client.write('chat', {message: line})) {
  168.             chats.push(line)
  169.         }
  170.     })
  171.  
  172.     client.on('chat', function (packet) {
  173.         const j = JSON.parse(packet.message)
  174.         const chat = parseFloat(j, {})
  175.         console.info(chat)
  176.     })
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement