Login
Username: Password:
Remember me

[Sign Up] / [Recover Password]

Theme / Language

Popular
New Torrents
new name
Size: 18.40 MB
Most active
new name
S: 74 L: 3
New Posters
User Posts

Go to Profile

I wish I was there lmao - its a local xampp install so its pretty rough. I tried putting the V3 files on the server but page just freezes (check.php works) (TTv3 is not PHP 8.1 ready, mass depreciations in class.mysql.php) - which I expect - nothing is prepared (to avoid SQL injection). I guess a lot of that was ignored in the official PHP 7 branch.

I hope to see to it today spiritblue!
Oh... so your looking at SELECT GROUP_CONCAT(id) AS ids ... FROM ... GROUP BY ...

And in a foreach looping a query WHERE id IN($row[id]) and pushing all that to a array.

I dont know the table structure but I think thats what needs to be done.

<?
if (!is_null($row['genre'])) {
   if (strpos($_data->Genre, ',') !== false) {
       SQL_Query_exec("UPDATE `torrents` SET `genre` = '" . mysqli_real_escape_string($GLOBALS["DBconnector"], $str) . "' WHERE `id` = $id");
   }
}
Help — 2022-11-27 05:54:43 in General Chat
UNIT3D is a joke. I’ll explain. That overbloated horse with the strict development policy of “latest breaking PHP features” almost no one has access to or default, runs like a snail on a quarter mile track.

I ported several visual features out of that script and tossed the rest. The performance load is just ridiculous. It is however, very well structured.

My guess is, they can only contribute so much to an empty CMS before it’s up to the community to use it. For the fact that they had numerous sponsors funding the project to call it quits seems like someone employed the guy for their own company.

All of that can be accomplished alone, and a lot faster without the crazy syntax sugar.
I will try to set up a torrent on the local xampp install and see what the issue is.

This is literally the first step in the code, so close lol
test — 2022-11-26 17:51:50 in v3 Mods Completed
Your welcome 😉
test — 2022-11-25 21:27:34 in v3 Mods Completed
This will automatically render any image urls in the torrent description as a HTML image tag. Images will show right away. Also, domain is listed under each image.

HTML can be replaced with BBCode (edit the markup).

Add to backend/functions.php:


function format_media(string $body): string
{
   $i = 0;
   return preg_replace_callback('~(http.*\.)(jpe?g|png|[tg]iff?|svg)~i', function($matches) use (&$i)
   {
       $i++;
       if (isset($matches[3])) {
           return "<a href='{$matches[2]}{$matches[3]}' target='_blank'><img src='{$matches[2]}{$matches[3]}' style='width:90px;height:90px;border-radius:4px'></a>";
       } else {
           $domain = parse_url($matches[1], PHP_URL_HOST);
           return "<div style='padding:5px;background:#d2d2d2;border-radius:4px;width:150px'><a href='{$matches[1]}{$matches[2]}' target='_blank'><img src='{$matches[1]}{$matches[2]}' style='width:100%;height:90px;border-radius:4px'></a><div style='text-align:center;margin-top:-3px'>$i - $domain</div></div>";
       }
   }, format_comment($body));
}


Open torrents-details.php and find:


print("<tr><td align='left' colspan='2'><b>" .T_("DESCRIPTION"). ":</b><br />" .  format_comment($row['descr']) . "</td></tr>\n");


Replace with:


print("<tr><td align='left' colspan='2'><b>" .T_("DESCRIPTION"). ":</b><br />" .  format_media($row['descr']) . "</td></tr>\n");


Example:

@spiritblue

Try this (replace $passkey)


$passkey = (string) '-----';


Tell me what it says. I'll edit post after and remove the hash.

For VPN I had to use a API, it worked perfectly but this was ~2 years ago and since then I think its important to use a VPN. There just doesn't seem to be a PHP all-solution without some service API that is the holy grail.

I wouldn't. The code is fairly loose and can be done in a single function without all of these different calls.

Never rely on JS regex for domain matching, anyone can edit website source and mess around (should be done in PHP with preg_match() and pass a bool to JSON). The same way they clone, by downloading the source and editing HTML and double clicking on the HTML document. This is why I use cross-origin policies, it blocks local POST/GET requests.

If you need this done, let me know.
Did you run the SQL? It might not be seeing 'slots' column.
Thank you! I was having problems on the mysqli version too, and it needed extra fixes to insert a peer (I lost confidence in this file at this point).

So it looks like compat edition is the way to go. That's what I figured. And its more integrated.

So that error in last photo "Failed getting user", if we see here


