mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-05-11 22:00:24 -04:00
add connect option to createClient for multiple (ping + normal) connections for the proxy examples, use the normal options for pinging in autoVersion to have that option available and fix the proxy examples accordingly
This commit is contained in:
parent
6279ae9afe
commit
010362ef78
6 changed files with 82 additions and 75 deletions
examples
|
@ -9,39 +9,41 @@ if(process.argv.length < 6 || process.argv.length > 8) {
|
|||
const proxyHost=process.argv[4];
|
||||
const proxyPort=process.argv[5];
|
||||
|
||||
const req = Http.request({
|
||||
host: proxyHost,
|
||||
port: proxyPort,
|
||||
method: 'CONNECT',
|
||||
path: process.argv[2] + ":" + parseInt(process.argv[3])
|
||||
});
|
||||
req.end();
|
||||
const client = mc.createClient({
|
||||
connect:(client) => {
|
||||
const req = Http.request({
|
||||
host: proxyHost,
|
||||
port: proxyPort,
|
||||
method: 'CONNECT',
|
||||
path: process.argv[2] + ":" + parseInt(process.argv[3])
|
||||
});
|
||||
req.end();
|
||||
|
||||
req.on("connect", function(res, stream) {
|
||||
const client = mc.createClient({
|
||||
stream: stream,
|
||||
req.on("connect", function(res, stream) {
|
||||
client.setSocket(stream);
|
||||
client.emit('connect');
|
||||
});
|
||||
},
|
||||
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});
|
||||
}
|
||||
});
|
||||
|
||||
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});
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
"name": "node-minecraft-protocol-example",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
},
|
||||
"dependencies": {},
|
||||
"description": "A node-minecraft-protocol example"
|
||||
}
|
||||
|
|
|
@ -9,44 +9,47 @@ if(process.argv.length < 6 || process.argv.length > 8) {
|
|||
const proxyHost=process.argv[4];
|
||||
const proxyPort=process.argv[5];
|
||||
|
||||
socks.createConnection({
|
||||
proxy: {
|
||||
ipaddress: proxyHost,
|
||||
port: proxyPort,
|
||||
type: 5
|
||||
},
|
||||
target: {
|
||||
host: process.argv[2],
|
||||
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]
|
||||
});
|
||||
const client = mc.createClient({
|
||||
connect: client => {
|
||||
socks.createConnection({
|
||||
proxy: {
|
||||
ipaddress: proxyHost,
|
||||
port: proxyPort,
|
||||
type: 5
|
||||
},
|
||||
target: {
|
||||
host: process.argv[2],
|
||||
port: parseInt(process.argv[3])
|
||||
},
|
||||
}, function(err, socket) {
|
||||
if (err) {
|
||||
console.log(err);
|
||||
return;
|
||||
}
|
||||
|
||||
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.setSocket(socket);
|
||||
client.emit('connect');
|
||||
});
|
||||
},
|
||||
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});
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue