Make getChatroomMessages.php work with new db method

This commit is contained in:
2025-12-31 23:36:00 -07:00
parent 34328de9b6
commit 1d29f5da84
2 changed files with 30 additions and 32 deletions

View File

@@ -5,15 +5,15 @@ if (getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") {
require __DIR__ . '/backported/1.5.1/getChatroomMessages.php'; require __DIR__ . '/backported/1.5.1/getChatroomMessages.php';
exit; exit;
} }
$conn = newConnection(); $conn0 = newConnection(0);
$conn1 = newConnection(1);
$stmt = $conn->prepare(" $stmt = $conn1->prepare("
SELECT c.id AS chat_id, c.content, c.deleted_at, u.id AS user_id, u.username, u.save_data SELECT id, content, deleted_at, userId
FROM chats c FROM chats
JOIN users u ON c.userId = u.id WHERE deleted_at = 0
WHERE u.banned = 0 AND c.deleted_at = 0 ORDER BY id DESC
ORDER BY c.id DESC LIMIT 500
LIMIT 50
"); ");
$stmt->execute(); $stmt->execute();
@@ -23,12 +23,27 @@ $rows = $result->fetch_all(MYSQLI_ASSOC);
$mapped = []; $mapped = [];
$icons = []; $icons = [];
foreach ($rows as $row) { 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; $customIcon = $savedata['bird']['customIcon']['selected'] ?? null;
if ($customIcon != null && strlen($customIcon) == 36 && $icons[$customIcon] == 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->bind_param("s", $customIcon);
$stmt->execute(); $stmt->execute();
$result = $stmt->get_result(); $result = $stmt->get_result();
@@ -40,11 +55,11 @@ foreach ($rows as $row) {
} }
$mapped[] = [ $mapped[] = [
'username' => $row['username'], 'username' => $row3['username'],
'userid' => $row['user_id'], 'userid' => $row['userId'],
'content' => (int)$row['deleted_at'] == 0 ? $row['content'] : null, 'content' => (int)$row['deleted_at'] == 0 ? $row['content'] : null,
'deleted' => (int)$row['deleted_at'] != 0, 'deleted' => (int)$row['deleted_at'] != 0,
'id' => $row['chat_id'], 'id' => $row['id'],
'icon' => $savedata['bird']['icon'] ?? 1, 'icon' => $savedata['bird']['icon'] ?? 1,
'overlay' => $savedata['bird']['overlay'] ?? 0, 'overlay' => $savedata['bird']['overlay'] ?? 0,
'birdColor' => $savedata['settings']['colors']['icon'] ?? [255,255,255], '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])); echo encrypt(json_encode(["messages" => array_reverse($mapped), "customIcons" => $icons == [] ? new stdClass() : $icons]));
} }
$conn->close(); $conn0->close();
$conn1->close();

View File

@@ -1,18 +0,0 @@
<?php
require __DIR__ . '/../incl/util.php';
setJsonHeader();
$conn = newConnection();
$stmt = $conn->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();