batch packets
This commit is contained in:
parent
522afb4dfd
commit
dc7c30482c
3 changed files with 33 additions and 19 deletions
|
|
@ -867,13 +867,9 @@
|
|||
"packet_mcpe_batch": [
|
||||
"container",
|
||||
[
|
||||
{
|
||||
"name": "payload_size",
|
||||
"type": "i32"
|
||||
},
|
||||
{
|
||||
"name": "payload",
|
||||
"type":["buffer",{"countType":"i16"}]
|
||||
"type":["buffer",{"countType":"i32"}]
|
||||
}
|
||||
]
|
||||
],
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ if(process.argv.length !=4) {
|
|||
var server = pmp.createServer({
|
||||
host: process.argv[2],
|
||||
port: parseInt(process.argv[3]),
|
||||
name: 'MCPE;numerous-alpaca test server!;45 45;0.0.1;0;20'
|
||||
name: 'MCPE;Minecraft: PE Server;45 45;0.14.1;0;20'
|
||||
});
|
||||
|
||||
server.on('connection', function(client) {
|
||||
|
|
|
|||
|
|
@ -1,48 +1,66 @@
|
|||
'use strict';
|
||||
const assert = require('assert');
|
||||
const raknet = require('raknet');
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const zlib = require('zlib');
|
||||
|
||||
function createClient(options) {
|
||||
assert.ok(options, "options is required");
|
||||
assert.ok(options, 'options is required');
|
||||
var port = options.port || 19132;
|
||||
var host = options.host || 'localhost';
|
||||
|
||||
assert.ok(options.username, "username is required");
|
||||
assert.ok(options.username, 'username is required');
|
||||
|
||||
options.customPackets=require("../data/protocol");
|
||||
options.customTypes=require("./datatypes/minecraft");
|
||||
options.customPackets=require('../data/protocol');
|
||||
options.customTypes=require('./datatypes/minecraft');
|
||||
|
||||
var client=raknet.createClient(options);
|
||||
client.username = options.username;
|
||||
client.on("mcpe",packet => client.emit(packet.name,packet.params))
|
||||
client.on('mcpe',packet => client.emit(packet.name,packet.params))
|
||||
client.writeMCPE=(name,packet) => {
|
||||
client.writeEncapsulated("mcpe",{
|
||||
client.writeEncapsulated('mcpe',{
|
||||
name:name,
|
||||
params:packet
|
||||
});
|
||||
};
|
||||
|
||||
client.on('login', function() {
|
||||
client.writeMCPE("mcpe_login",
|
||||
client.writeMCPE('mcpe_login',
|
||||
{
|
||||
username: client.username,
|
||||
protocol: 45,
|
||||
protocol2: 45,
|
||||
protocol: 46,
|
||||
protocol2: 46,
|
||||
client_id: [ -1, -697896776 ],
|
||||
client_uuid: '86372ed8-d055-b23a-9171-5e3ac594d766',
|
||||
server_address: client.host+":"+client.port,
|
||||
client_secret: new Buffer("e8 88 db 7b 9f f2 f0 44 a3 51 08 18 4e 8c 7f 9a".replace(/ /g,""),"hex"),
|
||||
client_secret: new Buffer('e8 88 db 7b 9f f2 f0 44 a3 51 08 18 4e 8c 7f 9a'.replace(/ /g,''),'hex'),
|
||||
skin:
|
||||
{
|
||||
skinType: 'Standard_Steve',
|
||||
texture: fs.readFileSync(path.join(__dirname,"texture"))
|
||||
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]);
|
||||
console.log(client.readEncapsulatedPacket(packetBuffer));
|
||||
}
|
||||
});
|
||||
|
||||
return client;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue