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.4KB

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