mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-27 21:24:25 -04:00
more recognized packets and data types
This commit is contained in:
parent
fd43515c42
commit
33bf57b6c2
@ -7,6 +7,8 @@ var net = require('net')
|
||||
, toUcs2 = new Iconv('UTF-8', 'utf16be')
|
||||
, fromUcs2 = new Iconv('utf16be', 'UTF-8')
|
||||
|
||||
require('buffer-more-ints');
|
||||
|
||||
module.exports = Parser;
|
||||
|
||||
function Parser(options) {
|
||||
@ -70,6 +72,11 @@ var readers = {
|
||||
'short': readShort,
|
||||
'int': readInt,
|
||||
'byte': readByte,
|
||||
'long': readLong,
|
||||
'slot': readSlot,
|
||||
'bool': readBool,
|
||||
'double': readDouble,
|
||||
'float': readFloat,
|
||||
};
|
||||
|
||||
function readString (buffer, offset) {
|
||||
@ -122,6 +129,33 @@ function readInt(buffer, offset) {
|
||||
};
|
||||
}
|
||||
|
||||
function readFloat(buffer, offset) {
|
||||
if (offset + 4 > buffer.length) return null;
|
||||
var value = buffer.readFloatBE(offset);
|
||||
return {
|
||||
value: value,
|
||||
size: 4,
|
||||
};
|
||||
}
|
||||
|
||||
function readDouble(buffer, offset) {
|
||||
if (offset + 8 > buffer.length) return null;
|
||||
var value = buffer.readDoubleBE(offset);
|
||||
return {
|
||||
value: value,
|
||||
size: 8,
|
||||
};
|
||||
}
|
||||
|
||||
function readLong(buffer, offset) {
|
||||
if (offset + 8 > buffer.length) return null;
|
||||
var value = buffer.readInt64BE(offset);
|
||||
return {
|
||||
value: value,
|
||||
size: 8,
|
||||
};
|
||||
}
|
||||
|
||||
function readByte(buffer, offset) {
|
||||
if (offset + 1 > buffer.length) return null;
|
||||
var value = buffer.readInt8(offset);
|
||||
@ -131,6 +165,56 @@ function readByte(buffer, offset) {
|
||||
};
|
||||
}
|
||||
|
||||
function readBool(buffer, offset) {
|
||||
if (offset + 1 > buffer.length) return null;
|
||||
var value = buffer.readInt8(offset);
|
||||
return {
|
||||
value: !!value,
|
||||
size: 1,
|
||||
};
|
||||
}
|
||||
|
||||
function readSlot(buffer, offset) {
|
||||
var results = readShort(buffer, offset);
|
||||
if (! results) return null;
|
||||
|
||||
var blockId = results.value;
|
||||
if (blockId === -1) {
|
||||
return {
|
||||
value: { id: blockId },
|
||||
size: results.size,
|
||||
};
|
||||
}
|
||||
|
||||
var cursor = offset + results.size;
|
||||
results = readByte(buffer, cursor);
|
||||
if (! results) return null;
|
||||
var itemCount = results.value;
|
||||
|
||||
cursor += results.size;
|
||||
results = readShort(buffer, cursor);
|
||||
if (! results) return null;
|
||||
var itemDamage = results.value;
|
||||
|
||||
cursor += results.size;
|
||||
results = readShort(buffer, cursor);
|
||||
if (! results) return null;
|
||||
var nbtDataSize = results.value;
|
||||
if (nbtDataSize === -1) nbtDataSize = 0;
|
||||
var nbtDataEnd = cursor + nbtDataSize;
|
||||
var nbtData = buffer.slice(cursor, nbtDataEnd);
|
||||
|
||||
return {
|
||||
value: {
|
||||
blockId: blockId,
|
||||
itemCount: itemCount,
|
||||
itemDamage: itemDamage,
|
||||
nbtData: nbtData,
|
||||
},
|
||||
size: nbtDataEnd - offset,
|
||||
};
|
||||
}
|
||||
|
||||
function StringWriter(value) {
|
||||
this.value = value;
|
||||
this.encoded = toUcs2.convert(value);
|
||||
@ -204,6 +288,7 @@ function createPacketBuffer(packetId, params) {
|
||||
function parsePacket(buffer) {
|
||||
if (buffer.length < 1) return null;
|
||||
var packetId = buffer.readUInt8(0);
|
||||
console.log("parsing packet " + packetId);
|
||||
var size = 1;
|
||||
var results = { id: packetId };
|
||||
var packetInfo = packets[packetId];
|
||||
|
114
packets.json
114
packets.json
@ -1,4 +1,10 @@
|
||||
{
|
||||
"0": [
|
||||
{
|
||||
"name": "keepAliveId",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
"1": [
|
||||
{
|
||||
"name": "entityId",
|
||||
@ -47,6 +53,114 @@
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
"3": [
|
||||
{
|
||||
"name": "message",
|
||||
"type": "string"
|
||||
}
|
||||
],
|
||||
"4": [
|
||||
{
|
||||
"name": "ageOfWorld",
|
||||
"type": "long"
|
||||
},
|
||||
{
|
||||
"name": "timeOfDay",
|
||||
"type": "long"
|
||||
}
|
||||
],
|
||||
"5": [
|
||||
{
|
||||
"name": "entityId",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"name": "slot",
|
||||
"type": "short"
|
||||
},
|
||||
{
|
||||
"name": "item",
|
||||
"type": "slot"
|
||||
}
|
||||
],
|
||||
"6": [
|
||||
{
|
||||
"name": "x",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"name": "y",
|
||||
"type": "int"
|
||||
},
|
||||
{
|
||||
"name": "z",
|
||||
"type": "int"
|
||||
}
|
||||
],
|
||||
"13": [
|
||||
{
|
||||
"name": "x",
|
||||
"type": "double"
|
||||
},
|
||||
{
|
||||
"name": "y",
|
||||
"type": "double"
|
||||
},
|
||||
{
|
||||
"name": "stance",
|
||||
"type": "double"
|
||||
},
|
||||
{
|
||||
"name": "z",
|
||||
"type": "double"
|
||||
},
|
||||
{
|
||||
"name": "yaw",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "pitch",
|
||||
"type": "float"
|
||||
},
|
||||
{
|
||||
"name": "onGround",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"16": [
|
||||
{
|
||||
"name": "slotId",
|
||||
"type": "short"
|
||||
}
|
||||
],
|
||||
"201": [
|
||||
{
|
||||
"name": "playerName",
|
||||
"type": "string"
|
||||
},
|
||||
{
|
||||
"name": "online",
|
||||
"type": "bool"
|
||||
},
|
||||
{
|
||||
"name": "ping",
|
||||
"type": "short"
|
||||
}
|
||||
],
|
||||
"202": [
|
||||
{
|
||||
"name": "flags",
|
||||
"type": "byte"
|
||||
},
|
||||
{
|
||||
"name": "flyingSpeed",
|
||||
"type": "byte"
|
||||
},
|
||||
{
|
||||
"name": "walkingSpeed",
|
||||
"type": "byte"
|
||||
}
|
||||
],
|
||||
"205": [
|
||||
{
|
||||
"name": "payload",
|
||||
|
Loading…
x
Reference in New Issue
Block a user