Skip to content

Instantly share code, notes, and snippets.

@brandon15811
Created January 13, 2013 17:59
Show Gist options
  • Save brandon15811/4525332 to your computer and use it in GitHub Desktop.
Save brandon15811/4525332 to your computer and use it in GitHub Desktop.
MCPE Packet Examples
var packet = require('../packet').packet;
var dgram = require('dgram');
var client = dgram.createSocket("udp4");
client.bind(19135);
type = new Buffer(process.argv['2'], 'hex').readUInt8(0);
switch (type)
{
case 0x02:
hex='02000000000000191c00ffff00fefefefefdfdfdfd12345678';
break;
case 0x1c:
hex= '1c000000000019d3f01718612f9080423b00ffff00fefefefefdfdfdfd12345678002e4d434350503b44656d6f3b50485020536572766572205b5320302f32305d20202054686973206973206120576f72';
break;
case 0x05:
hex = '0500ffff00fefefefefdfdfdfd1234567805000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';
break;
case 0x06:
hex = '0600ffff00fefefefefdfdfdfd123456781718612f9080423b0005b8';
break;
case 0x07:
hex = '0700ffff00fefefefefdfdfdfd12345678043f57fe6d4abe05d4ffffffffec9e1144';
break;
case 0x08:
hex = '0800ffff00fefefefefdfdfdfd123456781718612f9080423bbcbc05b800';
break;
case 0xc0:
if (process.argv['3'] == 'multiple')
{
//Multiple ACKS
hex = 'c00001001f0200220200';
}
else
{
hex = 'c0000101000000';
}
break;
//Add NACK
case checkData(type):
dataType = new Buffer(process.argv['3'], 'hex').readUInt8(0);
switch(dataType)
{
case 0x82:
hex = '840300004000900200008200074272616e646f6e0000000800000008';
break;
case 0x83:
hex = '800100000000288300000000';
break;
case 0x84:
hex = '840a00004000100500008401';
break;
case 0x85:
hex = '843800000000c085001557656c636f6d6520746f2050485020536572766572';
break;
case 0x86:
hex = '844100000000288600001022';
break;
case 0x87:
hex = '840200000000e887c70f83e100000000000000010000000242fd09e242900000430682cc';
break;
case 0x88:
hex = '88f616004000e8707802880000465e00000020437e80004290000042a50000f8000000212c017f';
break;
case 0x89:
hex = '802613000001a88900000000b009ffbd00074272616e646f6e0000002c0000000000000000000000002000000000c00000000000000000000000007f';
break;
case 0x8a:
hex = '84071e00400068c6ec028a000051b9ffffffffb92744b4';
break;
case 0x8c:
hex = '800809004000e058f7008c00010ccb504206a52342953135432f4ad9000107d9fdfae891d7af';
break;
case 0x8d:
hex = '80290a004000285611018d00010ccc';
break;
case 0x8e:
hex = '883d13004000c8dc00028e00010cdb002501000042db96d742ae6d6c433d511afa19fb';
break;
case 0x8f:
hex = '809304004000487a46008f0000001900000018';
break;
}
break;
}
msg = new Buffer(hex, 'hex');
console.log(packet.decode(new Buffer(hex, 'hex')));
client.send(msg, 0, msg.length, 19135, '192.168.1.141');
setTimeout(function()
{
client.close();
}, 10)
function checkData(type)
{
if (type >= 0x80 && type <= 0x8f)
{
return type;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment