node-minecraft-protocol/examples/client_echo.js

19 lines
580 B
JavaScript
Raw Normal View History

var mc = require('../')
, states = mc.protocol.states
2013-01-02 03:30:33 -05:00
var client = mc.createClient({
username: process.env.MC_USERNAME,
password: process.env.MC_PASSWORD,
});
client.on('connect', function() {
2013-07-09 02:11:09 -04:00
console.info('connected');
2013-01-02 03:30:33 -05:00
});
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);
if (jsonMsg.translate == 'chat.type.announcement' || jsonMsg.translate == 'chat.type.text') {
var username = jsonMsg.with[0];
var msg = jsonMsg.with[1];
2013-07-09 02:11:09 -04:00
if (username === client.username) return;
2014-01-14 00:56:56 -05:00
client.write('chat_message', {message: msg});
2013-07-09 02:11:09 -04:00
}
});