diff --git a/config/encryption.php b/config/encryption.php index 022ffbc..719a6c1 100644 --- a/config/encryption.php +++ b/config/encryption.php @@ -1,3 +1,5 @@ prepare("SELECT username, legacy_high_score, id, save_data FROM users WHERE legacy_high_score > 0 AND banned = 0 AND leaderboardsBanned = 0 ORDER BY legacy_high_score DESC LIMIT ?"); +$stmt->bind_param("i", $request_limit); +$stmt->execute(); + +$result = $stmt->get_result(); + +if ($result->num_rows > 0) { + $topPlayers = []; + + while ($row = $result->fetch_assoc()) { + $savedata = json_decode($row['save_data'], true); + $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]; + $topPlayers[] = base64_encode($row["username"]) . ":" . $row["legacy_high_score"] . ":" . $icon . ":" . $overlay . ":" . $row["id"] . ":" . $birdColor[0] . ":" . $birdColor[1] . ":" . $birdColor[2] . ":" . $overlayColor[0] . ":" . $overlayColor[1] . ":" . $overlayColor[2]; + } + + $output = implode(";", $topPlayers); + + echo encrypt($output); +} else { + echo encrypt("-1"); +} + +$conn->close(); +?> \ No newline at end of file diff --git a/database/getTopPlayers.php b/database/getTopPlayers.php index 39785ac..7441961 100644 --- a/database/getTopPlayers.php +++ b/database/getTopPlayers.php @@ -7,6 +7,12 @@ if (isAllowedDatabaseVersion(getClientVersion())) { exit; } } +if (isAllowedDatabaseVersion(getClientVersion())) { + if (getClientVersion() == "1.5.0" || getClientVersion() == "1.5.1" || getClientVersion() == "1.5.2") { + require __DIR__ . '/backported/1.5/getTopPlayers.php'; + exit; + } +} if ($_SERVER['HTTP_REQUESTER'] != 'BerryDashLauncher') { checkClientDatabaseVersion(); } diff --git a/incl/util.php b/incl/util.php index 99667a4..89bdaf9 100644 --- a/incl/util.php +++ b/incl/util.php @@ -21,10 +21,14 @@ function newConnection() { return $conn; } +function getClientVersion() { + return $_SERVER['HTTP_CLIENTVERSION']; +} + function encrypt($plainText) { include __DIR__.'/../config/encryption.php'; $iv = random_bytes(16); - $cipher = openssl_encrypt($plainText, 'aes-256-cbc', $SERVER_SEND_TRANSFER_KEY, OPENSSL_RAW_DATA, $iv); + $cipher = openssl_encrypt($plainText, 'aes-256-cbc', $SERVER_SEND_TRANSFER_KEY_SPECIFIC[getClientVersion()] ?? $SERVER_SEND_TRANSFER_KEY, OPENSSL_RAW_DATA, $iv); return base64_encode($iv . $cipher); } @@ -33,7 +37,7 @@ function decrypt($dataB64) { $data = base64_decode($dataB64); $iv = substr($data, 0, 16); $cipher = substr($data, 16); - $decrypted = openssl_decrypt($cipher, 'aes-256-cbc', $SERVER_RECEIVE_TRANSFER_KEY, OPENSSL_RAW_DATA, $iv); + $decrypted = openssl_decrypt($cipher, 'aes-256-cbc', $SERVER_RECEIVE_TRANSFER_KEY_SPECIFIC[getClientVersion()] ?? $SERVER_RECEIVE_TRANSFER_KEY, OPENSSL_RAW_DATA, $iv); if ($decrypted === false) { exit(encrypt('-997')); } @@ -49,10 +53,6 @@ function exitWithMessage($message, $encrypt = true) { exit; } -function getClientVersion() { - return $_SERVER['HTTP_CLIENTVERSION']; -} - function isLatestVersion($version) { global $latestVersion; if (!isset($latestVersion)) require __DIR__ . '/../config/general.php';