From a2f1748ff6969932ca24dacff7dd4c6e0cfe3c6d Mon Sep 17 00:00:00 2001 From: Lncvrt Date: Mon, 29 Sep 2025 13:24:56 -0700 Subject: [PATCH] Probably going to break something but use {} instead of [] --- .../backported/1.3-beta2/getTopPlayers.php | 2 +- .../backported/1.5.1/getChatroomMessages.php | 2 +- database/backported/1.5/getTopPlayers.php | 2 +- database/getChatroomMessages.php | 4 +- database/getMarketplaceIcons.php | 2 +- database/getPresets.php | 77 +++++++++++++++++++ database/getTopPlayers.php | 4 +- database/getTopPlayersAPI.php | 2 +- incl/util.php | 2 +- 9 files changed, 87 insertions(+), 10 deletions(-) create mode 100644 database/getPresets.php diff --git a/database/backported/1.3-beta2/getTopPlayers.php b/database/backported/1.3-beta2/getTopPlayers.php index af6ca4d..d1b8434 100644 --- a/database/backported/1.3-beta2/getTopPlayers.php +++ b/database/backported/1.3-beta2/getTopPlayers.php @@ -28,7 +28,7 @@ $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { - $topPlayers = []; + $topPlayers = new stdClass(); while ($row = $result->fetch_assoc()) { $savedata = json_decode($row['save_data'], true); diff --git a/database/backported/1.5.1/getChatroomMessages.php b/database/backported/1.5.1/getChatroomMessages.php index 6577cf5..ec3561f 100644 --- a/database/backported/1.5.1/getChatroomMessages.php +++ b/database/backported/1.5.1/getChatroomMessages.php @@ -11,7 +11,7 @@ $stmt = $conn->prepare(" $stmt->execute(); $result = $stmt->get_result(); -$rows = []; +$rows = new stdClass(); while ($row = $result->fetch_assoc()) { $savedata = json_decode($row['save_data'], true); $icon = $savedata['bird']['icon'] ?? 1; diff --git a/database/backported/1.5/getTopPlayers.php b/database/backported/1.5/getTopPlayers.php index dd1faa7..56876df 100644 --- a/database/backported/1.5/getTopPlayers.php +++ b/database/backported/1.5/getTopPlayers.php @@ -25,7 +25,7 @@ $stmt->execute(); $result = $stmt->get_result(); if ($result->num_rows > 0) { - $topPlayers = []; + $topPlayers = new stdClass(); while ($row = $result->fetch_assoc()) { $savedata = json_decode($row['save_data'], true); diff --git a/database/getChatroomMessages.php b/database/getChatroomMessages.php index 7900eb4..1459256 100644 --- a/database/getChatroomMessages.php +++ b/database/getChatroomMessages.php @@ -23,8 +23,8 @@ $stmt->execute(); $result = $stmt->get_result(); $rows = $result->fetch_all(MYSQLI_ASSOC); -$mapped = []; -$icons = []; +$mapped = new stdClass(); +$icons = new stdClass(); foreach ($rows as $row) { $savedata = json_decode($row['save_data'], true); diff --git a/database/getMarketplaceIcons.php b/database/getMarketplaceIcons.php index 2cb95e8..d6b4cde 100644 --- a/database/getMarketplaceIcons.php +++ b/database/getMarketplaceIcons.php @@ -17,7 +17,7 @@ $onlyShowValue = (string)$post['onlyShowValue'] ?? ''; $currentIcons = json_decode(base64_decode((string)($post['currentIcons'] ?? 'W10K'))); $where = ["u.banned = 0", "(c.state = 1 OR c.state = 2)"]; -$params = []; +$params = new stdClass(); $types = ""; $order = match($sortBy) { 1 => "ORDER BY c.price ASC", diff --git a/database/getPresets.php b/database/getPresets.php new file mode 100644 index 0000000..3a87ff6 --- /dev/null +++ b/database/getPresets.php @@ -0,0 +1,77 @@ + "ORDER BY c.id ASC", + 3 => "ORDER BY c.id DESC", + default => "", +}; + +if ($searchForEnabled && $searchForValue !== '') { + $where[] = "FROM_BASE64(c.name) LIKE ?"; + $params[] = "%$searchForValue%"; + $types .= "s"; +} + +if ($onlyShowEnabled) { + if ($onlyShowValue === '0') { + $where[] = "c.userId = ?"; + $params[] = $userId; + $types .= "i"; + } elseif ($onlyShowValue === '1') { + $where[] = "c.userId != ?"; + $params[] = $userId; + $types .= "i"; + } elseif ($onlyShowValue === '2') { + $placeholders = implode(',', array_fill(0, count($currentIcons), '?')); + $where[] = "c.uuid IN ($placeholders)"; + $params = array_merge($params, $currentIcons); + $types .= str_repeat('s', count($currentIcons)); + } elseif ($onlyShowValue === '3') { + $placeholders = implode(',', array_fill(0, count($currentIcons), '?')); + $where[] = "c.uuid NOT IN ($placeholders)"; + $params = array_merge($params, $currentIcons); + $types .= str_repeat('s', count($currentIcons)); + } +} + +$sql = " + SELECT c.data, u.username, u.id, c.name, c.uuid + FROM presets c + JOIN users u ON c.userId = u.id + WHERE " . implode(" AND ", $where) . " + $order +"; + +$stmt = $conn->prepare($sql); + +if (!empty($params)) { + $stmt->bind_param($types, ...$params); +} + +$stmt->execute(); +$result = $stmt->get_result(); + +echo encrypt(json_encode(array_map(fn($row) => ['username' => $row['username'], 'userid' => $row['id'], 'data' => $row['data'], 'uuid' => $row['uuid'], 'name' => base64_decode($row['name'])], $result->fetch_all(MYSQLI_ASSOC)))); + +$conn->close(); \ No newline at end of file diff --git a/database/getTopPlayers.php b/database/getTopPlayers.php index 8b3f908..c15a934 100644 --- a/database/getTopPlayers.php +++ b/database/getTopPlayers.php @@ -44,8 +44,8 @@ $stmt->execute(); $result = $stmt->get_result(); $rows = $result->fetch_all(MYSQLI_ASSOC); -$mapped = []; -$icons = []; +$mapped = new stdClass(); +$icons = new stdClass(); foreach ($rows as $row) { $savedata = json_decode($row['save_data'], true); if (!$savedata) continue; diff --git a/database/getTopPlayersAPI.php b/database/getTopPlayersAPI.php index a61486f..7493a7a 100644 --- a/database/getTopPlayersAPI.php +++ b/database/getTopPlayersAPI.php @@ -11,7 +11,7 @@ $stmt->execute(); $result = $stmt->get_result(); $rows = $result->fetch_all(MYSQLI_ASSOC); -$mapped = []; +$mapped = new stdClass(); foreach ($rows as $row) { $savedata = json_decode($row['save_data'], true); if (!$savedata) continue; diff --git a/incl/util.php b/incl/util.php index 89bdaf9..4f80065 100644 --- a/incl/util.php +++ b/incl/util.php @@ -89,7 +89,7 @@ function getPostData() { $raw = file_get_contents("php://input"); parse_str($raw, $postData); - $decrypted = []; + $decrypted = new stdClass(); foreach ($postData as $k => $v) { $decKey = decrypt($k); $decValue = decrypt($v);