Skip to content

Commit

Permalink
Improvement in server info page. Created list of rates from stages.lua.
Browse files Browse the repository at this point in the history
  • Loading branch information
elsongabriel committed Nov 21, 2023
1 parent 4bdfcdb commit 040ef24
Show file tree
Hide file tree
Showing 6 changed files with 673 additions and 354 deletions.
2 changes: 0 additions & 2 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,6 @@

'achievements_base' => 300000,

'server_save' => '05:00:00',

'signature_enabled' => false,
'signature_type' => 'tibian', // signature engine to use: tibian, mango, gesior
'signature_cache_time' => 5, // how long to store cached file (in minutes), default 5 minutes
Expand Down
69 changes: 66 additions & 3 deletions system/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,7 @@ function load_config_lua($filename)
elseif (in_array(@$value[0], array("'", '"')) && in_array(@$value[strlen($value) - 1], array("'", '"')))
$result[$key] = (string)substr(substr($value, 1), 0, -1);
elseif (in_array($value, array('true', 'false')))
$result[$key] = ($value === 'true') ? true : false;
$result[$key] = $value === 'true';
elseif (@$value[0] === '{') {
// arrays are not supported yet
// just ignore the error
Expand All @@ -1011,7 +1011,7 @@ function load_config_lua($filename)
}
}

$result = array_merge($result, isset($config['lua']) ? $config['lua'] : array());
$result = array_merge($result, $config['lua'] ?? array());
return $result;
}

Expand Down Expand Up @@ -1143,7 +1143,7 @@ function configLua($key)
return $config['lua'][$key[0]] = $key[1];
}

return @$config['lua'][$key];
return @$config['lua'][$key] ?? null;
}

function clearCache()
Expand Down Expand Up @@ -1338,6 +1338,69 @@ function isVipSystemEnabled(): bool
return getBoolean(configLua('vipSystemEnabled'));
}

/**
* @param $configFile
* @return array
*
* Function to get stages.lua from canary server.
*/
function loadStagesData($configFile)
{
if (!@file_exists($configFile)) {
log_append('error.log', "[loadStagesData] Fatal error: Cannot load stages.lua ($configFile).");
throw new RuntimeException("ERROR: Cannot find $configFile file.");
}

$result = [];
$config_string = str_replace(["\r\n", "\r"], "\n", file_get_contents($configFile));
$lines = explode("\n", $config_string);

$lastKey = "";
if (count($lines) > 0) {
for ($ln = 0; $ln < count($lines); $ln++) {
$line = str_replace(" ", "", trim($lines[$ln]));
if (strpos($line, '--') !== false || empty($line)) {
continue;
}

if (strpos($line, 'experienceStages') !== false) {
$lastKey = 'experienceStages';
$result[$lastKey] = [];

} else if (strpos($line, 'skillsStages') !== false) {
$lastKey = 'skillsStages';
$result[$lastKey] = [];

} else if (strpos($line, 'magicLevelStages') !== false) {
$lastKey = 'magicLevelStages';
$result[$lastKey] = [];
}

if (strpos($line, '{') !== false) {
$checks = [
'min' => @explode("=", $lines[$ln + 1]),
'max' => @explode("=", $lines[$ln + 2]),
'mul' => @explode("=", $lines[$ln + 3]),
];
$minlevel = isset($checks['min'][0]) && trim($checks['min'][0]) == 'minlevel' ? $checks['min'][1] : null;
$maxlevel = !isset($checks['mul'][1]) ? null : (trim($checks['max'][0]) == 'maxlevel' ? $checks['max'][1] : null);
$multiplier = isset($checks['mul'][0]) && trim($checks['mul'][0]) == 'multiplier' ? $checks['mul'][1] : (trim($checks['max'][0]) == 'multiplier' ? $checks['max'][1] : null);

if (!$minlevel && !$maxlevel && !$multiplier) {
continue;
}

$result[$lastKey][] = [
'minlevel' => $minlevel ? (int)str_replace([" ", ","], "", $minlevel) : null,
'maxlevel' => $maxlevel ? (int)str_replace([" ", ","], "", $maxlevel) : null,
'multiplier' => $multiplier ? (int)str_replace([" ", ","], "", $multiplier) : null,
];
}
}
}
return $result;
}

// validator functions
require_once LIBS . 'validator.php';
require_once SYSTEM . 'compat/base.php';
3 changes: 3 additions & 0 deletions system/init.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,6 @@
//////////////////////////////////////////////
// END - load towns from database (TFS 1.3) //
//////////////////////////////////////////////


$config['lua']['rateStages'] = loadStagesData($config['server_path'] . 'data/stages.lua');
131 changes: 41 additions & 90 deletions system/pages/serverinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,111 +11,62 @@
* @link https://github.com/opentibiabr/myaac
*/
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Server info';
$title = 'Server Info';

