Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ratio_watch.php 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?
  2. //----------------------- Manage Ratio Watch ----------------------//
  3. $OffRatioWatch = array();
  4. $OnRatioWatch = array();
  5. // Take users off ratio watch and enable leeching
  6. $UserQuery = $DB->query("
  7. SELECT
  8. m.ID,
  9. torrent_pass
  10. FROM users_info AS i
  11. JOIN users_main AS m ON m.ID = i.UserID
  12. WHERE m.Uploaded/m.Downloaded >= m.RequiredRatio
  13. AND i.RatioWatchEnds IS NOT NULL
  14. AND m.can_leech = '0'
  15. AND m.Enabled = '1'");
  16. $OffRatioWatch = $DB->collect('ID');
  17. if (count($OffRatioWatch) > 0) {
  18. $DB->query("
  19. UPDATE users_info AS ui
  20. JOIN users_main AS um ON um.ID = ui.UserID
  21. SET ui.RatioWatchEnds = NULL,
  22. ui.RatioWatchDownload = '0',
  23. um.can_leech = '1',
  24. ui.AdminComment = CONCAT('$sqltime - Leeching re-enabled by adequate ratio.\n\n', ui.AdminComment)
  25. WHERE ui.UserID IN(".implode(',', $OffRatioWatch).')');
  26. }
  27. foreach ($OffRatioWatch as $UserID) {
  28. $Cache->begin_transaction("user_info_heavy_$UserID");
  29. $Cache->update_row(false, array('RatioWatchEnds' => NULL, 'RatioWatchDownload' => '0', 'CanLeech' => 1));
  30. $Cache->commit_transaction(0);
  31. Misc::send_pm($UserID, 0, 'You have been taken off Ratio Watch', "Congratulations! Feel free to begin downloading again.\n To ensure that you do not get put on ratio watch again, please read the rules located [url=".site_url()."rules.php?p=ratio]here[/url].\n");
  32. echo "Ratio watch off: $UserID\n";
  33. }
  34. $DB->set_query_id($UserQuery);
  35. $Passkeys = $DB->collect('torrent_pass');
  36. foreach ($Passkeys as $Passkey) {
  37. Tracker::update_tracker('update_user', array('passkey' => $Passkey, 'can_leech' => '1'));
  38. }
  39. // Take users off ratio watch
  40. $UserQuery = $DB->query("
  41. SELECT m.ID, torrent_pass
  42. FROM users_info AS i
  43. JOIN users_main AS m ON m.ID = i.UserID
  44. WHERE m.Uploaded / m.Downloaded >= m.RequiredRatio
  45. AND i.RatioWatchEnds IS NOT NULL
  46. AND m.Enabled = '1'");
  47. $OffRatioWatch = $DB->collect('ID');
  48. if (count($OffRatioWatch) > 0) {
  49. $DB->query("
  50. UPDATE users_info AS ui
  51. JOIN users_main AS um ON um.ID = ui.UserID
  52. SET ui.RatioWatchEnds = NULL,
  53. ui.RatioWatchDownload = '0',
  54. um.can_leech = '1'
  55. WHERE ui.UserID IN(".implode(',', $OffRatioWatch).')');
  56. }
  57. foreach ($OffRatioWatch as $UserID) {
  58. $Cache->begin_transaction("user_info_heavy_$UserID");
  59. $Cache->update_row(false, array('RatioWatchEnds' => NULL, 'RatioWatchDownload' => '0', 'CanLeech' => 1));
  60. $Cache->commit_transaction(0);
  61. Misc::send_pm($UserID, 0, "You have been taken off Ratio Watch", "Congratulations! Feel free to begin downloading again.\n To ensure that you do not get put on ratio watch again, please read the rules located [url=".site_url()."rules.php?p=ratio]here[/url].\n");
  62. echo "Ratio watch off: $UserID\n";
  63. }
  64. $DB->set_query_id($UserQuery);
  65. $Passkeys = $DB->collect('torrent_pass');
  66. foreach ($Passkeys as $Passkey) {
  67. Tracker::update_tracker('update_user', array('passkey' => $Passkey, 'can_leech' => '1'));
  68. }
  69. // Put user on ratio watch if he doesn't meet the standards
  70. sleep(10);
  71. $DB->query("
  72. SELECT m.ID, m.Downloaded
  73. FROM users_info AS i
  74. JOIN users_main AS m ON m.ID = i.UserID
  75. WHERE m.Uploaded / m.Downloaded < m.RequiredRatio
  76. AND i.RatioWatchEnds IS NULL
  77. AND m.Enabled = '1'
  78. AND m.can_leech = '1'");
  79. $OnRatioWatch = $DB->collect('ID');
  80. $WatchList = array();
  81. foreach ($OnRatioWatch as $UserID) {
  82. if (!Permissions::get_permissions_for_user($UserID)['site_ratio_watch_immunity'])
  83. $WatchList[] = $UserID;
  84. }
  85. if (!empty($WatchList)) {
  86. $DB->query("
  87. UPDATE users_info AS i
  88. JOIN users_main AS m ON m.ID = i.UserID
  89. SET i.RatioWatchEnds = '".time_plus(60 * 60 * 24 * 14)."',
  90. i.RatioWatchTimes = i.RatioWatchTimes + 1,
  91. i.RatioWatchDownload = m.Downloaded
  92. WHERE m.ID IN(".implode(',', $WatchList).')');
  93. }
  94. foreach ($WatchList as $UserID) {
  95. $Cache->begin_transaction("user_info_heavy_$UserID");
  96. $Cache->update_row(false, array('RatioWatchEnds' => time_plus(60 * 60 * 24 * 14), 'RatioWatchDownload' => 0));
  97. $Cache->commit_transaction(0);
  98. Misc::send_pm($UserID, 0, 'You have been put on Ratio Watch', "This happens when your ratio falls below the requirements we have outlined in the rules located [url=".site_url()."rules.php?p=ratio]here[/url].\n For information about ratio watch, click the link above.");
  99. echo "Ratio watch on: $UserID\n";
  100. }
  101. //------------- Disable downloading ability of users on ratio watch
  102. $UserQuery = $DB->query("
  103. SELECT ID, torrent_pass
  104. FROM users_info AS i
  105. JOIN users_main AS m ON m.ID = i.UserID
  106. WHERE i.RatioWatchEnds IS NOT NULL
  107. AND i.RatioWatchEnds < '$sqltime'
  108. AND m.Enabled = '1'
  109. AND m.can_leech != '0'");
  110. $UserIDs = $DB->collect('ID');
  111. if (count($UserIDs) > 0) {
  112. $DB->query("
  113. UPDATE users_info AS i
  114. JOIN users_main AS m ON m.ID = i.UserID
  115. SET m.can_leech = '0',
  116. i.AdminComment = CONCAT('$sqltime - Leeching ability disabled by ratio watch system - required ratio: ', m.RequiredRatio, '\n\n', i.AdminComment)
  117. WHERE m.ID IN(".implode(',', $UserIDs).')');
  118. $DB->query("
  119. DELETE FROM users_torrent_history
  120. WHERE UserID IN (".implode(',', $UserIDs).')');
  121. }
  122. foreach ($UserIDs as $UserID) {
  123. $Cache->begin_transaction("user_info_heavy_$UserID");
  124. $Cache->update_row(false, array('RatioWatchDownload' => 0, 'CanLeech' => 0));
  125. $Cache->commit_transaction(0);
  126. Misc::send_pm($UserID, 0, 'Your downloading privileges have been disabled', "As you did not raise your ratio in time, your downloading privileges have been revoked. You will not be able to download any torrents until your ratio is above your new required ratio.");
  127. echo "Ratio watch disabled: $UserID\n";
  128. }
  129. $DB->set_query_id($UserQuery);
  130. $Passkeys = $DB->collect('torrent_pass');
  131. foreach ($Passkeys as $Passkey) {
  132. Tracker::update_tracker('update_user', array('passkey' => $Passkey, 'can_leech' => '0'));
  133. }
  134. ?>