mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2024-12-04 04:51:09 -05:00
f45c6dff49
* move general datatypes to protodef along with their tests * move states to states.js file * use one protodef serializer by state and direction instead of one big serializer for everything (same thing for the deserializer) * define a packet as a protodef type using a switch and a container, and adding each minecraft packet as a type (packet_ + name) * use mapper type from protodef to convert id to name in packet definition * use general string type : pstring * divide by 10 the number of iteration in the benchmark to get back to a reasonable test execution time
57 lines
1.2 KiB
JavaScript
57 lines
1.2 KiB
JavaScript
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 + ')');
|
|
});
|
|
|
|
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: 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);
|
|
});
|