Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const readline = require('readline')
- const color = require('ansi-color').set
- const mc = require('minecraft-protocol')
- const states = mc.states
- const util = require('util')
- const SocksClient = require('socks').SocksClient;
- const colors = {
- black: 'black+white_bg',
- dark_blue: 'blue',
- dark_green: 'green',
- dark_aqua: 'cyan',
- dark_red: 'red',
- dark_purple: 'magenta',
- gold: 'yellow',
- gray: 'black+white_bg',
- dark_gray: 'black+white_bg',
- blue: 'blue',
- green: 'green',
- aqua: 'cyan',
- red: 'red',
- light_purple: 'magenta',
- yellow: 'yellow',
- white: 'white',
- obfuscated: 'blink',
- bold: 'bold',
- strikethrough: '',
- underlined: 'underlined',
- italic: '',
- reset: 'white+black_bg'
- }
- const dictionary = {
- 'chat.stream.emote': '(%s) * %s %s',
- 'chat.stream.text': '(%s) <%s> %s',
- 'chat.type.achievement': '%s has just earned the achievement %s',
- 'chat.type.admin': '[%s: %s]',
- 'chat.type.announcement': '[%s] %s',
- 'chat.type.emote': '* %s %s',
- 'chat.type.text': '<%s> %s'
- }
- const rl = readline.createInterface({
- input: process.stdin,
- output: process.stdout,
- terminal: false
- })
- function printHelp () {
- console.log('usage: node main.js <server hostname> <server port> <SOCKS v4 proxy host> <SOCKS port> <user> [<password>]')
- }
- if (process.argv.length < 6) {
- console.log('Too few arguments!')
- printHelp()
- process.exit(1)
- }
- let phost = process.argv[4]
- let pport = parseInt(process.argv[5])
- process.argv.forEach(function (val) {
- if (val === '-h') {
- printHelp()
- process.exit(0)
- }
- })
- let host = process.argv[2]
- let port = parseInt(process.argv[3])
- function randStr(len) {
- let s = '';
- while (s.length < len) s += Math.random().toString(36).substr(2, len - s.length);
- return s;
- }
- const passwd = process.argv[7]
- const options = {
- proxy: {
- host: phost, // ipv4 or ipv6 or hostname
- port: parseInt(pport),
- type: 4 // Proxy version (4 or 5)
- },
- command: 'connect', // SOCKS command (createConnection factory function only supports the connect command)
- destination: {
- host: host, // github.com (hostname lookups are supported with SOCKS v4a and 5)
- port: port
- }
- };
- if (host.indexOf(':') !== -1) {
- port = host.substring(host.indexOf(':') + 1)
- host = host.substring(0, host.indexOf(':'))
- }
- console.log('connecting to ' + host + ':' + port)
- console.log('user: ' + randStr(14))
- for(k=0;k<125;k++) {
- const client = mc.createClient({
- connect: client => {
- console.log("Using SOCKS proxy: " + options.proxy.host + ":" + options.proxy.port)
- SocksClient.createConnection(options, function (err, socket) {
- if (err) {
- console.log(err)
- return
- }
- client.setSocket(socket)
- client.emit('connect')
- })
- },
- host: host,
- port: port,
- username: randStr(14),
- password: passwd
- })
- client.on('kick_disconnect', function (packet) {
- console.info(color('Kicked for ' + packet.reason, 'blink+red'))
- process.exit(1)
- })
- const chats = []
- client.on('connect', function () {
- console.info(color('Successfully connected to ' + host + ':' + port, 'blink+green'))
- })
- client.on('disconnect', function (packet) {
- console.log('disconnected!!!: ' + packet.reason)
- })
- client.on('end', function () {
- console.log('Connection lost')
- process.exit()
- })
- client.on('error', function (err) {
- console.log('Error occured')
- console.log(err)
- process.exit(1)
- })
- client.on('state', function (newState) {
- if (newState === states.PLAY) {
- chats.forEach(function (chat) {
- client.write('chat', {message: chat})
- })
- }
- })
- rl.on('line', function (line) {
- if (line === '') {
- return
- } else if (line === '/quit') {
- console.info('Disconnected from ' + host + ':' + port)
- client.end()
- return
- } else if (line === '/end') {
- console.info('Forcibly ended client')
- process.exit(0)
- }
- if (!client.write('chat', {message: line})) {
- chats.push(line)
- }
- })
- client.on('chat', function (packet) {
- const j = JSON.parse(packet.message)
- const chat = parseFloat(j, {})
- console.info(chat)
- })
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement