2018-05-13 16:50:16 -04:00
|
|
|
const mc = require('minecraft-protocol')
|
2020-02-11 06:31:24 -05:00
|
|
|
const socks = require('socks').SocksClient
|
|
|
|
const ProxyAgent = require('proxy-agent')
|
2017-07-13 08:42:42 -04:00
|
|
|
|
2018-05-13 16:50:16 -04:00
|
|
|
if (process.argv.length < 6 || process.argv.length > 8) {
|
|
|
|
console.log('Usage : node client_socks_proxy.js <host> <port> <proxyHost> <proxyPort> [<name>] [<password>]')
|
|
|
|
process.exit(1)
|
2017-07-13 08:42:42 -04:00
|
|
|
}
|
|
|
|
|
2018-05-13 16:50:16 -04:00
|
|
|
const proxyHost = process.argv[4]
|
|
|
|
const proxyPort = process.argv[5]
|
2017-07-13 08:42:42 -04:00
|
|
|
|
2017-07-19 12:39:25 -04:00
|
|
|
const client = mc.createClient({
|
|
|
|
connect: client => {
|
|
|
|
socks.createConnection({
|
2018-05-13 16:50:16 -04:00
|
|
|
proxy: {
|
2020-02-11 06:31:24 -05:00
|
|
|
host: proxyHost,
|
2018-05-13 16:50:16 -04:00
|
|
|
port: proxyPort,
|
|
|
|
type: 5
|
|
|
|
},
|
2020-02-11 06:31:24 -05:00
|
|
|
command: 'connect',
|
|
|
|
destination: {
|
2018-05-13 16:50:16 -04:00
|
|
|
host: process.argv[2],
|
|
|
|
port: parseInt(process.argv[3])
|
|
|
|
}
|
2020-02-11 06:31:24 -05:00
|
|
|
}, (err, info) => {
|
2018-05-13 16:50:16 -04:00
|
|
|
if (err) {
|
|
|
|
console.log(err)
|
|
|
|
return
|
|
|
|
}
|
2017-07-19 11:24:51 -04:00
|
|
|
|
2020-02-11 06:31:24 -05:00
|
|
|
client.setSocket(info.socket)
|
2018-05-13 16:50:16 -04:00
|
|
|
client.emit('connect')
|
|
|
|
})
|
2017-07-19 12:39:25 -04:00
|
|
|
},
|
2020-02-11 06:31:24 -05:00
|
|
|
agent: new ProxyAgent({ protocol: 'socks5', host: proxyHost, port: proxyPort }),
|
2018-05-13 16:50:16 -04:00
|
|
|
username: process.argv[6] ? process.argv[6] : 'echo',
|
2017-07-19 12:39:25 -04:00
|
|
|
password: process.argv[7]
|
2018-05-13 16:50:16 -04:00
|
|
|
})
|
2017-07-19 11:24:51 -04:00
|
|
|
|
2018-05-13 16:50:16 -04:00
|
|
|
client.on('connect', function () {
|
|
|
|
console.info('connected')
|
|
|
|
})
|
|
|
|
client.on('disconnect', function (packet) {
|
|
|
|
console.log('disconnected: ' + packet.reason)
|
|
|
|
})
|
|
|
|
client.on('end', function () {
|
|
|
|
console.log('Connection lost')
|
|
|
|
})
|
|
|
|
client.on('chat', function (packet) {
|
|
|
|
const jsonMsg = JSON.parse(packet.message)
|
|
|
|
if (jsonMsg.translate === 'chat.type.announcement' || jsonMsg.translate === 'chat.type.text') {
|
|
|
|
const username = jsonMsg.with[0].text
|
|
|
|
const msg = jsonMsg.with[1]
|
|
|
|
if (username === client.username) return
|
2018-09-24 16:07:34 -04:00
|
|
|
client.write('chat', { message: msg })
|
2017-07-19 12:39:25 -04:00
|
|
|
}
|
2018-05-13 16:50:16 -04:00
|
|
|
})
|