mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-05-14 07:10:24 -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
2 changed files with 40 additions and 28 deletions
examples/client_socks_proxy
|
@ -1,5 +1,5 @@
|
|||
const mc = require('minecraft-protocol');
|
||||
const Socks = require("socks5-client");
|
||||
const socks = require("socks");
|
||||
|
||||
if(process.argv.length < 6 || process.argv.length > 8) {
|
||||
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 proxyPort=process.argv[5];
|
||||
|
||||
const client = mc.createClient({
|
||||
stream: Socks.createConnection({
|
||||
socks.createConnection({
|
||||
proxy: {
|
||||
ipaddress: proxyHost,
|
||||
port: proxyPort,
|
||||
type: 5
|
||||
},
|
||||
target: {
|
||||
host: process.argv[2],
|
||||
port: parseInt(process.argv[3]),
|
||||
socksHost: proxyHost,
|
||||
socksPort: proxyPort
|
||||
}),
|
||||
username: process.argv[6] ? process.argv[6] : "echo",
|
||||
password: process.argv[7]
|
||||
port: parseInt(process.argv[3])
|
||||
},
|
||||
}, function(err, socket) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
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",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"socks5-client": "^1.2.5"
|
||||
"socks": "^1.1.10"
|
||||
},
|
||||
"description": "A node-minecraft-protocol example"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue