mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 21:52:17 -04:00
fix socks proxy using a socks module that actually works and provide a proper node stream
This commit is contained in:
parent
cab5a329bf
commit
6279ae9afe
@ -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,32 +9,44 @@ 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) {
|
||||||
username: process.argv[6] ? process.argv[6] : "echo",
|
console.log(err);
|
||||||
password: process.argv[7]
|
return;
|
||||||
|
}
|
||||||
|
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});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
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});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user