raklib\server\ServerHandler::handlePacket PHP Method

handlePacket() public method

public handlePacket ( ) : boolean
return boolean
    public function handlePacket()
    {
        if (strlen($packet = $this->server->readThreadToMainPacket()) > 0) {
            $id = ord($packet[0]);
            $offset = 1;
            if ($id === RakLib::PACKET_ENCAPSULATED) {
                $len = ord($packet[$offset++]);
                $identifier = substr($packet, $offset, $len);
                $offset += $len;
                $flags = ord($packet[$offset++]);
                $buffer = substr($packet, $offset);
                $this->instance->handleEncapsulated($identifier, EncapsulatedPacket::fromBinary($buffer, true), $flags);
            } elseif ($id === RakLib::PACKET_RAW) {
                $len = ord($packet[$offset++]);
                $address = substr($packet, $offset, $len);
                $offset += $len;
                $port = Binary::readShort(substr($packet, $offset, 2));
                $offset += 2;
                $payload = substr($packet, $offset);
                $this->instance->handleRaw($address, $port, $payload);
            } elseif ($id === RakLib::PACKET_SET_OPTION) {
                $len = ord($packet[$offset++]);
                $name = substr($packet, $offset, $len);
                $offset += $len;
                $value = substr($packet, $offset);
                $this->instance->handleOption($name, $value);
            } elseif ($id === RakLib::PACKET_OPEN_SESSION) {
                $len = ord($packet[$offset++]);
                $identifier = substr($packet, $offset, $len);
                $offset += $len;
                $len = ord($packet[$offset++]);
                $address = substr($packet, $offset, $len);
                $offset += $len;
                $port = Binary::readShort(substr($packet, $offset, 2));
                $offset += 2;
                $clientID = Binary::readLong(substr($packet, $offset, 8));
                $this->instance->openSession($identifier, $address, $port, $clientID);
            } elseif ($id === RakLib::PACKET_CLOSE_SESSION) {
                $len = ord($packet[$offset++]);
                $identifier = substr($packet, $offset, $len);
                $offset += $len;
                $len = ord($packet[$offset++]);
                $reason = substr($packet, $offset, $len);
                $this->instance->closeSession($identifier, $reason);
            } elseif ($id === RakLib::PACKET_INVALID_SESSION) {
                $len = ord($packet[$offset++]);
                $identifier = substr($packet, $offset, $len);
                $this->instance->closeSession($identifier, "Invalid session");
            } elseif ($id === RakLib::PACKET_ACK_NOTIFICATION) {
                $len = ord($packet[$offset++]);
                $identifier = substr($packet, $offset, $len);
                $offset += $len;
                $identifierACK = Binary::readInt(substr($packet, $offset, 4));
                $this->instance->notifyACK($identifier, $identifierACK);
            }
            return true;
        }
        return false;
    }

Usage Example

 public function process()
 {
     $work = \false;
     if ($this->interface->handlePacket()) {
         $work = \true;
         while ($this->interface->handlePacket()) {
         }
     }
     $this->doTick();
     return $work;
 }
All Usage Examples Of raklib\server\ServerHandler::handlePacket