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:
Sarjuuk
2025-06-13 13:55:12 +02:00
parent 069ca27b35
commit 91bb53aa1d
4 changed files with 105 additions and 62 deletions

View File

@@ -189,58 +189,58 @@ class Profiler
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(
'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)
// realm in db but no connection info set
if (!DB::isConnectable(DB_CHARACTERS . $rId))
{
// realm in db but no connection info set
if (!DB::isConnectable(DB_CHARACTERS . $rId))
{
unset(self::$realms[$rId]);
continue;
}
unset(self::$realms[$rId]);
continue;
}
// filter by access level
if ($rData['access'] == SEC_ADMINISTRATOR && (CLI || User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN)))
// filter by access level
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;
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)
else
{
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;
else
{
unset(self::$realms[$rId]);
continue;
}
}
}
}

View File

@@ -133,7 +133,7 @@ class RemoteArenaTeamList extends ArenaTeamList
// select DB by realm
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;
}
@@ -342,20 +342,25 @@ class LocalArenaTeamList extends ArenaTeamList
$realms = Profiler::getRealms();
// graft realm selection from miscData onto conditions
$realmIds = [];
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']))
$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');
$conditions = ['AND', ['realm', $realmIds], $conditions];
$conditions = ['AND', ['realm', array_keys($realms)], $conditions];
}
else if ($realmIds)
$conditions = [['realm', $realmIds]];
else
$conditions = [['realm', array_keys($realms)]];
parent::__construct($conditions, $miscData);

View File

@@ -168,7 +168,7 @@ class RemoteGuildList extends GuildList
// select DB by realm
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;
}
@@ -280,13 +280,34 @@ class LocalGuildList extends GuildList
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);
if ($this->error)
return;
$realms = Profiler::getRealms();
foreach ($this->iterate() as $id => &$curTpl)
{
if ($curTpl['realm'] && !isset($realms[$curTpl['realm']]))

View File

@@ -520,7 +520,7 @@ class RemoteProfileList extends ProfileList
// select DB by realm
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;
}
@@ -738,25 +738,42 @@ class LocalProfileList extends ProfileList
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);
if ($this->error)
return;
$realms = Profiler::getRealms();
foreach ($this->iterate() as $id => &$curTpl)
{
if ($curTpl['realm'] && !isset($realms[$curTpl['realm']]))
if (!$curTpl['realm']) // custom profile w/o realminfo
continue;
if (isset($realms[$curTpl['realm']]))
if (!isset($realms[$curTpl['realm']]))
{
$curTpl['realmName'] = $realms[$curTpl['realm']]['name'];
$curTpl['region'] = $realms[$curTpl['realm']]['region'];
unset($this->templates[$id]);
continue;
}
// battlegroup
$curTpl['realmName'] = $realms[$curTpl['realm']]['name'];
$curTpl['region'] = $realms[$curTpl['realm']]['region'];
$curTpl['battlegroup'] = Cfg::get('BATTLEGROUP');
}
}