add example chunk, use protodef to implement read and write batch, try to make the chunk sending work
This commit is contained in:
parent
e1559e6e1e
commit
863ddf1785
5 changed files with 69 additions and 23 deletions
|
|
@ -4,6 +4,10 @@ const raknet = require('raknet');
|
|||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const zlib = require('zlib');
|
||||
const ProtoDef = require('protodef').ProtoDef;
|
||||
const batchProto=new ProtoDef();
|
||||
batchProto.addTypes(require("./datatypes/minecraft"));
|
||||
batchProto.addType("insideBatch",["endOfArray",{"type":["buffer",{"countType":"i32"}]}]);
|
||||
|
||||
function createClient(options) {
|
||||
assert.ok(options, 'options is required');
|
||||
|
|
@ -41,24 +45,14 @@ function createClient(options) {
|
|||
texture: fs.readFileSync(path.join(__dirname,'texture'))
|
||||
}
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
client.on('mcpe_batch', function(packet) {
|
||||
var buf = zlib.inflateSync(packet.payload);
|
||||
var offset = 0;
|
||||
var length = buf.length;
|
||||
|
||||
while(offset < length) {
|
||||
var pkLength = buf.readInt32BE(offset);
|
||||
offset += 4;
|
||||
|
||||
var packetBuffer = buf.slice(offset, pkLength);
|
||||
offset += pkLength;
|
||||
|
||||
packetBuffer = Buffer.concat([new Buffer([0x8e]),packetBuffer]);
|
||||
client.readEncapsulatedPacket(packetBuffer);
|
||||
}
|
||||
var packets=batchProto.parsePacketBuffer("insideBatch",buf).data;
|
||||
packets.forEach(packet => client.readEncapsulatedPacket(Buffer.concat([new Buffer([0x8e]),packet])));
|
||||
});
|
||||
|
||||
return client;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue