2015-11-30 07:23:38 -05:00
|
|
|
var mc = require('minecraft-protocol');
|
2015-09-20 16:19:39 -04:00
|
|
|
|
|
|
|
if(process.argv.length < 4 || process.argv.length > 6) {
|
|
|
|
console.log("Usage : node echo.js <host> <port> [<name>] [<password>]");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2013-12-30 10:05:22 -05:00
|
|
|
|
2013-01-02 03:30:33 -05:00
|
|
|
var client = mc.createClient({
|
2015-09-20 16:19:39 -04:00
|
|
|
host: process.argv[2],
|
|
|
|
port: parseInt(process.argv[3]),
|
|
|
|
username: process.argv[4] ? process.argv[4] : "echo",
|
|
|
|
password: process.argv[5]
|
2013-01-02 03:30:33 -05:00
|
|
|
});
|
2015-09-20 16:19:39 -04:00
|
|
|
|
2013-01-02 03:30:33 -05:00
|
|
|
client.on('connect', function() {
|
2013-07-09 02:11:09 -04:00
|
|
|
console.info('connected');
|
2013-01-02 03:30:33 -05:00
|
|
|
});
|
2016-01-22 03:32:36 -05:00
|
|
|
client.on('disconnect', function(packet) {
|
|
|
|
console.log('disconnected: '+ packet.reason);
|
|
|
|
});
|
2016-02-07 03:05:55 -05:00
|
|
|
client.on('end', function(err) {
|
|
|
|
console.log('Connection lost');
|
|
|
|
});
|
2014-01-14 00:56:56 -05:00
|
|
|
client.on('chat', function(packet) {
|
2013-07-09 02:11:09 -04:00
|
|
|
var jsonMsg = JSON.parse(packet.message);
|
2015-05-14 16:08:49 -04:00
|
|
|
if(jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
|
2015-09-20 16:19:39 -04:00
|
|
|
var username = jsonMsg.with[0].text;
|
2013-12-30 10:05:22 -05:00
|
|
|
var msg = jsonMsg.with[1];
|
2015-05-14 16:08:49 -04:00
|
|
|
if(username === client.username) return;
|
2014-03-16 13:06:57 -04:00
|
|
|
client.write('chat', {message: msg});
|
2013-07-09 02:11:09 -04:00
|
|
|
}
|
2015-03-26 11:25:36 -04:00
|
|
|
});
|