PocketMine / PocketMine-MP

Legacy PocketMine-MP repository. Head to https://github.com/pmmp for up to date software.
https://www.pocketmine.net/
GNU Lesser General Public License v3.0
1.26k stars 660 forks source link

Crash on PlayerPreLoginEvent #3609

Closed inxomnyaa closed 8 years ago

inxomnyaa commented 8 years ago

The server crashes when you do

public function onPlayerLogin(PlayerPreLoginEvent $event){
        $player = $event->getPlayer();
        $player->close("", "You are banned");
        $event->setCancelled();
    }

Crash: Fatal error: Call to a member function setHeldItemSlot() on null in phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Player__32bit.php on line 1772

Call Stack: 0.0176 408808 1. {main}() C:\Users\Administrator\Desktop\Server\MinecraftPE\PocketMine-MP\PocketMine-MP.phar:0 0.0199 403904 2. require('phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\Users\Administrator\Desktop\Server\MinecraftPE\PocketMine-MP\PocketMine-MP.phar:1 0.1494 543960 3. pocketmine\Server->construct() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php:464 15.3231 19858488 4. pocketmine\Server->start() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server32bit.php:1778 15.3401 19874568 5. pocketmine\Server->tickProcessor() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server32bit.php:2178 279.9903 19920744 6. pocketmine\Server->tick() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server32bit.php:2300 279.9905 19920808 7. pocketmine\network\Network->processInterfaces() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server32bit.php:2485 279.9905 19920808 8. pocketmine\network\RakLibInterface->process() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/network/Network.php:146 279.9905 19920840 9. raklib\server\ServerHandler->handlePacket() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/network/RakLibInterface.php:79 279.9911 19938504 10. pocketmine\network\RakLibInterface->handleEncapsulated() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/raklib/server/ServerHandler32bit.php:90 279.9913 19949336 11. pocketmine\Player->handleDataPacket() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/network/RakLibInterface.php:140 279.9914 19949488 12. pocketmine\network\Network->processBatch() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Player__32bit.php:1597 279.9918 19982912 13. pocketmine\Player->handleDataPacket() phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/network/Network.php:228

Extends #3574

PEMapModder commented 8 years ago

This is indeed an issue PocketMine can try to prevent, but, https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/Player.php#L1683 already closes the player, why would a plugin close the player in the first place?

inxomnyaa commented 8 years ago

EDIT: @PEMapModder Thanks, this closes some rumors. I don't know, its ReasonWL.

$event->setKickMessage("Timerban");
$event->setCancelled();

and using ->getPlayer()->kick(); instead of $event->setCancelled(); also crashes it. I changed it from playerloginevent to playerjoinevent, also crashes.. but still, thank you :+1: :)

inxomnyaa commented 8 years ago

Aaahh.. i know i saw something like that before.. https://github.com/PocketMine/PocketMine-MP/commit/5baa87e9febc7312406e8ca263af292136c01ad4 The crash happens since this branch is merged! Shouldn't the whole thing be near that: https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/Player.php#L1832-L1841

PEMapModder commented 8 years ago

@thebigsmileXD Player.php runs $this->close() if PlayerPreLoginEvent or PlayerLoginEvent is cancelled. As for PlayerJoinEvent, it is not cancellable at all.

5baa87e9febc7312406e8ca263af292136c01ad4 doesn't make $this->inventory null. The issue now is that $this->inventory is null.

inxomnyaa commented 8 years ago

Dang it, appears that i was on the code of TimerBan xD But well.. there should be a fix for that.