<?php

//echo rand(10000,99999)." Onesignal id: ".$player_id = $_GET['userId'];
//header("refresh:10");
//exit;
?>

<style type="text/css">
.preloader span,.shadow{display:block;width:64px}body{background:#595bd4;font-family:'Titillium Web',sans-serif}p{color:#fff}.container{position:absolute;top:40%;left:50%;transform:translate(-50%,-50%)}.container .preloader{animation:2.3s cubic-bezier(.75,0,.5,1) infinite rotate}@keyframes rotate{50%{transform:rotate(360deg)}100%{transform:rotate(720deg)}}.preloader span{position:absolute;height:64px;background:#ff0082;border:1px solid #ff0082;border-radius:100%}.preloader span:first-child{transform:translate(-28px,-28px);animation:2.3s cubic-bezier(.75,0,.5,1) infinite shape_1}@keyframes shape_1{60%{transform:scale(.4)}}.preloader span:nth-child(2){transform:translate(28px,-28px);animation:2.3s cubic-bezier(.75,0,.5,1) infinite shape_2}@keyframes shape_2{40%{transform:scale(.4)}}.preloader span:nth-child(3){position:relative;border-radius:0;transform:scale(.98) rotate(-45deg);animation:2.3s cubic-bezier(.75,0,.5,1) infinite shape_3}@keyframes shape_3{50%{border-radius:100%;transform:scale(.5) rotate(-45deg)}100%{transform:scale(.98) rotate(-45deg)}}.shadow{position:relative;top:30px;left:50%;transform:translateX(-50%);height:16px;border-radius:50%;background-color:#d9d9d9;border:1px solid #d9d9d9;animation:2.3s cubic-bezier(.75,0,.5,1) infinite shadow}@keyframes shadow{50%{transform:translateX(-50%) scale(.5);border-color:#f2f2f2}}.yazi{margin-top:20vh;float:center;font-size:larger}
</style>
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<body>
    <div class="container">
      <div class="preloader">
        <span></span>
        <span></span>
        <span></span>

      </div>
<div class="shadow">
</div>
</div>
<div class="yazi">
<center><p>HeySen</p>
<p>Yakınındakiler Bulunuyor...</p></center>
</div>



</body>
<center><img src="https://cdn.dribbble.com/users/525106/screenshots/5471268/___.gif" style="max-width:110%; margin-top: 25vh; margin-left: -10px;"/></center>

<?php

include 'config.php';

$player_id = $_GET['userId'];
$user_token = $_COOKIE['user_token'];
$user_onesignal = $_COOKIE['user_onesignal'];
$ip = $_SERVER['REMOTE_ADDR'];
$useragent = $_SERVER['HTTP_USER_AGENT'];
$suan = time();

// Kontrol ve işlemler
if (!empty($player_id)) {
    setcookie("user_onesignal", $player_id, time() + (365 * 60 * 60 * 24));
} else {
    // "ONLY USE MOBILE APP!" mesajını gösterme
    die();
}

if (!empty($user_token)) {
    $userCheck = $db->query("SELECT COUNT(*) FROM kullanicilar where user_token = '{$user_token}'")->fetchColumn();

    if ($userCheck != 0) {
        $tekBak = $db->query("SELECT * FROM kullanicilar WHERE user_token = '{$user_token}'")->fetch(PDO::FETCH_ASSOC);

        $query = $db->prepare("UPDATE kullanicilar SET
            user_songiris = :bir,
            user_agent = :dort,
            user_ip = :uc"
        );

        // user_onesignal güncellemesi yapılacak mı kontrolü
        if (stripos($tekBak['user_onesignal'], "##_##_") === false) {
            $query = $db->prepare("UPDATE kullanicilar SET
                user_onesignal = :bes
                WHERE user_token = :iki"
            );
            $query->bindParam(':bes', $player_id, PDO::PARAM_STR);
        }

        // Diğer güncellemeler
        $query->bindParam(':bir', $suan, PDO::PARAM_INT);
        $query->bindParam(':dort', $useragent, PDO::PARAM_STR);
        $query->bindParam(':uc', $ip, PDO::PARAM_STR);
        $query->bindParam(':iki', $user_token, PDO::PARAM_STR);

        $update = $query->execute();

        if ($update) {
            echo '{"result":"14"}';
        } else {
            echo '{"result":"0"}';
        }

        // Sayfaya yönlendirme
        header("Location: index.php");
    } else {
        echo '{"result":"0"}';
        header("Location: index.php");
    }
} else {
    $coPlayer2 = $db->query("SELECT * FROM not_registered WHERE player_id = '{$player_id}'")->fetch(PDO::FETCH_ASSOC);

    if ($coPlayer2) {
        echo '{"result":"13"}';
        header("Location: index.php");
    } else {
        $query = $db->prepare("INSERT INTO not_registered SET player_id = ?, songiris = ?");
        $insert = $query->execute(array($player_id, $suan));

        if ($insert) {
            echo '{"result":"12"}';
        } else {
            echo '{"result":"0"}';
        }

        header("Location: index.php");
    }
}
?>

