'Method not allowed']); exit; } if (empty($_SESSION['access_token'])) { echo json_encode(['reauth' => true]); exit; } if (($_SESSION['token_expires'] ?? 0) <= time()) { echo json_encode(['reauth' => true]); exit; } $reportCode = preg_replace('/[^a-zA-Z0-9]/', '', $_POST['report_code'] ?? ''); $fightId = (int)($_POST['fight_id'] ?? 0); $startTime = (float)($_POST['start_time'] ?? 0); $endTime = (float)($_POST['end_time'] ?? 0); $playerName = trim($_POST['player_name'] ?? ''); $eventType = trim($_POST['event_type'] ?? ''); $abilityId = (int)($_POST['ability_id'] ?? 0); $limit = max(1, min(500, (int)($_POST['limit'] ?? 20))); $startOffset = (float)($_POST['start_offset'] ?? 0) * 1000; // s → ms $endOffset = isset($_POST['end_offset']) && $_POST['end_offset'] !== '' ? (float)$_POST['end_offset'] * 1000 : null; $allowedTypes = ['DamageTaken', 'DamageDone', 'Healing', 'Casts', 'Buffs', 'Deaths']; $dataType = in_array($_POST['data_type'] ?? '', $allowedTypes) ? $_POST['data_type'] : 'DamageTaken'; if (!$reportCode || !$fightId) { http_response_code(400); echo json_encode(['error' => 'Missing params']); exit; } $queryStart = $startTime + $startOffset; $queryEnd = $endOffset !== null ? $startTime + $endOffset : $endTime; $queryEnd = min($queryEnd, $endTime); $token = $_SESSION['access_token']; function dbg_gql(string $query): array { global $token; $ch = curl_init(GRAPHQL_URI); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode(['query' => $query]), CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => ['Content-Type: application/json', 'Authorization: Bearer ' . $token], CURLOPT_SSL_VERIFYPEER => !DEV_MODE, ]); $body = curl_exec($ch); curl_close($ch); return json_decode($body, true) ?? []; } // Resolve player name → actor IDs (source + target) $playerIds = []; if ($playerName !== '') { $pd = dbg_gql(<< 0 && (int)($ev['abilityGameID'] ?? 0) !== $abilityId) continue; if (!empty($playerIds)) { $srcId = (int)($ev['sourceID'] ?? -1); $tgtId = (int)($ev['targetID'] ?? -1); if (!in_array($srcId, $playerIds) && !in_array($tgtId, $playerIds)) continue; } $filtered[] = $ev; if (count($filtered) >= $limit) break; } echo json_encode([ 'data_type' => $dataType, 'event_type' => $eventType ?: null, 'ability_id' => $abilityId ?: null, 'player_name' => $playerName ?: null, 'player_ids' => $playerIds ?: null, 'time_range' => [ 'from_ms' => (int)$queryStart, 'to_ms' => (int)$queryEnd, ], 'total_before_limit' => count($events), 'count' => count($filtered), 'events' => $filtered, ], JSON_PRETTY_PRINT);