top 10 scores (GET) ?api=submit -> file a score (POST: name, score, wave, kills) Scores are persisted to pb_records.json next to this file. If you open the file without PHP, the game still runs fully — the record book just falls back to localStorage. ============================================================ */ $scoresFile = __DIR__ . '/pb_records.json'; if (isset($_GET['api'])) { header('Content-Type: application/json; charset=utf-8'); header('Cache-Control: no-store'); $records = array(); if (is_file($scoresFile)) { $records = json_decode((string)file_get_contents($scoresFile), true); if (!is_array($records)) $records = array(); } $rank = function (array $r) { usort($r, function ($a, $b) { return $b['score'] - $a['score']; }); return array_slice($r, 0, 10); }; if ($_GET['api'] === 'records') { echo json_encode($rank($records)); exit; } if ($_GET['api'] === 'submit' && $_SERVER['REQUEST_METHOD'] === 'POST') { $name = strtoupper(substr(preg_replace('/[^A-Za-z0-9]/', '', (string)($_POST['name'] ?? '')), 0, 6)); $score = max(0, min(99999999, (int)($_POST['score'] ?? 0))); $wave = max(0, min(9999, (int)($_POST['wave'] ?? 0))); $kills = max(0, min(999999, (int)($_POST['kills'] ?? 0))); if ($name === '') $name = '???'; $records[] = array('name' => $name, 'score' => $score, 'wave' => $wave, 'kills' => $kills, 'ts' => time()); @file_put_contents($scoresFile, json_encode($records, JSON_PRETTY_PRINT)); echo json_encode($rank($records)); exit; } http_response_code(404); echo json_encode(array('error' => 'unknown api')); exit; } ?>
P / ESC — RESUME
| # | NAME | SCORE | WAVE |
|---|