<?php
// 数据库配置
$servername = "localhost"; // 数据库服务器地址
$username = "awa"; // 数据库用户名
$password = "yzculture"; // 数据库密码
$dbname = "ccs_auth"; // 数据库名

// Pterodactyl API 配置
$mcsm_api_key = 'c57ad04e28634bd08bb47532a44005b1'; // 替换为你的 Pterodactyl 应用 API 密钥
$mcsm_api_url = 'http://60.214.107.205:30000'; // 替换为你的 Pterodactyl 域名
$pterodactyl_panel_url = 'http://60.214.107.205:20000';
// 创建数据库连接
$conn = new mysqli($servername, $username, $password, $dbname);

// 检查连接是否成功
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}

// 检查 Token
$token = isset($_COOKIE['auth_token']) ? $_COOKIE['auth_token'] : null;
if ($token) {
    $stmt = $conn->prepare("SELECT id, username FROM users WHERE token = ?");
    $stmt->bind_param("s", $token);
    $stmt->execute();
    $stmt->store_result();
    $stmt->bind_result($id, $username);
    $stmt->fetch();

    if ($stmt->num_rows > 0) {
        $_SESSION['user_id'] = $id;
        $_SESSION['username'] = $username;
    } else {
        // Token 无效，清除 Cookie
        setcookie('auth_token', '', time() - 3600, '/');
    }

    $stmt->close();
}
