node-minecraft-protocol/examples/client_echo.js
Andrew Kelley df3f95e1ff don't require both email and username. closes #32
This change breaks backwards compatibility.

`createClient` no longer takes an `email` argument. Instead, the
`username` argument is used to authenticate and determine the
case correct username.

There is a special case if you leave out the `password` argument.
In this case, `username` is used to connect directly to the server,
and you may get kicked if the server is in online mode.
2013-01-30 19:56:43 -05:00

16 lines
448 B
JavaScript

var mc = require('../');
var client = mc.createClient({
username: process.env.MC_USERNAME,
password: process.env.MC_PASSWORD,
});
client.on('connect', function() {
console.info("connected");
});
client.on(0x03, function(packet) {
var match = packet.message.match(/^<(.+?)> (.*)$/);
if (! match) return;
var username = match[1];
var msg = match[2];
if (username === client.username) return;
client.write(0x03, {message: msg});
});