more packets and parsers

This commit is contained in:
Andrew Kelley 2013-01-01 19:05:20 -05:00
parent f1da7b152b
commit 7aeea8a320
2 changed files with 271 additions and 2 deletions

View file

@ -70,7 +70,9 @@ var writers = {
var readers = {
'string': readString,
'byteArray': readByteArray,
'bigByteArray': readBigByteArray,
'short': readShort,
'ushort': readUShort,
'int': readInt,
'byte': readByte,
'ubyte': readUByte,
@ -84,6 +86,9 @@ var readers = {
'entityMetadata': readEntityMetadata,
'objectData': readObjectData,
'intArray': readIntArray,
'intVector': readIntVector,
'byteVector': readByteVector,
'byteVectorArray': readByteVectorArray,
};
function readIntArray(buffer, offset) {
@ -113,10 +118,45 @@ var entityMetadataReaders = {
3: readFloat,
4: readString,
5: readSlot,
6: readVector,
6: readIntVector,
};
function readVector(buffer, offset) {
function readByteVectorArray(buffer, offset) {
var results = readInt(buffer, offset);
if (! results) return null;
var count = results.value;
var cursor = offset + results.size;
var cursorEnd = cursor + 3 * count;
if (cursorEnd > buffer.length) return null;
var array = [];
for (var i = 0; i < count; ++i) {
array.push({
x: buffer.readInt8(cursor),
y: buffer.readInt8(cursor + 1),
z: buffer.readInt8(cursor + 2),
});
cursor += 3;
}
return {
value: array,
size: cursorEnd - offset,
};
}
function readByteVector(buffer, offset) {
if (offset + 3 > buffer.length) return null;
return {
value: {
x: buffer.readInt8(offset),
y: buffer.readInt8(offset + 1),
z: buffer.readInt8(offset + 2),
},
size: 3,
};
}
function readIntVector(buffer, offset) {
if (offset + 12 > buffer.length) return null;
return {
value: {
@ -261,6 +301,22 @@ function readByteArray (buffer, offset) {
};
}
function readBigByteArray(buffer, offset) {
var results = readInt(buffer, offset);
if (! results) return null;
var bytesBegin = offset + results.size;
var bytesSize = results.value;
var bytesEnd = bytesBegin + bytesSize;
if (bytesEnd > buffer.length) return null;
var bytes = buffer.slice(bytesBegin, bytesEnd);
return {
value: bytes,
size: bytesEnd - offset,
};
}
function readSlotArray (buffer, offset) {
var results = readShort(buffer, offset);
if (! results) return null;
@ -290,6 +346,15 @@ function readShort(buffer, offset) {
};
}
function readUShort(buffer, offset) {
if (offset + 2 > buffer.length) return null;
var value = buffer.readUInt16BE(offset);
return {
value: value,
size: 2,
};
}
function readInt(buffer, offset) {
if (offset + 4 > buffer.length) return null;
var value = buffer.readInt32BE(offset);

View file

@ -455,6 +455,54 @@
"type": "entityMetadata"
}
],
"25": [
{
"name": "entityId",
"type": "int"
},
{
"name": "title",
"type": "string"
},
{
"name": "x",
"type": "int"
},
{
"name": "y",
"type": "int"
},
{
"name": "z",
"type": "int"
},
{
"name": "direction",
"type": "int"
}
],
"26": [
{
"name": "entityId",
"type": "int"
},
{
"name": "x",
"type": "int"
},
{
"name": "y",
"type": "int"
},
{
"name": "z",
"type": "int"
},
{
"name": "count",
"type": "short"
}
],
"28": [
{
"name": "entityId",
@ -479,6 +527,12 @@
"type": "intArray"
}
],
"30": [
{
"name": "entityId",
"type": "int"
}
],
"31": [
{
"name": "entityId",
@ -603,6 +657,74 @@
"type": "entityMetadata"
}
],
"41": [
{
"name": "entityId",
"type": "int"
},
{
"name": "effectId",
"type": "byte"
},
{
"name": "amplifier",
"type": "byte"
},
{
"name": "duration",
"type": "short"
}
],
"42": [
{
"name": "entityId",
"type": "int"
},
{
"name": "effectId",
"type": "byte"
}
],
"43": [
{
"name": "experienceBar",
"type": "float"
},
{
"name": "level",
"type": "short"
},
{
"name": "totalExperience",
"type": "short"
}
],
"51": [
{
"name": "x",
"type": "int"
},
{
"name": "z",
"type": "int"
},
{
"name": "groundUpContinuous",
"type": "bool"
},
{
"name": "primaryBitMap",
"type": "ushort"
},
{
"name": "addBitMap",
"type": "ushort"
},
{
"name": "compressedData",
"type": "bigByteArray"
}
],
"52": [
{
"name": "chunkX",
@ -643,12 +765,94 @@
"type": "byte"
}
],
"54": [
{
"name": "x",
"type": "int"
},
{
"name": "y",
"type": "short"
},
{
"name": "z",
"type": "int"
},
{
"name": "byte1",
"type": "byte"
},
{
"name": "byte2",
"type": "byte"
},
{
"name": "blockId",
"type": "short"
}
],
"55": [
{
"name": "entityId",
"type": "int"
},
{
"name": "x",
"type": "int"
},
{
"name": "y",
"type": "int"
},
{
"name": "z",
"type": "int"
},
{
"name": "destroyStage",
"type": "byte"
}
],
"56": [
{
"name": "data",
"type": "mapChunkBulk"
}
],
"60": [
{
"name": "x",
"type": "double"
},
{
"name": "y",
"type": "double"
},
{
"name": "z",
"type": "double"
},
{
"name": "radius",
"type": "float"
},
{
"name": "affectedBlockOffsets",
"type": "byteVectorArray"
},
{
"name": "playerMotionX",
"type": "float"
},
{
"name": "playerMotionY",
"type": "float"
},
{
"name": "playerMotionZ",
"type": "float"
}
],
"61": [
{
"name": "effectId",