superjoe30/node-minecraft-protocol — pull request #69 by roblabla (2014-01-05 17:28:40+00:00)
Title: Feature mc1.7

We all know having too much time is deadly.

This is a fix for #66 , 1.7 support for node-minecraft-protocol. Featuring a cool new chat client in the examples.

Here are some thoughts I had during the development of this patch :
Minecraft protocol currently sends a lot of data as arrays, with a count prefix. Our current solution is to create a new parser for each array. It's a bit messy, and I think instead, we might as well create something along those lines :

```javascript
0x01: [
{ name: "serverId", type: "string" },
{ name: "countPublicKey", type: "short" },
{ name: "publicKey", type: "byte", count: "countPublicKey" },
{ name: "countVerifyToken", type: "short" },
{ name: "verifyToken", type: "byte", count: "countVerifyToken" }
]
```

We would still need a tiny bit of boilerplate (if type is byte, then output it as buffer instead of array) but it would be a lot less code, and much cleaner code, than what we have right now. It would allow complex structures to be easily parsable. Also, might need a container type.

```javascript
0x26: [
{ name: "columnCount", type: "short" },
{ name: "dataCount", type: "int" },
{ name: "skylight", type: "bool" },
{ name: "data", type: "byte", count: "dataCount" },
{ name: "meta", type: "array", count: "columnCount", contents: [
{ name: "chunkX", type: "int" },
{ name: "chunkZ", type: "int" },
{ name: "bitMap", type: "short" },
{ name: "addBitMap", type: "short" }
]}
]
```

Since right now, MC Protocol gives us the length-prefix, I thought it might be a good idea to do opportunistic parsing. Right now, every parser is ran for every packets, even if there are no listeners. I didn't code that in yet because... well... I thought about it a little late, but performance should jump straight up if we were to implement such a feature.

Currently, longs are stored in an array, since they are too big to fit in a JavaScript Number. I think it might be a good idea to instead use a BigNumber library to store them in. I know node-minecraft-protocol strives to stay a low-level implementation, but seriously, manipulating a long as an array is just a headache. Luckily the minecraft protocol doesn't use longs all that much. But for instance time updates, which uses them, are a headache to parse right now.