<?php
set_time_limit(0); 
if(file_exists('/home/tamimsho/public_html/guild1280/config.php')){
    require '/home/tamimsho/public_html/guild1280/config.php';
} else {
    require 'config.php';
}
$conn->set_charset("utf8mb4");

$target_clan_id = "3066573253"; 
$ban_reason = "এই প্লেয়ারটি কে গিল্ড থেকে বের করে দেওয়া হয়েছে কারণ রুলস অমান্য করেছে।";
$safe_reason = $conn->real_escape_string($ban_reason);

$sql = "SELECT uid, id FROM members WHERE is_banned = 0 ORDER BY id ASC";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        $uid = $row['uid'];
        $url = "https://tamim1280.vercel.app/player-info?uid=" . $uid;
        
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_TIMEOUT, 15);
        $response = curl_exec($ch);
        $data = json_decode($response, true);
        curl_close($ch);

        // স্ক্রিনশট অনুযায়ী clanBasicInfo এবং clanId চেক
        $api_clan_id = $data['clanBasicInfo']['clanId'] ?? $data['basicInfo']['clanId'] ?? $data['clanbasicinfo']['clanid'] ?? "";

        // ডাটা পাওয়া গেলে চেকিং হবে
        if (isset($data['basicInfo']) || isset($data['clanBasicInfo'])) {
            if ($api_clan_id == $target_clan_id) {
                $conn->query("UPDATE members SET is_checked = 1 WHERE uid = '$uid'");
                echo "UID: $uid - <span style='color:green;'>Safe</span><br>";
            } else {
                // গিল্ডে নেই অথবা আইডি আলাদা - ব্যান
                $conn->query("UPDATE members SET is_banned = 1, ban_reason = '$safe_reason' WHERE uid = '$uid'");
                echo "UID: $uid - <span style='color:red;'>Banned (Not in Guild)</span><br>";
            }
        } else {
            echo "UID: $uid - <span style='color:orange;'>Not Found (Skipped)</span><br>";
        }
        flush();
        sleep(2); 
    }
}
$conn->close();
?>