mirror of
https://github.com/slawkens/myaac.git
synced 2025-12-15 05:19:47 +01:00
Compare commits
9 Commits
feature/ge
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
78a3535b6a | ||
|
|
497959fd30 | ||
|
|
6ba00eea96 | ||
|
|
9ed06782e6 | ||
|
|
18a1178e4b | ||
|
|
c86257e6da | ||
|
|
fd74f01291 | ||
|
|
3011b969a4 | ||
|
|
8e6749c599 |
2
.github/workflows/cypress.yml
vendored
2
.github/workflows/cypress.yml
vendored
@@ -22,7 +22,7 @@ jobs:
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
php-versions: [ '8.1', '8.2', '8.3', '8.4' ]
|
||||
php-versions: [ '8.1', '8.2', '8.3', '8.4', '8.5' ]
|
||||
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:
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
# Changelog
|
||||
|
||||
## [1.8.6 - 14.12.2025]
|
||||
|
||||
### Added
|
||||
* Added hook for adding custom rules to validate new character name (https://github.com/slawkens/myaac/commit/8e6749c59984631288e8e9803819b2f0ff389761)
|
||||
|
||||
### Fixed
|
||||
* Highscores: Fix ordering by different skills (Adjust order by desc: skill_tries, manaspent, experience) - More exact results (https://github.com/slawkens/myaac/commit/c86257e6dacbad773aa09c0958eeaa106a967f2d)
|
||||
* Fix exception shown on first install, when there is no vendor - Before it displayed 500 white page, now it display the exception (https://github.com/slawkens/myaac/commit/18a1178e4b93607a350259679e0366cb83fb4126)
|
||||
* Fix typo $up -> $down, in migration nr 7, was failing due that (https://github.com/slawkens/myaac/commit/fd74f01291d0e9cdb92ee1b95021c9d7b591ad7c)
|
||||
|
||||
### Changed
|
||||
* Ini set html_errors = 0, to show html code in exceptions (https://github.com/slawkens/myaac/commit/9ed06782e67772826d927ad847a077b99df5060d)
|
||||
|
||||
## [1.8.5 - 21.11.2025]
|
||||
|
||||
### Added
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
## [2.0-dev - x.x.2025]
|
||||
|
||||
### Changed
|
||||
* Reworked account action logs to use single IP column as varchar(45) for both ipv4 and ipv6 (https://github.com/slawkens/myaac/pull/289)
|
||||
@@ -9,7 +9,6 @@
|
||||
*/
|
||||
|
||||
use MyAAC\Models\Account as AccountModel;
|
||||
use MyAAC\Models\AccountAction;
|
||||
use MyAAC\Models\Player;
|
||||
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
@@ -482,8 +481,9 @@ else if (isset($_REQUEST['search'])) {
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
$accountActions = AccountAction::where('account_id', $account->getId())->orderByDesc('date')->get();
|
||||
$accountActions = \MyAAC\Models\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>
|
||||
|
||||
17
common.php
17
common.php
@@ -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 = '2.0-dev';
|
||||
const DATABASE_VERSION = 47;
|
||||
const MYAAC_VERSION = '1.8.7-dev';
|
||||
const DATABASE_VERSION = 46;
|
||||
const TABLE_PREFIX = 'myaac_';
|
||||
define('START_TIME', microtime(true));
|
||||
define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX'));
|
||||
@@ -148,16 +148,17 @@ if(!IS_CLI) {
|
||||
|
||||
/** @var array $config */
|
||||
ini_set('log_errors', 1);
|
||||
if(@$config['env'] === 'dev' || defined('MYAAC_INSTALL')) {
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
else {
|
||||
if(isset($config['env']) && $config['env'] !== 'dev' && !defined('MYAAC_INSTALL')) {
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('display_startup_errors', 0);
|
||||
error_reporting(E_ALL & ~E_DEPRECATED & ~E_STRICT);
|
||||
}
|
||||
else {
|
||||
ini_set('html_errors', 0);
|
||||
ini_set('display_errors', 1);
|
||||
ini_set('display_startup_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
}
|
||||
|
||||
$autoloadFile = VENDOR . 'autoload.php';
|
||||
if (!is_file($autoloadFile)) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS `myaac_account_actions`
|
||||
(
|
||||
`id` int NOT NULL AUTO_INCREMENT,
|
||||
`account_id` int NOT NULL,
|
||||
`ip` varchar(45) NOT NULL DEFAULT '',
|
||||
`ip` int unsigned NOT NULL DEFAULT 0,
|
||||
`ipv6` binary(16) NOT NULL DEFAULT 0,
|
||||
`date` int NOT NULL DEFAULT 0,
|
||||
`action` varchar(255) NOT NULL DEFAULT '',
|
||||
PRIMARY KEY (`id`)
|
||||
KEY (`account_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARACTER SET=utf8mb4;
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `myaac_account_emails_verify`
|
||||
|
||||
@@ -17,8 +17,6 @@ use MyAAC\Models\Guild;
|
||||
use MyAAC\Models\House;
|
||||
use MyAAC\Models\Pages;
|
||||
use MyAAC\Models\Player;
|
||||
use MyAAC\Models\PlayerDeath;
|
||||
use MyAAC\Models\PlayerKillers;
|
||||
use MyAAC\News;
|
||||
use MyAAC\Plugins;
|
||||
use MyAAC\Settings;
|
||||
@@ -1137,29 +1135,11 @@ function csrfProtect(): void
|
||||
}
|
||||
}
|
||||
|
||||
function getTopPlayers($limit = 5, $skill = POT::SKILL_LEVEL)
|
||||
{
|
||||
function getTopPlayers($limit = 5, $skill = 'level') {
|
||||
global $db;
|
||||
|
||||
$skillOriginal = $skill;
|
||||
|
||||
if (is_string($skill)) {
|
||||
$skills = [
|
||||
'level' => POT::SKILL_LEVEL,
|
||||
'experience' => POT::SKILL_LEVEL,
|
||||
|
||||
'magic' => POT::SKILL_MAGIC,
|
||||
'maglevel' => POT::SKILL_MAGIC,
|
||||
|
||||
'balance' => SKILL_BALANCE,
|
||||
'frags' => SKILL_FRAGS,
|
||||
];
|
||||
|
||||
$skill = $skills[$skill] ?? null;
|
||||
}
|
||||
|
||||
if (!is_numeric($skill)) {
|
||||
throw new RuntimeException("getTopPlayers: Invalid skill: $skillOriginal");
|
||||
if ($skill === 'level') {
|
||||
$skill = 'experience';
|
||||
}
|
||||
|
||||
return Cache::remember("top_{$limit}_{$skill}", 2 * 60, function () use ($db, $limit, $skill) {
|
||||
@@ -1180,64 +1160,15 @@ function getTopPlayers($limit = 5, $skill = POT::SKILL_LEVEL)
|
||||
$columns[] = 'lookmount';
|
||||
}
|
||||
|
||||
$query = Player::query()
|
||||
return Player::query()
|
||||
->select($columns)
|
||||
->withOnlineStatus()
|
||||
->notDeleted()
|
||||
->where('group_id', '<', setting('core.highscores_groups_hidden'))
|
||||
->whereNotIn('id', setting('core.highscores_ids_hidden'))
|
||||
->where('account_id', '!=', 1)
|
||||
->orderByDesc('value');
|
||||
|
||||
if ($limit > 0) {
|
||||
$query->limit($limit);
|
||||
}
|
||||
|
||||
if ($skill >= POT::SKILL_FIRST && $skill <= POT::SKILL_LAST) { // skills
|
||||
if ($db->hasColumn('players', 'skill_fist')) {// tfs 1.0
|
||||
$skill_ids = array(
|
||||
POT::SKILL_FIST => 'skill_fist',
|
||||
POT::SKILL_CLUB => 'skill_club',
|
||||
POT::SKILL_SWORD => 'skill_sword',
|
||||
POT::SKILL_AXE => 'skill_axe',
|
||||
POT::SKILL_DIST => 'skill_dist',
|
||||
POT::SKILL_SHIELD => 'skill_shielding',
|
||||
POT::SKILL_FISH => 'skill_fishing',
|
||||
);
|
||||
|
||||
$query
|
||||
->addSelect($skill_ids[$skill] . ' as value')
|
||||
->orderByDesc($skill_ids[$skill] . '_tries');
|
||||
} else {
|
||||
$query
|
||||
->join('player_skills', 'player_skills.player_id', '=', 'players.id')
|
||||
->where('skillid', $skill)
|
||||
->addSelect('player_skills.value as value');
|
||||
}
|
||||
} else if ($skill == SKILL_FRAGS) // frags
|
||||
{
|
||||
if ($db->hasTable('player_killers')) {
|
||||
$query->addSelect(['value' => PlayerKillers::whereColumn('player_killers.player_id', 'players.id')->selectRaw('COUNT(*)')]);
|
||||
} else {
|
||||
$query->addSelect(['value' => PlayerDeath::unjustified()->whereColumn('player_deaths.killed_by', 'players.name')->selectRaw('COUNT(*)')]);
|
||||
}
|
||||
} else if ($skill == SKILL_BALANCE) // balance
|
||||
{
|
||||
$query
|
||||
->addSelect('players.balance as value');
|
||||
} else {
|
||||
if ($skill == POT::SKILL_MAGIC) {
|
||||
$query
|
||||
->addSelect('players.maglevel as value', 'players.maglevel')
|
||||
->orderByDesc('manaspent');
|
||||
} else { // level
|
||||
$query
|
||||
->addSelect('players.level as value', 'players.experience')
|
||||
->orderByDesc('experience');
|
||||
}
|
||||
}
|
||||
|
||||
return $query
|
||||
->orderByDesc($skill)
|
||||
->limit($limit)
|
||||
->get()
|
||||
->map(function ($e, $i) {
|
||||
$row = $e->toArray();
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
* @license http://www.gnu.org/licenses/lgpl-3.0.txt GNU Lesser General Public License, Version 3
|
||||
*/
|
||||
|
||||
use MyAAC\Models\AccountAction;
|
||||
|
||||
/**
|
||||
* OTServ account abstraction.
|
||||
*
|
||||
@@ -1009,16 +1007,26 @@ class OTS_Account extends OTS_Row_DAO implements IteratorAggregate, Countable
|
||||
|
||||
public function logAction($action)
|
||||
{
|
||||
AccountAction::create([
|
||||
'account_id' => $this->getId(),
|
||||
'ip' => get_browser_real_ip(),
|
||||
'date' => time(),
|
||||
'action' => $action,
|
||||
]);
|
||||
$ip = get_browser_real_ip();
|
||||
if(!str_contains($ip, ":")) {
|
||||
$ipv6 = '0';
|
||||
}
|
||||
else {
|
||||
$ipv6 = $ip;
|
||||
$ip = '';
|
||||
}
|
||||
|
||||
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($limit) {
|
||||
return AccountAction::where('account_id', $this->data['id'])->orderByDesc('date')->limit($limit)->get()->toArray();
|
||||
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;
|
||||
}
|
||||
/**
|
||||
* Returns players iterator.
|
||||
|
||||
@@ -277,7 +277,6 @@ class OTS_DB_MySQL extends OTS_Base_DB
|
||||
'field' => $result['Field'],
|
||||
'type' => $result['Type'],
|
||||
'null' => strtolower($result['Null']),
|
||||
'key' => strtolower($result['Key'] ?? ''),
|
||||
'default' => $result['Default'],
|
||||
'extra' => $result['Extra'],
|
||||
];
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?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) {
|
||||
$accountActionsInfo = $db->getColumnInfo(TABLE_PREFIX . 'account_actions', 'account_id');
|
||||
if ($accountActionsInfo && is_array($accountActionsInfo) && $accountActionsInfo['key'] == 'pri') {
|
||||
$db->query("ALTER TABLE `myaac_account_actions` DROP KEY `account_id`;");
|
||||
}
|
||||
|
||||
if (!$db->hasColumn(TABLE_PREFIX . 'account_actions', 'id')) {
|
||||
$db->addColumn(TABLE_PREFIX . 'account_actions', 'id', 'INT 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';");
|
||||
|
||||
if ($db->hasColumn(TABLE_PREFIX . 'account_actions', 'ipv6')) {
|
||||
$db->dropColumn(TABLE_PREFIX . 'account_actions', 'ipv6');
|
||||
}
|
||||
};
|
||||
|
||||
$down = function () use ($db) {
|
||||
if ($db->hasColumn(TABLE_PREFIX . 'account_actions', 'id')) {
|
||||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` DROP `id`;");
|
||||
}
|
||||
|
||||
$db->query("ALTER TABLE `" . TABLE_PREFIX . "account_actions` ADD KEY (`account_id`);");
|
||||
|
||||
if (!$db->hasColumn(TABLE_PREFIX . 'account_actions', 'ipv6')) {
|
||||
$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;");
|
||||
};
|
||||
@@ -9,7 +9,7 @@ $up = function () use ($db) {
|
||||
}
|
||||
};
|
||||
|
||||
$up = function () use ($db) {
|
||||
$down = function () use ($db) {
|
||||
if (!$db->hasColumn(TABLE_PREFIX . 'screenshots', 'name')) {
|
||||
$db->addColumn(TABLE_PREFIX . 'screenshots', 'name', 'VARCHAR(30) NOT NULL');
|
||||
}
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Example of using getTopPlayers() function
|
||||
* to display the best players for each skill
|
||||
*/
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
|
||||
$skills = [
|
||||
'magic', 'level',
|
||||
'balance', 'frags',
|
||||
POT::SKILL_FIST, POT::SKILL_CLUB,
|
||||
POT::SKILL_SWORD, POT::SKILL_AXE,
|
||||
POT::SKILL_DISTANCE, POT::SKILL_SHIELD,
|
||||
POT::SKILL_FISH
|
||||
];
|
||||
|
||||
foreach ($skills as $skill) {?>
|
||||
<ul>
|
||||
<?php
|
||||
echo '<strong>' . ucwords(is_string($skill) ? $skill : getSkillName($skill)) . '</strong>';
|
||||
foreach (getTopPlayers(5, $skill) as $player) {?>
|
||||
<li><?= $player['rank'] . '. ' . $player['name'] . ' - ' . $player['value']; ?></li>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<?php
|
||||
}
|
||||
|
||||
@@ -96,8 +96,12 @@ if($email_new_time > 1)
|
||||
}
|
||||
}
|
||||
|
||||
$actions = $account_logged->getActionsLog(1000);
|
||||
$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']));
|
||||
}
|
||||
|
||||
$players = array();
|
||||
/** @var OTS_Players_List $account_players */
|
||||
$account_players = $account_logged->getPlayersList();
|
||||
$account_players->orderBy('id');
|
||||
|
||||
@@ -176,7 +176,9 @@ if (empty($highscores)) {
|
||||
POT::SKILL_FISH => 'skill_fishing',
|
||||
);
|
||||
|
||||
$query->addSelect($skill_ids[$skill] . ' as value');
|
||||
$query
|
||||
->addSelect($skill_ids[$skill] . ' as value')
|
||||
->orderByDesc($skill_ids[$skill] . '_tries');
|
||||
} else {
|
||||
$query
|
||||
->join('player_skills', 'player_skills.player_id', '=', 'players.id')
|
||||
@@ -198,11 +200,11 @@ if (empty($highscores)) {
|
||||
if ($skill == POT::SKILL__MAGLEVEL) {
|
||||
$query
|
||||
->addSelect('players.maglevel as value', 'players.maglevel')
|
||||
->orderBy('manaspent');
|
||||
->orderByDesc('manaspent');
|
||||
} else { // level
|
||||
$query
|
||||
->addSelect('players.level as value', 'players.experience')
|
||||
->orderBy('experience');
|
||||
->orderByDesc('experience');
|
||||
$list = 'experience';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ class AccountAction extends Model {
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
protected $fillable = ['account_id', 'ip', 'date', 'action'];
|
||||
protected $fillable = ['account_id', 'ip', 'ipv6', 'date', 'action'];
|
||||
|
||||
}
|
||||
|
||||
@@ -342,6 +342,16 @@ class Validator
|
||||
}
|
||||
}
|
||||
|
||||
global $hooks;
|
||||
|
||||
$params = ['name' => $name, 'error' => ''];
|
||||
$hooks->triggerFilter(HOOK_FILTER_VALIDATE_CHARACTER_NEW_NAME, $params);
|
||||
|
||||
if (!empty($params['error'])) {
|
||||
self::$lastError = $params['error'];
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,6 +108,7 @@ define('HOOK_FILTER_ROUTES', ++$i);
|
||||
define('HOOK_FILTER_TWIG_DISPLAY', ++$i);
|
||||
define('HOOK_FILTER_TWIG_RENDER', ++$i);
|
||||
define('HOOK_FILTER_THEME_FOOTER', ++$i);
|
||||
define('HOOK_FILTER_VALIDATE_CHARACTER_NEW_NAME', ++$i);
|
||||
|
||||
const HOOK_FIRST = HOOK_INIT;
|
||||
define('HOOK_LAST', $i);
|
||||
|
||||
Reference in New Issue
Block a user