<?php
require './config.php'; // 确保此文件中有数据库连接和 MCSManager 配置
$instanceUuid = $_GET['instanceUuid'] ?? '';
$daemonId = $_GET['daemonId'] ?? '';
$api_key = $mcsm_api_key;

$ch = curl_init();
$instance_info_url = "http://60.214.107.205:30000/api/instance?apikey=" . urlencode($api_key) . "&uuid=" . urlencode($instanceUuid) . "&daemonId=" . urlencode($daemonId);
curl_setopt($ch, CURLOPT_URL, $instance_info_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$instance_response = curl_exec($ch);
$instance_http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($instance_http_code != 200) {
    echo json_encode(['success' => false, 'error' => "获取实例信息失败: HTTP Code $instance_http_code"]);
} else {
    $instance_data = json_decode($instance_response, true);
    echo json_encode([
        'success' => true,
        'name' => $instance_data['data']['config']['nickname'],
        'ip' => "play.none.pw:" . $instance_data['data']['config']['pingConfig']['port'],
        'cpu' => $instance_data['data']['processInfo']['cpu'],
        'memory' => $instance_data['data']['processInfo']['memory']
    ]);
}
?>