if ($upthis < 0) $upthis = 0;max($upthis, 0)
// Get waiting peers due to maxslot queue for this torrent - July 30, 2022
function checkSlotWait(int $torrent_id)
{
global $db;
$waiting = $db->query_params("SELECT (SELECT COUNT(DISTINCT torrent_id) FROM peers WHERE user_id = p.user_id AND seeder = 'no') AS total_active, u.slots, u.username, u.avatar_thumb, p.torrent_id, p.seeder FROM peers p LEFT JOIN users u ON u.user_id = p.user_id WHERE u.user_id = p.user_id AND p.seeder = 'no' AND p.torrent_id = :torrent_id", array(
'torrent_id' => $torrent_id
));
foreach ($waiting->fetchAll() as $checkslotwait) {
if (intval($checkslotwait['total_active']) > intval($checkslotwait['slots'])) {
printf('<div>Peer waiting: <img style="vertical-align:middle;margin-left:7px;width:15px;height:15px" alt="%s" src="/%s"></div>', html_escape($checkslotwait['username']), $checkslotwait['avatar_thumb']);
}
}
}
checkSlotWait($row['torrent_id']);
MicroMonkey:Wouldnt you wanna change those sql queries toto avoid that zero date issue? I remember something like that being a problem a little bit`added` datetime NOT NULL,`expiry` datetime NOT NULL,
// AJAX Live File Search - Meta Data - July 15, 2022
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['meta_file_name'])) {
$matchedfile = $db->query_params('SELECT b.torrent_id, t.name, t.cover1 FROM torrents_blob b LEFT JOIN torrents t ON t.torrent_id = b.torrent_id WHERE b.data LIKE :matched_metafile', array(
'matched_metafile' => '%' . html_escape(trim($_POST['meta_file_name'])) . '%'
));
$matched = array();
foreach ($matchedfile->fetchAll() as $row) {
$data['torrent_id'] = intval($row['torrent_id']);
$data['name'] = html_escape(trim($row['name']));
$data['cover'] = $row['cover1'];
array_push($matched, $data);
}
}
echo empty($matched) ? json_encode(array(
'matched' => 'false'
)) : json_encode($matched, JSON_UNESCAPED_SLASHES);
}
<?
// BEP 39 - Updating Torrents Via Feed URL
$dict['info']['update-url'] = sprintf('%/update.php', $CONFIG['base_url']);
$dict['info']['originator'] = $certificate_DER_encoded
<?
// BEP 39 - Updating Torrents Via Feed URL
if (array_key_exists('info_hash', $_GET)) {
$res = $db->query_params('SELECT b.data FROM torrents_blob b LEFT JOIN torrents t ON t.torrent_id = b.torrent_id WHERE t.info_hash = :info_hash LIMIT 1', array(
'info_hash' => trim($_GET['info_hash'])
));
if ($row = $res->fetch()) {
http_response_code(200);
die($row['data']);
}
}
<?
// BEP 39 - Updating Torrents Via Feed URL
$pKey = file_get_contents('private.key');
$pKey = openssl_pkey_get_private($pKey, 'somepass');
openssl_sign(Bencode::encode($parse['info']), $signature, $pKey);
$buffer = file_get_contents('certificate.pem');
$convert = convertToDer($buffer);
if ($convert->status === 'success') {
$parse['info']['update-url'] = sprintf('%s/update.php', $CONFIG['base_url']);
$parse['info']['originator'] = $convert->result;
}
// Get available seed bonuse upgrades available for current user points balance
$bonus = $db->query_params('SELECT * FROM bonus');
$getbonusinfo = $bonus->fetchAll();
$seedbonus = $db->query_params('SELECT seedbonus FROM users WHERE user_id = :user_id LIMIT 1', array(
'user_id' => 1
));
$current = array(); // current points
foreach ($seedbonus->fetchAll() as $value) {
array_push($current, floatval($value['seedbonus']));
}
foreach ($getbonusinfo as $row) {
if ($current[0] > floatval($row['cost'])) {
printf('You can get: %s <br>', $row['title']);
}
}
// BEP-12 Multitracker Metadata Extension
$multitracker = array(
'udp://tracker.com/announce1',
'udp://tracker.com/announce2'
);
if (!empty($multitracker)) {
$arr['announce-list'] = [['udp://tracker.com/announce1', 'udp://tracker.com/announce2'], [sprintf('%s/announce?%stoken=%s', $CONFIG['base_url'], 'v=1&', $token)]];
shuffle($arr['announce-list']);
}
// BEP-38 Finding Local Data Via Torrent File Hints
$similar = $db->query_params("SELECT t.info_hash, c.name AS cat_name, t.name FROM torrents t LEFT JOIN categories c ON t.category = c.id WHERE t.name LIKE :match", array(
'match' => '%' . strtok($name, ' ') . '%'
));
$hashes = array();
foreach ($similar->fetchAll() as $row) {
array_push($hashes, hex2bin($row['info_hash']));
$parse['collections'] = sprintf('com.%s.%s', strtolower(strtok($row['cat_name'], ' ')), strtolower(strtok($row['name'], ' ')));
}
if (!empty($hashes)) {
$parse['similar'] = $hashes;
}
public function verifyToken(string $passkey, string $token, string $peer_id): never
{
$filter = array(
'_',
'-',
'[',
']',
'!',
'@',
'$'
);
$getuserid = $this->query_params('SELECT u.user_id FROM peers p LEFT JOIN users u ON u.user_id = p.user_id WHERE p.chosen_peer_id = :peer_id LIMIT 1', array(
'peer_id' => $peer_id
));
foreach ($filter as $char) {
if (strpbrk($token, $char) !== false) {
$this->fail('Token invalid. Err(1)');
}
}
if (strlen($this->decryptToken($token)) === 0) {
if ($u = $getuserid->fetch()) {
$this->sendNotif($u['user_id'], 'Client token is invalid.', 'Tracker');
}
$this->fail('Token invalid. Err(2)');
}
if (strpos($token, $filter[0]) !== false) {
if ($u = $getuserid->fetch()) {
$this->sendNotif($u['user_id'], 'Client token is invalid.', 'Tracker');
}
$this->fail('Token invalid. Err(3)');
}
if (hash_equals($this->decryptToken($token), $passkey) !== true) {
$this->fail('Token invalid. Err(4)');
}
}
function unesc(string $x): mixed {
return is_string($x) ? stripslashes($x) : null
}
if (unesc($str) != null) {
// String was escape, continue...
}
return stripslashes($x);