$res = SQL_Query_exec("SELECT id, passkey, username, class, enabled, uploaded, downloaded, slots, gender FROM users WHERE passkey = '$passkey'");
$user_row = mysqli_fetch_assoc($res) or fail('Failed getting user');


We see it is failing to get a value from $passkey. Can anyone else confirm this?

Try this. Replace:

$passkey = !empty($data['passkey']) ? trim($data['passkey']) : fail('Missing passkey');

With this

$passkey = !empty($_GET['passkey']) ? trim($_GET['passkey']) : fail('Missing passkey');


Let's ignore the mysqli edition for now.
The parsing is not matching the correct lines and for whatever reason, the expression it is using to match the [code/] tags is causing a visual fault, or the js is failing to render and its just giving up so no post is seen. Weird.

Delete this post, I made a new post with a ZIP
Files attached. Instructions are provided. Leave your feedback in the comments.
If I click edit post, I have my entire post in the box. I have no idea why it wont appear.
Run SQL

ALTER TABLE torrents ADD COLUMN slots INT DEFAULT 3;


Built-in DB class
Save as announce.php

<?php
require_once("backend/mysql.php");
require_once("backend/config.php");
require_once("backend/mysql.class.php");
require_once("backend/BEncode.php");
error_reporting(0);
$GLOBALS['DBconnector'] = mysqli_connect($mysql_host, $mysql_user, $mysql_pass) or die('dbconn: mysqli_connect: ' . mysqli_connect_error());
mysqli_select_db($GLOBALS["DBconnector"], $mysql_db) or die('dbconn: mysqli_select_db: ' . mysqli_error($GLOBALS['DBconnector']));
function sqlesc($x)
{
   return "'" . mysqli_real_escape_string($GLOBALS["DBconnector"], $x) . "'";
}
function get_date_time($timestamp = 0)
{
   if ($timestamp)
       return date("Y-m-d H:i:s", $timestamp);
   else
       return gmdate("Y-m-d H:i:s");
}
SQL_Query_exec("DELETE FROM peers WHERE last_action + '1 HOUR' < CURRENT_TIMESTAMP");
header('Content-Type: text/plain');
function getip()
{
   if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
       return $_SERVER['HTTP_CF_CONNECTING_IP'];
   }
   foreach (array(
       'HTTP_CLIENT_IP',
       'HTTP_X_FORWARDED_FOR',
       'HTTP_X_FORWARDED',
       'HTTP_X_CLUSTER_CLIENT_IP',
       'HTTP_FORWARDED_FOR',
       'HTTP_FORWARDED',
       'HTTP_CF_CONNECTING_IP',
       'REMOTE_ADDR'
   ) as $key) {
       if (array_key_exists($key, $_SERVER) === true) {
           foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
               if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
                   return $ip;
               }
           }
       }
   }
}
$freeleech_days = array(
   'Monday',
   'Tuesday'
);
$slotfree_days  = array(
   'Thursday',
   'Friday'
);
$freeuser_days  = array(
   'Tuesday',
   'Wednesday'
);
$bonus_days     = array(
   'Sunday',
   'Friday'
);
function fail($reason)
{
   die(BEncode(array(
       'failure reason' => $reason,
       'retry in' => '5'
   )));
}
function lastshoutdate($message)
{
   $lastshout = SQL_Query_exec("SELECT message, date FROM shoutbox WHERE message = '$message' ORDER BY date DESC LIMIT 1");
   if ($lastdate = mysqli_fetch_assoc($lastshout)) {
       return $lastdate['date'];
   }
   return false;
}
$data              = $_GET;
$client            = substr($data['peer_id'], 0, 8);
$data['info_hash'] = bin2hex($data['info_hash']);
$data['peer_id']   = bin2hex($data['peer_id']);
$passkey           = !empty($data['passkey']) ? trim($data['passkey']) : fail('Missing passkey');
$res               = SQL_Query_exec("SELECT id, passkey, username, class, enabled, uploaded, downloaded, slots, gender FROM users WHERE passkey = '$passkey'");
$user_row = mysqli_fetch_assoc($res) or fail('Failed getting user');
$freeuser = false;
if (in_array(date('l'), $freeuser_days)) {
   $freeuser = true;
}
$freeleech = false;
if (in_array(date('l'), $freeleech_days)) {
   $freeleech = true;
}
$freeslots = false;
if (in_array(date('l'), $slotfree_days)) {
   $freeslots = true;
}
$bonusdays = false;
if (in_array(date('l'), $bonus_days)) {
   $bonusdays = true;
}
if ($freeuser === true) {
   $event   = "Today is Free User Day! All limited accounts are Unlocked Today!";
   $lastmsg = lastshoutdate($event);
   if (strtotime($lastmsg) < strtotime('-2 minutes')) {
       SQL_Query_exec("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', '$event', NOW(), 0)");
   }
}
if ($freeleech === true) {
   $event   = "Today is Freeleech Day! UP/DL Boosts Stackable!";
   $lastmsg = lastshoutdate($event);
   if (strtotime($lastmsg) < strtotime('-2 minutes')) {
       SQL_Query_exec("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', '$event', NOW(), 0)");
   }
}
if ($freeslots === true) {
   $event   = "Today is Free Slots Day! All slot limits Turned Off!";
   $lastmsg = lastshoutdate($event);
   if (strtotime($lastmsg) < strtotime('-2 minutes')) {
       SQL_Query_exec("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', '$event', NOW(), 0)");
   }
}
if ($bonusdays === true) {
   $event   = "Today is Bonus Data Day! Bonus data is Doubled X2!";
   $lastmsg = lastshoutdate($event);
   if (strtotime($lastmsg) < strtotime('-2 minutes')) {
       SQL_Query_exec("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', '$event', NOW(), 0)");
   }
}
if (!is_numeric($data['port']))
   fail('invalid port');
