<?php require_once 'include/bittorrent_announce.php'; require_once 'include/benc.php'; dbconn_announce(); // BLOCK ACCESS WITH WEB BROWSERS AND CHEATS! block_browser(); preg_match_all('/info_hash=([^&]*)/i', $_SERVER["QUERY_STRING"], $info_hash_array); $fields = "info_hash, times_completed, seeders, leechers"; if (count($info_hash_array[1]) < 1) { $query = "SELECT {$fields} FROM torrents ORDER BY id"; } else { $query = "SELECT {$fields} FROM torrents WHERE " . hash_where_arr('info_hash', $info_hash_array[1]); } $r = "d" . benc_str("files") . "d"; $res = sql_query($query); if (mysql_num_rows($res) < 1) { err("Torrent not registered with this tracker."); } 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"; benc_resp_raw($r);
if (!$check) { mysql_query("INSERT LOW_PRIORITY INTO snatched (torrent, userid, port, startdat, last_action) VALUES ({$torrentid}, {$userid}, {$port}, {$dt}, {$dt})"); } $ret = mysql_query("INSERT LOW_PRIORITY INTO peers (connectable, torrent, peer_id, ip, port, uploaded, downloaded, to_go, started, last_action, seeder, userid, agent, uploadoffset, downloadoffset, passkey) VALUES ('{$connectable}', {$torrentid}, " . sqlesc($peer_id) . ", " . sqlesc($ip) . ", {$port}, {$uploaded}, {$downloaded}, {$left}, NOW(), NOW(), '{$seeder}', {$userid}, " . sqlesc($agent) . ", {$uploaded}, {$downloaded}, " . sqlesc($passkey) . ")"); if ($ret) { if ($seeder == 'yes') { $updateset[] = 'seeders = seeders + 1'; } else { $updateset[] = 'leechers = leechers + 1'; } } } } if ($seeder == 'yes') { if ($torrent['banned'] != 'yes') { $updateset[] = 'visible = \'yes\''; } $updateset[] = 'last_action = NOW()'; } if (count($updateset)) { mysql_query('UPDATE LOW_PRIORITY torrents SET ' . join(", ", $updateset) . ' WHERE id = ' . $torrentid); } if (count($snatch_updateset)) { mysql_query('UPDATE LOW_PRIORITY snatched SET ' . join(", ", $snatch_updateset) . ' WHERE torrent = ' . $torrentid . ' AND userid = ' . $userid) or err(mysql_error() . "Line: " . __LINE__); } if ($_SERVER["HTTP_ACCEPT_ENCODING"] == "gzip") { header("Content-Encoding: gzip"); echo gzencode(benc_resp_raw($resp), 9, FORCE_GZIP); } else { benc_resp_raw($resp); }
function err($msg) { mysql_close(); return benc_resp_raw("d" . benc_str("failure reason") . benc_str($msg) . "e"); }
function benc_resp($d) { benc_resp_raw(benc(array(type => "dictionary", value => $d))); }
function benc_resp($d) { benc_resp_raw(benc(array('type' => 'dictionary', 'value' => $d))); }
$db->port = $data['port']; $db->uploaded = 0; $db->downloaded = 0; $db->to_go = $data['left']; $db->seeder = $data['seeder']; $db->started = time(); $db->last_action = time(); $db->passkey = $data['passkey']; $db->connectable = $data['connectable']; $db->insert(); if ($data['seeder']) { $torrent_query[] = "torrent_seeders = torrent_seeders + 1"; } else { $torrent_query[] = "torrent_leechers = torrent_leechers + 1"; } } } if ($data['seeder']) { $torrent_query[] = "torrent_visible = '1'"; $torrent_query[] = "torrent_last_action = '" . time() . "'"; } $db = new DB(); if (count($torrent_query)) { $db->query("UPDATE {PREFIX}torrents SET " . implode(", ", $torrent_query) . " WHERE torrent_id = '{$torrent_id}'"); } $callback[] = benc_str("private") . 'i1e'; benc_resp_raw(implode("", $callback)); } catch (Exception $e) { benc_resp(array('failure reason' => array('type' => 'string', 'value' => $e->getMessage()))); exit; }