public function receiveStream()
{
if (\strlen($packet = $this->server->readMainToThreadPacket()) > 0) {
$id = \ord($packet[0]);
$offset = 1;
if ($id === RakLib::PACKET_ENCAPSULATED) {
$len = \ord($packet[$offset++]);
$identifier = \substr($packet, $offset, $len);
$offset += $len;
if (isset($this->sessions[$identifier])) {
$flags = \ord($packet[$offset++]);
$buffer = \substr($packet, $offset);
$this->sessions[$identifier]->addEncapsulatedToQueue(EncapsulatedPacket::fromBinary($buffer, \true), $flags);
} else {
$this->streamInvalid($identifier);
}
} elseif ($id === RakLib::PACKET_RAW) {
$len = \ord($packet[$offset++]);
$address = \substr($packet, $offset, $len);
$offset += $len;
$port = \unpack("n", \substr($packet, $offset, 2))[1];
$offset += 2;
$payload = \substr($packet, $offset);
$this->socket->writePacket($payload, $address, $port);
} elseif ($id === RakLib::PACKET_CLOSE_SESSION) {
$len = \ord($packet[$offset++]);
$identifier = \substr($packet, $offset, $len);
if (isset($this->sessions[$identifier])) {
$this->removeSession($this->sessions[$identifier]);
} else {
$this->streamInvalid($identifier);
}
} elseif ($id === RakLib::PACKET_INVALID_SESSION) {
$len = \ord($packet[$offset++]);
$identifier = \substr($packet, $offset, $len);
if (isset($this->sessions[$identifier])) {
$this->removeSession($this->sessions[$identifier]);
}
} elseif ($id === RakLib::PACKET_SET_OPTION) {
$len = \ord($packet[$offset++]);
$name = \substr($packet, $offset, $len);
$offset += $len;
$value = \substr($packet, $offset);
switch ($name) {
case "name":
$this->name = $value;
break;
case "portChecking":
$this->portChecking = (bool) $value;
break;
case "packetLimit":
$this->packetLimit = (int) $value;
break;
}
} elseif ($id === RakLib::PACKET_BLOCK_ADDRESS) {
$len = \ord($packet[$offset++]);
$address = \substr($packet, $offset, $len);
$offset += $len;
$timeout = \PHP_INT_SIZE === 8 ? \unpack("N", \substr($packet, $offset, 4))[1] << 32 >> 32 : \unpack("N", \substr($packet, $offset, 4))[1];
$this->blockAddress($address, $timeout);
} elseif ($id === RakLib::PACKET_SHUTDOWN) {
foreach ($this->sessions as $session) {
$this->removeSession($session);
}
$this->socket->close();
$this->shutdown = \true;
} elseif ($id === RakLib::PACKET_EMERGENCY_SHUTDOWN) {
$this->shutdown = \true;
} else {
return \false;
}
return \true;
}
return \false;
}