mirror of
https://github.com/unmojang/node-minecraft-protocol.git
synced 2025-09-28 21:52:17 -04:00
Add some debug information (useful to update to an updated protocol)
This commit is contained in:
parent
f625cd8e8b
commit
d2435c8dcd
@ -140,6 +140,8 @@ srv.on('login', function(client) {
|
||||
console.log("client<-server: Error in packetId " + state + ".0x" + packetId.value.toString(16));
|
||||
console.log(buffer.toString('hex'));
|
||||
console.log(packetBuff.toString('hex'));
|
||||
console.log(buffer.length);
|
||||
console.log(packetBuff.length);
|
||||
}
|
||||
/*if (client.state == states.PLAY && brokenPackets.indexOf(packetId.value) !== -1)
|
||||
{
|
||||
|
@ -24,7 +24,14 @@ function generateFunctions(bufferReader,bufferWriter,size)
|
||||
};
|
||||
};
|
||||
var writer=function(value, buffer, offset) {
|
||||
buffer[bufferWriter](value, offset);
|
||||
try {
|
||||
buffer[bufferWriter](value, offset);
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
console.log("value:"+ value);
|
||||
throw err;
|
||||
}
|
||||
return offset + size;
|
||||
};
|
||||
return [reader, writer, size];
|
||||
|
@ -84,7 +84,16 @@ function writeContainer(value, buffer, offset, typeArgs, rootNode) {
|
||||
debug(new Error("Missing Property " + typeArgs.fields[index].name).stack);
|
||||
console.log(context);
|
||||
}
|
||||
offset = this.write(context[typeArgs.fields[index].name], buffer, offset, typeArgs.fields[index], rootNode);
|
||||
try {
|
||||
offset = this.write(context[typeArgs.fields[index].name], buffer, offset, typeArgs.fields[index], rootNode);
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
console.log("typeArgs : " + JSON.stringify(typeArgs.fields[index]));
|
||||
console.log("context : "+JSON.stringify(context));
|
||||
console.log("value : " + JSON.stringify(context[typeArgs.fields[index].name]));
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
rootNode.this = backupThis;;
|
||||
return offset;
|
||||
|
@ -16,9 +16,7 @@ NMProtocols.prototype.addTypes = function(types) {
|
||||
NMProtocols.prototype.read = function(buffer, cursor, fieldInfo, rootNodes) {
|
||||
var type = this.types[fieldInfo.type];
|
||||
if(!type) {
|
||||
return {
|
||||
error: new Error("missing data type: " + fieldInfo.type)
|
||||
};
|
||||
throw new Error("missing data type: " + fieldInfo.type);
|
||||
}
|
||||
var readResults = type[0].call(this, buffer, cursor, fieldInfo.typeArgs, rootNodes);
|
||||
if(readResults == null) {
|
||||
@ -31,9 +29,7 @@ NMProtocols.prototype.read = function(buffer, cursor, fieldInfo, rootNodes) {
|
||||
NMProtocols.prototype.write = function(value, buffer, offset, fieldInfo, rootNode) {
|
||||
var type = this.types[fieldInfo.type];
|
||||
if(!type) {
|
||||
return {
|
||||
error: new Error("missing data type: " + fieldInfo.type)
|
||||
};
|
||||
throw new Error("missing data type: " + fieldInfo.type);
|
||||
}
|
||||
return type[1].call(this, value, buffer, offset, fieldInfo.typeArgs, rootNode);
|
||||
};
|
||||
|
@ -84,13 +84,25 @@ function createPacketBuffer(packetId, state, params, isServer) {
|
||||
var buffer = new Buffer(size);
|
||||
var offset = 0;//utils.varint[1](length, buffer, 0);
|
||||
offset = utils.varint[1](packetId, buffer, offset);
|
||||
packet.forEach(function(fieldInfo) {
|
||||
var value = params[fieldInfo.name];
|
||||
// TODO : A better check is probably needed
|
||||
if(typeof value === "undefined" && fieldInfo.type != "count" && (fieldInfo.type != "condition" || evalCondition(fieldInfo.typeArgs, params)))
|
||||
debug(new Error("Missing Property " + fieldInfo.name).stack);
|
||||
offset = proto.write(value, buffer, offset, fieldInfo, params);
|
||||
});
|
||||
packet.forEach(function(fieldInfo) {
|
||||
var value = params[fieldInfo.name];
|
||||
// TODO : A better check is probably needed
|
||||
if(typeof value === "undefined" && fieldInfo.type != "count" && (fieldInfo.type != "condition" || evalCondition(fieldInfo.typeArgs, params)))
|
||||
debug(new Error("Missing Property " + fieldInfo.name).stack);
|
||||
|
||||
try {
|
||||
offset = proto.write(value, buffer, offset, fieldInfo, params);
|
||||
}
|
||||
catch(err)
|
||||
{
|
||||
console.log("Error in creating packet 0x"+packetId.toString(16)+" with params "+JSON.stringify(params));
|
||||
console.log("In particular :");
|
||||
|
||||
console.log("fieldInfo : " + JSON.stringify(fieldInfo));
|
||||
console.log("value : " + JSON.stringify(value));
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
return buffer;
|
||||
}
|
||||
|
||||
@ -139,7 +151,16 @@ function parsePacketData(buffer, state, isServer, packetsToParse = {"packet": tr
|
||||
var i, fieldInfo, readResults;
|
||||
for(i = 0; i < packetInfo.length; ++i) {
|
||||
fieldInfo = packetInfo[i];
|
||||
readResults = proto.read(buffer, cursor, fieldInfo, results);
|
||||
try {
|
||||
readResults = proto.read(buffer, cursor, fieldInfo, results);
|
||||
}
|
||||
catch(err) {
|
||||
console.log("Error in parsing packet 0x" + packetId.toString(16));
|
||||
console.log("In particular :");
|
||||
|
||||
console.log("fieldInfo : " + JSON.stringify(fieldInfo));
|
||||
throw err;
|
||||
}
|
||||
/* A deserializer cannot return null anymore. Besides, proto.read() returns
|
||||
* null when the condition is not fulfilled.
|
||||
if (!!!readResults) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user