/** sync torrent counts - pdq **/ function docleanup($data) { global $INSTALLER09, $queries, $mc1; set_time_limit(0); ignore_user_abort(1); require_once INCL_DIR . 'ann_functions.php'; $torrent_seeds = $torrent_leeches = array(); $deadtime = TIME_NOW - floor($INSTALLER09['announce_interval'] * 1.3); $dead_peers = sql_query('SELECT torrent, userid, peer_id, seeder FROM peers WHERE last_action < ' . $deadtime); while ($dead_peer = mysqli_fetch_assoc($dead_peers)) { $torrentid = (int) $dead_peer['torrent']; $userid = (int) $dead_peer['userid']; $seed = $dead_peer['seeder'] === 'yes'; // you use 'yes' i thinks :P sql_query('DELETE FROM peers WHERE torrent = ' . $torrentid . ' AND peer_id = ' . sqlesc($dead_peer['peer_id'])); if (!isset($torrent_seeds[$torrentid])) { $torrent_seeds[$torrentid] = $torrent_leeches[$torrentid] = 0; } if ($seed) { $torrent_seeds[$torrentid]++; } else { $torrent_leeches[$torrentid]++; } } foreach (array_keys($torrent_seeds) as $tid) { $update = array(); adjust_torrent_peers($tid, -$torrent_seeds[$tid], -$torrent_leeches[$tid], 0); if ($torrent_seeds[$tid]) { $update[] = 'seeders = (seeders - ' . $torrent_seeds[$tid] . ')'; } if ($torrent_leeches[$tid]) { $update[] = 'leechers = (leechers - ' . $torrent_leeches[$tid] . ')'; } sql_query('UPDATE torrents SET ' . implode(', ', $update) . ' WHERE id = ' . $tid); } if ($queries > 0) { write_log("Peers clean-------------------- Peer cleanup Complete using {$queries} queries --------------------"); } if (false !== mysqli_affected_rows($GLOBALS["___mysqli_ston"])) { $data['clean_desc'] = mysqli_affected_rows($GLOBALS["___mysqli_ston"]) . " items deleted/updated"; } if ($data['clean_log']) { cleanup_log($data); } }
$snatch_updateset[] = "ip = " . ann_sqlesc($realip) . ", port = " . ann_sqlesc($port) . ", connectable = " . ann_sqlesc($connectable) . ", uploaded = uploaded + {$upthis}, " . ($INSTALLER09['ratio_free'] ? "downloaded = downloaded + 0" : "downloaded = downloaded + {$downthis}") . ", to_go = " . ann_sqlesc($left) . ", upspeed = " . ($upthis > 0 ? $upthis / $self["announcetime"] : 0) . ", downspeed = " . ($downthis > 0 ? $downthis / $self["announcetime"] : 0) . ", " . ($self["seeder"] == "yes" ? "seedtime = seedtime + {$self['announcetime']}" : "leechtime = leechtime + {$self['announcetime']}") . ", last_action = " . TIME_NOW . ", seeder = " . ann_sqlesc($seeder) . ", agent = " . ann_sqlesc($agent) . ", timesann = timesann + 1"; } } } else { if ($user["parked"] == "yes") { err("Your account is parked! (Read the FAQ)"); } elseif ($user["downloadpos"] == 0 or $user["downloadpos"] > 1 and $user['hnrwarn'] == 'no') { err("Your downloading priviledges have been disabled! (Read the rules)"); } mysqli_query($GLOBALS["___mysqli_ston"], "INSERT LOW_PRIORITY INTO peers (torrent, userid, peer_id, ip, port, connectable, uploaded, downloaded, to_go, started, last_action, seeder, agent, downloadoffset, uploadoffset, passkey) VALUES (" . ann_sqlesc($torrentid) . ", " . ann_sqlesc($userid) . ", " . ann_sqlesc($peer_id) . ", " . ann_sqlesc($realip) . ", " . ann_sqlesc($port) . ", " . ann_sqlesc($connectable) . ", " . ann_sqlesc($uploaded) . ", " . ($INSTALLER09['ratio_free'] ? "0" : "" . ann_sqlesc($downloaded) . "") . ", " . ann_sqlesc($left) . ", " . TIME_NOW . ", " . TIME_NOW . ", " . ann_sqlesc($seeder) . ", " . ann_sqlesc($agent) . ", " . ($INSTALLER09['ratio_free'] ? "0" : "" . ann_sqlesc($downloaded) . "") . ", " . ann_sqlesc($uploaded) . ", " . ann_sqlesc($passkey) . ")") or ann_sqlerr(__FILE__, __LINE__); if (mysqli_affected_rows($GLOBALS["___mysqli_ston"])) { $updateset[] = $seeder == "yes" ? "seeders = seeders + 1" : "leechers = leechers + 1"; if ($seeder == "yes") { adjust_torrent_peers($torrentid, 1, 0, 0); } else { adjust_torrent_peers($torrentid, 0, 1, 0); } if ($a) { $snatch_updateset[] = "ip = " . ann_sqlesc($realip) . ", port = " . ann_sqlesc($port) . ", connectable = " . ann_sqlesc($connectable) . ", to_go = " . ann_sqlesc($left) . ", last_action = " . TIME_NOW . ", seeder = " . ann_sqlesc($seeder) . ", agent = " . ann_sqlesc($agent) . ", timesann = timesann + 1, hit_and_run = '0', mark_of_cain = 'no'"; } } } if ($seeder == 'yes') { if ($torrent['banned'] != 'yes') { $updateset[] = 'visible = \'yes\''; } $updateset[] = 'last_action = ' . TIME_NOW; $mc1->begin_transaction('torrent_details_' . $torrentid); $mc1->update_row(false, array('visible' => 'yes')); $mc1->commit_transaction($INSTALLER09['expires']['torrent_details']); $mc1->begin_transaction('last_action_' . $torrentid);