Synapse\Synapse::handleDataPacket PHP Method

handleDataPacket() public method

public handleDataPacket ( synapse\network\protocol\spp\DataPacket $pk )
$pk synapse\network\protocol\spp\DataPacket
    public function handleDataPacket(DataPacket $pk)
    {
        $this->logger->debug("Received packet " . $pk::NETWORK_ID . " from {$this->serverIp}:{$this->port}");
        switch ($pk::NETWORK_ID) {
            case Info::DISCONNECT_PACKET:
                /** @var DisconnectPacket $pk */
                $this->verified = false;
                switch ($pk->type) {
                    case DisconnectPacket::TYPE_GENERIC:
                        $this->getLogger()->notice("Synapse Client has disconnected due to " . $pk->message);
                        $this->interface->reconnect();
                        break;
                    case DisconnectPacket::TYPE_WRONG_PROTOCOL:
                        $this->getLogger()->error($pk->message);
                        break;
                }
                break;
            case Info::INFORMATION_PACKET:
                /** @var InformationPacket $pk */
                switch ($pk->type) {
                    case InformationPacket::TYPE_LOGIN:
                        if ($pk->message == InformationPacket::INFO_LOGIN_SUCCESS) {
                            $this->logger->info("Login success to {$this->serverIp}:{$this->port}");
                            $this->verified = true;
                        } elseif ($pk->message == InformationPacket::INFO_LOGIN_FAILED) {
                            $this->logger->info("Login failed to {$this->serverIp}:{$this->port}");
                        }
                        break;
                    case InformationPacket::TYPE_CLIENT_DATA:
                        $this->clientData = json_decode($pk->message, true)["clientList"];
                        $this->lastRecvInfo = microtime();
                        break;
                }
                break;
            case Info::PLAYER_LOGIN_PACKET:
                /** @var PlayerLoginPacket $pk */
                $player = new Player($this->synLibInterface, mt_rand(0, PHP_INT_MAX), $pk->address, $pk->port);
                $player->setUniqueId($pk->uuid);
                $this->server->addPlayer(spl_object_hash($player), $player);
                $this->players[$pk->uuid->toBinary()] = $player;
                $player->handleLoginPacket($pk);
                break;
            case Info::REDIRECT_PACKET:
                /** @var RedirectPacket $pk */
                if (isset($this->players[$uuid = $pk->uuid->toBinary()])) {
                    $pk = $this->getPacket($pk->mcpeBuffer);
                    if ($pk != null) {
                        //drop unknown packet
                        $pk->decode();
                        $this->players[$uuid]->handleDataPacket($pk);
                    }
                }
                break;
            case Info::PLAYER_LOGOUT_PACKET:
                /** @var PlayerLogoutPacket $pk */
                if (isset($this->players[$uuid = $pk->uuid->toBinary()])) {
                    $this->players[$uuid]->close("", $pk->reason, false);
                    $this->removePlayer($this->players[$uuid]);
                }
                break;
        }
    }