<?
if (ob_get_level() == 0) ob_start();
require_once("include/bittorrent.inc.php");
require_once("include/benc.php");
dbconn();

header("Content-Type: text/plain");

$r = "d" . benc_str("files") . "d";

$fields = "info_hash, times_completed, seeders, leechers";


// new feature for azureus 2.8.5 and more : can check multiples torrent from the same tracker !
if (!isset($_GET["info_hash"])) {
$query = "SELECT $fields FROM torrents ORDER BY info_hash";
} else {
$sql_info_hash = "";
$i = 0;
$info_hashs = split("&info_hash=", substr(urldecode($_SERVER['QUERY_STRING']),10));
foreach ($info_hashs as $info_hash) {
 if (strlen($info_hash) == 20) {
  if ($i > 0) {
   $sql_info_hash .= " OR ";
  }
  $sql_info_hash .= hash_where("info_hash", $info_hash);
  $i++;
 }
}

if ($i > 0) {
 $query = "SELECT $fields FROM torrents WHERE $sql_info_hash ORDER BY info_hash";
} else {
 $query = "SELECT $fields FROM torrents ORDER BY info_hash";
}
}

$res = mysql_query($query);

while ($row = mysql_fetch_assoc($res)) {
	$r .= "20:" . hash_pad($row["info_hash"]) . "d" .
		benc_str("complete") . "i" . $row["seeders"] . "e" .
		benc_str("downloaded") . "i" . $row["times_completed"] . "e" .
		benc_str("incomplete") . "i" . $row["leechers"] . "e" .
		"e";
}

$r .= "ee";

print($r);

?>