$data['port'] = intval($data['port']);
if ($data['port'] < 1 || $data['port'] >= 65536)
   fail('Invalid port');
if (array_key_exists('left', $data)) {
   if (!is_numeric($data['left']))
       fail('Invalid left');
   $data['left'] = intval($data['left']);
   if ($data['left'] < 0)
       fail('Invalid left');
}
if (array_key_exists('numwant', $data)) {
   if (!is_numeric($data['numwant']))
       fail('invalid numwant');
   $data['numwant'] = intval($data['numwant']);
   if ($data['numwant'] < 0)
       $data['numwant'] = 1000;
   if ($data['numwant'] > 1000)
       $data['numwant'] = 1000;
} else {
   $data['numwant'] = 30;
}
$data['ip'] = getip();

$res        = SQL_Query_exec("SELECT size, seeders, leechers, id, freeleech FROM torrents WHERE info_hash = '$_GET[info_hash]'");
$torrent_row = mysqli_fetch_assoc($res) or fail('Tracker: torrent missing');
$seeder = (isset($data['left']) && $data['left'] === 0) === 0 ? 'no' : 'yes';
$res = SQL_Query_exec("SELECT to_go, peer_id, seeder, last_action FROM peers WHERE userid = $user_row[id] AND torrent = $torrent_row[id] AND peer_id = '$data[peer_id]'") or fail('No peer found');
if ($freeuser === false) {
   if ($seeder === 'no') {
       if ($user_row['enabled'] == 'no') {
           $event = "Client kicked [url=$site_config[base_url]/user/?id=$user_row[id]/ ] $user_row[username][/url] due to a limited account state";
           SQL_Query_exec("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', '$event', NOW(), 0)");
           fail('Account is limited. Sign in to resolve.');
       }
   }
}
if ($freeslots === false) {
   if ($seeder === 'no') {
       $maxslots = SQL_Query_exec("SELECT COUNT(DISTINCT torrent) AS total, last_announce FROM peers WHERE userid = $user_row[id] AND seeder = 'no'");
       $current  = mysqli_fetch_assoc($maxslots);
       if ($current['total'] > $user_row['slots']) {
           fail("$current[total]/$user_row[slots] Slots used up!");
       }
   }
}
if (max(($user_row['uploaded'] - $user_row['downloaded']), 0) === 0 && ($seeder === 'no')) {
   $kick    = SQL_Query_exec("DELETE FROM peers WHERE userid = $user_row[id] AND seeder = 'no'");
   $seeding = SQL_Query_exec("SELECT COUNT(torrent) as total FROM peers WHERE userid = $user_row[id] AND seeder = 'yes'");
   $seeding = (($s = mysqli_fetch_assoc($seeding)) && intval($s['total']) > 0) ? '[/b], but is seeding ' . intval($s['total']) . ($s['total'] == 1 ? ' torrent' : ' torrents') . ' to earn seedbonus points & free data.' : '![/b]';
   $event   = "[url=$site_config[base_url]/user/?id=$user_row[id] ] $user_row[username][/url] used all of " . (($user_row['gender'] == 'Male') ? 'his' : 'her') . " upload data" . $seeding;
   SQL_Query_exec("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, '$user_row[username]', '$event', NOW(), 0)");
   fail('No data left! Upgrade w/ More Data.');
}
$connectable = fsockopen($data['ip'], $data['port']) ? 'yes' : 'no';
if (!($peer_row = mysqli_fetch_assoc($res))) {
   $res = SQL_Query_exec("INSERT INTO peers (downloaded, uploaded, to_go, started, passkey, connectable, userid, torrent, peer_id, ip, port, client) VALUES (0, 0, $torrent_row[size], NOW(), '$passkey', '$connectable', $user_row[id], $torrent_row[id], '$data[peer_id]', '$data[ip]', $data[port], '$client')") or fail('Cant insert peer.');
   $peer_row = array(
       'peer_id' => $res
   );
} else {
   $uploaded   = max(0, $data['uploaded'] - $peer_row['uploaded']);
   $downloaded = max(0, $data['downloaded'] - $peer_row['downloaded']);
   if ($freeleech === true) {
       if (!empty($torrent_row['freeleech'])) {
           if ($torrent_row['freeleech'] == 1) {
               $downloaded = 0;
           } else if ($torrent_row['freeleech'] == 'silver') {
               $downloaded = round($downloaded / 2);
           } else if ($torrent_row['freeleech'] == 'upboost') {
               $uploaded = round($uploaded * 5);
           } else if ($torrent_row['freeleech'] == 'dlboost') {
               $downloaded = round($downloaded * 5);
           }
       }
   }
   if (($data['left'] === 0) > 0) {
       $downloaded = 0;
   }
   SQL_Query_exec("UPDATE peers SET passkey = '$user_row[passkey]', connectable = '$connectable', to_go = $data[left], uploaded = uploaded + $uploaded, downloaded = downloaded + $downloaded, seeder = '$seeder', client = '$client', ip = '$data[ip]', port = $data[port], last_action = CURRENT_TIMESTAMP WHERE peer_id = '$peer_row[peer_id]'") or fail('Cant update peer');
}

