mirror of
https://github.com/Shadowss/TravianZ.git
synced 2026-07-26 22:46:09 +00:00
2e53094b48
Add T4 Hero Resource and some fix
126 lines
5.7 KiB
PHP
126 lines
5.7 KiB
PHP
<?php
|
|
#################################################################################
|
|
## -= YOU MAY NOT REMOVE OR CHANGE THIS NOTICE =- ##
|
|
## --------------------------------------------------------------------------- ##
|
|
## Filename config_template.php ##
|
|
## Project TravianZ ##
|
|
## License TravianZ Project ##
|
|
#################################################################################
|
|
|
|
// Shared helper for the admin "Server Settings" Mods, which regenerate
|
|
// GameEngine/config.php from the constant_format.tpl template.
|
|
//
|
|
// Issue #322: each Mod used to read the install-time copy
|
|
// GameEngine/Admin/Mods/constant_format.tpl. That copy is written once by the
|
|
// installer and is gitignored, so a code update NEVER refreshes it. When a new
|
|
// line is added to config.php (e.g. the per-user LANG block, issue #166),
|
|
// servers installed before that change keep the stale copy and the admin panel
|
|
// silently rewrites config.php without the new line.
|
|
//
|
|
// Fix: prefer the version-controlled template (install/data/constant_format.tpl)
|
|
// so shipping a new template via git is enough. Fall back to the install-time
|
|
// copy only when the install folder was deleted (a common hardening step once
|
|
// setup is done).
|
|
|
|
if (!function_exists('admin_config_template_path')) {
|
|
|
|
// Absolute path of the template to use, or false when none is available.
|
|
function admin_config_template_path() {
|
|
$canonical = __DIR__ . '/../../../install/data/constant_format.tpl';
|
|
if (is_file($canonical)) {
|
|
return $canonical;
|
|
}
|
|
|
|
$local = __DIR__ . '/constant_format.tpl';
|
|
return is_file($local) ? $local : false;
|
|
}
|
|
|
|
function admin_config_template_available() {
|
|
return admin_config_template_path() !== false;
|
|
}
|
|
|
|
// Raw template contents, or false when unavailable.
|
|
//
|
|
// Placeholders are left untouched for the caller to fill in, with ONE
|
|
// exception: %CRONKEY%. Every edit*.php mod regenerates config.php from this
|
|
// template and replaces only the placeholders it knows about, so a value that
|
|
// no mod handles would be written to config.php literally — breaking the key
|
|
// used to call cron.php over HTTP. CRON_KEY is not something the admin edits
|
|
// in any of those forms, so it is resolved here, once, for all callers:
|
|
// - existing server -> keep the current CRON_KEY (survives config saves)
|
|
// - key not defined -> provision a fresh random one (servers installed
|
|
// before CRON_KEY existed in the template)
|
|
// $overrides permite unui mod de editare sa IMPUNA o valoare pentru un
|
|
// placeholder pe care altfel l-am pastra din constanta curenta (ex.
|
|
// editServerSet care schimba HERO_BASE_REGEN). Celelalte module apeleaza
|
|
// fara argumente si valorile curente raman neatinse.
|
|
function admin_config_template_contents(array $overrides = array()) {
|
|
$path = admin_config_template_path();
|
|
|
|
if ($path === false) {
|
|
return false;
|
|
}
|
|
|
|
$text = file_get_contents($path);
|
|
|
|
if ($text === false) {
|
|
return false;
|
|
}
|
|
|
|
if (strpos($text, '%CRONKEY%') !== false) {
|
|
$cronKey = (defined('CRON_KEY') && CRON_KEY !== '' && CRON_KEY !== '%CRONKEY%')
|
|
? CRON_KEY
|
|
: bin2hex(random_bytes(24));
|
|
|
|
$text = str_replace('%CRONKEY%', $cronKey, $text);
|
|
}
|
|
|
|
// Acelasi tratament pentru durata ciclului si intervalul de tick: sunt
|
|
// editate din ACP (editCronSet), deci orice alt mod care regenereaza
|
|
// config.php trebuie sa PASTREZE valorile curente, nu sa le reseteze la
|
|
// cele din template.
|
|
if (strpos($text, '%CRONLOOP%') !== false) {
|
|
$cronLoop = defined('CRON_LOOP_SECONDS') ? (int) CRON_LOOP_SECONDS : 300;
|
|
$text = str_replace('%CRONLOOP%', (string) $cronLoop, $text);
|
|
}
|
|
|
|
if (strpos($text, '%CRONTICK%') !== false) {
|
|
$cronTick = defined('CRON_TICK_SECONDS') ? (int) CRON_TICK_SECONDS : 60;
|
|
$text = str_replace('%CRONTICK%', (string) $cronTick, $text);
|
|
}
|
|
|
|
// Retentiile de curatenie: la fel, editate din ACP, deci orice alt mod
|
|
// care regenereaza config.php trebuie sa le pastreze.
|
|
$cleanupDefaults = array(
|
|
'%CLEANUPREPORTS%' => array('CLEANUP_REPORTS_DAYS', 14),
|
|
'%CLEANUPCHAT%' => array('CLEANUP_CHAT_DAYS', 7),
|
|
'%CLEANUPMESSAGES%' => array('CLEANUP_MESSAGES_DAYS', 0),
|
|
);
|
|
|
|
// regenerarea de baza a eroului: acelasi tratament, sa nu fie resetata
|
|
$cleanupDefaults['%HEROBASEREGEN%'] = array('HERO_BASE_REGEN', 10);
|
|
$cleanupDefaults['%HEROSILVERPERGOLD%'] = array('HERO_SILVER_PER_GOLD', 10);
|
|
$cleanupDefaults['%HEROSILVERTOGOLD%'] = array('HERO_SILVER_TO_GOLD', 25);
|
|
$cleanupDefaults['%HERORESALL%'] = array('HERO_RES_PER_POINT_ALL', 3);
|
|
$cleanupDefaults['%HERORESONE%'] = array('HERO_RES_PER_POINT_ONE', 10);
|
|
|
|
foreach ($overrides as $ovPlaceholder => $ovValue) {
|
|
if (strpos($text, $ovPlaceholder) !== false) {
|
|
$text = str_replace($ovPlaceholder, (string) $ovValue, $text);
|
|
}
|
|
}
|
|
|
|
foreach ($cleanupDefaults as $placeholder => $info) {
|
|
if (strpos($text, $placeholder) === false) {
|
|
continue;
|
|
}
|
|
|
|
list($constant, $default) = $info;
|
|
$value = defined($constant) ? (int) constant($constant) : $default;
|
|
$text = str_replace($placeholder, (string) $value, $text);
|
|
}
|
|
|
|
return $text;
|
|
}
|
|
}
|