<?php
/**
 * BiteFight - Modern Edition
 * Yapilandirma dosyasi
 *
 * Sadece DB bilgilerini duzenle. APP_URL otomatik tespit edilir.
 */

// ========== VERITABANI ==========
const DB_HOST    = 'localhost';
const DB_NAME    = 'bitefight';
const DB_USER    = 'root';
const DB_PASS    = '';
const DB_CHARSET = 'utf8mb4';

// ========== UYGULAMA ==========
const APP_NAME       = 'BiteFight';
const APP_TIMEZONE   = 'Europe/Istanbul';
const APP_DEBUG      = true; // Sorun cikarsa hatalari gormek icin acik tutuyoruz; canliya alirken false yap

// Oturum
const SESSION_NAME   = 'bf_session';

// ========== OYUN ==========
const GAME_HP_MIN          = 25;
const GAME_GOLD_RATE       = 1;
const GAME_EXP_RATE        = 1;
const GAME_MAIL_NORMAL_MAX = 50;
const GAME_MAIL_LORD_MAX   = 200;
const GAME_START_GOLD      = 100;
const GAME_START_HP        = 100;

// ========== DIL ==========
const LANG_DEFAULT   = 'en';
const LANG_AVAILABLE = ['tr', 'en', 'de', 'es', 'fr', 'pt'];

// ========== SISTEM ==========
date_default_timezone_set(APP_TIMEZONE);
mb_internal_encoding('UTF-8');

if (APP_DEBUG) {
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
} else {
    error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
    ini_set('display_errors', '0');
}

// ========== APP_URL OTOMATIK TESPIT ==========
// Hangi adresten girersen (localhost, IP, domain) otomatik dogru URL'i bulur
if (!defined('APP_URL')) {
    $is_https = (
        (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') ||
        (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https') ||
        (!empty($_SERVER['SERVER_PORT']) && (int)$_SERVER['SERVER_PORT'] === 443)
    );
    $protocol = $is_https ? 'https' : 'http';
    $host = $_SERVER['HTTP_HOST'] ?? 'localhost';

    // Script'in bulundugu klasoru bul (ornek: /bitefight)
    $script = $_SERVER['SCRIPT_NAME'] ?? '';        // /bitefight/index.php
    $base = rtrim(str_replace('\\', '/', dirname($script)), '/');
    // Eger admin/ icindeysek base'den admin'i cikar
    if (substr($base, -6) === '/admin') {
        $base = substr($base, 0, -6);
    }
    define('APP_URL', $protocol . '://' . $host . $base);
} else {
    $is_https = strpos(APP_URL, 'https://') === 0;
}

// ========== OTURUM ==========
if (session_status() === PHP_SESSION_NONE) {
    session_name(SESSION_NAME);
    session_set_cookie_params([
        'lifetime' => 0,
        'path'     => '/',
        'domain'   => '',
        'secure'   => $is_https,    // HTTP icin false (HTTPS yoksa cookie iletilir)
        'httponly' => true,
        'samesite' => 'Lax',
    ]);
    session_start();
}

// ========== CSRF TOKEN ==========
if (empty($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}

// Path sabiti
define('APP_PATH', realpath(__DIR__ . '/..'));
