/** * @param ReplayInterface $replay * @param string $pathFolder * @param int $fileId * @param bool $saveFile * * @return string */ public function getBinary(ReplayInterface $replay, $pathFolder, $fileId, $saveFile = false) { $path = $pathFolder . '/' . $fileId; if (!is_file($path)) { return false; } $decodedKey = base64_decode($replay->getEncryptionKey()); $decodedKey = $this->decrypt($replay->getGameId(), $decodedKey); $keyframeBinary = file_get_contents($path); $decodedKeyframeBinary = gzdecode($this->decrypt($decodedKey, $keyframeBinary)); // File should saved only in development environment. // If parsing is needed, you have to do it in the ReplayDownloader::onReplayFileDecrypted() method if ($saveFile) { file_put_contents($pathFolder . '.decoded/' . $fileId, $decodedKeyframeBinary); } return $decodedKeyframeBinary; }
/** * @param ReplayInterface $replay */ public function updateMetas(ReplayInterface $replay) { // Download end game metas $endMetas = $this->client->getMetas($replay->getRegion(), $replay->getGameId()); $endMetas = json_decode($endMetas, true); // Update metas $metas = $replay->getMetas(); $metas['lastChunkId'] = $replay->getLastChunkId(); $metas['endGameChunkId'] = $replay->getLastChunkId(); $metas['lastKeyFrameId'] = $replay->getLastKeyframeId(); $metas['endGameKeyFrameId'] = $replay->getLastKeyframeId(); $metas['firstChunkId'] = $this->findFirstChunkId($metas); $metas['gameEnded'] = true; $metas['gameLength'] = $endMetas['gameLength']; // Update replay object $replay->setDuration(round($endMetas['gameLength'] / 1000)); $replay->setMetas($metas); // Save metas $this->saveMetas($replay); }
/** * Executed on success. Throws exception to stop the process, then failure handler will be thrown. * * @param ReplayInterface $replay * @param string $replayFolderPath */ public function onSuccess(OutputInterface $output, ReplayInterface $replay, $replayFolderPath) { $payload = ['foreignId' => (string) $replay->getGameId(), 'platformId' => (string) $replay->getRegion()]; $this->statsdClient->increment("replay.onSuccess"); $this->redisClient->publish("/interestmanager/extract", json_encode($payload)); }