if(isset($config['lua']['experience_stages']))
$config['lua']['experienceStages'] = $config['lua']['experience_stages'];

if(isset($config['lua']['min_pvp_level']))
$config['lua']['protectionLevel'] = $config['lua']['min_pvp_level'];

$rent = trim(strtolower($config['lua']['houseRentPeriod']));
if($rent != 'yearly' && $rent != 'monthly' && $rent != 'weekly' && $rent != 'daily')
$rent = trim(strtolower(configLua('houseRentPeriod')));
if ($rent != 'yearly' && $rent != 'monthly' && $rent != 'weekly' && $rent != 'daily')
$rent = 'never';

if(isset($config['lua']['houseCleanOld']))
$cleanOld = (int)(eval('return ' . $config['lua']['houseCleanOld'] . ';') / (24 * 60 * 60));

if(isset($config['lua']['rate_exp']))
$config['lua']['rateExp'] = $config['lua']['rate_exp'];
if(isset($config['lua']['rateExperience']))
$config['lua']['rateExp'] = $config['lua']['rateExperience'];
if(isset($config['lua']['rate_mag']))
$config['lua']['rateMagic'] = $config['lua']['rate_mag'];
if(isset($config['lua']['rate_skill']))
$config['lua']['rateSkill'] = $config['lua']['rate_skill'];
if(isset($config['lua']['rate_loot']))
$config['lua']['rateLoot'] = $config['lua']['rate_loot'];
if(isset($config['lua']['rate_spawn']))
$config['lua']['rateSpawn'] = $config['lua']['rate_spawn'];
$houseLevel = configLua('houseBuyLevel');
$cleanOld = null;

$house_level = NULL;
if(isset($config['lua']['levelToBuyHouse']))
$house_level = $config['lua']['levelToBuyHouse'];
else if(isset($config['lua']['house_level']))
$house_level = $config['lua']['house_level'];
if ($pzLocked = configLua('pzLocked') ?? null)
$pzLocked = eval('return ' . $pzLocked . ';');

if(isset($config['lua']['in_fight_duration']))
$config['lua']['pzLocked'] = $config['lua']['in_fight_duration'];

$pzLocked = eval('return ' . $config['lua']['pzLocked'] . ';');
$whiteSkullTime = isset($config['lua']['whiteSkullTime']) ? $config['lua']['whiteSkullTime'] : NULL;
if(!isset($whiteSkullTime) && isset($config['lua']['unjust_skull_duration']))
$whiteSkullTime = $config['lua']['unjust_skull_duration'];

if(isset($whiteSkullTime))
if ($whiteSkullTime = configLua('whiteSkullTime') ?? null)
$whiteSkullTime = eval('return ' . $whiteSkullTime . ';');

$redSkullLength = isset($config['lua']['redSkullLength']) ? $config['lua']['redSkullLength'] : NULL;
if(!isset($redSkullLength) && isset($config['lua']['red_skull_duration']))
$redSkullLength = $config['lua']['red_skull_duration'];
if ($redSkullDuration = configLua('redSkullDuration') ?? null)
$redSkullDuration = eval('return ' . $redSkullDuration . ';');

if(isset($redSkullLength))
$redSkullLength = eval('return ' . $redSkullLength . ';');
if ($blackSkullDuration = configLua('blackSkullDuration') ?? null)
$blackSkullDuration = eval('return ' . $blackSkullDuration . ';');

$blackSkull = false;
$blackSkullLength = NULL;
if(isset($config['lua']['useBlackSkull']) && getBoolean($config['lua']['useBlackSkull']))
{
$blackSkullLength = $config['lua']['blackSkullLength'];
$blackSkull = true;
}
else if(isset($config['lua']['black_skull_duration'])) {
$blackSkullLength = eval('return ' . $config['lua']['blackSkullLength'] . ';');
$blackSkull = true;
}

$server_save = $config['server_save'];
$explodeServerSave = explode(':', $server_save);
$explodeServerSave = explode(':', configLua('globalServerSaveTime') ?? '05:00:00');
$hours_ServerSave = $explodeServerSave[0];
$minutes_ServerSave = $explodeServerSave[1];
$seconds_ServerSave = $explodeServerSave[2];

$clientVersion = NULL;
if(isset($status['online']))
$clientVersion = isset($status['clientVersion']) ? $status['clientVersion'] : null;
$now = new DateTime();
$serverSaveTime = new DateTime();
$serverSaveTime->setTime($hours_ServerSave, $minutes_ServerSave, $seconds_ServerSave);

