mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-29 22:23:21 -04:00
more protocol.js fixes
This commit is contained in:
parent
db4c25883e
commit
c45c4d3cf4
@ -306,9 +306,8 @@ var packets = {
|
|||||||
multi_block_change: {id: 0x22, fields: [
|
multi_block_change: {id: 0x22, fields: [
|
||||||
{ name: "chunkX", type: "int" },
|
{ name: "chunkX", type: "int" },
|
||||||
{ name: "chunkZ", type: "int" },
|
{ name: "chunkZ", type: "int" },
|
||||||
{ name: "recordCount", type: "varint" },
|
{ name: "recordCount", type: "count", typeArgs: { type: "varint", countFor: "records" } },
|
||||||
/* TODO: Is dataLength needed? */
|
{ name: "records", type: "array", typeArgs: { count: "recordCount", type: "container", typeArgs: { fields: [
|
||||||
{ name: "records", type: "array", typeArgs: { count: "recordsCount", type: "container", typeArgs: { fields: [
|
|
||||||
{ name: "horizontalPos", type: "ubyte" },
|
{ name: "horizontalPos", type: "ubyte" },
|
||||||
{ name: "y", type: "ubyte" },
|
{ name: "y", type: "ubyte" },
|
||||||
{ name: "blockId", type: "varint" }
|
{ name: "blockId", type: "varint" }
|
||||||
@ -883,6 +882,11 @@ var entityMetadataTypes = {
|
|||||||
{ name: 'x', type: 'int' },
|
{ name: 'x', type: 'int' },
|
||||||
{ name: 'y', type: 'int' },
|
{ name: 'y', type: 'int' },
|
||||||
{ name: 'z', type: 'int' }
|
{ name: 'z', type: 'int' }
|
||||||
|
]}},
|
||||||
|
7: { type: 'container', typeArgs: { fields: [
|
||||||
|
{ name: 'pitch', type: 'float' },
|
||||||
|
{ name: 'yaw', type: 'float' },
|
||||||
|
{ name: 'roll', type: 'float' }
|
||||||
]}}
|
]}}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -942,7 +946,7 @@ function readEntityMetadata(buffer, offset) {
|
|||||||
type = item >> 5;
|
type = item >> 5;
|
||||||
dataType = entityMetadataTypes[type];
|
dataType = entityMetadataTypes[type];
|
||||||
typeName = dataType.type;
|
typeName = dataType.type;
|
||||||
debug("Reading entity metadata type " + dataType + " (" + ( typeName || "unknown" ) + ")");
|
//debug("Reading entity metadata type " + dataType + " (" + ( typeName || "unknown" ) + ")");
|
||||||
if (!dataType) {
|
if (!dataType) {
|
||||||
return {
|
return {
|
||||||
error: new Error("unrecognized entity metadata type " + type)
|
error: new Error("unrecognized entity metadata type " + type)
|
||||||
@ -1099,36 +1103,30 @@ function readSlot(buffer, offset) {
|
|||||||
var results = readShort(buffer, offset);
|
var results = readShort(buffer, offset);
|
||||||
if (! results) return null;
|
if (! results) return null;
|
||||||
value.blockId = results.value;
|
value.blockId = results.value;
|
||||||
var cursor = offset + results.size;
|
|
||||||
|
|
||||||
if (value.blockId === -1) {
|
if (value.blockId === -1) {
|
||||||
return {
|
return {
|
||||||
value: value,
|
value: value,
|
||||||
size: cursor - offset,
|
size: 2,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
var cursorEnd = cursor + 4;
|
var cursorEnd = offset + 6;
|
||||||
if (cursorEnd > buffer.length) return null;
|
if (cursorEnd > buffer.length) return null;
|
||||||
value.itemCount = buffer.readInt8(cursor);
|
value.itemCount = buffer.readInt8(offset + 2);
|
||||||
value.itemDamage = buffer.readInt16BE(cursor + 1);
|
value.itemDamage = buffer.readInt16BE(offset + 3);
|
||||||
var nbtData = buffer.readInt8(cursor + 3);
|
var nbtData = buffer.readInt8(offset + 5);
|
||||||
if (nbtData == 0) {
|
if (nbtData == 0) {
|
||||||
return {
|
return {
|
||||||
value: value,
|
value: value,
|
||||||
size: cursor + 4 - offset
|
size: 6
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var nbtData = readNbt(buffer, offset);
|
var nbtData = readNbt(buffer, offset + 5);
|
||||||
|
value.nbtData = nbtData.value;
|
||||||
return {
|
return {
|
||||||
value: {
|
value: value,
|
||||||
id: blockId,
|
size: nbtData.size + 5
|
||||||
itemCount: itemCount,
|
|
||||||
itemDamage: itemDamage,
|
|
||||||
nbtData: nbtData,
|
|
||||||
},
|
|
||||||
size: nbtDataEnd - offset,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1296,11 +1294,15 @@ function readContainer(buffer, offset, typeArgs, rootNode) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function writeContainer(value, buffer, offset, typeArgs, rootNode) {
|
function writeContainer(value, buffer, offset, typeArgs, rootNode) {
|
||||||
|
var context = value.this ? value.this : value;
|
||||||
rootNode.this = value;
|
rootNode.this = value;
|
||||||
for (var index in typeArgs.fields) {
|
for (var index in typeArgs.fields) {
|
||||||
if (!value.hasOwnProperty(typeArgs.fields[index].name && typeArgs.fields[index].type != "count" && !typeArgs.fields[index].condition))
|
if (!context.hasOwnProperty(typeArgs.fields[index].name) && typeArgs.fields[index].type != "count" && !typeArgs.fields[index].condition)
|
||||||
|
{
|
||||||
debug(new Error("Missing Property " + typeArgs.fields[index].name).stack);
|
debug(new Error("Missing Property " + typeArgs.fields[index].name).stack);
|
||||||
offset = write(value[typeArgs.fields[index].name], buffer, offset, typeArgs.fields[index], rootNode);
|
console.log(context);
|
||||||
|
}
|
||||||
|
offset = write(context[typeArgs.fields[index].name], buffer, offset, typeArgs.fields[index], rootNode);
|
||||||
}
|
}
|
||||||
delete rootNode.this;
|
delete rootNode.this;
|
||||||
return offset;
|
return offset;
|
||||||
@ -1308,9 +1310,10 @@ function writeContainer(value, buffer, offset, typeArgs, rootNode) {
|
|||||||
|
|
||||||
function sizeOfContainer(value, typeArgs, rootNode) {
|
function sizeOfContainer(value, typeArgs, rootNode) {
|
||||||
var size = 0;
|
var size = 0;
|
||||||
|
var context = value.this ? value.this : value;
|
||||||
rootNode.this = value;
|
rootNode.this = value;
|
||||||
for (var index in typeArgs.fields) {
|
for (var index in typeArgs.fields) {
|
||||||
size += sizeOf(value[typeArgs.fields[index].name], typeArgs.fields[index], rootNode);
|
size += sizeOf(context[typeArgs.fields[index].name], typeArgs.fields[index], rootNode);
|
||||||
}
|
}
|
||||||
delete rootNode.this;
|
delete rootNode.this;
|
||||||
return size;
|
return size;
|
||||||
@ -1471,7 +1474,13 @@ function createPacketBuffer(packetId, state, params, isServer) {
|
|||||||
var packet = get(packetId, state, !isServer);
|
var packet = get(packetId, state, !isServer);
|
||||||
assert.notEqual(packet, null);
|
assert.notEqual(packet, null);
|
||||||
packet.forEach(function(fieldInfo) {
|
packet.forEach(function(fieldInfo) {
|
||||||
|
try {
|
||||||
length += sizeOf(params[fieldInfo.name], fieldInfo, params);
|
length += sizeOf(params[fieldInfo.name], fieldInfo, params);
|
||||||
|
} catch (e) {
|
||||||
|
console.log(`fieldInfo : ${JSON.stringify(fieldInfo)}`);
|
||||||
|
console.log(`params : ${JSON.stringify(params)}`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
length += sizeOfVarInt(packetId);
|
length += sizeOfVarInt(packetId);
|
||||||
var size = length;// + sizeOfVarInt(length);
|
var size = length;// + sizeOfVarInt(length);
|
||||||
@ -1569,6 +1578,8 @@ function parsePacketData(buffer, state, isServer, packetsToParse) {
|
|||||||
results[fieldInfo.name] = readResults.value;
|
results[fieldInfo.name] = readResults.value;
|
||||||
cursor += readResults.size;
|
cursor += readResults.size;
|
||||||
}
|
}
|
||||||
|
if (buffer.length > cursor)
|
||||||
|
console.log("DID NOT PARSE THE WHOLE THING!");
|
||||||
debug(results);
|
debug(results);
|
||||||
return {
|
return {
|
||||||
results: results,
|
results: results,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user