mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 13:45:37 -04:00
This commit is contained in:
parent
5e64acce36
commit
ed425e775d
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
node_modules
|
||||
test/npm-debug.log
|
||||
test/server
|
||||
package-lock.json
|
||||
|
46
examples/client_http_proxy/client_http_proxy.js
Normal file
46
examples/client_http_proxy/client_http_proxy.js
Normal file
@ -0,0 +1,46 @@
|
||||
const mc = require('minecraft-protocol');
|
||||
const Http = require("http");
|
||||
|
||||
if(process.argv.length < 6 || process.argv.length > 8) {
|
||||
console.log("Usage : node echo.js <host> <port> <proxyHost> <proxyPort> [<name>] [<password>]");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
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.on("connect", function(res, stream) {
|
||||
const client = mc.createClient({
|
||||
stream: stream,
|
||||
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});
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
|
8
examples/client_http_proxy/package.json
Normal file
8
examples/client_http_proxy/package.json
Normal file
@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "node-minecraft-protocol-example",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
},
|
||||
"description": "A node-minecraft-protocol example"
|
||||
}
|
40
examples/client_socks_proxy/client_socks_proxy.js
Normal file
40
examples/client_socks_proxy/client_socks_proxy.js
Normal file
@ -0,0 +1,40 @@
|
||||
const mc = require('minecraft-protocol');
|
||||
const Socks = require("socks5-client");
|
||||
|
||||
if(process.argv.length < 6 || process.argv.length > 8) {
|
||||
console.log("Usage : node echo.js <host> <port> <proxyHost> <proxyPort> [<name>] [<password>]");
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
const proxyHost=process.argv[4];
|
||||
const proxyPort=process.argv[5];
|
||||
|
||||
const client = mc.createClient({
|
||||
stream: Socks.createConnection({
|
||||
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]
|
||||
});
|
||||
|
||||
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});
|
||||
}
|
||||
});
|
9
examples/client_socks_proxy/package.json
Normal file
9
examples/client_socks_proxy/package.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"name": "node-minecraft-protocol-example",
|
||||
"version": "0.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"socks5-client": "^1.2.5"
|
||||
},
|
||||
"description": "A node-minecraft-protocol example"
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user