Skip to content

Commit

Permalink
Merge pull request #8 from SomeoneWeird/parsers
Browse files Browse the repository at this point in the history
more parsers + serialisers
  • Loading branch information
deoxxa committed Nov 9, 2012
2 parents 08e5fcd + d4a9a02 commit 70fed14
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/parser.js
Expand Up @@ -19,10 +19,12 @@ var Parser = module.exports = function Parser() {
case 0x0c: this.floatbe("yaw").floatbe("pitch").uint8("on_ground"); break;
case 0x0d: this.doublebe("x").doublebe("y").doublebe("stance").doublebe("z").floatbe("yaw").floatbe("pitch").uint8("on_ground"); break;
case 0x0e: this.uint8("status").int32be("x").uint8("y").int32be("z").uint8("face"); break;
case 0x0f: this.uint32be("x").uint8("y").uint32be("z").uint8("direction").mcslot("slot").uint8("curser_x").uint8("curser_y").uint8("curser_z"); break;
case 0x10: this.int16be("slot_id"); break;
case 0x12: this.uint32be("eid").uint8("animation"); break;
case 0x13: this.uint32be("eid").uint8("action"); break;
case 0x65: this.uint8("window_id"); break;
case 0x66: this.uint8("window_id").int16be("slot").uint8("button").int16be("action").uint8("shift").mcslot("item"); break;
case 0x6c: this.uint8("window_id").uint8("enchantment"); break;
case 0xca: this.uint8("flags").uint8("flying_speed").uint8("walking_speed"); break;
case 0xcc: this.mcstring16("locale").uint8("view_distance").uint8("chat_flags").uint8("difficulty").uint8("show_cape"); break;
Expand Down
46 changes: 43 additions & 3 deletions lib/serialiser.js
Expand Up @@ -97,7 +97,7 @@ S.prototype.mcslot = function mcslot(slot) {
if (slot.metadata) {
this.int16be(-1);
} else {
this.uint16be(slot.metdata.length).buffer(slot.metadata);
this.uint16be(slot.metadata.length).buffer(slot.metadata);
}

return this;
Expand Down Expand Up @@ -130,6 +130,11 @@ Serialiser.prototype.write = function write(packet) {
this.emit("data", S().uint8(packet.pid).mcstring16(packet.message).result());
break;
}

case 0x05: {
this.emit("data", S().uint8(packet.pid).int16be(packet.slot_number).mcslot(packet.slot).result());
break;
}

case 0x06: {
this.emit("data", S().uint8(packet.pid).int32be(packet.x).int32be(packet.y).int32be(packet.z).result());
Expand Down Expand Up @@ -166,6 +171,11 @@ Serialiser.prototype.write = function write(packet) {
break;
}

case 0x15: {
this.emit("data", S().uint8(packet.pid).mcslot(packet.slot).uint32be(packet.x).uint32be(packet.y).uint32be(packet.z).uint8(packet.rotation).uint8(packet.pitch).uint8(packet.roll).result());
break;
}

case 0x17: {
this.emit("data", S().uint8(packet.pid).uint32be(packet.eid).uint8(packet.type).uint(packet.x).uint(packet.y).uint(packet.z).uint(packet.data).uint16be(packet.speed_x).uint16be(packet.speed_y).uint16be(packet.speed_z).result());
break;
Expand All @@ -191,13 +201,43 @@ Serialiser.prototype.write = function write(packet) {
break;
}

case 0x64: {
this.emit("data", S().uint8(packet.pid).uint8(packet.window).uint8(packet.type).mcstring16(packet.title).uint8(packet.slots).result());
break;
}

case 0x65: {
this.emit("data", S().uint8(packet.pid).uint8(packet.window).result());
break;
}

case 0x67: {
this.emit("data", S().uint8(packet.pid).int8(-1).int16be(-1).result());
this.emit("data", S().uint8(packet.pid).int8(-1).int16be(packet.slot).mcslot(packet.data).result());
break;
}

case 0x68: {
this.emit("data", S().uint8(packet.pid).int8(0).int16be(0).result());
this.emit("data", S().uint8(packet.pid).int8(0).int16be(packet.count).mcslots(packet.slots).result());
break;
}

case 0x69: {
this.emit("data", S().uint8(packet.pid).uint8(packet.window).int16be(packet.property).int16be(packet.value).result());
break;
}

case 0x6b: {
this.emit("data", S().uint8(packet.pid).int16be(packet.slot).mcslot(packet.item).result());
break;
}

case 0xc8: {
this.emit("data", S().uint8(packet.pid).uint32be(packet.id).uint8(packet.amount).result());
break;
}

case 0xc9: {
this.emit("data", S().uint8(packet.pid).mcstring16(packet.name).uint8(packet.online).int16be(packet.ping).result());
break;
}

Expand Down

0 comments on commit 70fed14

Please sign in to comment.