fix socks proxy using a socks module that actually works and provide a proper node stream

This commit is contained in:
Romain Beaumont 2017-07-19 17:24:51 +02:00
parent cab5a329bf
commit 6279ae9afe
No known key found for this signature in database
GPG Key ID: DB60E388B3BCF286
2 changed files with 40 additions and 28 deletions

View File

@ -1,5 +1,5 @@
const mc = require('minecraft-protocol'); const mc = require('minecraft-protocol');
const Socks = require("socks5-client"); const socks = require("socks");
if(process.argv.length < 6 || process.argv.length > 8) { if(process.argv.length < 6 || process.argv.length > 8) {
console.log("Usage : node client_socks_proxy.js <host> <port> <proxyHost> <proxyPort> [<name>] [<password>]"); console.log("Usage : node client_socks_proxy.js <host> <port> <proxyHost> <proxyPort> [<name>] [<password>]");
@ -9,13 +9,23 @@ if(process.argv.length < 6 || process.argv.length > 8) {
const proxyHost=process.argv[4]; const proxyHost=process.argv[4];
const proxyPort=process.argv[5]; const proxyPort=process.argv[5];
const client = mc.createClient({ socks.createConnection({
stream: Socks.createConnection({ proxy: {
ipaddress: proxyHost,
port: proxyPort,
type: 5
},
target: {
host: process.argv[2], host: process.argv[2],
port: parseInt(process.argv[3]), port: parseInt(process.argv[3])
socksHost: proxyHost, },
socksPort: proxyPort }, function(err, socket) {
}), if (err) {
console.log(err);
return;
}
const client = mc.createClient({
stream: socket,
username: process.argv[6] ? process.argv[6] : "echo", username: process.argv[6] ? process.argv[6] : "echo",
password: process.argv[7] password: process.argv[7]
}); });
@ -38,3 +48,5 @@ client.on('chat', function(packet) {
client.write('chat', {message: msg}); client.write('chat', {message: msg});
} }
}); });
});

View File

@ -3,7 +3,7 @@
"version": "0.0.0", "version": "0.0.0",
"private": true, "private": true,
"dependencies": { "dependencies": {
"socks5-client": "^1.2.5" "socks": "^1.1.10"
}, },
"description": "A node-minecraft-protocol example" "description": "A node-minecraft-protocol example"
} }