<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>SurvivalCraft | Home</title>
    <script>
        // Disable right-click context menu
        document.addEventListener('contextmenu', function(event) {
            event.preventDefault();
        });

        // Disable F12 and Ctrl+Shift+I
        document.addEventListener('keydown', function(event) {
            // F12 key
            if (event.key === 'F12') {
                event.preventDefault();
            }
        });

        // Disable all key
        document.addEventListener('keydown', function(event) {
            // All key
            if (event.ctrlKey && event.shiftKey && event.key === 'Ctrl + Shift + C') {
                event.preventDefault();
            }
     });

        // Disable all key
        document.addEventListener('keydown', function(event) {
            // All key
            if (event.ctrlKey && event.shiftKey && event.key === 'Ctrl + Shift + J') {
                event.preventDefault();
            }
     });

        // Disable all key
        document.addEventListener('keydown', function(event) {
            // All key
            if (event.ctrlKey && event.shiftKey && event.key === 'Ctrl + Shift + K') {
                event.preventDefault();
            }
            // Ctrl+Shift+I
            if (event.ctrlKey && event.shiftKey && event.key === 'I') {
                event.preventDefault();
            }
        });

        // Optionally, detect developer tools (for additional protection)
        (function() {
            var devtools = /./;
            devtools.toString = function() {
                this.opened = true;  // Detect when dev tools are opened
            };
            setInterval(function() {
                if (devtools.opened) {
                    alert("Developer Tools Detected!");
                }
            }, 1000);
        })();
    </script>
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600;700&amp;display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css">
    <link rel="stylesheet" href="css/survivalcraft.css">
</head>
<body>
    <div class="container">
        <div class="logo-container">
            <img src="images/oJey0LT.png" alt="SC Logo" class="logo">
        </div>
        
        <div class="server-ip">
            <span id="ip">play.survivalcraft.life</span>
            <button onclick="copyIP()" class="copy-btn" title="Copy IP">
                <i class="fas fa-copy"></i>
            </button>
        </div>

        <div class="server-status">
            <div class="player-count">
                <i class="fas fa-users"></i>
                <span id="playerCount">Loading...</span>
            </div>
            <div class="server-status-indicator" id="statusIndicator"></div>
        </div>

        <div class="main-buttons">
            <a href="shop/store.html" class="main-btn">
                <i class="fas fa-store"></i>
                <span>Store</span>
            </a>
            <a href="https://dsc.gg/geosurvival" class="main-btn">
                <i class="fab fa-discord"></i>
                <span>Discord (<span id="discordCount">Loading...</span>)</span>
            </a>
        </div>

<footer>
    <p>Not affiliated with Mojang AB</p>
    <p>Copyright &copy; <span id="currentYear"></span> SC. All rights reserved.</p>
</footer>

<script>
    // Dynamically update the year
    document.getElementById('currentYear').textContent = new Date().getFullYear();

    function copyIP() {
        navigator.clipboard.writeText('play.survivalcraft.life');
        const btn = document.querySelector('.copy-btn');
        btn.innerHTML = '<i class="fas fa-check">';
        setTimeout(() => {
            btn.innerHTML = '<i class="fas fa-copy">';
        }, 2000);
    }

    async function checkServerStatus() {
        try {
            const response = await fetch('https://api.mcsrvstat.us/3/play.survivalcraft.com');
            const data = await response.json();
            
            const playerCountElement = document.getElementById('playerCount');
            const statusIndicator = document.getElementById('statusIndicator');
            
            if (data.online) {
                statusIndicator.classList.add('online');
                statusIndicator.classList.remove('offline');
                
                const players = data.players.online;
                const maxPlayers = data.players.max;
                playerCountElement.textContent = `${players}/${maxPlayers} Players`;
            } else {
                statusIndicator.classList.add('offline');
                statusIndicator.classList.remove('online');
                playerCountElement.textContent = 'Server Offline';
            }
        } catch (error) {
            console.error('Error fetching server status:', error);
            document.getElementById('playerCount').textContent = 'Status Unavailable';
        }
    }

    async function fetchDiscordUserCount() {
        try {
            const response = await fetch('https://discord.com/api/guilds/1320673450670555136/widget.json'); // Replace {guild_id} with the actual Discord Guild ID
            const data = await response.json();

            if (data.presence_count) {
                document.getElementById('discordCount').textContent = `${data.presence_count} Online`;
            } else {
                document.getElementById('discordCount').textContent = 'Unavailable';
            }
        } catch (error) {
            console.error('Error fetching Discord user count:', error);
            document.getElementById('discordCount').textContent = 'Unavailable';
        }
    }

    checkServerStatus();
    fetchDiscordUserCount();
    setInterval(checkServerStatus, 30000);
    setInterval(fetchDiscordUserCount, 30000);
</script>

    </div>
</body>
</html>
