login event, jwt decoding

This commit is contained in:
mhsjlw 2016-06-15 06:53:00 -04:00
commit 1dc00237fa
3 changed files with 39 additions and 96 deletions

View file

@ -739,25 +739,13 @@
"packet_game_login": [
"container",
[
{
"name": "unknown",
"type": "i16"
},
{
"name": "protocol",
"type": "i64"
},
{
"name": "bodyLength",
"type": "i32"
},
{
"name": "chain",
"type": ["pstring", {"countType": "li32"}]
},
{
"name": "clientData",
"type": ["pstring", {"countType": "li32"}]
"name": "body",
"type": ["buffer",{"countType":"i32"}]
}
]
],

View file

@ -15,87 +15,10 @@ var server = pmp.createServer({
});
server.on('connection', function(client) {
//client.on("mcpe", packet => console.log(packet));
client.on("mcpe",packet => console.log(JSON.stringify(packet)));
client.on("game_login",packet => {
console.log(packet);
// client.writeMCPE("player_status",{
// status:0
// });
// client.writeMCPE('move_player', {
// entityId: [0,0],
// x: 1,
// y: 64 + 1.62,
// z: 1,
// yaw: 0,
// headYaw: 0,
// pitch: 0,
// mode: 0,
// onGround: 1
// });
//
// client.writeMCPE("start_game",{
// seed:-1,
// dimension:0,
// generator:1,
// gamemode:1,
// entityId:[0,0],
// spawnX:1,
// spawnY:1,
// spawnZ:1,
// x:0,
// y:1+1.62,
// z:0,
// isLoadedInCreative:false,
// dayCycleStopTime:0,
// eduMode:false,
// unknown:""
// });
//
// client.writeMCPE('set_spawn_position', {
// x: 1,
// y: 64,
// z: 1
// });
// client.writeMCPE("set_time",{
// time:0,
// started:1
// });
//
// client.writeMCPE('respawn', {
// x: 1,
// y: 64,
// z: 1
// });
// });
//
// client.on("request_chunk_radius",() => {
// client.writeMCPE('chunk_radius_update',{
// chunkRadius:1
// });
//
// for (let x = -1; x <=1; x++) {
// for (let z = -1; z <=1; z++) {
// client.writeBatch([{"name":"mcpe","params":{name:"full_chunk_data",params:{
// chunkX: x,
// chunkZ: z,
// order: 1,
// chunk_data:fs.readFileSync(__dirname+"/chunk")
// }}}]);
// }
// }
//
// client.writeMCPE('player_status', {
// status: 3
// });
//
// client.writeMCPE('set_time', {
// time: 0,
// started: 1
// });
client.on("login", data => {
console.log(client.displayName + '(' + client.XUID + ') ' + ' joined the game');
});
client.on('error', function(err) {

View file

@ -1,10 +1,16 @@
const raknet = require('raknet');
const zlib = require('zlib');
const ProtoDef = require('protodef').ProtoDef;
const batchProto=new ProtoDef();
const jwt = require('jwt-simple');
const batchProto = new ProtoDef();
batchProto.addTypes(require("./datatypes/minecraft"));
batchProto.addType("insideBatch",["endOfArray",{"type":["buffer",{"countType":"i32"}]}]);
const dataProto = new ProtoDef();
dataProto.addType("data_chain", [ "container", [ { "name":"chain", "type":[ "pstring", { "countType":"li32" } ] }, { "name":"clientData", "type":[ "pstring", { "countType":"li32" } ] } ] ]);
const secret = 'MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE8ELkixyLcwlZryUQcu1TvPOmI2B7vX83ndnWRUaXm74wFfa5f/lwQNTfrLVHa2PmenpGI6JhIMUJaWZrjmMj90NoKNFSNBuKdm8rYiXsfaz3K36x/1U26HpG0ZxK/V1V';
function createServer(options) {
options = options || {};
var port = options.port != null ?
@ -26,7 +32,33 @@ function createServer(options) {
server.on("connection", function (client) {
client.on("mcpe",packet => client.emit(packet.name,packet.params));
client.writeMCPE=(name,packet) => {
client.on("game_login", packet => {
var body = packet.body;
var body2 = zlib.inflateSync(body);
var parsed = dataProto.parsePacketBuffer("data_chain", body2);
parsed.data.chain = JSON.parse(parsed.data.chain);
var clientData = parsed.data.clientData;
var chain1 = parsed.data.chain.chain[0];
var chain2 = parsed.data.chain.chain[1].replace('\n', '');
var decode1 = jwt.decode(chain1, secret, 'ES384');
var nextKey1 = decode1.identityPublicKey;
var decode2 = jwt.decode(chain2, nextKey1, 'ES384');
var nextKey2 = decode2.identityPublicKey;
var clientDecode = jwt.decode(clientData, nextKey1, 'ES384');
client.randomId = clientDecode.ClientRandomId;
client.skinData = clientDecode.SkinData;
client.skinId = clientDecode.SkinId
client.identity = decode2.extraData.identity;
client.displayName = decode2.extraData.displayName;
client.XUID = decode2.extraData.XUID;
client.emit('login', {displayName: client.displayName, randomId: client.randomId, skinData: client.skinData, skinId: client.skinId, identity: client.identity, XUID: client.XUID})
});
client.writeMCPE = (name,packet) => {
client.writeEncapsulated("mcpe",{
name:name,
params:packet