0) { $invites = do_mysql_query("SELECT invites FROM users WHERE id = $arr[invited_by]"); $arr2 = mysql_fetch_assoc($invites); if ($arr2[invites] < 10) { $invites = $arr2[invites] +1; do_mysql_query("UPDATE users SET invites='$invites' WHERE id = $arr[invited_by]"); } do_mysql_query("DELETE FROM users WHERE status = 'pending' AND added < FROM_UNIXTIME($deadtime) AND last_access = '0000-00-00 00:00:00'"); } $torrents = array(); $res = do_mysql_query("SELECT torrent, seeder, COUNT(*) AS c FROM peers GROUP BY torrent, seeder"); while ($row = mysql_fetch_assoc($res)) { if ($row["seeder"] == "yes") $key = "seeders"; else $key = "leechers"; $torrents[$row["torrent"]][$key] = $row["c"]; } $res = do_mysql_query("SELECT torrent, COUNT(*) AS c FROM comments GROUP BY torrent"); while ($row = mysql_fetch_assoc($res)) { $torrents[$row["torrent"]]["comments"] = $row["c"]; } $fields = array('comments', 'leechers','seeders'); $res = do_mysql_query("SELECT id, seeders, leechers, comments FROM torrents"); while ($row = mysql_fetch_assoc($res)) { $id = $row["id"]; $torr = $torrents[$id]; foreach ($fields as $field) { if (!isset($torr[$field])) $torr[$field] = 0; } $update = array(); foreach ($fields as $field) { if ($torr[$field] != $row[$field]) $update[] = "$field = " . $torr[$field]; } if (count($update)) do_mysql_query("UPDATE torrents SET " . implode(",", $update) . " WHERE id = $id"); } //delete requests after 21 days $res = do_mysql_query("SELECT id FROM requests WHERE added < DATE_SUB(NOW(), INTERVAL 21 DAY)"); do_mysql_query("DELETE FROM addedrequests WHERE requestid = $res"); do_mysql_query("DELETE FROM requests WHERE added < DATE_SUB(NOW(), INTERVAL 21 DAY)"); //delete inactive user accounts after 28 days $maxclass = UC_USER; $res = do_mysql_query("SELECT id FROM users WHERE parked='no' AND status='confirmed' AND class <= $maxclass AND last_access < DATE_SUB(NOW(), INTERVAL 28 DAY)"); while ($arr = mysql_fetch_assoc($res)) { clean_user($arr['id']); } //delete old/ no upload accounts after 28 days $maxclass = UC_USER; $res = do_mysql_query("SELECT id FROM users WHERE uploaded < 10 AND class <= $maxclass AND added < DATE_SUB(NOW(), INTERVAL 28 DAY)"); while ($arr = mysql_fetch_assoc($res)) { clean_user($arr['id']); } //delete 4 week old messages do_mysql_query("DELETE FROM messages WHERE added < DATE_SUB(NOW(), INTERVAL 28 DAY)"); //delete parked user accounts after 56 days $maxclass = UC_USER; $res = do_mysql_query("SELECT id FROM users WHERE parked='yes' AND status='confirmed' AND class <= $maxclass AND last_access < DATE_SUB(NOW(), INTERVAL 56 DAY)"); while ($arr = mysql_fetch_assoc($res)) { clean_user($arr['id']); } // lock topics where last post was made more than x days ago $secs = 14*86400; $res = do_mysql_query("SELECT topics.id FROM topics LEFT JOIN posts ON topics.lastpost = posts.id AND topics.sticky = 'no' WHERE " . gmtime() . " - UNIX_TIMESTAMP(posts.added) > $secs") or sqlerr(__FILE__, __LINE__); while ($arr = mysql_fetch_assoc($res)) do_mysql_query("UPDATE topics SET locked='yes' WHERE id=$arr[id]") or sqlerr(__FILE__, __LINE__); //remove expired warnings $res = do_mysql_query("SELECT id FROM users WHERE warned='yes' AND warneduntil < NOW() AND warneduntil <> '0000-00-00 00:00:00'") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { $msg = "Your warning has been removed. Please keep in your best behaviour from now on.\n"; while ($arr = mysql_fetch_assoc($res)) { do_mysql_query("UPDATE users SET warned = 'no', warneduntil = '0000-00-00 00:00:00' WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__); new_msg(0, $arr['id'], $msg); } } /* /////////////////////////////////////////////Automatic Demotion to Peasant Stuff/////////////////////////////// /////////Update last_check for classes great than 10///////// do_mysql_query("UPDATE users SET last_check = NOW() WHERE class > 10) or sqlerr(__FILE__, __LINE__); /////////Update last_check for users who downloaded less than 1 GB///////// $limit = 1*1024*1024*1024; do_mysql_query("UPDATE users SET last_check = NOW(), maxtorrents = 5 WHERE class=10 AND downloaded < $limit") or sqlerr(__FILE__, __LINE__); /////////Promote peasant user if ratio is above .3///////// $minratio = 0.30; $res = do_mysql_query("SELECT id FROM users WHERE class = 0 AND uploaded / downloaded >= $minratio") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { $msg = "Congratulations, you have been auto-promoted to User again.You can now stand without shame of your fellow compadres. You are allowed to have 10 active torrents.\n"; while ($arr = mysql_fetch_assoc($res)) { do_mysql_query("UPDATE users SET last_check = NOW(), class = 10, maxtorrents = 10, warned = 'no', leechwarn = 'no' WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__); new_msg(0, $arr['id'], $msg); } } /////////Warn user of demotion to peasant if they have downloaded over 1 GB, ratio is below .3 for 1 weeks///////// $limit = 1*1024*1024*1024; $minratio = 0.30; $res = do_mysql_query("SELECT id FROM users WHERE class = 10 AND downloaded > $limit AND last_check < DATE_SUB(NOW(), INTERVAL 7 DAY) AND uploaded / downloaded < $minratio AND leechwarn = 'no'") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { $msg = "You will be auto-demoted from User to Peasant in another week because your ratio has dropped below $minratio for a week. You are only allowed to have 5 active torrents.\n"; while ($arr = mysql_fetch_assoc($res)) { do_mysql_query("UPDATE users SET leechwarn = 'yes', maxtorrents = 5, warned = 'yes' WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__); new_msg(0, $arr['id'], $msg); } } /////////Demote user to peasant if they have downloaded over 1 GB, ratio is below .3 for 2 weeks///////// $limit = 1*1024*1024*1024; $secs = 14*86400; $minratio = 0.30; $res = do_mysql_query("SELECT id FROM users WHERE class = 10 AND downloaded > $limit AND last_check < DATE_SUB(NOW(), INTERVAL 14 DAY) AND uploaded / downloaded < $minratio") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { $msg = "You have been auto-demoted from User to Peasant because your share ratio has dropped below $minratio for 2 weeks. Your account will be automatically deleted in 2 weeks if your ratio is not above $minratio. You are only allowed to have 2 active torrents.\n"; while ($arr = mysql_fetch_assoc($res)) { do_mysql_query("UPDATE users SET class = 0, maxtorrents = 2 WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__); new_msg(0, $arr['id'], $msg); } } //////////disable peasant accounts after 4 weeks//////////// do_mysql_query("UPDATE users SET enabled = 'no' WHERE class = 0 AND last_check < DATE_SUB(NOW(), INTERVAL 28 DAY)"); /////////Update last_check for users with ratio above .30 and have warning///////// $minratio = 0.30; $res = do_mysql_query("SELECT id FROM users WHERE class = 10 AND leechwarn = 'yes' AND uploaded / downloaded > $minratio") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { $msg = "Congratulations, your warning has automatically been removed.You are allowed to have 10 active torrents again.\n"; while ($arr = mysql_fetch_assoc($res)) { do_mysql_query("UPDATE users SET last_check = NOW(), maxtorrents = 10, leechwarn = 'no', warned = 'no' WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__); new_msg(0, $arr['id'], $msg); } } /////////Update last_check for users with ratio above .30 & downloaded over 1 GB///////// $limit = 1*1024*1024*1024; $minratio = 0.30; $res = do_mysql_query("SELECT id FROM users WHERE class = 10 AND uploaded / downloaded > $minratio AND downloaded >= $limit") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { while ($arr = mysql_fetch_assoc($res)) { do_mysql_query("UPDATE users SET last_check = NOW(), maxtorrents = 20 WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__); } } ///////////////////////////////////////End of Automatic Demotion to Peasant Stuff//////////////////////////// */ //////////////////////////////////////Start of Invites/////////////////////////////////////////////// function autoinvites($length, $minlimit, $maxlimit, $minratio, $invites) { $time = $length*86400; $minlimit = $minlimit*1024*1024*1024; $maxlimit = $maxlimit*1024*1024*1024; $res = do_mysql_query("SELECT id, invites FROM users WHERE class > 0 AND enabled = 'yes' AND downloaded >= $minlimit AND downloaded < $maxlimit AND uploaded / downloaded >= $minratio AND warned = 'no' AND invites < 10 AND invitedate < DATE_SUB(NOW(), INTERVAL $time SECOND)") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { while ($arr = mysql_fetch_assoc($res)) { if ($arr[invites] == 9) $invites = 1; elseif ($arr[invites] == 8 && $invites == 3) $invites = 2; do_mysql_query("UPDATE users SET invites = invites+$invites, invitedate = NOW() WHERE id=$arr[id]") or sqlerr(__FILE__, __LINE__); } } } autoinvites(10,1,4,.90,1); autoinvites(10,4,7,.95,2); autoinvites(10,7,10,1.00,3); autoinvites(10,10,100000,1.05,4); //////////////////////////////////////End of Invites/////////////////////////////////////////////// // promote power users $limit = 10*1024*1024*1024; $minratio = 1.05; $maxdt = sqlesc(get_date_time(gmtime() - 86400*28)); $res = do_mysql_query("SELECT id FROM users WHERE class = 10 AND uploaded >= $limit AND uploaded / downloaded >= $minratio AND added < DATE_SUB(NOW(), INTERVAL 28 DAY)") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { $msg = "Congratulations, you have been auto-promoted to [b]Power User[/b]. :)\nYour account can not be deleted automatically. You are allowed to have 100 active torrents.\n"; while ($arr = mysql_fetch_assoc($res)) { do_mysql_query("UPDATE users SET class = 20, invites = 5, maxtorrents = 100 WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__); new_msg(0, $arr['id'], $msg); } } // demote power users $minratio = 0.95; $res = do_mysql_query("SELECT id FROM users WHERE class = 20 AND uploaded / downloaded < $minratio") or sqlerr(__FILE__, __LINE__); if (mysql_num_rows($res) > 0) { $msg = "You have been auto-demoted from [b]Power User[/b] to [b]User[/b] because your share ratio has dropped below $minratio. You are allowed to have 10 active torrents.\n"; while ($arr = mysql_fetch_assoc($res)) { do_mysql_query("UPDATE users SET class = 10, maxtorrents = 10, invites = 0 WHERE id = $arr[id]") or sqlerr(__FILE__, __LINE__); new_msg(0, $arr['id'], $msg); } } // Update stats $seeders = get_row_count("peers", "WHERE seeder='yes'"); $leechers = get_row_count("peers", "WHERE seeder='no'"); do_mysql_query("UPDATE avps SET value_u=$seeders WHERE arg='seeders'") or sqlerr(__FILE__, __LINE__); do_mysql_query("UPDATE avps SET value_u=$leechers WHERE arg='leechers'") or sqlerr(__FILE__, __LINE__); // update forum post/topic count $forums = do_mysql_query("select id from forums"); while ($forum = mysql_fetch_assoc($forums)) { $postcount = 0; $topiccount = 0; $topics = do_mysql_query("select id from topics where forumid=$forum[id]"); while ($topic = mysql_fetch_assoc($topics)) { $res = do_mysql_query("select count(*) from posts where topicid=$topic[id]"); $arr = mysql_fetch_row($res); $postcount += $arr[0]; ++$topiccount; } do_mysql_query("update forums set postcount=$postcount, topiccount=$topiccount where id=$forum[id]"); } /////////////////////////////////delete inactive torrents///////////////////////////////////// $days = 30; $res = do_mysql_query("SELECT id, name FROM torrents WHERE seeders = 0 AND last_action < DATE_SUB(NOW(), INTERVAL $days DAY)"); while ($arr = mysql_fetch_assoc($res)) { @unlink("$torrent_dir/$arr[id].torrent"); do_mysql_query("DELETE FROM torrents WHERE id=$arr[id]"); do_mysql_query("DELETE FROM peers WHERE torrent=$arr[id]"); do_mysql_query("DELETE FROM comments WHERE torrent=$arr[id]"); do_mysql_query("DELETE FROM files WHERE torrent=$arr[id]"); do_mysql_query("DELETE FROM ratings WHERE torrent=$arr[id]"); do_mysql_query("DELETE FROM snatched WHERE torrentid =".$arr['id']); write_log("Torrent $arr[id] ($arr[name]) was deleted by system (older than $days days)"); } // delete items older than a week $days = 14; do_mysql_query("DELETE FROM sitelog WHERE added < DATE_SUB(NOW(), INTERVAL $days DAY)") or sqlerr(__FILE__, __LINE__); } ?>