mirror of
				https://github.com/slawkens/myaac.git
				synced 2025-10-30 23:46:24 +01:00 
			
		
		
		
	Compare commits
	
		
			45 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | e719725841 | ||
|   | 4ca58b4178 | ||
|   | 03e2752139 | ||
|   | 2fece725a4 | ||
|   | bb3e90110d | ||
|   | c24c580796 | ||
|   | 620a47da72 | ||
|   | 9b75011224 | ||
|   | 5b4b7b8a97 | ||
|   | 99997eb57d | ||
|   | 73a5829974 | ||
|   | 497338c2d6 | ||
|   | beb348fe27 | ||
|   | 5b1bd4f005 | ||
|   | f09606d01b | ||
|   | 67ab425bb9 | ||
|   | 113473f256 | ||
|   | d6ac4e8d85 | ||
|   | 6845869838 | ||
|   | 2f0758e351 | ||
|   | 6667c8c364 | ||
|   | 0fbd4bf1be | ||
|   | 1e45d5c393 | ||
|   | dbea69f314 | ||
|   | 4e6aa0f262 | ||
|   | fa1f927082 | ||
|   | de0512f11a | ||
|   | c13a540878 | ||
|   | 869ec035d9 | ||
|   | 9d696d31d8 | ||
|   | 8cc4caf587 | ||
|   | e1d1c7d5db | ||
|   | 320733c2c1 | ||
|   | c1809a98d1 | ||
|   | 46ed541015 | ||
|   | 29207361b7 | ||
|   | 25013ae91b | ||
|   | 5d630ba9dd | ||
|   | feadf1314d | ||
|   | 08b8a716d4 | ||
|   | cc26b5c744 | ||
|   | cb6e9a6a88 | ||
|   | 4adb0758c5 | ||
|   | 7312383f73 | ||
|   | 3c1210fefa | 
							
								
								
									
										4
									
								
								.github/workflows/cypress.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/cypress.yml
									
									
									
									
										vendored
									
									
								
							| @@ -22,7 +22,7 @@ jobs: | ||||
