<?php
session_start();
require_once(__DIR__ . "/config/db.php");
require_once(__DIR__."/session.php");
require_once(__DIR__ . "/api/AuraGaming-API.php");

$errorMsg = "";

$gameplay = $user['gameplay'] ?? null;
if ($gameplay === null || $gameplay == 0) {
    $_SESSION['error'] = "Silahkan hubungi Admin/Livechat untuk melanjutkan permainan!";
    header('Location: /');
    exit();
}

if (isset($user['extplayer'], $_GET['provider_code'], $_GET['game_code'])) {
    $extplayer = $user['extplayer'];
    $provider_code = $_GET['provider_code'];
    $game_code = $_GET['game_code'];
    $lang = "id";

    $act = json_decode($AG->launch($agent_code, $agent_token, $extplayer, $provider_code, $game_code, $lang), true);

    if ($act['msg'] == "SUCCESS") {
            header('Location: ' . $act['launch_url']);
            exit();
    } else {
        $_SESSION['error'] = "Silahkan hubungi Admin/Livechat untuk melanjutkan permainan!";
        header('Location: /');
        exit();
    }
}
?>