// if user has already completed this torrent, mysql will give error because of unique index (uid+infohash) // upload/download will be updated on stop event... // record should already exist (created on stated event) quickQuery("UPDATE history SET date = UNIX_TIMESTAMP(), active = 'yes', agent = '" . getagent($agent, $peer_id) . "' WHERE uid = " . (int) $curuid["id"] . " AND infohash = '" . $info_hash . "'"); // record is not present, create it if ($db->affected_rows == 0) { quickQuery("INSERT INTO history (uid, infohash, date, active, agent) VALUES (" . (int) $curuid["id"] . ", '" . $info_hash . "', UNIX_TIMESTAMP(), 'yes', '" . getagent($agent, $peer_id) . "')"); } } $resu->free(); } break; // client sent no event // client sent no event case '': verifyTorrent($info_hash) or show_error("Torrent is not authorized for use on this tracker."); $peer_exists = getPeerInfo($peer_id, $info_hash); $where = "WHERE natuser = '******'"; if (!is_array($peer_exists)) { $where = start($info_hash, $ip, $port, $peer_id, $left, $downloaded, $uploaded, $pid); } if ($peer_exists["bytes"] != 0 && $left == 0) { quickQuery("UPDATE peers SET bytes = 0, status = 'seeder' WHERE sequence = '" . $GLOBALS['trackerid'] . "' AND infohash = '" . $info_hash . "'"); if ($db->affected_rows == 1) { summaryAdd("leechers", -1); summaryAdd("seeds", 1); summaryAdd("finished", 1); summaryAdd("lastcycle", "UNIX_TIMESTAMP()", true); } } collectBytes($peer_exists, $info_hash, $left, $downloaded, $uploaded, $pid);
} } elseif ($event == "stopped") { verifyTorrent($info_hash) or evilReject($ip, $peer_id, $port); killPeer($peer_id, $info_hash, $left); // I don't know why, but the real tracker returns peers on event=stopped // but I'll just send an empty list. On the other hand, // TheSHADOW asked for this. if (isset($_GET["tracker"])) { $peers = getRandomPeers($info_hash); } else { $peers = array("size" => 0); } sendPeerList($peers); } elseif ($event == "completed") { // now the same as an empty string verifyTorrent($info_hash) or evilReject($ip, $peer_id, $port); $peer_exists = getPeerInfo($peer_id, $info_hash); if (!is_array($peer_exists)) { start($info_hash, $ip, $port, $peer_id, $left, $uploaded, $clientVer); } else { quickQuery("UPDATE x{$info_hash} SET bytes=0, status=\"seeder\", uploaded={$uploaded} WHERE sequence=\"{$GLOBALS["trackerid"]}\""); // Race check if (mysql_affected_rows() == 1) { summaryAdd("leechers", -1); summaryAdd("seeds", 1); summaryAdd("finished", 1); } } updatePeer($peer_id, $info_hash); collectBytes($peer_exists, $info_hash, $left, $uploaded); $peers = getRandomPeers($info_hash);