-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to node-minecraft-protocol 0.16 (major changes including using protodef) #21
Conversation
…iome mineflayer's lib/block.js and lib/biome.js moved to separate modules, prismarine-block and prismarine-biome. Use them indirectly through mineflayer's export object instead of referencing the now-nonexistent library files. GH-19
For supporting requireindex in mineflayer, see porting progress #19
…global brfs transform
… Client() constructor
Current status, makes some progress:
Looks like the last packet is fragmented (varint length 04, followed by 4 byte payload: 00 09 00 00), expect to receive it in whole in one ws frame. |
Debugging on the client (mcwebchat example), for now editing node-minecraft-protocol/src/debug.js to always log (then After sending the username, the first MC packet sent over the websocket is for the > chunk
Object {name: "held_item_slot", params: Object}name: "held_item_slot"params: ObjectslotId: 0__proto__: Object__proto__: Object
> this.createPacketBuffer(chunk)
[9, 0, 0] Length is not added at this point yet. Has node-minecraft-protocol changed to write the packet length and packet data in two write calls? |
Maybe this? https://github.com/PrismarineJS/node-minecraft-protocol/blob/master/src/transforms/framing.js#L17-L24 _transform(chunk, enc, cb) {
var buffer = new Buffer(sizeOfVarInt(chunk.length));
writeVarInt(chunk.length, buffer, 0);
this.push(buffer);
this.push(chunk);
return cb();
}
}
How to ensure the ws client only sends full mc packets in each ws frame? |
https://nodejs.org/api/stream.html#stream_writable_cork "Forces buffering of all writes." - I would think this would work to do only one write: _transform(chunk, enc, cb) {
var buffer = new Buffer(sizeOfVarInt(chunk.length));
writeVarInt(chunk.length, buffer, 0);
this.cork();
this.push(buffer);
this.push(chunk);
this.uncork();
return cb();
} but it seems to have no effect (still sends two writes) at least in browserify - maybe a browser module limitation or something? Manually combining the two buffers and calling _transform(chunk, enc, cb) {
var buffer = new Buffer(sizeOfVarInt(chunk.length) + chunk.length);
writeVarInt(chunk.length, buffer, 0);
chunk.copy(buffer, sizeOfVarInt(chunk.length));
this.push(buffer);
return cb();
} With this change in node-minecraft-protocol/src/transforms/framing.js, browserify mineflayer is back again! mcwebchat demo works at least, able to send/receive chat messages to/from mc server. Although, copying the buffer into another buffer is undesirable, maybe there is a better way to fix this (try cork/uncork again? have wsmc buffer the packets itself?!). |
Perhaps better, if possible: disable MC packet framing on the WS<->MC stream. Websockets have their own framing: http://lucumr.pocoo.org/2012/9/24/websockets-101/#framing - so MC's framing is redundant in this context. Ensure each WS frame is one MC packet. update: disabled framing with commits below, works well |
…litting MC packet transforms from node-minecraft-protocol
…WS is already framed)
Update to node-minecraft-protocol 0.16
#19