From f88be868fd81d5806ec7d425e5e8cecd08958a76 Mon Sep 17 00:00:00 2001 From: Keegan Date: Sun, 6 Mar 2016 07:34:53 -0500 Subject: [PATCH] start datatypes --- README.md | 12 ++++++------ data/protocol.json | 12 +++++++++--- index.js | 2 +- src/datatypes.js | 28 ++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 10 deletions(-) create mode 100644 src/datatypes.js diff --git a/README.md b/README.md index 227d458..1c1c314 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -pocket-minecraft-protocol +pocket-minecraft-protocol ========================= [![NPM version](https://img.shields.io/npm/v/pocket-minecraft-protocol.svg)](http://npmjs.com/package/pocket-minecraft-protocol) @@ -7,21 +7,21 @@ pocket-minecraft-protocol Parse and serialize Minecraft PE packets. ## Features - + * Supports Minecraft PE `0.14.0` - * Pure javascript + * Pure JavaScript * Easily send and listen for any packet - * RakNet support through node-raknet + * RakNet support through [node-raknet](https://github.com/mhsjlw/node-raknet) ## Installation Simply run npm install pocket-minecraft-protcol - + Then view our `examples` for inspiration! ## Contributors This project is run by these guys: - [mhsjlw](https://github.com/mhsjlw) ([mhsjlw@aol.com](mailto:mhsjlw@aol.com)) - - [rom1504](https://github.com/rom1504) \ No newline at end of file + - [rom1504](https://github.com/rom1504) diff --git a/data/protocol.json b/data/protocol.json index 6551c6c..7595a7c 100644 --- a/data/protocol.json +++ b/data/protocol.json @@ -1,5 +1,11 @@ { "types": { + "string": [ + "pstring" + { + "countType":"short" + } + ], "packet": [ "container", [ @@ -223,7 +229,7 @@ }, { "name": "payload", - "type": "byte_array" + "type":["buffer",{"countType":"i16"}] } ] ], @@ -1135,7 +1141,7 @@ }, { "name": "chunk_data", - "type": "byte_array" + "type":["buffer",{"countType":"i16"}] } ] ], @@ -1210,4 +1216,4 @@ ] ] } -} \ No newline at end of file +} diff --git a/index.js b/index.js index 08a522a..ed39ab5 100644 --- a/index.js +++ b/index.js @@ -1 +1 @@ -module.exports = require('./dist/index.js'); \ No newline at end of file +module.exports = require('./index.js'); diff --git a/src/datatypes.js b/src/datatypes.js new file mode 100644 index 0000000..9dac09a --- /dev/null +++ b/src/datatypes.js @@ -0,0 +1,28 @@ +function readUUID(buffer, offset) { + if(offset+16>buffer.length) + throw new PartialReadError(); + return { + value: UUID.stringify(buffer.slice(offset,16+offset)), + size: 16 + }; +} + +function writeUUID(value, buffer, offset) { + const buf=UUID.parse(value); + buf.copy(buffer,offset); + return offset + 16; +} + +module.exports = { + 'uuid': [readUUID, writeUUID, 16], // done + 'vector3': [readVector3, writeVector3, sizeOfVector3] + + 'metadatadictionary': [readLTriad, writeLTriad, 3], + 'skin': [readIpAddress, writeIpAddress, 4], + 'entitylocations': [readRestBuffer, writeRestBuffer, sizeOfRestBuffer], + 'blockrecords':[readEndOfArray,writeEndOfArray,sizeOfEndOfArray], + 'records':[readToByte,writeToByte,sizeOfToByte], + 'playerattributes': [], + 'item': [], + 'blockcoordinates': [] +};