<?php
require "../../main.php";

$mcServ = new mcServ;

if (!$mcServ->checkApiAuth()) {
    die('{"status":500, "error":"Unauthrized"}');
}

$db = $mcServ->getDB();

$sql = "SELECT * FROM servers";
$stmt = $db->query($sql);

$result = $stmt->fetchAll(PDO::FETCH_ASSOC);

$servers = [];

if ($result) {
    foreach ($result as $server_res) {
        $server["name"] = $server_res["name"];
        $server["uuid"] = $server_res["uuid"];

        $servers[] = $server;
    }

    $json["servers"] = $servers;
}else{
    $json["servers"] = [];
}

$json["status"] = 200;

echo json_encode($json);
?>