Send and recieve entire savefile from server

This commit is contained in:
2025-08-24 23:15:28 -07:00
parent 7ad4525b0e
commit 8761c74966
2 changed files with 18 additions and 44 deletions

View File

@@ -6,19 +6,17 @@ checkClientDatabaseVersion();
$post = getPostData();
$token = $post['token'] ?? '';
$username = $post['username'] ?? '';
$highScore = (string)$post['highScore'] ?? '0';
$icon = (int)$post['icon'] ?? 1;
$overlay = (int)$post['overlay'] ?? 0;
$totalNormalBerries = (string)$post['totalNormalBerries'] ?? '0';
$totalPoisonBerries = (string)$post['totalPoisonBerries'] ?? '0';
$totalSlowBerries = (string)$post['totalSlowBerries'] ?? '0';
$totalUltraBerries = (string)$post['totalUltraBerries'] ?? '0';
$totalSpeedyBerries = (string)$post['totalSpeedyBerries'] ?? '0';
$totalCoinBerries = (string)$post['totalCoinBerries'] ?? '0';
$totalAttempts = (string)$post['totalAttempts'] ?? '0';
$birdColor = (string)$post['birdColor'] ?? '[255,255,255]';
$overlayColor = (string)$post['overlayColor'] ?? '[255,255,255]';
$marketplaceData = (string)$post['marketplaceData'] ?? '[]';
$savedata = $post['saveData'] ?? 'e30=';
try {
$savedata = json_decode(base64_decode($savedata), true);
$savedata['account']['id'] = null;
$savedata['account']['name'] = null;
$savedata['account']['session'] = null;
$savedata = json_encode($savedata);
} catch (Exception $e) {
echo encrypt(json_encode(["success" => false, "message" => "Couldn't parse save data"]));
}
$conn = newConnection();
@@ -28,24 +26,8 @@ $stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$updateStmt = $conn->prepare("UPDATE users SET highScore = ?, icon = ?, overlay = ?, totalNormalBerries = ?, totalPoisonBerries = ?, totalSlowBerries = ?, totalUltraBerries = ?, totalSpeedyBerries = ?, totalCoinBerries = ?, totalAttempts = ?, birdColor = ?, overlayColor = ?, marketplaceData = ? WHERE token = ? AND username = ?");
$updateStmt->bind_param("iiiiiiiiiisssss",
$highScore,
$icon,
$overlay,
$totalNormalBerries,
$totalPoisonBerries,
$totalSlowBerries,
$totalUltraBerries,
$totalSpeedyBerries,
$totalCoinBerries,
$totalAttempts,
$birdColor,
$overlayColor,
$marketplaceData,
$token,
$username
);
$updateStmt = $conn->prepare("UPDATE users SET save_data = ? WHERE token = ? AND username = ?");
$updateStmt->bind_param("sss", $savedata, $token, $username);
$updateStmt->execute();
$updateStmt->close();
echo encrypt(json_encode(["success" => true]));