diff --git a/README.md b/README.md
index 767911d1..e34e806a 100644
--- a/README.md
+++ b/README.md
@@ -1,6 +1,6 @@
# [MyAAC](https://my-aac.org)
-MyAAC is a free and open-source Automatic Account Creator (AAC) written in PHP. It is a fork of the [Gesior](https://github.com/gesior/Gesior2012) project. It supports only MySQL databases.
+MyAAC is a free and open-source Automatic Account Creator (AAC) for Open Tibia Servers written in PHP. It is a fork of the [Gesior](https://github.com/gesior/Gesior2012) project. It supports only MySQL databases.
Official website: https://my-aac.org
diff --git a/index.php b/index.php
index 4526e892..bc8a3663 100644
--- a/index.php
+++ b/index.php
@@ -168,6 +168,7 @@ if ($logged && admin()) {
'username' => USE_ACCOUNT_NAME ? $account_logged->getName() : $account_logged->getId()
]);
}
+
$title_full = (isset($title) ? $title . ' - ' : '') . $config['lua']['serverName'];
require $template_path . '/' . $template_index;
diff --git a/install/tools/7-finish.php b/install/tools/7-finish.php
index 6620f7d9..6f6b2d30 100644
--- a/install/tools/7-finish.php
+++ b/install/tools/7-finish.php
@@ -54,12 +54,13 @@ if ($db->hasTable('players')) {
}
}
-Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php');
-Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php');
-
DataLoader::setLocale($locale);
DataLoader::load();
+// add menus entries
+require_once SYSTEM . 'migrations/17.php';
+$up();
+
// update config.highscores_ids_hidden
require_once SYSTEM . 'migrations/20.php';
$up();
diff --git a/system/compat/base.php b/system/compat/base.php
index d29c9f3a..5a46ecf2 100644
--- a/system/compat/base.php
+++ b/system/compat/base.php
@@ -74,7 +74,3 @@ function fieldExist($field, $table)
global $db;
return $db->hasColumn($table, $field);
}
-
-function getCreatureImgPath($creature): string {
- return getMonsterImgPath($creature);
-}
diff --git a/system/functions.php b/system/functions.php
index b0dbc82e..6e58ca9d 100644
--- a/system/functions.php
+++ b/system/functions.php
@@ -575,7 +575,7 @@ function template_footer(): string
$footer[] = base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4=');
global $hooks;
- $footer = $hooks->triggerFilter(HOOK_FILTER_THEME_FOOTER, $footer);
+ $hooks->triggerFilter(HOOK_FILTER_THEME_FOOTER, $footer);
return implode('
', $footer);
}
@@ -1578,22 +1578,6 @@ function right($str, $length) {
return substr($str, -$length);
}
-function getMonsterImgPath($monster): string
-{
- $monster_path = setting('core.monsters_images_url');
- $monster_gfx_name = trim(strtolower($monster)) . setting('core.monsters_images_extension');
- if (!file_exists($monster_path . $monster_gfx_name)) {
- $monster_gfx_name = str_replace(" ", "", $monster_gfx_name);
- if (file_exists($monster_path . $monster_gfx_name)) {
- return $monster_path . $monster_gfx_name;
- } else {
- return $monster_path . 'nophoto.png';
- }
- } else {
- return $monster_path . $monster_gfx_name;
- }
-}
-
function between($x, $lim1, $lim2) {
if ($lim1 < $lim2) {
$lower = $lim1; $upper = $lim2;
diff --git a/system/libs/pot/OTS_Monster.php b/system/libs/pot/OTS_Monster.php
index 759375f5..ea20c0e1 100644
--- a/system/libs/pot/OTS_Monster.php
+++ b/system/libs/pot/OTS_Monster.php
@@ -284,7 +284,7 @@ class OTS_Monster extends DOMDocument
*/
public function getLook()
{
- $look = array();
+ $look = [];
$element = $this->documentElement->getElementsByTagName('look')->item(0);
@@ -292,14 +292,30 @@ class OTS_Monster extends DOMDocument
return $look;
}
- $look['type'] = $element->getAttribute('type');
- $look['typeex'] = $element->getAttribute('typeex');
- $look['head'] = $element->getAttribute('head');
- $look['body'] = $element->getAttribute('body');
- $look['legs'] = $element->getAttribute('legs');
- $look['feet'] = $element->getAttribute('feet');
- $look['addons'] = $element->getAttribute('addons');
- $look['corpse'] = $element->getAttribute('corpse');
+ if ($element->hasAttribute('typeex')) {
+ $look['typeEx'] = (int) $element->getAttribute('typeex');
+ }
+ if ($element->hasAttribute('type')) {
+ $look['type'] = (int) $element->getAttribute('type');
+ }
+ if ($element->hasAttribute('head')) {
+ $look['head'] = (int) $element->getAttribute('head');
+ }
+ if ($element->hasAttribute('body')) {
+ $look['body'] = (int) $element->getAttribute('body');
+ }
+ if ($element->hasAttribute('legs')) {
+ $look['legs'] = (int) $element->getAttribute('legs');
+ }
+ if ($element->hasAttribute('feet')) {
+ $look['feet'] = (int) $element->getAttribute('feet');
+ }
+ if ($element->hasAttribute('addons')) {
+ $look['addons'] = (int) $element->getAttribute('addons');
+ }
+ if ($element->hasAttribute('corpse')) {
+ $look['corpse'] = (int) $element->getAttribute('corpse');
+ }
return $look;
}
diff --git a/system/migrations/17.php b/system/migrations/17.php
index 497e3e3c..c29d277e 100644
--- a/system/migrations/17.php
+++ b/system/migrations/17.php
@@ -10,8 +10,13 @@ $up = function () use ($db) {
$db->exec(file_get_contents(__DIR__ . '/17-menu.sql'));
}
- Plugins::installMenus('kathrine', require TEMPLATES . 'kathrine/menus.php');
- Plugins::installMenus('tibiacom', require TEMPLATES . 'tibiacom/menus.php');
+ $themes = ['kathrine', 'tibiacom',];
+ foreach ($themes as $theme) {
+ $file = TEMPLATES . $theme . '/menus.php';
+ if (is_file($file)) {
+ Plugins::installMenus($theme, require $file);
+ }
+ }
};
$down = function () use ($db) {
diff --git a/system/pages/monsters.php b/system/pages/monsters.php
index 1678291e..a7d94188 100644
--- a/system/pages/monsters.php
+++ b/system/pages/monsters.php
@@ -16,18 +16,22 @@ defined('MYAAC') or die('Direct access not allowed!');
$title = 'Monsters';
if (empty($_REQUEST['name'])) {
- // display list of monsters
$preview = setting('core.monsters_images_preview');
- $monsters = Monster::where('hide', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) {
- $query->where('rewardboss', 1);
- })->get()->toArray();
- if ($preview) {
- foreach($monsters as $key => &$monster)
- {
- $monster['img_link'] = getMonsterImgPath($monster['name']);
+ // display list of monsters
+ $monsters = MyAAC\Cache::remember('monsters', 30 * 60, function () use ($preview) {
+ $monsters = Monster::where('hide', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) {
+ $query->where('rewardboss', 1);
+ })->get()->toArray();
+
+ if ($preview) {
+ foreach($monsters as &$monster) {
+ $monster['img_link'] = getMonsterImage($monster);
+ }
}
- }
+
+ return $monsters;
+ });
$twig->display('monsters.html.twig', array(
'monsters' => $monsters,
@@ -45,7 +49,7 @@ if ($monsterModel && isset($monsterModel->name)) {
/** @var array $monster */
$monster = $monsterModel->toArray();
- function sort_by_chance($a, $b)
+ function sort_by_chance($a, $b): int
{
if ($a['chance'] == $b['chance']) {
return 0;
@@ -55,7 +59,7 @@ if ($monsterModel && isset($monsterModel->name)) {
$title = $monster['name'] . " - Monsters";
- $monster['img_link']= getMonsterImgPath($monster_name);
+ $monster['img_link']= getMonsterImage($monster);
$voices = json_decode($monster['voices'], true);
$summons = json_decode($monster['summons'], true);
@@ -89,3 +93,39 @@ if ($monsterModel && isset($monsterModel->name)) {
// back button
$twig->display('monsters.back_button.html.twig');
+
+function getMonsterImage($monster): string
+{
+ $outfit = json_decode($monster['look'], true);
+
+ if (!empty($outfit['typeEx'])) {
+ return setting('core.item_images_url') . $outfit['typeEx'] . setting('core.item_images_extension');
+ }
+
+ if (isset($outfit['type'])) {
+ $getValue = function ($val) use ($outfit) {
+ return (!empty($outfit[$val])
+ ? '&' . $val . '=' . $outfit[$val] : '');
+ };
+
+ return setting('core.outfit_images_url') . '?id=' . $outfit['type'] . $getValue('addons') . $getValue('head') . $getValue('body') . $getValue('legs') . $getValue('feet');
+ }
+
+ return getMonsterImgPath($monster['name']);
+}
+
+function getMonsterImgPath($name): string
+{
+ $monster_path = setting('core.monsters_images_url');
+ $monster_gfx_name = trim(strtolower($name)) . setting('core.monsters_images_extension');
+ if (!file_exists($monster_path . $monster_gfx_name)) {
+ $monster_gfx_name = str_replace(" ", "", $monster_gfx_name);
+ if (file_exists($monster_path . $monster_gfx_name)) {
+ return $monster_path . $monster_gfx_name;
+ } else {
+ return $monster_path . 'nophoto.png';
+ }
+ } else {
+ return $monster_path . $monster_gfx_name;
+ }
+}
diff --git a/system/router.php b/system/router.php
index e0bcc04f..b87a843d 100644
--- a/system/router.php
+++ b/system/router.php
@@ -317,6 +317,11 @@ $content .= ob_get_contents();
ob_end_clean();
$hooks->trigger(HOOK_AFTER_PAGE);
+if (isset($_REQUEST['_page_only'])) {
+ echo $content;
+ die;
+}
+
if(!isset($title)) {
$title = str_replace('index.php/', '', $page);
$title = ucfirst($title);
diff --git a/system/settings.php b/system/settings.php
index d2c2745b..729527c0 100644
--- a/system/settings.php
+++ b/system/settings.php
@@ -1473,7 +1473,7 @@ Sent by MyAAC,
],
'status_timeout' => [
'name' => 'Status Timeout',
- 'type' => 'number',
+ 'type' => 'double',
'min' => 0,
'max' => 10, // more than 10 seconds waiting makes no sense
'step' => 0.1,
diff --git a/system/src/Hook.php b/system/src/Hook.php
index 9f4b7978..161b2ffc 100644
--- a/system/src/Hook.php
+++ b/system/src/Hook.php
@@ -37,7 +37,7 @@ class Hook
return !isset($ret) || $ret == 1 || $ret;
}
- public function executeFilter(...$args) {
+ public function executeFilter(&$args) {
return include BASE . $this->_file;
}
diff --git a/system/src/Hooks.php b/system/src/Hooks.php
index 084d5e1a..8dac8eda 100644
--- a/system/src/Hooks.php
+++ b/system/src/Hooks.php
@@ -30,16 +30,14 @@ class Hooks
return $ret;
}
- public function triggerFilter($type, $args = [])
+ public function triggerFilter($type, &$args): void
{
if(isset(self::$_hooks[$type])) {
foreach(self::$_hooks[$type] as $hook) {
/** @var Hook $hook */
- $args = $hook->executeFilter(...$args);
+ $hook->executeFilter($args);
}
}
-
- return $args;
}
public function exist($type): bool {
diff --git a/system/src/Plugins.php b/system/src/Plugins.php
index f9d4d5ce..4acca75e 100644
--- a/system/src/Plugins.php
+++ b/system/src/Plugins.php
@@ -198,6 +198,9 @@ class Plugins {
}
}
+ global $hooks;
+ $hooks->triggerFilter(HOOK_FILTER_ROUTES, $routes);
+
usort($routes, function ($a, $b)
{
// key 3 is priority
diff --git a/system/src/Settings.php b/system/src/Settings.php
index e243687e..0df8fa81 100644
--- a/system/src/Settings.php
+++ b/system/src/Settings.php
@@ -219,7 +219,7 @@ class Settings implements \ArrayAccess
if ($setting['type'] === 'boolean') {
$value = ($setting['default'] ? 'true' : 'false');
}
- else if (in_array($setting['type'], ['text', 'number', 'email', 'password', 'textarea'])) {
+ else if (in_array($setting['type'], ['text', 'number', 'float', 'double', 'email', 'password', 'textarea'])) {
$value = $setting['default'];
}
else if ($setting['type'] === 'options') {
@@ -245,7 +245,11 @@ class Settings implements \ArrayAccess
$checkbox($key, false, $value);
}
- else if (in_array($setting['type'], ['text', 'number', 'email', 'password'])) {
+ else if (in_array($setting['type'], ['text', 'number', 'float', 'double', 'email', 'password'])) {
+ if (in_array($setting['type'], ['float', 'double'])) {
+ $setting['type'] = 'number';
+ }
+
if ($setting['type'] === 'number') {
$min = (isset($setting['min']) ? ' min="' . $setting['min'] . '"' : '');
$max = (isset($setting['max']) ? ' max="' . $setting['max'] . '"' : '');
@@ -351,7 +355,7 @@ class Settings implements \ArrayAccess
if ($setting['type'] === 'boolean') {
echo ($setting['default'] ? 'Yes' : 'No');
}
- else if (in_array($setting['type'], ['text', 'number', 'email', 'password', 'textarea'])) {
+ else if (in_array($setting['type'], ['text', 'number', 'float', 'double', 'email', 'password', 'textarea'])) {
echo $setting['default'];
}
else if ($setting['type'] === 'options') {
@@ -498,9 +502,12 @@ class Settings implements \ArrayAccess
break;
case 'number':
- if (!isset($ret['step']) || (int)$ret['step'] == 1) {
- $ret['value'] = (int)$ret['value'];
- }
+ $ret['value'] = (int)$ret['value'];
+ break;
+
+ case 'double':
+ case 'float':
+ $ret['value'] = (double)($ret['value']);
break;
default:
diff --git a/system/src/Twig/EnvironmentBridge.php b/system/src/Twig/EnvironmentBridge.php
index ab54bd25..4b8423f8 100644
--- a/system/src/Twig/EnvironmentBridge.php
+++ b/system/src/Twig/EnvironmentBridge.php
@@ -11,7 +11,7 @@ class EnvironmentBridge extends Environment
global $hooks;
$context['viewName'] = $name;
- $context = $hooks->triggerFilter(HOOK_FILTER_TWIG_DISPLAY, $context);
+ $hooks->triggerFilter(HOOK_FILTER_TWIG_DISPLAY, $context);
parent::display($name, $context);
}
@@ -21,7 +21,7 @@ class EnvironmentBridge extends Environment
global $hooks;
$context['viewName'] = $name;
- $context = $hooks->triggerFilter(HOOK_FILTER_TWIG_RENDER, $context);
+ $hooks->triggerFilter(HOOK_FILTER_TWIG_RENDER, $context);
return parent::render($name, $context);
}
diff --git a/system/src/global.php b/system/src/global.php
index ed9df203..62366c1c 100644
--- a/system/src/global.php
+++ b/system/src/global.php
@@ -98,6 +98,7 @@ define('HOOK_INSTALL_FINISH', ++$i);
define('HOOK_INSTALL_FINISH_END', ++$i);
// hook filters
+define('HOOK_FILTER_ROUTES', ++$i);
define('HOOK_FILTER_TWIG_DISPLAY', ++$i);
define('HOOK_FILTER_TWIG_RENDER', ++$i);
define('HOOK_FILTER_THEME_FOOTER', ++$i);