From 1d29f5da84d801aff3598c375fdf25261a0286c4 Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Wed, 31 Dec 2025 23:36:00 -0700 Subject: [PATCH] Make getChatroomMessages.php work with new db method --- database/getChatroomMessages.php | 44 ++++++++++++++++++++--------- database/getChatroomMessagesAPI.php | 18 ------------ 2 files changed, 30 insertions(+), 32 deletions(-) delete mode 100644 database/getChatroomMessagesAPI.php diff --git a/database/getChatroomMessages.php b/database/getChatroomMessages.php index 740aba8..c9210df 100644 --- a/database/getChatroomMessages.php +++ b/database/getChatroomMessages.php @@ -5,15 +5,15 @@ if (getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") { require __DIR__ . '/backported/1.5.1/getChatroomMessages.php'; exit; } -$conn = newConnection(); +$conn0 = newConnection(0); +$conn1 = newConnection(1); -$stmt = $conn->prepare(" - 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 AND c.deleted_at = 0 - ORDER BY c.id DESC - LIMIT 50 +$stmt = $conn1->prepare(" + SELECT id, content, deleted_at, userId + FROM chats + WHERE deleted_at = 0 + ORDER BY id DESC + LIMIT 500 "); $stmt->execute(); @@ -23,12 +23,27 @@ $rows = $result->fetch_all(MYSQLI_ASSOC); $mapped = []; $icons = []; foreach ($rows as $row) { - $savedata = json_decode($row['save_data'], true); + $userId = $row["userId"]; + $stmt2 = $conn1->prepare("SELECT legacy_high_score, save_data FROM userdata WHERE id = ? LIMIT 1"); + $stmt2->bind_param("i", $userId); + $stmt2->execute(); + $result2 = $stmt2->get_result(); + if ($result2->num_rows != 1) continue; + $row2 = $result2->fetch_assoc(); + + $stmt3 = $conn0->prepare("SELECT username FROM users WHERE id = ? LIMIT 1"); + $stmt3->bind_param("i", $userId); + $stmt3->execute(); + $result3 = $stmt3->get_result(); + if ($result3->num_rows != 1) continue; + $row3 = $result3->fetch_assoc(); + + $savedata = json_decode($row2['save_data'], true); $customIcon = $savedata['bird']['customIcon']['selected'] ?? null; if ($customIcon != null && strlen($customIcon) == 36 && $icons[$customIcon] == null) { - $stmt = $conn->prepare("SELECT data FROM marketplaceicons WHERE uuid = ?"); + $stmt = $conn1->prepare("SELECT data FROM marketplaceicons WHERE uuid = ?"); $stmt->bind_param("s", $customIcon); $stmt->execute(); $result = $stmt->get_result(); @@ -40,11 +55,11 @@ foreach ($rows as $row) { } $mapped[] = [ - 'username' => $row['username'], - 'userid' => $row['user_id'], + 'username' => $row3['username'], + 'userid' => $row['userId'], 'content' => (int)$row['deleted_at'] == 0 ? $row['content'] : null, 'deleted' => (int)$row['deleted_at'] != 0, - 'id' => $row['chat_id'], + 'id' => $row['id'], 'icon' => $savedata['bird']['icon'] ?? 1, 'overlay' => $savedata['bird']['overlay'] ?? 0, 'birdColor' => $savedata['settings']['colors']['icon'] ?? [255,255,255], @@ -60,4 +75,5 @@ if (getClientVersion() == "1.6") { echo encrypt(json_encode(["messages" => array_reverse($mapped), "customIcons" => $icons == [] ? new stdClass() : $icons])); } -$conn->close(); \ No newline at end of file +$conn0->close(); +$conn1->close(); \ No newline at end of file diff --git a/database/getChatroomMessagesAPI.php b/database/getChatroomMessagesAPI.php deleted file mode 100644 index bd7fb6f..0000000 --- a/database/getChatroomMessagesAPI.php +++ /dev/null @@ -1,18 +0,0 @@ -prepare(" - SELECT c.id, c.content, u.username - FROM chats c - JOIN users u ON c.userId = u.id - WHERE u.banned = 0 AND c.deleted_at = 0 - ORDER BY c.id ASC LIMIT 50 -"); -$stmt->execute(); -$result = $stmt->get_result(); - -echo json_encode(array_map(fn($row) => ['username' => $row['username'], 'content' => base64_decode($row['content']), 'contentRaw' => $row['content'], 'messageId' => $row['id']], $result->fetch_all(MYSQLI_ASSOC)), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES); - -$conn->close(); \ No newline at end of file