if (array_key_exists('left', $data)) {
   SQL_Query_exec("UPDATE peers SET seeder = '$seeder' WHERE peer_id = '$peer_row[peer_id]'");
}
if ($data['event'] === 'stopped') {
   SQL_Query_exec("DELETE FROM peers WHERE WHERE peer_id = '$peer_row[peer_id]'");
}
if ($data['event'] === 'paused') {
}
if ($data['event'] === 'completed') {
   SQL_Query_exec("DELETE FROM peers WHERE peer_id = '$peer_row[peer_id]'");
   SQL_Query_exec("UPDATE torrents SET times_completed = times_completed + 1 WHERE id = $torrent_row[id]");
}
$res = SQL_Query_exec("SELECT (SELECT COUNT(torrent) FROM peers WHERE seeder = 'yes' AND torrent = p.torrent) AS complete, (SELECT COUNT(torrent) FROM peers WHERE seeder = 'no' AND torrent = p.torrent) AS incomplete, (SELECT times_completed FROM torrents WHERE id = p.torrent) AS downloaded FROM peers p LEFT JOIN torrents t ON t.id = p.torrent WHERE p.torrent = $torrent_row[id] LIMIT 1");
$comp_res = mysqli_fetch_assoc($res) or fail('Cant get stats');

// output array !!!!!
$output = array(
   'interval' => 30 * 60,
   'min interval' => 10 * 60,
   'complete' => intval($comp_res['complete']),
   'incomplete' => intval($comp_res['incomplete']),
   'external ip' => inet_pton($data['ip']),
   'downloaded' => intval($comp_res['downloaded']),
   'peers' => array()
);
$res = SQL_Query_exec("SELECT peer_id, ip, port FROM peers WHERE torrent = $torrent_row[id] AND peer_id != '$peer_row[peer_id]' ORDER BY RAND() LIMIT $data[numwant]") or fail('Cant find peers');
while ($row = mysqli_fetch_assoc($res)) {
   $peer = array(
       'ip' => $row['ip'],
       'port' => intval($row['port'])
   );
   if (!array_key_exists('no_peer_id', $data)) {
       $peer['peer_id'] = hex2bin($row['peer_id']);
   }
   $output['peers'][] = $peer;
}
if (array_key_exists('compact', $data)) {
   $peer_data = '';
   foreach ($output['peers'] as $peer) {
       $bs = inet_pton($peer['ip']);
       if (is_null($bs))
           continue;
       $peer_data .= $bs;
       $peer_data .= chr($peer['port'] >> 8);
       $peer_data .= chr($peer['port'] & 0xff);
   }
   if (empty($output['peers']) || !empty($peer_data)) {
       $output['peers'] = $peer_data;
   }
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {
   SQL_Query_exec("UPDATE peers SET client = '$client' WHERE peer_id = '$peer_row[peer_id]'");
}
echo BEncode($output);
mysqli_close($GLOBALS['DBconnector']);


Or MySQLi class

<?php
require_once("backend/mysql.php");
require_once("backend/config.php");
require_once("backend/BEncode.php");
error_reporting(0);
$mysqli = new mysqli($mysql_host, $mysql_user, $mysql_pass, $mysql_db);
$mysqli->prepare("DELETE FROM peers WHERE last_action + '1 HOUR' < CURRENT_TIMESTAMP");
header('Content-Type: text/plain');
function getip()
{
   if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
       return $_SERVER['HTTP_CF_CONNECTING_IP'];
   }
   foreach (array(
       'HTTP_CLIENT_IP',
       'HTTP_X_FORWARDED_FOR',
       'HTTP_X_FORWARDED',
       'HTTP_X_CLUSTER_CLIENT_IP',
       'HTTP_FORWARDED_FOR',
       'HTTP_FORWARDED',
       'HTTP_CF_CONNECTING_IP',
       'REMOTE_ADDR'
   ) as $key) {
       if (array_key_exists($key, $_SERVER) === true) {
           foreach (array_map('trim', explode(',', $_SERVER[$key])) as $ip) {
               if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) {
                   return $ip;
               }
           }
       }
   }
}
$freeleech_days = array(
   'Monday',
   'Tuesday'
);
$slotfree_days  = array(
   'Thursday',
   'Friday'
);
$freeuser_days  = array(
   'Tuesday',
   'Wednesday'
);
$bonus_days     = array(
   'Sunday',
   'Friday'
);
function fail($reason)
{
   die(BEncode(array(
       'failure reason' => $reason,
       'retry in' => '5'
   )));
}
function lastshoutdate($message)
{
   global $mysqli;
   $sql = $mysqli->prepare('SELECT message, date FROM shoutbox WHERE message = ? ORDER BY date DESC LIMIT 1');
   $sql->bind_param('s', $message);
   $sql->execute();
   $res = $sql->get_result();
   if ($lastdate = $res->fetch_assoc()) {
       return $lastdate['date'];
   }
   return false;
}
$data              = $_GET;
$client            = substr($data['peer_id'], 0, 8);
$data['info_hash'] = bin2hex($data['info_hash']);
$data['peer_id']   = bin2hex($data['peer_id']);
$passkey           = !empty($data['passkey']) ? trim($data['passkey']) : fail('Missing passkey');
$sql               = $mysqli->prepare('SELECT id, passkey, username, class, enabled, uploaded, downloaded, slots, gender FROM users WHERE passkey = ?');
$sql->bind_param('s', $passkey);
$sql->execute();
$res = $sql->get_result();
$user_row = $res->fetch_assoc() or fail('Failed getting user');
$freeuser = false;
if (in_array(date('l'), $freeuser_days)) {
   $freeuser = true;
}
$freeleech = false;
if (in_array(date('l'), $freeleech_days)) {
   $freeleech = true;
}
$freeslots = false;
if (in_array(date('l'), $slotfree_days)) {
   $freeslots = true;
}
$bonusdays = false;
if (in_array(date('l'), $bonus_days)) {
   $bonusdays = true;
}
if ($freeuser === true) {
   $event   = "Today is [b]Free User Day!
All limited accounts are Unlocked Today!";
   $lastmsg = lastshoutdate($event);
   if (strtotime($lastmsg) < strtotime('-2 minutes')) {
       $sql = $mysqli->prepare("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', ?, NOW(), 0)");
       $sql->bind_param('s', $event);
       $sql->execute();
   }
}
if ($freeleech === true) {
   $event   = "Today is Freeleech Day! UP/DL Boosts Stackable!";
   $lastmsg = lastshoutdate($event);
   if (strtotime($lastmsg) < strtotime('-2 minutes')) {
       $sql = $mysqli->prepare("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', ?, NOW(), 0)");
       $sql->bind_param('s', $event);
       $sql->execute();
   }
}
if ($freeslots === true) {
   $event   = "Today is Free Slots Day! All slot limits Turned Off!";
   $lastmsg = lastshoutdate($event);
   if (strtotime($lastmsg) < strtotime('-2 minutes')) {
       $sql = $mysqli->prepare("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', ?, NOW(), 0)");
       $sql->bind_param('s', $event);
       $sql->execute();
   }
}
if ($bonusdays === true) {
   $event   = "Today is Bonus Data Day! Bonus data is Doubled X2!";
   $lastmsg = lastshoutdate($event);
   if (strtotime($lastmsg) < strtotime('-2 minutes')) {
       $sql = $mysqli->prepare("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', ?, NOW(), 0)");
       $sql->bind_param('s', $event);
       $sql->execute();
   }
}
if (!is_numeric($data['port']))
   fail('invalid port');
