Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  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 < 7) {
  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. const user = process.argv[6]
  71. const passwd = process.argv[7]
  72. const options = {
  73. proxy: {
  74. host: phost, // ipv4 or ipv6 or hostname
  75. port: parseInt(pport),
  76. type: 4 // Proxy version (4 or 5)
  77. },
  78.  
  79. command: 'connect', // SOCKS command (createConnection factory function only supports the connect command)
  80.  
  81. destination: {
  82. host: host, // github.com (hostname lookups are supported with SOCKS v4a and 5)
  83. port: port
  84. }
  85. };
  86. if (host.indexOf(':') !== -1) {
  87. port = host.substring(host.indexOf(':') + 1)
  88. host = host.substring(0, host.indexOf(':'))
  89. }
  90.  
  91. console.log('connecting to ' + host + ':' + port)
  92. console.log('user: ' + user)
  93.  
  94. const client = mc.createClient({
  95. connect: client => {
  96. console.log("Using SOCKS proxy: "+options.proxy.host + ":" +options.proxy.port)
  97. SocksClient.createConnection(options, function (err, socket) {
  98. if (err) {
  99. console.log(err)
  100. return
  101. }
  102.  
  103. client.setSocket(socket)
  104. client.emit('connect')
  105. })
  106. },
  107. host: host,
  108. port: port,
  109. username: user,
  110. password: passwd
  111. })
  112.  
  113. client.on('kick_disconnect', function (packet) {
  114. console.info(color('Kicked for ' + packet.reason, 'blink+red'))
  115. process.exit(1)
  116. })
  117.  
  118. const chats = []
  119.  
  120. client.on('connect', function () {
  121. console.info(color('Successfully connected to ' + host + ':' + port, 'blink+green'))
  122. })
  123.  
  124. client.on('disconnect', function (packet) {
  125. console.log('disconnected!!!: ' + packet.reason)
  126. })
  127.  
  128. client.on('end', function () {
  129. console.log('Connection lost')
  130. process.exit()
  131. })
  132.  
  133. client.on('error', function (err) {
  134. console.log('Error occured')
  135. console.log(err)
  136. process.exit(1)
  137. })
  138.  
  139. client.on('state', function (newState) {
  140. if (newState === states.PLAY) {
  141. chats.forEach(function (chat) {
  142. client.write('chat', { message: chat })
  143. })
  144. }
  145. })
  146.  
  147. rl.on('line', function (line) {
  148. if (line === '') {
  149. return
  150. } else if (line === '/quit') {
  151. console.info('Disconnected from ' + host + ':' + port)
  152. client.end()
  153. return
  154. } else if (line === '/end') {
  155. console.info('Forcibly ended client')
  156. process.exit(0)
  157. }
  158. if (!client.write('chat', { message: line })) {
  159. chats.push(line)
  160. }
  161. })
  162.  
  163. client.on('chat', function (packet) {
  164. const j = JSON.parse(packet.message)
  165. const chat = parseChat(j, {})
  166. console.info(chat)
  167. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement