PlayerPreLoginEvent: New, more elegant way to control authentication requirement

Previously the only way to deal with this was to cancel the PlayerKickEvent generated by lack of authentication. Now, plugins can decide whether auth should be required for a specific player. The default is whatever xbox-auth is set to in server.properties.

cc @Johnmacrocraft
This commit is contained in:
Dylan K. Taylor
2018-12-23 18:24:33 +00:00
parent f313d06070
commit 02efa93e3a
3 changed files with 30 additions and 8 deletions

View File

@ -59,6 +59,8 @@ class ProcessLoginTask extends AsyncTask{
* root public key.
*/
private $authenticated = false;
/** @var bool */
private $authRequired;
/**
* @var bool
@ -74,9 +76,10 @@ class ProcessLoginTask extends AsyncTask{
/** @var string|null */
private $handshakeJwt = null;
public function __construct(Player $player, LoginPacket $packet, bool $useEncryption = true){
public function __construct(Player $player, LoginPacket $packet, bool $authRequired, bool $useEncryption = true){
$this->storeLocal($player);
$this->packet = $packet;
$this->authRequired = $authRequired;
$this->useEncryption = $useEncryption;
if($useEncryption){
if(self::$SERVER_PRIVATE_KEY === null){
@ -220,7 +223,7 @@ class ProcessLoginTask extends AsyncTask{
$player = $this->fetchLocal();
if(!$player->isConnected()){
$this->worker->getLogger()->error("Player " . $player->getName() . " was disconnected before their login could be verified");
}elseif($player->setAuthenticationStatus($this->authenticated, $this->error)){
}elseif($player->setAuthenticationStatus($this->authenticated, $this->authRequired, $this->error)){
if(!$this->useEncryption){
$player->getNetworkSession()->onLoginSuccess();
}else{