<html lang="tr" class="browser-Chrome" style="--vh: 6.67px;">

<head>
    <meta charset="utf-8">
    <title data-rh="true"></title>



    <meta name="viewport" content="width=device-width, maximum-scale=1, viewport-fit=cover">


   

 
<style>
html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    background: transparent;
}
.dark-loader {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #111111;
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.loader-content {
    text-align: center;
}

.spinner-box {
    width: 80px;
    height: 80px;
    margin: 0 auto 20px;
    position: relative;
}

.spinner {
    width: 100%;
    height: 100%;
    border: 4px solid #1a1a1a;
    border-top: 4px solid #ff1a1a;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.loader-text {
    color: #ff1a1a;
    font-family: Arial, sans-serif;
    font-size: 18px;
    letter-spacing: 4px;
    animation: pulse 1.5s ease-in-out infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.game-container {
    position: relative;
    width: 100%;
    height: 100%;
    margin: 0; /* üst/alt boşlukları kaldır */
    background: transparent; /* dış sayfanın arka planıyla uyumlu olsun */
    overflow: hidden;
    z-index: 99;
    border-radius: 0;
    box-shadow: none;
}

.game-container iframe {
    width: 100%;
    height: 100%; /* containerı tamamen doldursun */
    border: none;
    margin: 0;
    padding: 0;
    display: block;
    background: transparent;
}

@media (max-width: 768px) {
    .game-container {
        height: 100%;
        margin: 0;
    }
}
</style>
    <script charset="utf-8" src="/sporassets/8.a500c882c1ef3af42595.js"></script>
</head>

<body class="">

   
       

              
<?php
ob_start();
session_start();
date_default_timezone_set('Europe/Istanbul');

// Veritabanı bilgileri
$servername = "localhost";
$db_user = "blacrhdy_bet1";
$db_pass = "blacrhdy_bet1";
$dbname = "blacrhdy_bet1";

// Kullanıcı bilgileri
$isLoggedIn = isset($_SESSION['loggedin']) && $_SESSION['loggedin'];
$userUsername = $isLoggedIn ? $_SESSION['username'] : '';

// Veritabanı bağlantısı
$conn = new mysqli($servername, $db_user, $db_pass, $dbname);
if ($conn->connect_error) exit;

// Kullanıcı bakiyesi ve ID
$userBalance = null;
$users_id = null;

if ($isLoggedIn && !empty($userUsername)) {
    $stmt = $conn->prepare("SELECT id, ana_bakiye FROM kullanicilar WHERE username = ?");
    $stmt->bind_param("s", $userUsername);
    $stmt->execute();
    $stmt->bind_result($users_id_db, $userBalance_db);
    if ($stmt->fetch()) {
        $users_id = $users_id_db;
        $userBalance = $userBalance_db;
    }
    $stmt->close();
}

// Session'a bakiyeyi kaydet
$_SESSION['ana_bakiye'] = $userBalance;

// Eğer kullanıcı giriş yapmamışsa guest ID oluştur
if (empty($users_id)) {
    $users_id = "guest_" . rand(1000,9999); // örnek guest ID
}

$conn->close();

// -------- Veritral Oyun Başlatma --------
class AgentGameExample {
    private $api_key = 'api_68df7464c7bc9_9aae3eaa0228a0a7';
    private $secret_key = 'secret_13ea3a59fc49f44584caab9e40ad3971';
    private $base_url = 'https://api.veritral.com/api/v2/launch';

    public function startGame($game_id, $username, $player_id) {
        $data = [
            'api_key'    => $this->api_key,
            'secret_key' => $this->secret_key,
            'mode'       => 'sports',
            'username'   => $username ?: $player_id,
            'player_id'  => $player_id,
            'game_id'    => $game_id,
            'currency'   => 'TRY',
            'language'   => 'tur'
        ];

        $response = $this->makeRequest($data);

        if (isset($response['status']) && $response['status'] === 'success') {
            return $response['data']['launch_url'];
        } else {
            return ''; // hata durumunda boş URL
        }
    }

    private function makeRequest($data) {
        $ch = curl_init($this->base_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
        $response = curl_exec($ch);
        curl_close($ch);
        return json_decode($response,true);
    }
}

// Oyun başlat
$agent = new AgentGameExample();
$game_url = $agent->startGame("2", $userUsername, $users_id);
?>

<div class="dark-loader" id="loadingScreen">
    <div class="loader-content">
        <div class="spinner-box">
            <div class="spinner"></div>
        </div>
        <div class="loader-text" data-i18n="spor_yukleniyor">Yükleniyor</div>
    </div>
</div>

<div id="gameContent" style="display: none;">
    <div class="game-container">
        <iframe 
            src="<?php echo htmlspecialchars($game_url); ?>"
            id="gameFrame"
            allow="fullscreen; autoplay; clipboard-write; encrypted-media"
            sandbox="allow-same-origin allow-scripts allow-popups allow-forms allow-top-navigation"
            referrerpolicy="no-referrer"
            allowfullscreen
        ></iframe>
    </div>
</div>


<script>
window.addEventListener("load", function () {
    const loader = document.getElementById("loadingScreen");
    const content = document.getElementById("gameContent");
    const gameFrame = document.getElementById("gameFrame");

    let isLoaded = false;

    gameFrame.addEventListener("load", function() {
        isLoaded = true;
        hideLoader();
    });

    function checkIframeContent() {
        try {
            if (gameFrame.contentWindow.document.readyState === 'complete') {
                isLoaded = true;
                hideLoader();
            }
        } catch(e) {}

    }

    const checkInterval = setInterval(() => {
        if (isLoaded) {
            clearInterval(checkInterval);
            return;
        }
        checkIframeContent();
    }, 500);

    function hideLoader() {
        loader.style.transition = "opacity 0.8s ease-out";
        loader.style.opacity = "0";
        content.style.display = "block";
        
        setTimeout(() => {
            loader.style.display = "none";
        }, 800);
    }

    setTimeout(() => {
        if (!isLoaded) {
            hideLoader();
            clearInterval(checkInterval);
        }
    }, 1000);
});
</script>







</body>

</html>