node-minecraft-protocol/examples/client_echo.js

19 lines
496 B
JavaScript
Raw Normal View History

2013-01-02 03:30:33 -05:00
var mc = require('../');
var client = mc.createClient({
username: process.env.MC_USERNAME,
email: process.env.MC_EMAIL,
password: process.env.MC_PASSWORD,
verbose: true,
});
client.on('connect', function() {
console.info("connected");
});
client.on(0x03, function(packet) {
2013-01-02 03:30:33 -05:00
var match = packet.message.match(/^<(.+?)> (.*)$/);
if (! match) return;
var username = match[1];
var msg = match[2];
if (username === client.username) return;
2013-01-03 21:42:35 -05:00
client.write(0x03, {message: msg});
2013-01-02 03:30:33 -05:00
});