Merge pull request #208 from rom1504/better_error_and_fix_from_1.9

Better error and fix from 1.9
This commit is contained in:
Robin Lambertz 2015-08-08 14:53:23 +02:00
commit 9eeea84e92
4 changed files with 21 additions and 8 deletions

View file

@ -1,6 +1,6 @@
machine:
environment:
MC_SERVER_JAR: /home/ubuntu/node-minecraft-protocol/minecraft-server/minecraft_server.1.8.3.jar
MC_SERVER_JAR: /home/ubuntu/node-minecraft-protocol/minecraft-server/minecraft_server.jar
node:
version: 0.10.28
java:

View file

@ -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)
{
@ -159,6 +161,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);
}
});
targetClient.on('end', function() {
@ -167,9 +171,10 @@ srv.on('login', function(client) {
if(!endedClient)
client.end("End");
});
targetClient.on('error', function() {
targetClient.on('error', function(err) {
endedTargetClient = true;
console.log('Connection error by server', '(' + addr + ')');
console.log('Connection error by server', '(' + addr + ') ',err);
console.log(err.stack);
if(!endedClient)
client.end("Error");
});

View file

@ -174,6 +174,14 @@ for(var n in entityMetadataTypes) {
entityMetadataTypeBytes[entityMetadataTypes[n].type] = n;
}
// container is ambiguous
function findByte(type,value)
{
if(type!="container")
return entityMetadataTypeBytes[type];
return value["x"]===undefined ? 7 : 6;
}
function readEntityMetadata(buffer, offset) {
var cursor = offset;
@ -214,7 +222,7 @@ function readEntityMetadata(buffer, offset) {
function writeEntityMetadata(value, buffer, offset) {
var self = this;
value.forEach(function(item) {
var type = entityMetadataTypeBytes[item.type];
var type = findByte(item.type,item.value);
var headerByte = (type << 5) | item.key;
buffer.writeUInt8(headerByte, offset);
offset += 1;
@ -230,7 +238,7 @@ function sizeOfEntityMetadata(value) {
var item;
for(var i = 0; i < value.length; ++i) {
item = value[i];
size += this.sizeOf(item.value, entityMetadataTypes[entityMetadataTypeBytes[item.type]], {});
size += this.sizeOf(item.value, entityMetadataTypes[findByte(item.type,item.value)], {});
}
return size;
}

View file

@ -546,9 +546,9 @@ describe("mc-server", function() {
assert.ok(results.latency <= 1000);
delete results.latency;
assert.deepEqual(results, {
version: { //TODO : Make this dynamic, based on protocol.version
name: "1.8.1",
protocol: 47
version: {
name: mc.minecraftVersion,
protocol: mc.version
},
players: {
max: 120,