Backport 1.5 leaderboards

This commit is contained in:
2025-09-12 07:20:59 -07:00
parent e15d5f997b
commit 03243fcde7
5 changed files with 64 additions and 9 deletions

View File

@@ -1,3 +1,5 @@
<?php
$SERVER_RECEIVE_TRANSFER_KEY = ""; //SERVER_SEND_TRANSFER_KEY on the client
$SERVER_SEND_TRANSFER_KEY = ""; //SERVER_RECEIVE_TRANSFER_KEY on the client
$SERVER_SEND_TRANSFER_KEY = ""; //SERVER_RECEIVE_TRANSFER_KEY on the client
$SERVER_RECEIVE_TRANSFER_KEY_SPECIFIC = [];
$SERVER_SEND_TRANSFER_KEY_SPECIFIC = [];

View File

@@ -2,5 +2,5 @@
$latestVersion = "1.8";
$latestBetaVersion = $latestVersion;
$latestLauncherVersion = "1.1.0";
$allowedVersions = [$latestVersion, $latestBetaVersion, "1.7.1", "1.7", "1.6.3", "1.6.2", "1.6.1", "1.6"];
$allowedDatabaseVersions = [$latestVersion, $latestBetaVersion, "1.7.1", "1.7", "1.6.3", "1.6.2", "1.6.1", "1.6", "1.3-beta2", "1.3-beta1", "1.21", "1.2", "1.2-beta2"];
$allowedVersions = [$latestVersion, $latestBetaVersion, "1.7.1", "1.7", "1.6.3", "1.6.2", "1.6.1", "1.6", "1.5.2", "1.5.1", "1.5.0"];
$allowedDatabaseVersions = [$latestVersion, $latestBetaVersion, "1.7.1", "1.7", "1.6.3", "1.6.2", "1.6.1", "1.6", "1.5.2", "1.5.1", "1.5.0", "1.3-beta2", "1.3-beta1", "1.21", "1.2", "1.2-beta2"];

View File

@@ -0,0 +1,47 @@
<?php
$conn = newConnection();
$request_showamount = isset($_POST['showAmount']) ? $_POST['showAmount'] : 0;
switch ($request_showamount) {
case 1:
$request_limit = 100;
break;
case 2:
$request_limit = 250;
break;
case 3:
$request_limit = 500;
break;
default:
$request_limit = 50;
break;
}
$stmt = $conn->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();
?>

View File

@@ -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();
}

View File

@@ -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';