Skip to content

Instantly share code, notes, and snippets.

@vimes1984
Created March 21, 2016 14:31
Show Gist options
  • Save vimes1984/24c1ff60e39c9d1019f8 to your computer and use it in GitHub Desktop.
Save vimes1984/24c1ff60e39c9d1019f8 to your computer and use it in GitHub Desktop.
var mc = require('minecraft-protocol');
var states = mc.states;
var srv = mc.createServer({
'online-mode': false,
port: 25566,
keepAlive: false,
version:'1.8'
});
srv.on('login', function(client) {
client.on('packet', function(data, meta) {
console.log("client->server:", client.state + " "+ meta.name + " :", JSON.stringify(data));
});
var addr = client.socket.remoteAddress;
console.log('Incoming connection', '(' + addr + ')');
client.on('end', function() {
console.log('Connection closed', '(' + addr + ')');
});
client.on('error', function(error) {
console.log('Error:', error);
});
// send init data so client will start rendering world
client.write('login', {
entityId: client.id,
levelType: 'default',
gameMode: 0,
dimension: 0,
difficulty: 2,
maxPlayers: srv.maxPlayers,
reducedDebugInfo: false
});
client.write('position', {
x: 0,
y: 1.62,
z: 0,
yaw: 0,
pitch: 0,
flags: 0x00
});
var msg = {
translate: 'chat.type.announcement',
"with": [
'Server',
'Hello, world!'
]
};
client.write('chat', {message: JSON.stringify(msg), position: 0});
});
srv.on('error', function(error) {
console.log('Error:', error);
});
srv.on('listening', function() {
console.log('Server listening on port', srv.socketServer.address().port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment