Merge pull request #52 from onddo/some-proto-fixes

Some Minecraft Protocol fixes
This commit is contained in:
Andrew Kelley 2013-04-07 11:58:48 -07:00
commit 7ec4cfc2bf
2 changed files with 16 additions and 6 deletions

View file

@ -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);
}

View file

@ -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 {