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 canBeSentBeforeLogin() : bool{ return true; } public function decodePayload(){ $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(); $this->setBuffer($this->getString(), 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 encodePayload(){ //TODO } public function decodeToken($token){ list($headB64, $payloadB64, $sigB64) = explode(".", $token); return json_decode(base64_decode($payloadB64), true); } public function handle(NetworkSession $session) : bool{ return $session->handleLogin($this); } }