$data['port'] = intval($data['port']);
if ($data['port'] < 1 || $data['port'] >= 65536)
   fail('Invalid port');
if (array_key_exists('left', $data)) {
   if (!is_numeric($data['left']))
       fail('Invalid left');
   $data['left'] = intval($data['left']);
   if ($data['left'] < 0)
       fail('Invalid left');
}
if (array_key_exists('numwant', $data)) {
   if (!is_numeric($data['numwant']))
       fail('invalid numwant');
   $data['numwant'] = intval($data['numwant']);
   if ($data['numwant'] < 0)
       $data['numwant'] = 1000;
   if ($data['numwant'] > 1000)
       $data['numwant'] = 1000;
} else {
   $data['numwant'] = 30;
}
$data['ip'] = getip();
$sql        = $mysqli->prepare('SELECT size, seeders, leechers, id, freeleech FROM torrents WHERE info_hash = ?');
$sql->bind_param('s', $_GET['info_hash']);
$sql->execute();
$res = $sql->get_result();
$torrent_row = $res->fetch_assoc() or fail('Tracker: torrent missing');
$seeder = (isset($data['left']) && $data['left'] === 0) === 0 ? 'no' : 'yes';
$sql = $mysqli->prepare('SELECT to_go, peer_id, seeder, last_action FROM peers WHERE userid = ? AND torrent = ? AND peer_id = ?') or fail('No peer found');
$sql->bind_param('iis', $user_row['id'], $torrent_row['id'], $data['peer_id']);
$sql->execute();
$res = $sql->get_result();
if ($freeuser === false) {
   if ($seeder === 'no') {
       if ($user_row['enabled'] == 'no') {
           $event = "Client kicked [url=$site_config[base_url]/user/?id=$user_row[id]/ ] $user_row[username][/url] due to a limited account state";
           $sql   = $mysqli->prepare("INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, 'Tracker', ?, NOW(), 0)");
           $sql->bind_param('s', $event);
           $sql->execute();
           fail('Account is limited. Sign in to resolve.');
       }
   }
}
if ($freeslots === false) {
   if ($seeder === 'no') {
       $sql = $mysqli->prepare("SELECT COUNT(DISTINCT torrent) AS total, last_announce FROM peers WHERE userid = ? AND seeder = 'no'");
       $sql->bind_param('i', $user_row['id']);
       $sql->execute();
       $maxslots = $sql->get_result();
       $current  = $maxslots->fetch_assoc();
       if ($current['total'] > $user_row['slots']) {
           fail("$current[total]/$user_row[slots] Slots used up!");
       }
       $sql->free_result();
   }
}
if (max(($user_row['uploaded'] - $user_row['downloaded']), 0) === 0 && ($seeder === 'no')) {
   $sql = $mysqli->prepare("DELETE FROM peers WHERE userid = ? AND seeder = 'no'");
   $sql->bind_param('i', $user_row['id']);
   $sql->execute();
   $sql = $mysqli->prepare("SELECT COUNT(torrent) as total FROM peers WHERE userid = ? AND seeder = 'yes'");
   $sql->bind_param('i', $user_row['id']);
   $sql->execute();
   $seedstatus = $sql->get_result();
   $seeding    = (($s = $seedbonus->fetch_assoc()) && intval($s['total']) > 0) ? '[/b], but is seeding ' . intval($s['total']) . ($s['total'] == 1 ? ' torrent' : ' torrents') . ' to earn seedbonus points & free data.' : '![/b]';
   $event      = "[url=$site_config[base_url]/user/?id=$user_row[id] ] $user_row[username][/url] used all of " . (($user_row['gender'] == 'Male') ? 'his' : 'her') . " upload data" . $seeding;
   $sql        = $mysqli->prepare('INSERT INTO shoutbox (msgid, user, message, date, userid) VALUES (NULL, ?, ?, NOW(), 0)');
   $sql->bind_param('ss', $user_row['username'], $event);
   $sql->execute();
   $sql->free_result();
   fail('No data left! Upgrade w/ More Data.');
}
$connectable = fsockopen($data['ip'], $data['port']) ? 'yes' : 'no';
if (!($peer_row = $res->fetch_assoc())) {
   $sql = $mysqli->prepare("INSERT INTO peers (ip, torrent, peer_id, port, uploaded, downloaded, to_go, seeder, started, last_action, connectable, client, userid, passkey) VALUES (?, ?, ?, ?, 0, 0, ?, ?, NOW(), NOW(), ?, ?, ?, ?)") or fail('Cant insert peer.');
   $sql->bind_param('sisiisssis', getip(), $torrent_row['id'], $data['peer_id'], $data['port'], $torrent_row['size'], $seeder, $connectable, $client, $user_row['id'], $passkey);
   $sql->execute();
   $peer_row = array(
       'peer_id' => $sql->insert_id
   );
   $sql->close();
} else {
   $uploaded   = max(0, $data['uploaded'] - $peer_row['uploaded']);
   $downloaded = max(0, $data['downloaded'] - $peer_row['downloaded']);
   if ($freeleech === true) {
       if (!empty($torrent_row['freeleech'])) {
           if ($torrent_row['freeleech'] == 1) {
               $downloaded = 0;
           } else if ($torrent_row['freeleech'] == 'silver') {
               $downloaded = round($downloaded / 2);
           } else if ($torrent_row['freeleech'] == 'upboost') {
               $uploaded = round($uploaded * 5);
           } else if ($torrent_row['freeleech'] == 'dlboost') {
               $downloaded = round($downloaded * 5);
           }
       }
   }
   if (($data['left'] === 0) > 0) {
       $downloaded = 0;
   }
   $sql = $mysqli->prepare('UPDATE peers SET passkey = ?, connectable = ?, to_go = ?, uploaded = uploaded + ?, downloaded = downloaded + ?, seeder = ?, client = ?, ip = ?, port = ?, last_action = CURRENT_TIMESTAMP WHERE peer_id = ?') or fail('Cant update peer');
   $sql->bind_param('ssiiisssis', $user_row['passkey'], $connectable, $data['left'], $uploaded, $downloaded, $seeder, $client, $data['ip'], $data['port'], $peer_row['peer_id']);
   $sql->execute();
}
if (array_key_exists('left', $data)) {
   $sql = $mysqli->prepare('UPDATE peers SET seeder = ? WHERE peer_id = ?');
   $sql->bind_param('ss', $seeder, $peer_row['peer_id']);
   $sql->execute();
}
if ($data['event'] === 'stopped') {
   $sql = $mysqli->prepare('DELETE FROM peers WHERE WHERE peer_id = ?');
   $sql->bind_param('s', $peer_row['peer_id']);
   $sql->execute();
}
if ($data['event'] === 'paused') {
}
if ($data['event'] === 'completed') {
   $sql = $mysqli->prepare('DELETE FROM peers WHERE peer_id = ?');
   $sql->bind_param('s', $peer_row['peer_id']);
   $sql->execute();
   $sql = $mysqli->prepare('UPDATE torrents SET times_completed = times_completed + 1 WHERE id = ?');
   $sql->bind_param('i', $torrent_row['id']);
   $sql->execute();
}
$sql = $mysqli->prepare("SELECT (SELECT COUNT(torrent) FROM peers WHERE seeder = 'yes' AND torrent = p.torrent) AS complete, (SELECT COUNT(torrent) FROM peers WHERE seeder = 'no' AND torrent = p.torrent) AS incomplete, (SELECT times_completed FROM torrents WHERE id = p.torrent) AS downloaded FROM peers p LEFT JOIN torrents t ON t.id = p.torrent WHERE p.torrent = ? LIMIT 1");
$sql->bind_param('i', $torrent_row['id']);
$sql->execute();
$res = $sql->get_result();
$comp_res = $res->fetch_assoc() or fail('Cant get stats');
$output = array(
   'interval' => 30 * 60,
   'min interval' => 10 * 60,
   'complete' => intval($comp_res['complete']),
   'incomplete' => intval($comp_res['incomplete']),
   'external ip' => inet_pton($data['ip']),
   'downloaded' => intval($comp_res['downloaded']),
   'peers' => array()
);
$sql = $mysqli->prepare('SELECT peer_id, ip, port FROM peers WHERE torrent = ? AND peer_id != ? ORDER BY RAND() LIMIT ?') or fail('Cant find peers');
$sql->bind_param('isi', $torrent_row['id'], $peer_row['peer_id'], $data['numwant']);
$sql->execute();
$res = $sql->get_result();
while ($row = $res->fetch_assoc()) {
   $peer = array(
       'ip' => $row['ip'],
       'port' => intval($row['port'])
   );
   if (!array_key_exists('no_peer_id', $data)) {
       $peer['peer_id'] = hex2bin($row['peer_id']);
   }
   $output['peers'][] = $peer;
}
$sql->free_result();
if (array_key_exists('compact', $data)) {
   $peer_data = '';
   foreach ($output['peers'] as $peer) {
       $bs = inet_pton($peer['ip']);
       if (is_null($bs))
           continue;
       $peer_data .= $bs;
       $peer_data .= chr($peer['port'] >> 8);
       $peer_data .= chr($peer['port'] & 0xff);
   }
   if (empty($output['peers']) || !empty($peer_data)) {
       $output['peers'] = $peer_data;
   }
}
if (isset($_SERVER['HTTP_USER_AGENT'])) {
   $sql = $mysqli->prepare('UPDATE peers SET client = ? WHERE peer_id = ?');
   $sql->bind_param('ss', $client, $peer_row['peer_id']);
   $sql->execute();
}
$mysqli->close();
echo BEncode($output);


