<?php
require_once('session.php');
require_once('api/nexus.php');


// Ambil user info dari sesi
$usersID = $u['cuid'];
$externalPlayerId = $_GET['extplayer'];
// Validasi `gamecode`
$gamecode = $_GET['gamecode']; 
$providercode = $_GET['provider']; 
// Buat URL kembali
$urlBack = htmlspecialchars($urlweb . '/');
// Inisialisasi objek API NGaming
//$NG = new API();
$hasil = $NG->launch_game($externalPlayerId, $providercode, $gamecode);
// Tanggapi hasil peluncuran
if ($hasil && isset($hasil['status']) && $hasil['status'] == 1) {
    $playUrl = $hasil['launch_url'];


    header('Location: ' . $playUrl);
    exit();
} else {
    error_log("Game launch failed. Redirecting back to: $urlBack");
    header('Location: ' . $urlBack);
    exit();
}
?>
