From 0eef634aabdfa94aac86c56ef2b44b600d90aef9 Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Fri, 28 Dec 2018 19:30:05 +0000 Subject: [PATCH] Player: Give me ALLLLL your crashdumps I suspect this is going to cause a firestorm, but once it does we'll be able to see what needs fixing. --- src/pocketmine/Player.php | 132 ++++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 71 deletions(-) diff --git a/src/pocketmine/Player.php b/src/pocketmine/Player.php index 523096f85..188c2dde0 100644 --- a/src/pocketmine/Player.php +++ b/src/pocketmine/Player.php @@ -3398,92 +3398,82 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{ */ final public function close($message = "", string $reason = "generic reason", bool $notify = true) : void{ if($this->isConnected() and !$this->closed){ + if($notify and strlen($reason) > 0){ + $pk = new DisconnectPacket(); + $pk->message = $reason; + $this->directDataPacket($pk); + } + $this->interface->close($this, $notify ? $reason : ""); + $this->sessionAdapter = null; - try{ - if($notify and strlen($reason) > 0){ - $pk = new DisconnectPacket(); - $pk->message = $reason; - $this->directDataPacket($pk); + PermissionManager::getInstance()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); + PermissionManager::getInstance()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this); + + $this->stopSleep(); + + if($this->spawned){ + $ev = new PlayerQuitEvent($this, $message, $reason); + $ev->call(); + if($ev->getQuitMessage() != ""){ + $this->server->broadcastMessage($ev->getQuitMessage()); } - $this->interface->close($this, $notify ? $reason : ""); - $this->sessionAdapter = null; - PermissionManager::getInstance()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_USERS, $this); - PermissionManager::getInstance()->unsubscribeFromPermission(Server::BROADCAST_CHANNEL_ADMINISTRATIVE, $this); + $this->save(); + } - $this->stopSleep(); - - if($this->spawned){ - $ev = new PlayerQuitEvent($this, $message, $reason); - $ev->call(); - if($ev->getQuitMessage() != ""){ - $this->server->broadcastMessage($ev->getQuitMessage()); + if($this->isValid()){ + foreach($this->usedChunks as $index => $d){ + Level::getXZ($index, $chunkX, $chunkZ); + $this->level->unregisterChunkLoader($this, $chunkX, $chunkZ); + foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ + $entity->despawnFrom($this); } + unset($this->usedChunks[$index]); + } + } + $this->usedChunks = []; + $this->loadQueue = []; - try{ - $this->save(); - }catch(\Throwable $e){ - $this->server->getLogger()->critical("Failed to save player data for " . $this->getName()); - $this->server->getLogger()->logException($e); + if($this->loggedIn){ + $this->server->onPlayerLogout($this); + foreach($this->server->getOnlinePlayers() as $player){ + if(!$player->canSee($this)){ + $player->showPlayer($this); } } + $this->hiddenPlayers = []; + } - if($this->isValid()){ - foreach($this->usedChunks as $index => $d){ - Level::getXZ($index, $chunkX, $chunkZ); - $this->level->unregisterChunkLoader($this, $chunkX, $chunkZ); - foreach($this->level->getChunkEntities($chunkX, $chunkZ) as $entity){ - $entity->despawnFrom($this); - } - unset($this->usedChunks[$index]); - } - } - $this->usedChunks = []; - $this->loadQueue = []; + $this->removeAllWindows(true); + $this->windows = []; + $this->windowIndex = []; + $this->cursorInventory = null; + $this->craftingGrid = null; - if($this->loggedIn){ - $this->server->onPlayerLogout($this); - foreach($this->server->getOnlinePlayers() as $player){ - if(!$player->canSee($this)){ - $player->showPlayer($this); - } - } - $this->hiddenPlayers = []; - } + if($this->constructed){ + parent::close(); + } + $this->spawned = false; - $this->removeAllWindows(true); - $this->windows = []; - $this->windowIndex = []; - $this->cursorInventory = null; - $this->craftingGrid = null; + if($this->loggedIn){ + $this->loggedIn = false; + $this->server->removeOnlinePlayer($this); + } - if($this->constructed){ - parent::close(); - } - $this->spawned = false; + $this->server->removePlayer($this); - if($this->loggedIn){ - $this->loggedIn = false; - $this->server->removeOnlinePlayer($this); - } + $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logOut", [ + TextFormat::AQUA . $this->getName() . TextFormat::WHITE, + $this->ip, + $this->port, + $this->getServer()->getLanguage()->translateString($reason) + ])); - $this->server->getLogger()->info($this->getServer()->getLanguage()->translateString("pocketmine.player.logOut", [ - TextFormat::AQUA . $this->getName() . TextFormat::WHITE, - $this->ip, - $this->port, - $this->getServer()->getLanguage()->translateString($reason) - ])); + $this->spawnPosition = null; - $this->spawnPosition = null; - - if($this->perm !== null){ - $this->perm->clearPermissions(); - $this->perm = null; - } - }catch(\Throwable $e){ - $this->server->getLogger()->logException($e); - }finally{ - $this->server->removePlayer($this); + if($this->perm !== null){ + $this->perm->clearPermissions(); + $this->perm = null; } } }