add an optional argument to the proxy example to specify the version

This commit is contained in:
Romain Beaumont 2015-09-30 00:16:39 +02:00
parent 7871ac446a
commit 3f50a6f19a

View file

@ -2,7 +2,7 @@ var mc = require('../../');
var states = mc.states; var states = mc.states;
function printHelpAndExit(exitCode) { function printHelpAndExit(exitCode) {
console.log("usage: node proxy.js [<options>...] <target_srv> <user> [<password>]"); console.log("usage: node proxy.js [<options>...] <target_srv> <user> [<password>] [<version>]");
console.log("options:"); console.log("options:");
console.log(" --dump name"); console.log(" --dump name");
console.log(" print to stdout messages with the specified name."); console.log(" print to stdout messages with the specified name.");
@ -37,6 +37,7 @@ var host;
var port = 25565; var port = 25565;
var user; var user;
var passwd; var passwd;
var version;
var printAllNames = false; var printAllNames = false;
var printNameWhitelist = {}; var printNameWhitelist = {};
@ -59,10 +60,11 @@ var printNameBlacklist = {};
printHelpAndExit(1); printHelpAndExit(1);
} }
} }
if(!(i + 2 <= args.length && args.length <= i + 3)) printHelpAndExit(1); if(!(i + 2 <= args.length && args.length <= i + 4)) printHelpAndExit(1);
host = args[i++]; host = args[i++];
user = args[i++]; user = args[i++];
passwd = args[i++]; passwd = args[i++];
version = args[i++];
})(); })();
if(host.indexOf(':') != -1) { if(host.indexOf(':') != -1) {
@ -73,7 +75,8 @@ if(host.indexOf(':') != -1) {
var srv = mc.createServer({ var srv = mc.createServer({
'online-mode': false, 'online-mode': false,
port: 25566, port: 25566,
keepAlive: false keepAlive: false,
version:version
}); });
srv.on('login', function(client) { srv.on('login', function(client) {
var addr = client.socket.remoteAddress; var addr = client.socket.remoteAddress;
@ -98,7 +101,8 @@ srv.on('login', function(client) {
username: user, username: user,
password: passwd, password: passwd,
'online-mode': passwd != null ? true : false, 'online-mode': passwd != null ? true : false,
keepAlive:false keepAlive:false,
version:version
}); });
client.on('packet', function(data, meta) { client.on('packet', function(data, meta) {
if(targetClient.state == states.PLAY && meta.state == states.PLAY) { if(targetClient.state == states.PLAY && meta.state == states.PLAY) {