public function decode() { parent::decode(); $this->clientID = Binary::readLong($this->get(8)); $this->sendPing = Binary::readLong($this->get(8)); $this->useSecurity = \ord($this->get(1)) > 0; }
public function decode() { parent::decode(); $this->clientID = Binary::readLong($this->get(8)); $this->session = Binary::readLong($this->get(8)); $this->unknown = $this->get(1); }
public function decode() { parent::decode(); $this->offset += 16; //Magic $this->getAddress($this->serverAddress, $this->serverPort); $this->mtuSize = \unpack("n", $this->get(2))[1]; $this->clientID = Binary::readLong($this->get(8)); }
public function decode() { parent::decode(); $this->pingID = Binary::readLong($this->get(8)); $this->serverID = Binary::readLong($this->get(8)); $this->offset += 16; //magic $this->serverName = $this->getString(); }
public function decode() { parent::decode(); $this->offset += 16; //Magic $this->serverID = Binary::readLong($this->get(8)); \ord($this->get(1)); //security $this->mtuSize = \unpack("n", $this->get(2))[1]; }
public function decode() { parent::decode(); $this->offset += 16; //Magic $this->serverID = Binary::readLong($this->get(8)); $this->clientPort = unpack("n", $this->get(2))[1]; $this->mtuSize = unpack("n", $this->get(2))[1]; //server security }
public function decode() { parent::decode(); $this->getAddress($this->address, $this->port); for ($i = 0; $i < 10; ++$i) { $this->getAddress($addr, $port, $version); $this->systemAddresses[$i] = [$addr, $port, $version]; } $this->sendPing = Binary::readLong($this->get(8)); $this->sendPong = Binary::readLong($this->get(8)); }
public function decode() { parent::decode(); $this->cookie = $this->get(4); $this->security = $this->get(1); $this->port = unpack("n", $this->get(2))[1]; $this->dataArray0 = $this->get(ord($this->get(1))); $this->dataArray = $this->getDataArray(9); $this->timestamp = $this->get(2); $this->session2 = Binary::readLong($this->get(8)); $this->session = Binary::readLong($this->get(8)); }
public function decode() { parent::decode(); $this->pingID = Binary::readLong($this->get(8)); }
/** * @return bool */ 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 = unpack("n", substr($packet, $offset, 2))[1]; $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 = unpack("n", substr($packet, $offset, 2))[1]; $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 = PHP_INT_SIZE === 8 ? unpack("N", substr($packet, $offset, 4))[1] << 32 >> 32 : unpack("N", substr($packet, $offset, 4))[1]; $this->instance->notifyACK($identifier, $identifierACK); } return true; } return false; }
protected function getLong($signed = \true) { return Binary::readLong($this->get(8), $signed); }
protected function handleEncapsulatedPacketRoute(EncapsulatedPacket $packet) { if ($this->sessionManager === null) { return; } $id = ord($packet->buffer[0]); if ($id < 0x80) { //internal data packet if ($this->state === self::STATE_CONNECTING_2) { if ($id === CLIENT_CONNECT_DataPacket::$ID) { $dataPacket = new CLIENT_CONNECT_DataPacket(); $dataPacket->buffer = $packet->buffer; $dataPacket->decode(); $pk = new SERVER_HANDSHAKE_DataPacket(); $pk->port = $this->port; $pk->session = $dataPacket->session; $pk->session2 = Binary::readLong("D\v©"); $pk->encode(); $sendPacket = new EncapsulatedPacket(); $sendPacket->reliability = 0; $sendPacket->buffer = $pk->buffer; $this->addToQueue($sendPacket, RakLib::PRIORITY_IMMEDIATE); } elseif ($id === CLIENT_HANDSHAKE_DataPacket::$ID) { $dataPacket = new CLIENT_HANDSHAKE_DataPacket(); $dataPacket->buffer = $packet->buffer; $dataPacket->decode(); if ($dataPacket->port === $this->sessionManager->getPort() or !$this->sessionManager->portChecking) { $this->state = self::STATE_CONNECTED; //FINALLY! $this->sessionManager->openSession($this); foreach ($this->preJoinQueue as $p) { $this->sessionManager->streamEncapsulated($this, $p); } $this->preJoinQueue = []; } } } elseif ($id === CLIENT_DISCONNECT_DataPacket::$ID) { $this->disconnect("client disconnect"); } elseif ($id === PING_DataPacket::$ID) { $dataPacket = new PING_DataPacket(); $dataPacket->buffer = $packet->buffer; $dataPacket->decode(); $pk = new PONG_DataPacket(); $pk->pingID = $dataPacket->pingID; $pk->encode(); $sendPacket = new EncapsulatedPacket(); $sendPacket->reliability = 0; $sendPacket->buffer = $pk->buffer; $this->addToQueue($sendPacket); } //TODO: add PING/PONG (0x00/0x03) automatic latency measure } elseif ($this->state === self::STATE_CONNECTED) { $this->sessionManager->streamEncapsulated($this, $packet); //TODO: split packet handling //TODO: stream channels } else { $this->preJoinQueue[] = $packet; } }