<?php
header("Content-Type: application/json");

$username = $_POST['username'] ?? '';
$password = $_POST['password'] ?? '';
$device_id = $_POST['device_id'] ?? '';
$dns_id = $_POST['dns_id'] ?? '';
$device_name = $_POST['device_name'] ?? '';

if($username == '' || $password == ''){
    echo json_encode([
        "status" => "error",
        "message" => "Credenciais inválidas"
    ]);
    exit;
}

$xtream = "http://xtream.thefull.site/player_api.php?username=".$username."&password=".$password;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $xtream);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

$data = json_decode($response, true);

if(isset($data["user_info"]["auth"]) && $data["user_info"]["auth"] == 1){

    echo json_encode([
        "status" => "success",
        "username" => $username,
        "device_id" => $device_id,
        "dns_id" => $dns_id,
        "message" => "Login autorizado"
    ]);

}else{

    echo json_encode([
        "status" => "error",
        "message" => "Usuário ou senha inválidos"
    ]);

}
?>