BioTorrents.de’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.

freeleechpool.php 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. #declare(strict_types=1);
  3. # todo: Not working since 2020-04-24
  4. if (isset($_POST['donation'])) {
  5. $Donation = $_POST['donation'];
  6. if (!is_numeric($Donation) || $Donation < 1) {
  7. error('Invalid donation');
  8. }
  9. $UserID = $LoggedUser['ID'];
  10. $DB->prepared_query("
  11. SELECT BonusPoints
  12. FROM users_main
  13. WHERE ID = $UserID");
  14. if ($DB->has_results()) {
  15. list($Points) = $DB->next_record();
  16. if ($Points >= $Donation) {
  17. $PoolTipped = false;
  18. $DB->prepared_query("
  19. UPDATE users_main
  20. SET BonusPoints = BonusPoints - $Donation
  21. WHERE ID = $UserID");
  22. $DB->prepared_query("
  23. UPDATE misc
  24. SET First = First + $Donation
  25. WHERE Name = 'FreeleechPool'");
  26. $Cache->delete_value('user_info_heavy_'.$UserID);
  27. // Check to see if we're now over the target pool size
  28. $DB->prepared_query("
  29. SELECT First, Second
  30. FROM misc
  31. WHERE Name = 'FreeleechPool'");
  32. if ($DB->has_results()) {
  33. list($Pool, $Target) = $DB->next_record();
  34. if ($Pool > $Target) {
  35. $PoolTipped = true;
  36. $NumTorrents = rand(2, 6);
  37. $Torrents = [];
  38. for ($i = 0; $i < $NumTorrents; $i++) {
  39. $TorrentSize = intval($Pool * (($i===$NumTorrents-1)?1:(rand(10, 80)/100)) * 100000); # todo
  40. $DB->prepared_query("
  41. SELECT ID, Size
  42. FROM torrents
  43. WHERE Size < $TorrentSize
  44. AND Size > ($TorrentSize * 0.9)
  45. AND Seeders > 0
  46. AND FreeLeechType = '0'
  47. ORDER BY Seeders ASC, Size DESC
  48. LIMIT 1");
  49. if ($DB->has_results()) {
  50. list($TorrentID, $Size) = $DB->next_record();
  51. $DB->prepared_query("
  52. INSERT INTO shop_freeleeches
  53. (TorrentID, ExpiryTime)
  54. VALUES($TorrentID, NOW() + INTERVAL 2 DAY)");
  55. Torrents::freeleech_torrents($TorrentID, 1, 3);
  56. $Pool -= $TorrentSize/100000;
  57. } else {
  58. // Failed to find a torrent. Maybe try again with a new value, maybe move on
  59. if (rand(1, 5) > 1) {
  60. $i--;
  61. }
  62. }
  63. }
  64. $Target = rand(10000, 100000);
  65. $DB->prepared_query("
  66. UPDATE misc
  67. SET First = 0,
  68. Second = $Target
  69. WHERE Name = 'FreeleechPool'");
  70. }
  71. }
  72. $Cache->delete_value('shop_freeleech_list');
  73. } else {
  74. error("Not enough points to donate");
  75. }
  76. }
  77. View::show_header('Store'); ?>
  78. <div>
  79. <h2>Donation Successful</h2>
  80. <div class="box">
  81. <p>
  82. You donated
  83. <?=number_format($Donation)?>
  84. <?=BONUS_POINTS?>
  85. to the Freeleech Pool
  86. </p>
  87. <?php
  88. if ($PoolTipped) { ?>
  89. <p>
  90. Your donation triggered a freeleech!
  91. </p>
  92. <?php } ?>
  93. <p>
  94. <a href="/store.php">Back to Store</a>
  95. </p>
  96. </div>
  97. </div>
  98. <?php
  99. View::show_footer();
  100. } else {
  101. $DB->prepared_query("
  102. SELECT First
  103. FROM misc
  104. WHERE Name = 'FreeleechPool'");
  105. if ($DB->has_results()) {
  106. list($Pool) = $DB->next_record();
  107. } else {
  108. $Pool = 0;
  109. }
  110. View::show_header('Store'); ?>
  111. <div>
  112. <div class="box text-align: center;">
  113. <form action="store.php" method="POST">
  114. <input type="hidden" name="item" value="freeleechpool">
  115. <strong>
  116. There are currently
  117. <?=number_format($Pool)?>
  118. <?=BONUS_POINTS?>
  119. in the Freeleech Pool
  120. </strong>
  121. <br /><br />
  122. <input type="text" name="donation" value="">
  123. <input type="submit" value="Donate">
  124. </form>
  125. <p><a href="/store.php">Back to Store</a></p>
  126. </div>
  127. </div>
  128. <?php View::show_footer();
  129. }