And we get (showing 2 peers)

d10:downloadedi0e11:external ipde8:intervali1800e12:min intervali600e5:peersld2:ip0:7:peer_id20:646667646667646667644:porti3432eed2:ip3:::17:peer_idde4:porti3432eed2:ip0:7:peer_id20:dfgdfgdfgdfgdfgdfgdf4:porti3432eeee


Next update will remove SQL_Query_exec() and use mysql objects directly, the SQL here is very insecure and should not be used on a public server. Testing only.

Report in the comments. Use the [b]tracker message
from your client when posting a potential bug report.

Right now, its just reading $_GET. This will be updated.
Thats where that is! I've been looking everywhere in the GIT zip file, I know I saw some references in /backend/ but thats about it.

That makes clear sense now.. This will complete the announce code I'm on at the moment. Whew lol

---

Yup! You are all set. You got BEP-48 implemented. Clients will call it as they need. Check your access logs if you want to keep a eye on requests for /scrape?info_hash=xxx (uTorrent does it parodically, I found with stopping a torrent).
Oh... sorry. it is supposed to be WHERE info_hash = '$info_hash' (in single quotes).

Post updated. Yeah anything comparing a string (non-integer at least), always has to have single-quotes unless the statement is prepared - then it automatically escapes as needed.

We definitely know its there lol

