mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-16 02:38:54 +00:00
Player: clean up handling of authentication
This commit is contained in:
parent
f3cf64c2cf
commit
7541a6070f
@ -187,6 +187,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
protected $randomClientId;
|
protected $randomClientId;
|
||||||
/** @var string */
|
/** @var string */
|
||||||
protected $xuid = "";
|
protected $xuid = "";
|
||||||
|
/** @var bool */
|
||||||
|
protected $authenticated = false;
|
||||||
|
|
||||||
protected $windowCnt = 2;
|
protected $windowCnt = 2;
|
||||||
/** @var int[] */
|
/** @var int[] */
|
||||||
@ -325,7 +327,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function isAuthenticated() : bool{
|
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->uuid = UUID::fromString($packet->clientUUID);
|
||||||
$this->rawUUID = $this->uuid->toBinary();
|
$this->rawUUID = $this->uuid->toBinary();
|
||||||
|
$this->xuid = $packet->xuid;
|
||||||
|
|
||||||
$this->setSkin($packet->skin);
|
$this->setSkin($packet->skin);
|
||||||
|
|
||||||
@ -1794,42 +1797,40 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
if(!$packet->skipVerification){
|
if(!$packet->skipVerification){
|
||||||
$this->server->getAsyncPool()->submitTask(new VerifyLoginTask($this, $packet));
|
$this->server->getAsyncPool()->submitTask(new VerifyLoginTask($this, $packet));
|
||||||
}else{
|
}else{
|
||||||
$this->onVerifyCompleted($packet, null, true);
|
$this->onVerifyCompleted(true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function onVerifyCompleted(LoginPacket $packet, ?string $error, bool $signedByMojang) : void{
|
public function onVerifyCompleted(bool $authenticated, ?string $error) : void{
|
||||||
if($this->closed){
|
if($this->closed){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if($authenticated and $this->xuid === ""){
|
||||||
|
$error = "Expected XUID but none found";
|
||||||
|
}
|
||||||
|
|
||||||
if($error !== null){
|
if($error !== null){
|
||||||
$this->close("", $this->server->getLanguage()->translateString("pocketmine.disconnect.invalidSession", [$error]));
|
$this->close("", $this->server->getLanguage()->translateString("pocketmine.disconnect.invalidSession", [$error]));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$xuid = $packet->xuid;
|
$this->authenticated = $authenticated;
|
||||||
|
|
||||||
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");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if(!$this->authenticated){
|
||||||
if($this->server->requiresAuthentication() and $this->kick("disconnectionScreen.notAuthenticated", false)){ //use kick to allow plugins to cancel this
|
if($this->server->requiresAuthentication() and $this->kick("disconnectionScreen.notAuthenticated", false)){ //use kick to allow plugins to cancel this
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->server->getLogger()->debug($this->getName() . " is NOT logged into Xbox Live");
|
$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{
|
}else{
|
||||||
$this->server->getLogger()->debug($this->getName() . " is logged into Xbox Live");
|
$this->server->getLogger()->debug($this->getName() . " is logged into Xbox Live");
|
||||||
$this->xuid = $xuid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: encryption
|
//TODO: encryption
|
||||||
|
@ -148,7 +148,7 @@ class VerifyLoginTask extends AsyncTask{
|
|||||||
if($player->isClosed()){
|
if($player->isClosed()){
|
||||||
$server->getLogger()->error("Player " . $player->getName() . " was disconnected before their login could be verified");
|
$server->getLogger()->error("Player " . $player->getName() . " was disconnected before their login could be verified");
|
||||||
}else{
|
}else{
|
||||||
$player->onVerifyCompleted($this->packet, $this->error, $this->authenticated);
|
$player->onVerifyCompleted($this->authenticated, $this->error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user