node-minecraft-protocol/examples/client_echo/client_echo.js

19 lines
572 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;
client.write('chat', {message: msg});
2013-07-09 02:11:09 -04:00
}
});