mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 05:35:56 -04:00
readCondition now return value==null when the condition is not met instead of returning null (when read returns null it means there was an error), check if value is null in readContainer and parsePacketData and don't include it if so, improve "field x missing" error message in test.js a bit
This commit is contained in:
parent
63b332ce38
commit
04a3f72130
@ -123,7 +123,7 @@ for (var n in entityMetadataTypes) {
|
||||
function readCondition(buffer,offset,typeArgs, rootNode)
|
||||
{
|
||||
if(!evalCondition(typeArgs,rootNode))
|
||||
return null;
|
||||
return { value: null, size: 0 };
|
||||
return read(buffer, offset, { type: typeArgs.type, typeArgs:typeArgs.typeArgs }, rootNode);
|
||||
}
|
||||
|
||||
@ -546,7 +546,7 @@ function readContainer(buffer, offset, typeArgs, rootNode) {
|
||||
rootNode.this = results.value;
|
||||
for (var index in typeArgs.fields) {
|
||||
var readResults = read(buffer, offset, typeArgs.fields[index], rootNode);
|
||||
if (readResults == null) { continue; }
|
||||
if (readResults == null || readResults.value==null) { continue; }
|
||||
results.size += readResults.size;
|
||||
offset += readResults.size;
|
||||
results.value[typeArgs.fields[index].name] = readResults.value;
|
||||
@ -680,7 +680,7 @@ function read(buffer, cursor, fieldInfo, rootNodes) {
|
||||
};
|
||||
}
|
||||
var readResults = type[0](buffer, cursor, fieldInfo.typeArgs, rootNodes);
|
||||
if (readResults == null && fieldInfo.type!=="condition") {
|
||||
if (readResults == null) {
|
||||
throw new Error("Reader returned null : " + JSON.stringify(fieldInfo));
|
||||
}
|
||||
if (readResults && readResults.error) return { error: readResults.error };
|
||||
@ -829,7 +829,7 @@ function parsePacketData(buffer, state, isServer, packetsToParse) {
|
||||
results: results
|
||||
};
|
||||
}*/
|
||||
if (readResults === null) continue;
|
||||
if (readResults === null || readResults.value==null) continue;
|
||||
if (readResults.error) {
|
||||
return readResults;
|
||||
}
|
||||
|
@ -213,10 +213,10 @@ describe("packets", function() {
|
||||
});
|
||||
var field;
|
||||
for (field in p1) {
|
||||
assert.ok(field in p2, "field " + field + " missing in p2");
|
||||
assert.ok(field in p2, "field " + field + " missing in p2, in p1 it has value "+JSON.stringify(p1[field]));
|
||||
}
|
||||
for (field in p2) {
|
||||
assert.ok(field in p1, "field " + field + " missing in p1");
|
||||
assert.ok(field in p1, "field " + field + " missing in p1, in p2 it has value "+JSON.stringify(p2[field]));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user