Send and recieve entire savefile from server
This commit is contained in:
@@ -16,21 +16,13 @@ $result = $stmt->get_result();
|
|||||||
|
|
||||||
if ($result->num_rows > 0) {
|
if ($result->num_rows > 0) {
|
||||||
$row = $result->fetch_assoc();
|
$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([
|
echo encrypt(json_encode([
|
||||||
"success" => true,
|
"success" => true,
|
||||||
"highscore" => (string)$row['highScore'],
|
"data" => $savedata
|
||||||
"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'])
|
|
||||||
]));
|
]));
|
||||||
} else {
|
} else {
|
||||||
echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
|
echo encrypt(json_encode(["success" => false, "message" => "Invalid session token or username, please refresh login"]));
|
||||||
|
|||||||
@@ -6,19 +6,17 @@ checkClientDatabaseVersion();
|
|||||||
$post = getPostData();
|
$post = getPostData();
|
||||||
$token = $post['token'] ?? '';
|
$token = $post['token'] ?? '';
|
||||||
$username = $post['username'] ?? '';
|
$username = $post['username'] ?? '';
|
||||||
$highScore = (string)$post['highScore'] ?? '0';
|
$savedata = $post['saveData'] ?? 'e30=';
|
||||||
$icon = (int)$post['icon'] ?? 1;
|
|
||||||
$overlay = (int)$post['overlay'] ?? 0;
|
try {
|
||||||
$totalNormalBerries = (string)$post['totalNormalBerries'] ?? '0';
|
$savedata = json_decode(base64_decode($savedata), true);
|
||||||
$totalPoisonBerries = (string)$post['totalPoisonBerries'] ?? '0';
|
$savedata['account']['id'] = null;
|
||||||
$totalSlowBerries = (string)$post['totalSlowBerries'] ?? '0';
|
$savedata['account']['name'] = null;
|
||||||
$totalUltraBerries = (string)$post['totalUltraBerries'] ?? '0';
|
$savedata['account']['session'] = null;
|
||||||
$totalSpeedyBerries = (string)$post['totalSpeedyBerries'] ?? '0';
|
$savedata = json_encode($savedata);
|
||||||
$totalCoinBerries = (string)$post['totalCoinBerries'] ?? '0';
|
} catch (Exception $e) {
|
||||||
$totalAttempts = (string)$post['totalAttempts'] ?? '0';
|
echo encrypt(json_encode(["success" => false, "message" => "Couldn't parse save data"]));
|
||||||
$birdColor = (string)$post['birdColor'] ?? '[255,255,255]';
|
}
|
||||||
$overlayColor = (string)$post['overlayColor'] ?? '[255,255,255]';
|
|
||||||
$marketplaceData = (string)$post['marketplaceData'] ?? '[]';
|
|
||||||
|
|
||||||
$conn = newConnection();
|
$conn = newConnection();
|
||||||
|
|
||||||
@@ -28,24 +26,8 @@ $stmt->execute();
|
|||||||
$result = $stmt->get_result();
|
$result = $stmt->get_result();
|
||||||
|
|
||||||
if ($result->num_rows > 0) {
|
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 = $conn->prepare("UPDATE users SET save_data = ? WHERE token = ? AND username = ?");
|
||||||
$updateStmt->bind_param("iiiiiiiiiisssss",
|
$updateStmt->bind_param("sss", $savedata, $token, $username);
|
||||||
$highScore,
|
|
||||||
$icon,
|
|
||||||
$overlay,
|
|
||||||
$totalNormalBerries,
|
|
||||||
$totalPoisonBerries,
|
|
||||||
$totalSlowBerries,
|
|
||||||
$totalUltraBerries,
|
|
||||||
$totalSpeedyBerries,
|
|
||||||
$totalCoinBerries,
|
|
||||||
$totalAttempts,
|
|
||||||
$birdColor,
|
|
||||||
$overlayColor,
|
|
||||||
$marketplaceData,
|
|
||||||
$token,
|
|
||||||
$username
|
|
||||||
);
|
|
||||||
$updateStmt->execute();
|
$updateStmt->execute();
|
||||||
$updateStmt->close();
|
$updateStmt->close();
|
||||||
echo encrypt(json_encode(["success" => true]));
|
echo encrypt(json_encode(["success" => true]));
|
||||||
|
|||||||
Reference in New Issue
Block a user