mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-07-22 19:58:55 -04:00
Give each example its own package.json to resolve #122
This commit is contained in:
parent
304586aff7
commit
f9b3359577
10 changed files with 46 additions and 0 deletions
examples/server_helloworld
53
examples/server_helloworld/server_helloworld.js
Normal file
53
examples/server_helloworld/server_helloworld.js
Normal file
|
@ -0,0 +1,53 @@
|
|||
var mc = require('../');
|
||||
|
||||
var options = {
|
||||
'online-mode': true,
|
||||
};
|
||||
|
||||
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('login', {
|
||||
entityId: client.id,
|
||||
levelType: 'default',
|
||||
gameMode: 0,
|
||||
dimension: 0,
|
||||
difficulty: 2,
|
||||
maxPlayers: server.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 });
|
||||
});
|
||||
|
||||
server.on('error', function(error) {
|
||||
console.log('Error:', error);
|
||||
});
|
||||
|
||||
server.on('listening', function() {
|
||||
console.log('Server listening on port', server.socketServer.address().port);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue