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); } }