From 7541a6070fdda8d3f3a5e6a3e844aba15bff392f Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 27 Jul 2018 18:04:13 +0100 Subject: [PATCH] Player: clean up handling of authentication --- src/pocketmine/Player.php | 31 ++++++++++--------- .../network/mcpe/VerifyLoginTask.php | 2 +- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 391ecc881..eb52c3e65 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -187,6 +187,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ protected $randomClientId; /** @var string */ protected $xuid = ""; + /** @var bool */ + protected $authenticated = false; protected $windowCnt = 2; /** @var int[] */ @@ -325,7 +327,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ } public function isAuthenticated() : bool{ - return $this->xuid !== ""; + return $this->authenticated; } /** @@ -1765,6 +1767,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ $this->uuid = UUID::fromString($packet->clientUUID); $this->rawUUID = $this->uuid->toBinary(); + $this->xuid = $packet->xuid; $this->setSkin($packet->skin); @@ -1794,42 +1797,40 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ if(!$packet->skipVerification){ $this->server->getAsyncPool()->submitTask(new VerifyLoginTask($this, $packet)); }else{ - $this->onVerifyCompleted($packet, null, true); + $this->onVerifyCompleted(true, null); } return true; } - public function onVerifyCompleted(LoginPacket $packet, ?string $error, bool $signedByMojang) : void{ + public function onVerifyCompleted(bool $authenticated, ?string $error) : void{ if($this->closed){ return; } + if($authenticated and $this->xuid === ""){ + $error = "Expected XUID but none found"; + } + if($error !== null){ $this->close("", $this->server->getLanguage()->translateString("pocketmine.disconnect.invalidSession", [$error])); return; } - $xuid = $packet->xuid; - - if(!$signedByMojang and $xuid !== ""){ - $this->server->getLogger()->warning($this->getName() . " has an XUID, but their login keychain is not signed by Mojang"); - $xuid = ""; - } - - if($xuid === "" or !is_string($xuid)){ - if($signedByMojang){ - $this->server->getLogger()->error($this->getName() . " should have an XUID, but none found"); - } + $this->authenticated = $authenticated; + if(!$this->authenticated){ if($this->server->requiresAuthentication() and $this->kick("disconnectionScreen.notAuthenticated", false)){ //use kick to allow plugins to cancel this return; } $this->server->getLogger()->debug($this->getName() . " is NOT logged into Xbox Live"); + if($this->xuid !== ""){ + $this->server->getLogger()->warning($this->getName() . " has an XUID, but their login keychain is not signed by Mojang"); + $this->xuid = ""; + } }else{ $this->server->getLogger()->debug($this->getName() . " is logged into Xbox Live"); - $this->xuid = $xuid; } //TODO: encryption diff --git a/src/pocketmine/network/mcpe/VerifyLoginTask.php b/src/pocketmine/network/mcpe/VerifyLoginTask.php index a509e35ef..06cf93594 100644 --- a/src/pocketmine/network/mcpe/VerifyLoginTask.php +++ b/src/pocketmine/network/mcpe/VerifyLoginTask.php @@ -148,7 +148,7 @@ class VerifyLoginTask extends AsyncTask{ if($player->isClosed()){ $server->getLogger()->error("Player " . $player->getName() . " was disconnected before their login could be verified"); }else{ - $player->onVerifyCompleted($this->packet, $this->error, $this->authenticated); + $player->onVerifyCompleted($this->authenticated, $this->error); } } }