diff --git a/index.js b/index.js index 296f4d7..5f67fdb 100644 --- a/index.js +++ b/index.js @@ -8,6 +8,7 @@ var EventEmitter = require('events').EventEmitter , protocol = require('./lib/protocol') , Client = require('./lib/client') , Server = require('./lib/server') + , debug = protocol.debug module.exports = { createClient: createClient, @@ -261,12 +262,12 @@ function createClient(options) { return } - var hash = crypto.createHash('sha1'); - hash.update(packet.serverId); - if (haveCredentials) { joinServerRequest(onJoinServerResponse); } else { + if (packet.serverId != '-') { + debug('This server appears to be an online server and you are providing no password, the authentication will probably fail'); + } sendEncryptionKeyResponse(); } @@ -280,6 +281,8 @@ function createClient(options) { } function joinServerRequest(cb) { + var hash = crypto.createHash('sha1'); + hash.update(packet.serverId); hash.update(sharedSecret); hash.update(packet.publicKey); @@ -363,7 +366,7 @@ function mcHexDigest(hash) { newByte = ~value & 0xff; if (carry) { carry = newByte === 0xff; - buffer.writeUInt8(newByte + 1, i); + buffer.writeUInt8((newByte + 1) & 0xff, i); } else { buffer.writeUInt8(newByte, i); } diff --git a/lib/protocol.js b/lib/protocol.js index 21be784..0958be1 100644 --- a/lib/protocol.js +++ b/lib/protocol.js @@ -776,16 +776,22 @@ function readEntityMetadata(buffer, offset) { key = item & 0x1f; type = item >> 5; typeName = entityMetadataTypes[type]; + debug("Reading entity metadata type " + type + " (" + ( typeName || "unknown" ) + ")"); + if (!typeName) { + return { + error: new Error("unrecognized entity metadata type " + type) + } + } dataType = types[typeName]; if (!dataType) { return { - error: new Error("unrecognized entity metadata type " + type) + error: new Error("unrecognized entity metadata type name " + typeName) } } reader = dataType[0]; if (!reader) { return { - error: new Error("missing reader for entity metadata type " + type) + error: new Error("missing reader for entity metadata type name " + typeName) } } results = reader(buffer, cursor); @@ -1088,6 +1094,7 @@ function readSlot(buffer, offset) { var nbtDataSize = buffer.readInt16BE(cursor + 3); if (nbtDataSize === -1) nbtDataSize = 0; var nbtDataEnd = cursorEnd + nbtDataSize; + if (nbtDataEnd > buffer.length) return null; var nbtData = buffer.slice(cursorEnd, nbtDataEnd); return {