normalizedEngine(); $isModern = ($engine === 'TFS_10'); // TFS_16, Canary and BlackTek normalise to this $bansSupported = true; $accountBans = array(); $nameLocks = array(); $ipBanCount = 0; $now = time(); if ($isModern) { $isOthire = false; $accNameCol = '`a`.`name`'; // Characters are shown rather than the account name: that is what other // players recognise, and one account may have several. $rows = db()->fetchAll(" SELECT {$accNameCol} AS `account_name`, `b`.`reason`, `b`.`banned_at`, `b`.`expires_at`, (SELECT `name` FROM `players` WHERE `account_id` = `b`.`account_id` ORDER BY `level` DESC LIMIT 1) AS `character_name` FROM `account_bans` `b` INNER JOIN `accounts` `a` ON `a`.`id` = `b`.`account_id` ORDER BY `b`.`banned_at` DESC LIMIT 200; "); if (is_array($rows)) { foreach ($rows as $row) { $accountBans[] = array( 'name' => (string)($row['character_name'] !== null && $row['character_name'] !== '' ? $row['character_name'] : $row['account_name']), 'reason' => (string)$row['reason'], 'banned_at' => (int)$row['banned_at'], 'expires_at' => (int)$row['expires_at'], ); } } $locks = db()->fetchAll(" SELECT `p`.`name`, `n`.`reason`, `n`.`namelocked_at` FROM `player_namelocks` `n` INNER JOIN `players` `p` ON `p`.`id` = `n`.`player_id` ORDER BY `n`.`namelocked_at` DESC LIMIT 100; "); if (is_array($locks)) { foreach ($locks as $row) { $nameLocks[] = array( 'name' => (string)$row['name'], 'reason' => (string)$row['reason'], 'at' => (int)$row['namelocked_at'], ); } } $ipBanCount = (int)(db()->fetchOne(" SELECT COUNT(*) AS `c` FROM `ip_bans` WHERE `expires_at` <= 0 OR `expires_at` > ?; ", [$now])['c'] ?? 0); } elseif (in_array($engine, array('TFS_02', 'TFS_03', 'OTHIRE'), true)) { // One table, a type column: 1 = IP, 2 = namelock, 3 = account, 5 = deletion. $rows = db()->fetchAll(" SELECT `type`, `value`, `param`, `expires`, `added`, `comment`, `reason_id` FROM `bans` WHERE `active` = 1 OR `active` IS NULL ORDER BY `added` DESC LIMIT 200; "); if (is_array($rows)) { foreach ($rows as $row) { $type = (int)$row['type']; if ($type === 1) { $ipBanCount++; continue; } // value is a player id for namelocks, an account id for bans. $name = ''; if ($type === 2) { $player = db()->fetchOne("SELECT `name` FROM `players` WHERE `id` = ? LIMIT 1;", [(int)$row['value']]); $name = is_array($player) ? (string)$player['name'] : ''; } else { $player = db()->fetchOne("SELECT `name` FROM `players` WHERE `account_id` = ? ORDER BY `level` DESC LIMIT 1;", [(int)$row['value']]); $name = is_array($player) ? (string)$player['name'] : ''; } if ($name === '') { continue; } $entry = array( 'name' => $name, 'reason' => (string)$row['comment'], 'banned_at' => (int)$row['added'], 'expires_at' => (int)$row['expires'], 'at' => (int)$row['added'], ); if ($type === 2) { $nameLocks[] = $entry; } else { $accountBans[] = $entry; } } } } else { $bansSupported = false; } view('bans'); theme_close();