Fix leaderboards / chatroom

This commit is contained in:
2025-08-25 16:32:40 -07:00
parent 8761c74966
commit 6cca4e1a31
3 changed files with 77 additions and 11 deletions

View File

@@ -5,15 +5,35 @@ checkClientDatabaseVersion();
$conn = newConnection();
$stmt = $conn->prepare("
SELECT c.id AS chat_id, c.content, u.username, u.icon, u.overlay, u.id AS user_id, u.birdColor, u.overlayColor, c.deleted_at
SELECT c.id AS chat_id, c.content, c.deleted_at, u.id AS user_id, u.username, u.save_data
FROM chats c
JOIN users u ON c.userId = u.id
WHERE u.banned = 0
ORDER BY c.id DESC LIMIT 50
ORDER BY c.id DESC
LIMIT 50
");
$stmt->execute();
$result = $stmt->get_result();
echo encrypt(json_encode(array_reverse(array_map(fn($row) => ['username' => $row['username'], 'userid' => $row['user_id'], 'content' => (int)$row['deleted_at'] == 0 ? $row['content'] : null, 'deleted' => (int)$row['deleted_at'] != 0, 'id' => $row['chat_id'], 'icon' => $row['icon'], 'overlay' => $row['overlay'], 'birdColor' => json_decode($row['birdColor']), 'overlayColor' => json_decode($row['overlayColor'])], $result->fetch_all(MYSQLI_ASSOC)))));
$result = $stmt->get_result();
$rows = $result->fetch_all(MYSQLI_ASSOC);
$mapped = [];
foreach ($rows as $row) {
$savedata = json_decode($row['save_data'], true);
$mapped[] = [
'username' => $row['username'],
'userid' => $row['user_id'],
'content' => (int)$row['deleted_at'] == 0 ? $row['content'] : null,
'deleted' => (int)$row['deleted_at'] != 0,
'id' => $row['chat_id'],
'icon' => $savedata['bird']['icon'] ?? 1,
'overlay' => $savedata['bird']['overlay'] ?? 0,
'birdColor' => $savedata['settings']['colors']['icon'] ?? [255,255,255],
'overlayColor' => $savedata['settings']['colors']['overlay'] ?? [255,255,255],
];
}
echo encrypt(json_encode(array_reverse($mapped)));
$conn->close();

View File

@@ -26,11 +26,36 @@ if ($request_type === "0") {
exitWithMessage(json_encode([]));
}
$stmt = $conn->prepare("SELECT username, `$request_value`, icon, overlay, id, birdColor, overlayColor FROM users WHERE `$request_value` != 0 AND banned = 0 AND leaderboardsBanned = 0 ORDER BY `$request_value` DESC LIMIT 500");
$stmt = $conn->prepare("SELECT username, id, save_data
FROM users
WHERE banned = 0 AND leaderboardsBanned = 0");
$stmt->execute();
$result = $stmt->get_result();
$rows = $result->fetch_all(MYSQLI_ASSOC);
echo encrypt(json_encode(array_map(fn($row) => ['username' => $row['username'], 'userid' => $row['id'], 'value' => $row[$request_value], 'icon' => $row['icon'], 'overlay' => $row['overlay'], 'birdColor' => json_decode($row['birdColor']), 'overlayColor' => json_decode($row['overlayColor'])], $result->fetch_all(MYSQLI_ASSOC))));
$mapped = [];
foreach ($rows as $row) {
$savedata = json_decode($row['save_data'], true);
if (!$savedata) continue;
$value = $savedata['gameStore'][$request_value] ?? 0;
if ($value <= 0) continue;
$mapped[] = [
'username' => $row['username'],
'userid' => $row['id'],
'value' => $value,
'icon' => $savedata['bird']['icon'] ?? 1,
'overlay' => $savedata['bird']['overlay'] ?? 0,
'birdColor' => $savedata['settings']['colors']['icon'] ?? [255,255,255],
'overlayColor' => $savedata['settings']['colors']['overlay'] ?? [255,255,255],
];
}
usort($mapped, fn($a,$b) => $b['value'] <=> $a['value']);
$limited = array_slice($mapped, 0, 500);
echo encrypt(json_encode($limited));
$conn->close();

View File

@@ -3,11 +3,32 @@ require __DIR__ . '/../incl/util.php';
setJsonHeader();
$conn = newConnection();
$stmt = $conn->prepare("SELECT username, highScore FROM users WHERE highScore != 0 AND banned = 0 AND leaderboardsBanned = 0 ORDER BY highScore DESC LIMIT 500");
$stmt = $conn->prepare("SELECT username, id, save_data
FROM users
WHERE banned = 0 AND leaderboardsBanned = 0");
$stmt->execute();
$result = $stmt->get_result();
$rows = $result->fetch_all(MYSQLI_ASSOC);
echo json_encode(array_map(fn($row) => ['username' => $row['username'], 'score' => $row['highScore'], 'scoreFormatted' => number_format($row['highScore'])], $result->fetch_all(MYSQLI_ASSOC)), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
$mapped = [];
foreach ($rows as $row) {
$savedata = json_decode($row['save_data'], true);
if (!$savedata) continue;
$value = $savedata['gameStore']['highScore'] ?? 0;
if ($value <= 0) continue;
$mapped[] = [
'username' => $row['username'],
'score' => (int)$value,
'scoreFormatted' => number_format($value)
];
}
usort($mapped, fn($a,$b) => $b['score'] <=> $a['score']);
$limited = array_slice($mapped, 0, 500);
echo json_encode($limited);
$conn->close();