I realize uTorrent is querying this now and then, but uTorrent relies on announcement. This keeps peer counts - scraping - always available and active.

I implemented according to spec. Ported for TTv3.

Upload to root as scrape.php

Add to .htaccess

RewriteRule ^scrape?$ /scrape.php?%{QUERY_STRING} [NC,L]


<?php
// BEP-48: Tracker Protocol Extension: Scrape
// https://www.bittorrent.org/beps/bep_0048.html
require_once("backend/functions.php");
require_once("backend/BEncode.php");
dbconn();
const MIN_REQ_INTERVAL = 30;
$data = array();
header('Content-Type: text/plain');
if (isset($_GET['info_hash']) && strlen($_GET['info_hash']) > 0) {
   if (preg_match_all('/([a-f0-9]{40})/', trim($_SERVER['QUERY_STRING']), $reqhash, PREG_PATTERN_ORDER)) {
       foreach ($reqhash[0] as $info_hash) {
           $res      = SQL_Query_exec("SELECT times_completed, seeders, leechers FROM torrents WHERE info_hash = '$info_hash'");
           $comp_res = mysqli_fetch_assoc($res);
           $stats    = array(
               $info_hash => array(
                   'complete' => intval($comp_res['seeders']),
                   'downloaded' => intval($comp_res['times_completed']),
                   'incomplete' => intval($comp_res['leechers'])
               )
           );
           array_push($data, $stats);
       }
   }
   if (!empty($data)) {
       echo BEncode(array(
           'files' => array(
               array_merge(...$data) // PHP 5.6+
               ),
           'flags' => array(
               'min_request_interval' => MIN_REQ_INTERVAL
           )
       ));
   } else {
       echo BEncode(array(
           'failure reason' => 'Scrape failed'
       ));
   }
}


Let me know if any issues. Try a info hash in the browser

somesite.com/scrape.php?info_hash=xxx

You should see bencoded output. If you do, everything is working as expected.
It will output stats for the clients for unlimited info hashes. Clients usually query one, spec allows for as many as needed.

?info_hash=xxx (default, clients use one per transfers)

Allows:
?info_hash=xxx&info_hash=xxx&info_hash=xxx (and so on)
Help — 2022-11-10 21:54:03 in General Chat
That is a very old way of sorting array keys and listing, also depreciated.

You want to foreach that and work with the keys correctly, and sort accordingly or use a &array pointer to the foreach call and go that route. PHP will complain about that
Users online

No users online

Search



Statistics

    Torrents

  • Tracking: 3
  • Todays torrents: 0
  • Seeders: 0
  • Leechers: 0
  • Peers: 0
  • Downloaded: 89.96 GB
  • Uploaded: 9.86 GB

  • Members

  • We have: 838
  • New today: 0
  • Guest today: 9

  • Online

  • Total online: 1
  • Members: 0
  • Guests online: 1
  • Comments: 3
  • Messages: 1,728