2017-07-13 08:42:42 -04:00
|
|
|
const mc = require('minecraft-protocol');
|
2017-07-19 11:24:51 -04:00
|
|
|
const socks = require("socks");
|
2017-07-13 08:42:42 -04:00
|
|
|
|
|
|
|
if(process.argv.length < 6 || process.argv.length > 8) {
|
2017-07-17 09:30:14 -04:00
|
|
|
console.log("Usage : node client_socks_proxy.js <host> <port> <proxyHost> <proxyPort> [<name>] [<password>]");
|
2017-07-13 08:42:42 -04:00
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
const proxyHost=process.argv[4];
|
|
|
|
const proxyPort=process.argv[5];
|
|
|
|
|
2017-07-19 11:24:51 -04:00
|
|
|
socks.createConnection({
|
|
|
|
proxy: {
|
|
|
|
ipaddress: proxyHost,
|
|
|
|
port: proxyPort,
|
|
|
|
type: 5
|
|
|
|
},
|
|
|
|
target: {
|
2017-07-13 08:42:42 -04:00
|
|
|
host: process.argv[2],
|
2017-07-19 11:24:51 -04:00
|
|
|
port: parseInt(process.argv[3])
|
|
|
|
},
|
|
|
|
}, function(err, socket) {
|
|
|
|
if (err) {
|
|
|
|
console.log(err);
|
|
|
|
return;
|
2017-07-13 08:42:42 -04:00
|
|
|
}
|
2017-07-19 11:24:51 -04:00
|
|
|
const client = mc.createClient({
|
|
|
|
stream: socket,
|
|
|
|
username: process.argv[6] ? process.argv[6] : "echo",
|
|
|
|
password: process.argv[7]
|
|
|
|
});
|
|
|
|
|
|
|
|
client.on('connect', function() {
|
|
|
|
console.info('connected');
|
|
|
|
});
|
|
|
|
client.on('disconnect', function(packet) {
|
|
|
|
console.log('disconnected: '+ packet.reason);
|
|
|
|
});
|
|
|
|
client.on('end', function(err) {
|
|
|
|
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;
|
|
|
|
client.write('chat', {message: msg});
|
|
|
|
}
|
|
|
|
});
|
2017-07-13 08:42:42 -04:00
|
|
|
});
|
2017-07-19 11:24:51 -04:00
|
|
|
|