58 private \Closure $playerInfoConsumer,
59 private \Closure $authCallback
62 public function handleLogin(
LoginPacket $packet) : bool{
65 if(!Player::isValidUserName($extraData->displayName)){
66 $this->session->disconnectWithError(KnownTranslationFactory::disconnectionScreen_invalidName());
71 $clientData = $this->parseClientData($packet->clientDataJwt);
74 $skin = $this->session->getTypeConverter()->getSkinAdapter()->fromSkinData(ClientDataToSkinDataHelper::fromClientData($clientData));
76 $this->session->disconnectWithError(
77 reason:
"Invalid skin: " . $e->getMessage(),
78 disconnectScreenMessage: KnownTranslationFactory::disconnectionScreen_invalidSkin()
84 if(!Uuid::isValid($extraData->identity)){
85 throw new PacketHandlingException(
"Invalid login UUID");
87 $uuid = Uuid::fromString($extraData->identity);
88 $arrClientData = (array) $clientData;
89 $arrClientData[
"TitleID"] = $extraData->titleId;
91 if($extraData->XUID !==
""){
92 $playerInfo = new XboxLivePlayerInfo(
94 $extraData->displayName,
97 $clientData->LanguageCode,
101 $playerInfo = new PlayerInfo(
102 $extraData->displayName,
105 $clientData->LanguageCode,
109 ($this->playerInfoConsumer)($playerInfo);
113 $this->session->getIp(),
114 $this->session->getPort(),
115 $this->server->requiresAuthentication()
117 if($this->server->getNetwork()->getValidConnectionCount() > $this->server->getMaxPlayers()){
118 $ev->setKickFlag(PlayerPreLoginEvent::KICK_FLAG_SERVER_FULL, KnownTranslationFactory::disconnectionScreen_serverFull());
120 if(!$this->server->isWhitelisted($playerInfo->getUsername())){
121 $ev->setKickFlag(PlayerPreLoginEvent::KICK_FLAG_SERVER_WHITELISTED, KnownTranslationFactory::pocketmine_disconnect_whitelisted());
125 if(($banEntry = $this->server->getNameBans()->getEntry($playerInfo->getUsername())) !==
null){
126 $banReason = $banEntry->getReason();
127 $banMessage = $banReason ===
"" ? KnownTranslationFactory::pocketmine_disconnect_ban_noReason() : KnownTranslationFactory::pocketmine_disconnect_ban($banReason);
128 }elseif(($banEntry = $this->
server->getIPBans()->getEntry($this->session->getIp())) !==
null){
129 $banReason = $banEntry->getReason();
130 $banMessage = KnownTranslationFactory::pocketmine_disconnect_ban($banReason !==
"" ? $banReason : KnownTranslationFactory::pocketmine_disconnect_ban_ip());
132 if($banMessage !==
null){
133 $ev->setKickFlag(PlayerPreLoginEvent::KICK_FLAG_BANNED, $banMessage);
137 if(!$ev->isAllowed()){
138 $this->session->disconnect($ev->getFinalDisconnectReason(), $ev->getFinalDisconnectScreenMessage());
142 $this->processLogin($packet, $ev->isAuthRequired());
153 foreach($chain->chain as $jwt){
158 throw PacketHandlingException::wrap($e);
160 if(isset($claims[
"extraData"])){
161 if($extraData !==
null){
165 if(!is_array($claims[
"extraData"])){
168 $mapper = new \JsonMapper();
169 $mapper->bEnforceMapType =
false;
170 $mapper->bExceptionOnMissingData =
true;
171 $mapper->bExceptionOnUndefinedProperty =
true;
172 $mapper->bStrictObjectTypeChecking =
true;
176 }
catch(\JsonMapper_Exception $e){
177 throw PacketHandlingException::wrap($e);
181 if($extraData ===
null){
192 [, $clientDataClaims, ] =
JwtUtils::parse($clientDataJwt);
194 throw PacketHandlingException::wrap($e);
197 $mapper = new \JsonMapper();
198 $mapper->bEnforceMapType =
false;
199 $mapper->bExceptionOnMissingData =
true;
200 $mapper->bExceptionOnUndefinedProperty =
true;
201 $mapper->bStrictObjectTypeChecking =
true;
203 $clientData = $mapper->map($clientDataClaims,
new ClientData());
204 }
catch(\JsonMapper_Exception $e){
205 throw PacketHandlingException::wrap($e);
217 $this->
server->getAsyncPool()->submitTask(new
ProcessLoginTask($packet->chainDataJwt->chain, $packet->clientDataJwt, $authRequired, $this->authCallback));
218 $this->session->setHandler(
null);