39030-vm/load_world.php
Flatlogic Bot 6489bf1f14 ai
2026-03-07 04:07:33 +00:00

43 lines
1.0 KiB
PHP

<?php
declare(strict_types=1);
header('Content-Type: application/json');
require_once __DIR__ . '/db/config.php';
require_once __DIR__ . '/includes/worlds.php';
$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($id <= 0) {
echo json_encode(['success' => false, 'error' => 'Missing world id.']);
exit;
}
try {
ensureWorldsTable();
$world = getWorldById($id);
} catch (Throwable $e) {
echo json_encode(['success' => false, 'error' => 'Database unavailable.']);
exit;
}
if (!$world) {
echo json_encode(['success' => false, 'error' => 'World not found.']);
exit;
}
$worldData = json_decode($world['world_json'], true);
if (!is_array($worldData)) {
echo json_encode(['success' => false, 'error' => 'World data corrupted.']);
exit;
}
echo json_encode([
'success' => true,
'world' => $worldData,
'meta' => [
'id' => (int)$world['id'],
'name' => $world['name'],
'size' => (int)$world['size'],
'updated_at' => $world['updated_at']
]
]);