$twig->display('serverinfo.html.twig', array(
'server_save' => $explodeServerSave,
'experienceStages' => isset($config['lua']['experienceStages']) && getBoolean($config['lua']['experienceStages']) ? $config['lua']['experienceStages'] : null,
'serverIp' => str_replace('/', '', str_replace('http://', '', $config['lua']['url'])),
'clientVersion' => $clientVersion,
'globalSaveHour' => isset($config['lua']['globalSaveEnabled']) && getBoolean($config['lua']['globalSaveEnabled']) ? $config['lua']['globalSaveHour'] : null,
'protectionLevel' => $config['lua']['protectionLevel'],
if ($now > $serverSaveTime) {
$serverSaveTime->modify('+1 day');
}

$twig->display('serverinfo.html.twig', [
'serverSave' => $explodeServerSave,
'serverSaveTime' => $serverSaveTime->format('Y, n-1, j, G, i, s'),
'rateUseStages' => $rateUseStages = getBoolean(configLua('rateUseStages')),
'rateStages' => $rateUseStages && isset($config['lua']['rateStages']) ? $config['lua']['rateStages'] : [],
'serverIp' => str_replace(['http://', 'https://', '/'], '', configLua('url')),
'clientVersion' => $status['clientVersion'] ?? null,
'protectionLevel' => configLua('protectionLevel'),
'houseRent' => $rent == 'never' ? 'disabled' : $rent,
'houseOld' => isset($cleanOld) ? $cleanOld : null,
'rateExp' => $config['lua']['rateExp'],
'rateExpFromPlayers' => isset($config['lua']['rateExperienceFromPlayers']) ? $config['lua']['rateExperienceFromPlayers'] : null,
'rateMagic' => $config['lua']['rateMagic'],
'rateSkill' => $config['lua']['rateSkill'],
'rateLoot' => $config['lua']['rateLoot'],
'rateSpawn' => $config['lua']['rateSpawn'],
'houseLevel' => $house_level,
'houseOld' => $cleanOld ?? null, // in progressing
'rateExp' => configLua('rateExp'),
'rateMagic' => configLua('rateMagic'),
'rateSkill' => configLua('rateSkill'),
'rateLoot' => configLua('rateLoot'),
'rateSpawn' => configLua('rateSpawn'),
'houseLevel' => $houseLevel,
'pzLocked' => $pzLocked,
'whiteSkullTime' => $whiteSkullTime,
'redSkullLength' => $redSkullLength,
'blackSkull' => $blackSkull,
'blackSkullLength' => $blackSkullLength,
'dailyFragsToRedSkull' => isset($config['lua']['dailyFragsToRedSkull']) ? $config['lua']['dailyFragsToRedSkull'] : (isset($config['lua']['kills_per_day_red_skull']) ? $config['lua']['kills_per_day_red_skull'] : null),
'weeklyFragsToRedSkull' => isset($config['lua']['weeklyFragsToRedSkull']) ? $config['lua']['weeklyFragsToRedSkull'] : (isset($config['lua']['kills_per_week_red_skull']) ? $config['lua']['kills_per_week_red_skull'] : null),
'monthlyFragsToRedSkull' => isset($config['lua']['monthlyFragsToRedSkull']) ? $config['lua']['monthlyFragsToRedSkull'] : (isset($config['lua']['kills_per_month_red_skull']) ? $config['lua']['kills_per_month_red_skull'] : null),
'dailyFragsToBlackSkull' => isset($config['lua']['dailyFragsToBlackSkull']) ? $config['lua']['dailyFragsToBlackSkull'] : (isset($config['lua']['kills_per_day_black_skull']) ? $config['lua']['kills_per_day_black_skull'] : null),
'weeklyFragsToBlackSkull' => isset($config['lua']['weeklyFragsToBlackSkull']) ? $config['lua']['weeklyFragsToBlackSkull'] : (isset($config['lua']['kills_per_week_black_skull']) ? $config['lua']['kills_per_week_black_skull'] : null),
'monthlyFragsToBlackSkull' => isset($config['lua']['monthlyFragsToBlackSkull']) ? $config['lua']['monthlyFragsToBlackSkull'] : (isset($config['lua']['kills_per_month_black_skull']) ? $config['lua']['kills_per_month_black_skull'] : null),
'banishmentLength' => isset($config['lua']['banishment_length']) ? eval('return (' . $config['lua']['banishment_length'] . ') / (24 * 60 * 60);') : null,
'finalBanishmentLength' => isset($config['lua']['final_banishment_length']) ? eval('return (' . $config['lua']['final_banishment_length'] . ') / (24 * 60 * 60);') : null,
'ipBanishmentLength' => isset($config['lua']['ip_banishment_length']) ? eval('return (' . $config['lua']['ip_banishment_length'] . ') / (24 * 60 * 60);') : null,
));
?>

'redSkullDuration' => $redSkullDuration,
'blackSkullDuration' => $blackSkullDuration,
'dailyFragsToRedSkull' => configLua('dayKillsToRedSkull') ?? null,
'weeklyFragsToRedSkull' => configLua('weekKillsToRedSkull') ?? null,
'monthlyFragsToRedSkull' => configLua('monthKillsToRedSkull') ?? null,
]);

Loading

0 comments on commit 040ef24

Please sign in to comment.