mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
Profiler/Realms
* skip out of List construction if realms are empty or do not match preselection * also prefilter Guilds and Prolfiles Lists for server or region (unless custom profiles) * discard ProfileList entries for inaccessible realms
This commit is contained in:
@@ -189,10 +189,11 @@ class Profiler
|
|||||||
return $str;
|
return $str;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getRealms()
|
public static function getRealms() : array
|
||||||
{
|
|
||||||
if (DB::isConnectable(DB_AUTH) && !self::$realms)
|
|
||||||
{
|
{
|
||||||
|
if (!DB::isConnectable(DB_AUTH) || self::$realms)
|
||||||
|
return self::$realms;
|
||||||
|
|
||||||
self::$realms = DB::Auth()->select(
|
self::$realms = DB::Auth()->select(
|
||||||
'SELECT `id` AS ARRAY_KEY,
|
'SELECT `id` AS ARRAY_KEY,
|
||||||
`name`,
|
`name`,
|
||||||
@@ -242,7 +243,6 @@ class Profiler
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return self::$realms;
|
return self::$realms;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ class RemoteArenaTeamList extends ArenaTeamList
|
|||||||
// select DB by realm
|
// select DB by realm
|
||||||
if (!$this->selectRealms($miscData))
|
if (!$this->selectRealms($miscData))
|
||||||
{
|
{
|
||||||
trigger_error('no access to auth-db or table realmlist is empty', E_USER_WARNING);
|
trigger_error('RemoteArenaTeamList::__construct - cannot access any realm.', E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,20 +342,25 @@ class LocalArenaTeamList extends ArenaTeamList
|
|||||||
$realms = Profiler::getRealms();
|
$realms = Profiler::getRealms();
|
||||||
|
|
||||||
// graft realm selection from miscData onto conditions
|
// graft realm selection from miscData onto conditions
|
||||||
$realmIds = [];
|
|
||||||
if (isset($miscData['sv']))
|
if (isset($miscData['sv']))
|
||||||
$realmIds = array_merge($realmIds, array_keys(array_filter($realms, fn($x) => Profiler::urlize($x['name']) == Profiler::urlize($miscData['sv']))));
|
$realms = array_filter($realms, fn($x) => Profiler::urlize($x['name']) == Profiler::urlize($miscData['sv']));
|
||||||
|
|
||||||
if (isset($miscData['rg']))
|
if (isset($miscData['rg']))
|
||||||
$realmIds = array_merge($realmIds, array_keys(array_filter($realms, fn($x) => $x['region'] == $miscData['rg'])));
|
$realms = array_filter($realms, fn($x) => $x['region'] == $miscData['rg']);
|
||||||
|
|
||||||
if ($realmIds && $conditions)
|
if (!$realms)
|
||||||
|
{
|
||||||
|
trigger_error('LocalArenaTeamList::__construct - cannot access any realm.', E_USER_WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($conditions)
|
||||||
{
|
{
|
||||||
array_unshift($conditions, 'AND');
|
array_unshift($conditions, 'AND');
|
||||||
$conditions = ['AND', ['realm', $realmIds], $conditions];
|
$conditions = ['AND', ['realm', array_keys($realms)], $conditions];
|
||||||
}
|
}
|
||||||
else if ($realmIds)
|
else
|
||||||
$conditions = [['realm', $realmIds]];
|
$conditions = [['realm', array_keys($realms)]];
|
||||||
|
|
||||||
parent::__construct($conditions, $miscData);
|
parent::__construct($conditions, $miscData);
|
||||||
|
|
||||||
|
|||||||
@@ -168,7 +168,7 @@ class RemoteGuildList extends GuildList
|
|||||||
// select DB by realm
|
// select DB by realm
|
||||||
if (!$this->selectRealms($miscData))
|
if (!$this->selectRealms($miscData))
|
||||||
{
|
{
|
||||||
trigger_error('no access to auth-db or table realmlist is empty', E_USER_WARNING);
|
trigger_error('RemoteGuildList::__construct - cannot access any realm.', E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -280,13 +280,34 @@ class LocalGuildList extends GuildList
|
|||||||
|
|
||||||
public function __construct(array $conditions = [], array $miscData = [])
|
public function __construct(array $conditions = [], array $miscData = [])
|
||||||
{
|
{
|
||||||
|
$realms = Profiler::getRealms();
|
||||||
|
|
||||||
|
// graft realm selection from miscData onto conditions
|
||||||
|
if (isset($miscData['sv']))
|
||||||
|
$realms = array_filter($realms, fn($x) => Profiler::urlize($x['name']) == Profiler::urlize($miscData['sv']));
|
||||||
|
|
||||||
|
if (isset($miscData['rg']))
|
||||||
|
$realms = array_filter($realms, fn($x) => $x['region'] == $miscData['rg']);
|
||||||
|
|
||||||
|
if (!$realms)
|
||||||
|
{
|
||||||
|
trigger_error('LocalGuildList::__construct - cannot access any realm.', E_USER_WARNING);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($conditions)
|
||||||
|
{
|
||||||
|
array_unshift($conditions, 'AND');
|
||||||
|
$conditions = ['AND', ['realm', array_keys($realms)], $conditions];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$conditions = [['realm', array_keys($realms)]];
|
||||||
|
|
||||||
parent::__construct($conditions, $miscData);
|
parent::__construct($conditions, $miscData);
|
||||||
|
|
||||||
if ($this->error)
|
if ($this->error)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$realms = Profiler::getRealms();
|
|
||||||
|
|
||||||
foreach ($this->iterate() as $id => &$curTpl)
|
foreach ($this->iterate() as $id => &$curTpl)
|
||||||
{
|
{
|
||||||
if ($curTpl['realm'] && !isset($realms[$curTpl['realm']]))
|
if ($curTpl['realm'] && !isset($realms[$curTpl['realm']]))
|
||||||
|
|||||||
@@ -520,7 +520,7 @@ class RemoteProfileList extends ProfileList
|
|||||||
// select DB by realm
|
// select DB by realm
|
||||||
if (!$this->selectRealms($miscData))
|
if (!$this->selectRealms($miscData))
|
||||||
{
|
{
|
||||||
trigger_error('no access to auth-db or table realmlist is empty', E_USER_WARNING);
|
trigger_error('RemoteProfileList::__construct - cannot access any realm.', E_USER_WARNING);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -738,25 +738,42 @@ class LocalProfileList extends ProfileList
|
|||||||
|
|
||||||
public function __construct(array $conditions = [], array $miscData = [])
|
public function __construct(array $conditions = [], array $miscData = [])
|
||||||
{
|
{
|
||||||
|
$realms = Profiler::getRealms();
|
||||||
|
|
||||||
|
// graft realm selection from miscData onto conditions
|
||||||
|
$realmIds = [];
|
||||||
|
if (isset($miscData['sv']))
|
||||||
|
$realmIds = array_keys(array_filter($realms, fn($x) => Profiler::urlize($x['name']) == Profiler::urlize($miscData['sv'])));
|
||||||
|
|
||||||
|
if (isset($miscData['rg']))
|
||||||
|
$realmIds = array_merge($realmIds, array_keys(array_filter($realms, fn($x) => $x['region'] == $miscData['rg'])));
|
||||||
|
|
||||||
|
if ($conditions && $realmIds)
|
||||||
|
{
|
||||||
|
array_unshift($conditions, 'AND');
|
||||||
|
$conditions = ['AND', ['realm', $realmIds], $conditions];
|
||||||
|
}
|
||||||
|
else if ($realmIds)
|
||||||
|
$conditions = [['realm', $realmIds]];
|
||||||
|
|
||||||
parent::__construct($conditions, $miscData);
|
parent::__construct($conditions, $miscData);
|
||||||
|
|
||||||
if ($this->error)
|
if ($this->error)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
$realms = Profiler::getRealms();
|
|
||||||
|
|
||||||
foreach ($this->iterate() as $id => &$curTpl)
|
foreach ($this->iterate() as $id => &$curTpl)
|
||||||
{
|
{
|
||||||
if ($curTpl['realm'] && !isset($realms[$curTpl['realm']]))
|
if (!$curTpl['realm']) // custom profile w/o realminfo
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (isset($realms[$curTpl['realm']]))
|
if (!isset($realms[$curTpl['realm']]))
|
||||||
{
|
{
|
||||||
$curTpl['realmName'] = $realms[$curTpl['realm']]['name'];
|
unset($this->templates[$id]);
|
||||||
$curTpl['region'] = $realms[$curTpl['realm']]['region'];
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// battlegroup
|
$curTpl['realmName'] = $realms[$curTpl['realm']]['name'];
|
||||||
|
$curTpl['region'] = $realms[$curTpl['realm']]['region'];
|
||||||
$curTpl['battlegroup'] = Cfg::get('BATTLEGROUP');
|
$curTpl['battlegroup'] = Cfg::get('BATTLEGROUP');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user