Contributing back some bug fixes
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.

bonus_points.php 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?
  2. //------------------------ Update Bonus Points -------------------------//
  3. function bytesToGiB($bytes) {
  4. if ($bytes > 1048576) {
  5. $GiB = $bytes / 1073741824;
  6. } else {
  7. $GiB = 0;
  8. }
  9. return $GiB;
  10. }
  11. function calculateBP() {
  12. global $DB;
  13. global $Cache;
  14. $getUsers = $DB->query("SELECT DISTINCT(uid) AS uid FROM xbt_files_users");
  15. if ($DB->has_results()) {
  16. $users = array();
  17. while ($result = $DB->next_record()) {
  18. $users[] = $result['uid'];
  19. }
  20. foreach($users as $UserID) {
  21. $DB->query("
  22. SELECT t.Size,
  23. t.Seeders,
  24. (us.SeedTime/60/60/24) AS days
  25. FROM xbt_files_users AS x
  26. LEFT JOIN torrents AS t ON t.ID=x.fid
  27. LEFT JOIN users_seedtime AS us ON x.fid=us.TorrentID AND x.uid=us.UserID
  28. WHERE x.uid = $UserID AND x.active=1 AND x.remaining=0
  29. GROUP BY x.fid, x.ip");
  30. $totalBP = 0;
  31. while ($torrent = $DB->next_record()) {
  32. $points = bytesToGiB($torrent['Size']) * ( 0.25 + ( 0.6 * log(1+$torrent['days']) / pow($torrent['Seeders'],0.6) ) );
  33. $totalBP = $totalBP + $points;
  34. }
  35. if ($totalBP > 0) {
  36. $DB->query("SELECT BonusPoints, BPDems FROM users_main WHERE ID=$UserID");
  37. list($BonusPoints, $BPDems) = $DB->next_record();
  38. $OldBP = (float) $BonusPoints.'.'.$BPDems;
  39. $NewBP = $OldBP + $totalBP;
  40. $NewDems = $NewBP - floor($NewBP);
  41. $NewBP = $NewBP - $NewDems;
  42. $NewDems = (int) substr($NewDems, 2);
  43. $DB->query("
  44. UPDATE users_main
  45. SET BonusPoints = $NewBP, BPDems = $NewDems
  46. WHERE ID=$UserID");
  47. }
  48. $Cache->delete_value('user_info_heavy_'.$UserID);
  49. }
  50. }
  51. }
  52. calculateBP();
  53. ?>