mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 13:25:16 +00:00
122 lines
3.1 KiB
PHP
122 lines
3.1 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
namespace pocketmine\network\mcpe\protocol;
|
|
|
|
#include <rules/DataPacket.h>
|
|
|
|
|
|
use pocketmine\network\mcpe\NetworkSession;
|
|
|
|
class LoginPacket extends DataPacket{
|
|
const NETWORK_ID = ProtocolInfo::LOGIN_PACKET;
|
|
|
|
const EDITION_POCKET = 0;
|
|
|
|
public $username;
|
|
public $protocol;
|
|
public $gameEdition;
|
|
public $clientUUID;
|
|
public $clientId;
|
|
public $identityPublicKey;
|
|
public $serverAddress;
|
|
|
|
public $skinId;
|
|
public $skin = "";
|
|
|
|
public $clientData = [];
|
|
|
|
public function canBeBatched() : bool{
|
|
return false;
|
|
}
|
|
|
|
public function canBeSentBeforeLogin() : bool{
|
|
return true;
|
|
}
|
|
|
|
public function decode(){
|
|
$this->protocol = $this->getInt();
|
|
|
|
if($this->protocol !== ProtocolInfo::CURRENT_PROTOCOL){
|
|
$this->buffer = null;
|
|
return; //Do not attempt to decode for non-accepted protocols
|
|
}
|
|
|
|
$this->gameEdition = $this->getByte();
|
|
|
|
$str = $this->getString();
|
|
|
|
//TODO: remove this hack once the protocol gets bumped
|
|
if($str{0} === "\x78"){
|
|
try{
|
|
$str = zlib_decode($str, 1024 * 1024 * 64);
|
|
$this->protocol = 0;
|
|
$this->buffer = null; // <= 1.1.0.4
|
|
return;
|
|
}catch(\ErrorException $e){
|
|
// >= 1.1.0.5
|
|
}
|
|
}
|
|
|
|
$this->setBuffer($str, 0);
|
|
|
|
$chainData = json_decode($this->get($this->getLInt()));
|
|
foreach($chainData->{"chain"} as $chain){
|
|
$webtoken = $this->decodeToken($chain);
|
|
if(isset($webtoken["extraData"])){
|
|
if(isset($webtoken["extraData"]["displayName"])){
|
|
$this->username = $webtoken["extraData"]["displayName"];
|
|
}
|
|
if(isset($webtoken["extraData"]["identity"])){
|
|
$this->clientUUID = $webtoken["extraData"]["identity"];
|
|
}
|
|
if(isset($webtoken["identityPublicKey"])){
|
|
$this->identityPublicKey = $webtoken["identityPublicKey"];
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->clientData = $this->decodeToken($this->get($this->getLInt()));
|
|
|
|
$this->clientId = $this->clientData["ClientRandomId"] ?? null;
|
|
$this->serverAddress = $this->clientData["ServerAddress"] ?? null;
|
|
$this->skinId = $this->clientData["SkinId"] ?? null;
|
|
|
|
if(isset($this->clientData["SkinData"])){
|
|
$this->skin = base64_decode($this->clientData["SkinData"]);
|
|
}
|
|
}
|
|
|
|
public function encode(){
|
|
|
|
}
|
|
|
|
public function decodeToken($token){
|
|
$tokens = explode(".", $token);
|
|
list($headB64, $payloadB64, $sigB64) = $tokens;
|
|
|
|
return json_decode(base64_decode($payloadB64), true);
|
|
}
|
|
|
|
public function handle(NetworkSession $session) : bool{
|
|
return $session->handleLogin($this);
|
|
}
|
|
} |