-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.php
More file actions
129 lines (107 loc) · 3.58 KB
/
Copy pathconfig.php
File metadata and controls
129 lines (107 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* zero Random - Configuration
*/
define('APP_NAME', 'zero Random');
define('APP_URL', 'http://localhost:8000');
define('APP_VERSION', '1.0.0');
// Database - SQLite
define('DB_PATH', __DIR__ . '/data/oimanka.db');
// Session
define('SESSION_LIFETIME', 86400);
// Gacha settings
define('GACHA_SINGLE_COST', 10);
define('GACHA_MULTI_COST', 90);
define('GACHA_MULTI_COUNT', 10);
define('GACHA_HUNDRED_COST', 850);
define('GACHA_HUNDRED_COUNT', 100);
define('GACHA_LEGENDARY_PITY_100', 3);
// Trading
define('TRADE_FEE_PCT', 1.0);
define('PRICE_IMPACT_FACTOR', 0.001);
// Starter tokens
define('STARTER_TOKENS', 100);
// Rarity (heat-based)
define('RARITY_LEGENDARY_PCT', 5);
define('RARITY_EPIC_PCT', 15);
define('RARITY_RARE_PCT', 40);
// Token conversion: 1 AC = 10 tokens
define('TOKENS_PER_AC', 10);
define('SYNC_COOLDOWN_MINUTES', 10);
// Default adapter (stocks only come from adapters — no sample data)
define('DEFAULT_ADAPTER', 'hustoj');
// Debug
define('DEBUG_MODE', true);
if (DEBUG_MODE) {
error_reporting(E_ALL);
ini_set('display_errors', 1);
} else {
error_reporting(0);
ini_set('display_errors', 0);
}
date_default_timezone_set('Asia/Shanghai');
// Database initialization key
// If the database is not initialized, visit setup.php and enter this key to run migrations.
define('DB_INIT_KEY', 'oimankaconfigkey');
/**
* Get a platform config value from DB.
* Falls back to the provided default if not set.
*/
function platform_config(string $adapter, string $key, $default = null) {
static $cache = [];
$cacheKey = "{$adapter}:{$key}";
if (isset($cache[$cacheKey])) return $cache[$cacheKey];
try {
$db = Database::getInstance();
$stmt = $db->prepare("SELECT config_value FROM platform_config WHERE adapter_name = ? AND config_key = ?");
$stmt->execute([$adapter, $key]);
$val = $stmt->fetchColumn();
$cache[$cacheKey] = ($val !== false) ? $val : $default;
return $cache[$cacheKey];
} catch (Exception $e) {
return $default;
}
}
/**
* Set a platform config value in DB.
*/
function platform_config_set(string $adapter, string $key, $value): void {
$db = Database::getInstance();
$stmt = $db->prepare("
INSERT INTO platform_config (adapter_name, config_key, config_value)
VALUES (?, ?, ?)
ON CONFLICT(adapter_name, config_key) DO UPDATE SET config_value = excluded.config_value
");
$stmt->execute([$adapter, $key, (string)$value]);
}
/**
* Check if an adapter is configured.
*/
function platform_configured(string $adapter): bool {
return !empty(platform_config($adapter, 'db_host'));
}
/**
* Get OJ URL for the frontend (from whichever adapter is active).
*/
function oj_url(): string {
$adapter = platform_configured('hustoj') ? 'hustoj' : (platform_configured('hydroj') ? 'hydroj' : null);
if (!$adapter) return '';
return platform_config($adapter, 'oj_url', '');
}
define('OJ_URL_FN', true); // signal that oj_url() is available
// Kaleidoscope (天·界) layer — also defined in helpers.php for deployed server
/**
* Get the base path for URL generation.
* Extracted from APP_URL (e.g. APP_URL = "http://noiclub.cn/zeroran" → "/zeroran").
*/
define('BASE_PATH', rtrim(parse_url(APP_URL, PHP_URL_PATH) ?? '', '/') ?: '');
/**
* Generate a URL with the correct base path prepended.
* Use this for all internal links and redirects.
*
* @param string $path Path starting with /, e.g. '/login'
* @return string Full path with base, e.g. '/zeroran/login'
*/
function url(string $path): string {
return BASE_PATH . '/' . ltrim($path, '/');
}