private function handleEncapsulatedPacketRoute(EncapsulatedPacket $packet) { if ($this->sessionManager === null) { return; } if ($packet->hasSplit) { if ($this->state === self::STATE_CONNECTED) { $this->handleSplit($packet); } 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->address = $this->address; $pk->port = $this->port; $pk->sendPing = $dataPacket->sendPing; $pk->sendPong = bcadd($pk->sendPing, "1000"); $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->isTemporal = false; $this->sessionManager->openSession($this); } } } 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: stream channels } }
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; } }