mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-02 03:56:54 -05:00
c9ed8a2792
* add passing test for "starts listening" * server.socket -> server.socketServer * add client.id which can be used as entity id * add server.clients which is {clientId: client} * update server examples * server emits 'close' event, not 'end' event * add server.close()
45 lines
942 B
JavaScript
45 lines
942 B
JavaScript
var mc = require('../');
|
|
|
|
var options = {
|
|
'online-mode': false, // optional
|
|
};
|
|
|
|
var server = mc.createServer(options);
|
|
|
|
server.on('login', function(client) {
|
|
var addr = client.socket.remoteAddress;
|
|
console.log('Incoming connection', '('+addr+')');
|
|
|
|
client.on('end', function() {
|
|
console.log('Connection closed', '('+addr+')');
|
|
});
|
|
|
|
// send init data so client will start rendering world
|
|
client.write(0x01, {
|
|
entityId: client.id,
|
|
levelType: 'default',
|
|
gameMode: 0,
|
|
dimension: 0,
|
|
difficulty: 2,
|
|
maxPlayers: server.maxPlayers
|
|
});
|
|
client.write(0x0d, {
|
|
x: 0,
|
|
y: 1.62,
|
|
stance: 0,
|
|
z: 0,
|
|
yaw: 0,
|
|
pitch: 0,
|
|
onGround: true
|
|
});
|
|
|
|
client.write(0x03, { message: 'Hello, world!' });
|
|
});
|
|
|
|
server.on('error', function(error) {
|
|
console.log('Error:', error);
|
|
});
|
|
|
|
server.on('listening', function() {
|
|
console.log('Server listening on port', server.socketServer.address().port);
|
|
});
|