|     strategy: | ||||
|       fail-fast: false | ||||
|       matrix: | ||||
|         php-versions: [ '8.1', '8.2', '8.3' ] | ||||
|         php-versions: [ '8.1', '8.2', '8.3', '8.4' ] | ||||
|         ots: ['tfs-1.4', 'canary-3.1.2'] # TODO: add 'tfs-master' (actually doesn't work cause AAC doesn't support reading .env configuration) | ||||
|     name: Cypress (PHP ${{ matrix.php-versions }}, ${{ matrix.ots }}) | ||||
|     steps: | ||||
| @@ -146,6 +146,7 @@ jobs: | ||||
|           with: | ||||
|             name: cypress-screenshots-${{ matrix.php-versions }}-${{ matrix.ots }} | ||||
|             path: cypress/screenshots | ||||
|             if-no-files-found: ignore | ||||
|  | ||||
|         - name: Upload Cypress Videos | ||||
|           uses: actions/upload-artifact@v4 | ||||
| @@ -153,6 +154,7 @@ jobs: | ||||
|           with: | ||||
|             name: cypress-videos-${{ matrix.php-versions }}-${{ matrix.ots }} | ||||
|             path: cypress/videos | ||||
|             if-no-files-found: ignore | ||||
|  | ||||
|         - name: Upload PHP Logs | ||||
|           uses: actions/upload-artifact@v4 | ||||
|   | ||||
| @@ -6,7 +6,7 @@ | ||||
| 	Options -MultiViews | ||||
| </IfModule> | ||||
|  | ||||
| <FilesMatch "^(CHANGELOG\.md|README\.md|composer\.json|composer\.lock|package\.json|package-lock\.json|cypress\.env\.json)$"> | ||||
| <FilesMatch "^(.*\.md|.*\.json|.*\.dist|.*\.sql|CHANGELOG|README|composer\.lock)$"> | ||||
| 	Require all denied | ||||
| </FilesMatch> | ||||
|  | ||||
|   | ||||
| @@ -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 | ||||
|  | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
|  */ | ||||
|  | ||||
| use MyAAC\Models\Account as AccountModel; | ||||
| use MyAAC\Models\AccountAction; | ||||
| use MyAAC\Models\Player; | ||||
|  | ||||
| defined('MYAAC') or die('Direct access not allowed!'); | ||||
| @@ -466,9 +467,8 @@ else if (isset($_REQUEST['search'])) { | ||||
| 									</thead> | ||||
| 									<tbody> | ||||
| 										<?php | ||||
| 											$accountActions = \MyAAC\Models\AccountAction::where('account_id', $account->getId())->orderByDesc('date')->get(); | ||||
| 											$accountActions = AccountAction::where('account_id', $account->getId())->orderByDesc('date')->get(); | ||||
| 											foreach ($accountActions as $i => $log): | ||||
| 												$log->ip = ($log->ip != 0 ? long2ip($log->ip) : inet_ntop($log->ipv6)); | ||||
| 												?> | ||||
| 											<tr> | ||||
| 												<td><?php echo $i + 1; ?></td> | ||||
|   | ||||
| @@ -26,8 +26,8 @@ | ||||
| if (version_compare(phpversion(), '8.1', '<')) die('PHP version 8.1 or higher is required.'); | ||||
|  | ||||
| const MYAAC = true; | ||||
| const MYAAC_VERSION = '1.4'; | ||||
| const DATABASE_VERSION = 43; | ||||
| const MYAAC_VERSION = '2.0-dev'; | ||||
| const DATABASE_VERSION = 44; | ||||
| const TABLE_PREFIX = 'myaac_'; | ||||
| define('START_TIME', microtime(true)); | ||||
| define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX')); | ||||
|   | ||||
| @@ -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; | ||||
|  | ||||
|   | ||||
| @@ -2,12 +2,12 @@ SET @myaac_database_version = 43; | ||||
|  | ||||
| CREATE TABLE `myaac_account_actions` | ||||
| ( | ||||
| 	`id` int NOT NULL AUTO_INCREMENT, | ||||
| 	`account_id` int NOT NULL, | ||||
| 	`ip` int unsigned NOT NULL DEFAULT 0, | ||||
| 	`ipv6` binary(16) NOT NULL DEFAULT 0, | ||||
| 	`ip` varchar(45) NOT NULL DEFAULT '', | ||||
| 	`date` int NOT NULL DEFAULT 0, | ||||
| 	`action` varchar(255) NOT NULL DEFAULT '', | ||||
| 	KEY (`account_id`) | ||||
| 	PRIMARY KEY (`id`) | ||||
| ) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4; | ||||
|  | ||||
| CREATE TABLE `myaac_admin_menu` | ||||
|   | ||||
| @@ -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(); | ||||
|   | ||||
| @@ -86,7 +86,7 @@ switch ($action) { | ||||
| 		die(json_encode(['eventlist' => $eventlist, 'lastupdatetimestamp' => time()])); | ||||
|  | ||||
| 	case 'boostedcreature': | ||||
| 		$boostedCreature = BoostedCreature::latest(); | ||||
| 		$boostedCreature = BoostedCreature::first(); | ||||
| 		die(json_encode([ | ||||
| 			'boostedcreature' => true, | ||||
| 			'raceid' => $boostedCreature->raceid | ||||
|   | ||||
| @@ -14,7 +14,7 @@ server { | ||||
|  | ||||
| 	# block .htaccess, CHANGELOG.md, composer.json etc. | ||||
| 	# this is to prevent finding software versions | ||||
| 	location ~\.(ht|md|json|dist)$ { | ||||
| 	location ~\.(ht|md|json|dist|sql)$ { | ||||
| 		deny all; | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -74,7 +74,3 @@ function fieldExist($field, $table) | ||||
| 	global $db; | ||||
| 	return $db->hasColumn($table, $field); | ||||
| } | ||||
|  | ||||
| function getCreatureImgPath($creature): string { | ||||
| 	return getMonsterImgPath($creature); | ||||
| } | ||||
|   | ||||
| @@ -545,33 +545,39 @@ function template_header($is_admin = false): string | ||||
|  */ | ||||
| function template_footer(): string | ||||
| { | ||||
| 	global $views_counter; | ||||
| 	$ret = ''; | ||||
| 	$footer = []; | ||||
|  | ||||
| 	if(admin()) { | ||||
| 		$ret .= generateLink(ADMIN_URL, 'Admin Panel', true); | ||||
| 		$footer[] = generateLink(ADMIN_URL, 'Admin Panel', true); | ||||
| 	} | ||||
|  | ||||
| 	if(setting('core.visitors_counter')) { | ||||
| 		global $visitors; | ||||
| 		$amount = $visitors->getAmountVisitors(); | ||||
| 		$ret .= '<br/>Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.'; | ||||
| 		$footer[] = 'Currently there ' . ($amount > 1 ? 'are' : 'is') . ' ' . $amount . ' visitor' . ($amount > 1 ? 's' : '') . '.'; | ||||
| 	} | ||||
|  | ||||
| 	if(setting('core.views_counter')) { | ||||
| 		$ret .= '<br/>Page has been viewed ' . $views_counter . ' times.'; | ||||
| 		global $views_counter; | ||||
| 		$footer[] = 'Page has been viewed ' . $views_counter . ' times.'; | ||||
| 	} | ||||
|  | ||||
| 	if(setting('core.footer_load_time')) { | ||||
| 		$ret .= '<br/>Load time: ' . round(microtime(true) - START_TIME, 4) . ' seconds.'; | ||||
| 		$footer[] = 'Load time: ' . round(microtime(true) - START_TIME, 4) . ' seconds.'; | ||||
| 	} | ||||
|  | ||||
| 	$settingFooter = setting('core.footer'); | ||||
| 	if(isset($settingFooter[0])) { | ||||
| 		$ret .= '<br/>' . $settingFooter; | ||||
| 		$footer[] = '' . $settingFooter; | ||||
| 	} | ||||
|  | ||||
| 	// please respect my work and help spreading the word, thanks! | ||||
| 	return $ret . '<br/>' . base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4='); | ||||
| 	$footer[] = base64_decode('UG93ZXJlZCBieSA8YSBocmVmPSJodHRwOi8vbXktYWFjLm9yZyIgdGFyZ2V0PSJfYmxhbmsiPk15QUFDLjwvYT4='); | ||||
|  | ||||
| 	global $hooks; | ||||
| 	$hooks->triggerFilter(HOOK_FILTER_THEME_FOOTER, $footer); | ||||
|  | ||||
| 	return implode('<br/>', $footer); | ||||
| } | ||||
|  | ||||
| function template_ga_code() | ||||
| @@ -1572,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; | ||||
|   | ||||
| @@ -12,6 +12,8 @@ | ||||
|  * @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3 | ||||
|  */ | ||||
|  | ||||
| use MyAAC\Models\AccountAction; | ||||
|  | ||||
| /** | ||||
|  * OTServ account abstraction. | ||||
|  * | ||||
| @@ -1010,26 +1012,16 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable | ||||
|  | ||||
| 	public function logAction($action) | ||||
| 	{ | ||||
| 		$ip = get_browser_real_ip(); | ||||
| 		if(!str_contains($ip, ":")) { | ||||
| 			$ipv6 = '0'; | ||||
| 		} | ||||
| 		else { | ||||
| 			$ipv6 = $ip; | ||||
| 			$ip = ''; | ||||
| 		AccountAction::create([ | ||||
| 			'account_id' => $this->getId(), | ||||
| 			'ip' => get_browser_real_ip(), | ||||
| 			'date' => time(), | ||||
| 			'action' => $action, | ||||
| 		]); | ||||
| 	} | ||||
|  | ||||
| 		return $this->db->exec('INSERT INTO `' . TABLE_PREFIX . 'account_actions` (`account_id`, `ip`, `ipv6`, `date`, `action`) VALUES (' . $this->db->quote($this->getId()).', ' . ($ip == '' ? '0' : $this->db->quote(ip2long($ip))) . ', (' . ($ipv6 == '0' ? $this->db->quote('') : $this->db->quote(inet_pton($ipv6))) . '), UNIX_TIMESTAMP(NOW()), ' . $this->db->quote($action).')'); | ||||
| 	} | ||||
|  | ||||
| 	public function getActionsLog($limit1, $limit2) | ||||
| 	{ | ||||
| 		$actions = array(); | ||||
|  | ||||
| 		foreach($this->db->query('SELECT `ip`, `ipv6`, `date`, `action` FROM `' . TABLE_PREFIX . 'account_actions` WHERE `account_id` = ' . $this->data['id'] . ' ORDER by `date` DESC LIMIT ' . $limit1 . ', ' . $limit2 . '')->fetchAll() as $a) | ||||
| 			$actions[] = array('ip' => $a['ip'], 'ipv6' => $a['ipv6'], 'date' => $a['date'], 'action' => $a['action']); | ||||
|  | ||||
| 		return $actions; | ||||
| 	public function getActionsLog($limit) { | ||||
| 		return AccountAction::where('account_id', $this->data['id'])->orderByDesc('date')->limit($limit)->get()->toArray(); | ||||
| 	} | ||||
| /** | ||||
|  * Returns players iterator. | ||||
|   | ||||
| @@ -97,7 +97,7 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable | ||||
|  * | ||||
|  * @param IOTS_GuildAction $invites Invites driver (don't pass it to clear driver). | ||||
|  */ | ||||
|     public function setInvitesDriver(IOTS_GuildAction $invites = null) | ||||
|     public function setInvitesDriver(?IOTS_GuildAction $invites = null) | ||||
|     { | ||||
|         $this->invites = $invites; | ||||
|     } | ||||
| @@ -107,7 +107,7 @@ class OTS_Guild extends OTS_Row_DAO implements IteratorAggregate, Countable | ||||
|  * | ||||
|  * @param IOTS_GuildAction $requests Membership requests driver (don't pass it to clear driver). | ||||
|  */ | ||||
|     public function setRequestsDriver(IOTS_GuildAction $requests = null) | ||||
|     public function setRequestsDriver(?IOTS_GuildAction $requests = null) | ||||
|     { | ||||
|         $this->requests = $requests; | ||||
|     } | ||||
|   | ||||
| @@ -60,7 +60,7 @@ class OTS_GuildRank extends OTS_Row_DAO implements IteratorAggregate, Countable | ||||
|  * @throws PDOException On PDO operation error. | ||||
|  * @throws E_OTS_NotLoaded If given <var>$guild</var> object is not loaded. | ||||
|  */ | ||||
|     public function find($name, OTS_Guild $guild = null) | ||||
|     public function find($name, ?OTS_Guild $guild = null) | ||||
|     { | ||||
|         $where = ''; | ||||
|  | ||||
|   | ||||
| @@ -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; | ||||
| 	} | ||||
|   | ||||
| @@ -2026,7 +2026,7 @@ class OTS_Player extends OTS_Row_DAO | ||||
|  * @param OTS_GuildRank|null Guild rank (null to clear assign). | ||||
|  * @throws E_OTS_NotLoaded If passed <var>$guildRank</var> parameter is not loaded. | ||||
|  */ | ||||
| 	public function setRank(OTS_GuildRank $guildRank = null) | ||||
| 	public function setRank(?OTS_GuildRank $guildRank = null) | ||||
| 	{ | ||||
| 		if(isset($guildRank)) | ||||
| 			$this->setRankId($guildRank->getId(), $guildRank->getGuild()->getId()); | ||||
| @@ -2632,7 +2632,7 @@ class OTS_Player extends OTS_Row_DAO | ||||
|  * @throws E_OTS_NotLoaded If player is not loaded. | ||||
|  * @throws PDOException On PDO operation error. | ||||
|  */ | ||||
| 	public function setSlot($slot, OTS_Item $item = null, $pid = 0) | ||||
| 	public function setSlot($slot, ?OTS_Item $item = null, $pid = 0) | ||||
| 	{ | ||||
| 		static $sid; | ||||
|  | ||||
| @@ -2776,7 +2776,7 @@ class OTS_Player extends OTS_Row_DAO | ||||
|  * @throws E_OTS_NotLoaded If player is not loaded. | ||||
|  * @throws PDOException On PDO operation error. | ||||
|  */ | ||||
| 	public function setDepot($depot, OTS_Item $item = null, $pid = 0, $depot_id = 0) | ||||
| 	public function setDepot($depot, ?OTS_Item $item = null, $pid = 0, $depot_id = 0) | ||||
| 	{ | ||||
| 		static $sid; | ||||
|  | ||||
|   | ||||
| @@ -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) { | ||||
|   | ||||
							
								
								
									
										27
									
								
								system/migrations/44.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								system/migrations/44.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,27 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @var OTS_DB_MySQL $db | ||||
|  */ | ||||
|  | ||||
| // 2025-02-27 | ||||
| // remove ipv6, change to ip (for both ipv4 + ipv6) as VARCHAR(45) | ||||
| $up = function () use ($db) { | ||||
| 	$db->query("ALTER TABLE `myaac_account_actions` DROP KEY `account_id`;"); | ||||
| 	$db->query("ALTER TABLE  `myaac_account_actions` ADD COLUMN `id` INT(11) NOT NULL AUTO_INCREMENT FIRST, ADD PRIMARY KEY (`id`);"); | ||||
|  | ||||
| 	$db->modifyColumn(TABLE_PREFIX . 'account_actions', 'ip', "VARCHAR(45) NOT NULL DEFAULT ''"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = INET_NTOA(`ip`) WHERE `ip` != '0';"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = INET6_NTOA(`ipv6`) WHERE `ip` = '0';"); | ||||
| 	$db->dropColumn(TABLE_PREFIX . 'account_actions', 'ipv6'); | ||||
| }; | ||||
|  | ||||
| $down = function () use ($db) { | ||||
| 	$db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` DROP `id`;"); | ||||
| 	$db->query("ALTER TABLE  `" . TABLE_PREFIX . "account_actions` ADD KEY (`account_id`);"); | ||||
|  | ||||
| 	$db->addColumn(TABLE_PREFIX . 'account_actions', 'ipv6', "BINARY(16) NOT NULL DEFAULT 0x00000000000000000000000000000000 AFTER ip"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ipv6` = INET6_ATON(ip) WHERE NOT IS_IPV4(`ip`);"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = INET_ATON(`ip`) WHERE IS_IPV4(`ip`);"); | ||||
| 	$db->query("UPDATE `" . TABLE_PREFIX . "account_actions` SET `ip` = 0 WHERE `ipv6` != 0x00000000000000000000000000000000;"); | ||||
| 	$db->modifyColumn(TABLE_PREFIX . 'account_actions', 'ip', "INT(11) UNSIGNED NOT NULL DEFAULT 0;"); | ||||
| }; | ||||
| @@ -85,12 +85,8 @@ if($email_new_time > 1) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| $actions = array(); | ||||
| foreach($account_logged->getActionsLog(0, 1000) as $action) { | ||||
| 	$actions[] = array('action' => $action['action'], 'date' => $action['date'], 'ip' => $action['ip'] != 0 ? long2ip($action['ip']) : inet_ntop($action['ipv6'])); | ||||
| } | ||||
| $actions = $account_logged->getActionsLog(1000); | ||||
|  | ||||
| $players = array(); | ||||
| /** @var OTS_Players_List $account_players */ | ||||
| $account_players = $account_logged->getPlayersList(); | ||||
| $account_players->orderBy('id'); | ||||
|   | ||||
| @@ -16,19 +16,23 @@ defined('MYAAC') or die('Direct access not allowed!'); | ||||
| $title = 'Monsters'; | ||||
|  | ||||
| if (empty($_REQUEST['name'])) { | ||||
| 	// display list of monsters | ||||
| 	$preview = setting('core.monsters_images_preview'); | ||||
|  | ||||
| 	// 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 $key => &$monster) | ||||
| 		{ | ||||
| 			$monster['img_link'] = getMonsterImgPath($monster['name']); | ||||
| 			foreach($monsters as &$monster) { | ||||
| 				$monster['img_link'] = getMonsterImage($monster); | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		return $monsters; | ||||
| 	}); | ||||
|  | ||||
| 	$twig->display('monsters.html.twig', array( | ||||
| 		'monsters' => $monsters, | ||||
| 		'preview' => $preview | ||||
| @@ -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; | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -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); | ||||
|   | ||||
| @@ -1473,7 +1473,7 @@ Sent by MyAAC,<br/> | ||||
| 		], | ||||
| 		'status_timeout' => [ | ||||
| 			'name' => 'Status Timeout', | ||||
| 			'type' => 'number', | ||||
| 			'type' => 'double', | ||||
| 			'min' => 0, | ||||
| 			'max' => 10, // more than 10 seconds waiting makes no sense | ||||
| 			'step' => 0.1, | ||||
|   | ||||
| @@ -37,6 +37,11 @@ class Hook | ||||
| 		return !isset($ret) || $ret == 1 || $ret; | ||||
| 	} | ||||
|  | ||||
| 	public function executeFilter(&$args) { | ||||
| 		return include BASE . $this->_file; | ||||
| 	} | ||||
|  | ||||
| 	public function name() {return $this->_name;} | ||||
| 	public function type() {return $this->_type;} | ||||
| 	public function file() {return $this->_file;} | ||||
| } | ||||
|   | ||||
| @@ -4,22 +4,23 @@ namespace MyAAC; | ||||
|  | ||||
| class Hooks | ||||
| { | ||||
| 	private static $_hooks = array(); | ||||
| 	private static array $_hooks = []; | ||||
|  | ||||
| 	public function register($hook, $type = '', $file = null) { | ||||
| 	public function register($hook, $type = '', $file = null): void | ||||
| 	{ | ||||
| 		if(!($hook instanceof Hook)) | ||||
| 			$hook = new Hook($hook, $type, $file); | ||||
|  | ||||
| 		self::$_hooks[$hook->type()][] = $hook; | ||||
| 	} | ||||
|  | ||||
| 	public function trigger($type, $params = array()) | ||||
| 	public function trigger($type, $params = []): bool | ||||
| 	{ | ||||
| 		$ret = true; | ||||
| 		if(isset(self::$_hooks[$type])) | ||||
| 		{ | ||||
|  | ||||
| 		if(isset(self::$_hooks[$type])) { | ||||
| 			foreach(self::$_hooks[$type] as $name => $hook) { | ||||
| 				/** @var $hook Hook */ | ||||
| 				/** @var Hook $hook */ | ||||
| 				if (!$hook->execute($params)) { | ||||
| 					$ret = false; | ||||
| 				} | ||||
| @@ -29,11 +30,21 @@ class Hooks | ||||
| 		return $ret; | ||||
| 	} | ||||
|  | ||||
| 	public function exist($type) { | ||||
| 	public function triggerFilter($type, &$args): void | ||||
| 	{ | ||||
| 		if(isset(self::$_hooks[$type])) { | ||||
| 			foreach(self::$_hooks[$type] as $hook) { | ||||
| 				/** @var Hook $hook */ | ||||
| 				$hook->executeFilter($args); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	public function exist($type): bool { | ||||
| 		return isset(self::$_hooks[$type]); | ||||
| 	} | ||||
|  | ||||
| 	public function load() | ||||
| 	public function load(): void | ||||
| 	{ | ||||
| 		foreach(Plugins::getHooks() as $hook) { | ||||
| 			$this->register($hook['name'], $hook['type'], $hook['file']); | ||||
|   | ||||
| @@ -9,6 +9,6 @@ class AccountAction extends Model { | ||||
|  | ||||
| 	public $timestamps = false; | ||||
|  | ||||
| 	protected $fillable = ['account_id', 'ip', 'ipv6', 'date', 'action']; | ||||
| 	protected $fillable = ['account_id', 'ip', 'date', 'action']; | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -198,6 +198,9 @@ class Plugins { | ||||
| 			} | ||||
| 		} | ||||
|  | ||||
| 		global $hooks; | ||||
| 		$hooks->triggerFilter(HOOK_FILTER_ROUTES, $routes); | ||||
|  | ||||
| 		usort($routes, function ($a, $b) | ||||
| 		{ | ||||
| 			// key 3 is priority | ||||
|   | ||||
| @@ -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']; | ||||
| 					} | ||||
| 					break; | ||||
|  | ||||
| 				case 'double': | ||||
| 				case 'float': | ||||
| 					$ret['value'] = (double)($ret['value']); | ||||
| 					break; | ||||
|  | ||||
| 				default: | ||||
|   | ||||
							
								
								
									
										28
									
								
								system/src/Twig/EnvironmentBridge.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								system/src/Twig/EnvironmentBridge.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| <?php | ||||
|  | ||||
| namespace MyAAC\Twig; | ||||
|  | ||||
| use Twig\Environment; | ||||
|  | ||||
| class EnvironmentBridge extends Environment | ||||
| { | ||||
| 	public function display($name, array $context = []): void | ||||
| 	{ | ||||
| 		global $hooks; | ||||
|  | ||||
| 		$context['viewName'] = $name; | ||||
| 		$hooks->triggerFilter(HOOK_FILTER_TWIG_DISPLAY, $context); | ||||
|  | ||||
| 		parent::display($name, $context); | ||||
| 	} | ||||
|  | ||||
| 	public function render($name, array $context = []): string | ||||
| 	{ | ||||
| 		global $hooks; | ||||
|  | ||||
| 		$context['viewName'] = $name; | ||||
| 		$hooks->triggerFilter(HOOK_FILTER_TWIG_RENDER, $context); | ||||
|  | ||||
| 		return parent::render($name, $context); | ||||
| 	} | ||||
| } | ||||
| @@ -97,6 +97,12 @@ define('HOOK_CACHE_CLEAR', ++$i); | ||||
| 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); | ||||
|  | ||||
| const HOOK_FIRST = HOOK_INIT; | ||||
| define('HOOK_LAST', $i); | ||||
|  | ||||
|   | ||||
| @@ -136,6 +136,11 @@ if($forumSetting != '') | ||||
| $twig->addGlobal('template_name', $template_name); | ||||
| $twig->addGlobal('template_path', $template_path); | ||||
| if($twig_loader) { | ||||
| 	$viewsPath = BASE . $template_path . '/views'; | ||||
| 	if (is_dir($viewsPath)) { | ||||
| 		$twig_loader->prependPath($viewsPath); | ||||
| 	} | ||||
|  | ||||
| 	$twig_loader->prependPath(BASE . $template_path); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -4,7 +4,9 @@ | ||||
| 	let colors = []; | ||||
|  | ||||
| 	{% for cat, menu in menus %} | ||||
| 		{% if config('menu_categories')[cat] is not empty %} | ||||
| 			last_id[{{ cat }}] = {{ last_id[cat] }}; | ||||
| 		{% endif %} | ||||
| 	{% endfor %} | ||||
|  | ||||
| 	{% set menuDefaultLinksColor = config('menu_default_links_color') %} | ||||
|   | ||||
| @@ -9,8 +9,7 @@ | ||||
|  */ | ||||
| defined('MYAAC') or die('Direct access not allowed!'); | ||||
|  | ||||
| use MyAAC\CsrfToken; | ||||
| use Twig\Environment as Twig_Environment; | ||||
| use MyAAC\Twig\EnvironmentBridge as MyAAC_Twig_EnvironmentBridge; | ||||
| use Twig\Extension\DebugExtension as Twig_DebugExtension; | ||||
| use Twig\Loader\FilesystemLoader as Twig_FilesystemLoader; | ||||
| use Twig\TwigFilter; | ||||
| @@ -20,7 +19,7 @@ global $twig, $twig_loader; | ||||
|  | ||||
| $dev_mode = (config('env') === 'dev'); | ||||
| $twig_loader = new Twig_FilesystemLoader(SYSTEM . 'templates'); | ||||
| $twig = new Twig_Environment($twig_loader, array( | ||||
| $twig = new MyAAC_Twig_EnvironmentBridge($twig_loader, array( | ||||
| 	'cache' => CACHE . 'twig/', | ||||
| 	'auto_reload' => $dev_mode, | ||||
| 	'debug' => $dev_mode | ||||
|   | ||||
		Reference in New Issue
	
	Block a user