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,58 +189,58 @@ 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(
|
||||||
|
'SELECT `id` AS ARRAY_KEY,
|
||||||
|
`name`,
|
||||||
|
CASE WHEN `timezone` BETWEEN 2 AND 5 THEN "us" # US, Oceanic, Latin America, Americas-Tournament
|
||||||
|
WHEN `timezone` BETWEEN 6 AND 7 THEN "kr" # KR, KR-Tournament
|
||||||
|
WHEN `timezone` BETWEEN 8 AND 13 THEN "eu" # GB, DE, FR, ES, RU, EU-Tournament
|
||||||
|
WHEN `timezone` BETWEEN 14 AND 15 THEN "tw" # TW, TW-Tournament
|
||||||
|
WHEN `timezone` BETWEEN 16 AND 25 THEN "cn" # CN, CN1-8, CN-Tournament
|
||||||
|
ELSE "dev" END AS "region", # 1: Dev, 26: Test, 27: Test Tournament, 28: QA, 30: Test2, 31+: misc
|
||||||
|
`allowedSecurityLevel` AS "access"
|
||||||
|
FROM `realmlist`
|
||||||
|
WHERE `gamebuild` = ?d',
|
||||||
|
WOW_BUILD
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach (self::$realms as $rId => &$rData)
|
||||||
{
|
{
|
||||||
self::$realms = DB::Auth()->select(
|
// realm in db but no connection info set
|
||||||
'SELECT `id` AS ARRAY_KEY,
|
if (!DB::isConnectable(DB_CHARACTERS . $rId))
|
||||||
`name`,
|
|
||||||
CASE WHEN `timezone` BETWEEN 2 AND 5 THEN "us" # US, Oceanic, Latin America, Americas-Tournament
|
|
||||||
WHEN `timezone` BETWEEN 6 AND 7 THEN "kr" # KR, KR-Tournament
|
|
||||||
WHEN `timezone` BETWEEN 8 AND 13 THEN "eu" # GB, DE, FR, ES, RU, EU-Tournament
|
|
||||||
WHEN `timezone` BETWEEN 14 AND 15 THEN "tw" # TW, TW-Tournament
|
|
||||||
WHEN `timezone` BETWEEN 16 AND 25 THEN "cn" # CN, CN1-8, CN-Tournament
|
|
||||||
ELSE "dev" END AS "region", # 1: Dev, 26: Test, 27: Test Tournament, 28: QA, 30: Test2, 31+: misc
|
|
||||||
`allowedSecurityLevel` AS "access"
|
|
||||||
FROM `realmlist`
|
|
||||||
WHERE `gamebuild` = ?d',
|
|
||||||
WOW_BUILD
|
|
||||||
);
|
|
||||||
|
|
||||||
foreach (self::$realms as $rId => &$rData)
|
|
||||||
{
|
{
|
||||||
// realm in db but no connection info set
|
unset(self::$realms[$rId]);
|
||||||
if (!DB::isConnectable(DB_CHARACTERS . $rId))
|
continue;
|
||||||
{
|
}
|
||||||
unset(self::$realms[$rId]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// filter by access level
|
// filter by access level
|
||||||
if ($rData['access'] == SEC_ADMINISTRATOR && (CLI || User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN)))
|
if ($rData['access'] == SEC_ADMINISTRATOR && (CLI || User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN)))
|
||||||
|
$rData['access'] = U_GROUP_DEV | U_GROUP_ADMIN;
|
||||||
|
else if ($rData['access'] == SEC_GAMEMASTER && (CLI || User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_MOD)))
|
||||||
|
$rData['access'] = U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_MOD;
|
||||||
|
else if ($rData['access'] == SEC_MODERATOR && (CLI || User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_MOD | U_GROUP_BUREAU)))
|
||||||
|
$rData['access'] = U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_MOD | U_GROUP_BUREAU;
|
||||||
|
else if ($rData['access'] > SEC_PLAYER && !CLI)
|
||||||
|
{
|
||||||
|
unset(self::$realms[$rId]);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// filter dev realms
|
||||||
|
if ($rData['region'] === 'dev')
|
||||||
|
{
|
||||||
|
if (CLI || User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN))
|
||||||
$rData['access'] = U_GROUP_DEV | U_GROUP_ADMIN;
|
$rData['access'] = U_GROUP_DEV | U_GROUP_ADMIN;
|
||||||
else if ($rData['access'] == SEC_GAMEMASTER && (CLI || User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_MOD)))
|
else
|
||||||
$rData['access'] = U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_MOD;
|
|
||||||
else if ($rData['access'] == SEC_MODERATOR && (CLI || User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_MOD | U_GROUP_BUREAU)))
|
|
||||||
$rData['access'] = U_GROUP_DEV | U_GROUP_ADMIN | U_GROUP_MOD | U_GROUP_BUREAU;
|
|
||||||
else if ($rData['access'] > SEC_PLAYER && !CLI)
|
|
||||||
{
|
{
|
||||||
unset(self::$realms[$rId]);
|
unset(self::$realms[$rId]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter dev realms
|
|
||||||
if ($rData['region'] === 'dev')
|
|
||||||
{
|
|
||||||
if (CLI || User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN))
|
|
||||||
$rData['access'] = U_GROUP_DEV | U_GROUP_ADMIN;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unset(self::$realms[$rId]);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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