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

@@ -16,21 +16,13 @@ $result = $stmt->get_result();
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
$savedata = json_decode($row['save_data'], true);
$savedata['account']['id'] = $row['id'];
$savedata['account']['name'] = $row['username'];
$savedata['account']['session'] = $row['token'];
echo encrypt(json_encode([
"success" => true,
"highscore" => (string)$row['highScore'],
"icon" => (int)$row['icon'],
"overlay" => (int)$row['overlay'],
"totalNormalBerries" => (string)$row['totalNormalBerries'],
"totalPoisonBerries" => (string)$row['totalPoisonBerries'],
"totalSlowBerries" => (string)$row['totalSlowBerries'],
"totalUltraBerries" => (string)$row['totalUltraBerries'],
"totalSpeedyBerries" => (string)$row['totalSpeedyBerries'],
"totalCoinBerries" => (string)$row['totalCoinBerries'],
"totalAttempts" => (string)$row['totalAttempts'],
"birdColor" => json_decode((string)$row['birdColor']),
"overlayColor" => json_decode((string)$row['overlayColor']),
"marketplaceData" => json_decode((string)$row['marketplaceData'])
"data" => $savedata
]));
} else {
echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));

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]));