Guest User

Untitled

a guest
Jun 30th, 2018
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.48 KB | None | 0 0
  1. <?php
  2.  
  3. class main {
  4.  
  5. public $connection;
  6.  
  7. /**
  8. * Opens a connection to the DB
  9. */
  10.  
  11. public function __construct() {
  12. $this->connection = mysql_connect(localhost, trama_vote, hudecki123) or die(mysql_connect_error());
  13. mysql_select_db(trama_vote,$this->connection);
  14. //echo("Connected");
  15. }
  16.  
  17. /**
  18. * Clsoes the connection to the DB
  19. */
  20.  
  21. public function __destruct() {
  22. mysql_close($this->connection);
  23. }
  24.  
  25. /**
  26. *
  27. * @return time user voted if note it returns -1
  28. */
  29.  
  30. public function hasVoted() {
  31. $ip = gethostbyname($_SERVER['REMOTE_ADDR']);
  32. $query = "SELECT UNIX_TIMESTAMP(time) as time FROM `votes` WHERE UNIX_TIMESTAMP(NOW()) < UNIX_TIMESTAMP(time)+86000 AND `ip` LIKE '$ip'";
  33. $result = mysql_query($query);
  34. if (mysql_num_rows($result) > 0) {
  35. $result = mysql_fetch_assoc($result);
  36. return $result["time"];
  37. } else {
  38. return -1;
  39. }
  40. }
  41.  
  42. /**
  43. * checks if runetoplist has calledback saying the user has voted
  44. * @returns true if the user can continue
  45. * @returns false if the user hasnt voted
  46. */
  47.  
  48. public function canFindTempId($callback_id) {
  49. $callback_id = mysql_real_escape_string($callback_id);
  50. $query = mysql_query("SELECT null FROM `verifying_votes` WHERE callbackid='".$callback_id."'");
  51. if (mysql_num_rows($query) > 0) {
  52. return true;
  53. } else {
  54. return false;
  55. }
  56. }
  57.  
  58. /**
  59. *
  60. * @return type true if ports 80, 8080 or 3128 are open
  61. */
  62.  
  63. public function isCheating() {
  64. if(@fsockopen($_SERVER['REMOTE_ADDR'], 80, $errno, $errstr, 1) ||
  65. @fsockopen($_SERVER['REMOTE_ADDR'], 8080, $errno, $errstr, 1) ||
  66. @fsockopen($_SERVER['REMOTE_ADDR'], 3128, $errno, $errstr, 1)) {
  67. return true;
  68. } else {
  69. return false;
  70. }
  71. }
  72.  
  73. /**
  74. * gets the top 10 people who have voted the most
  75. * @returns a stack of data
  76. */
  77.  
  78. public function getTop10Voters() {
  79. $query = mysql_query("SELECT `username` , COUNT( `username` ) AS times FROM `items` GROUP BY `username` LIMIT 10");
  80. if (mysql_num_rows($query) > 0) {
  81. $stack = array();
  82. while ($result = mysql_fetch_assoc($query)){
  83. array_push($stack, $result["username"], $result["times"]);
  84. }
  85.  
  86. return $stack;
  87. } else {
  88. return null;
  89. }
  90. }
  91.  
  92. /**
  93. * gets the amount of votes inbetween two time sets
  94. * @returns the amount of votes
  95. * @param1 start of the time set (unix time)
  96. * @param2 end of time set (unix time)
  97. */
  98.  
  99. public function getTotalVotes($start, $end) {
  100. $start = mysql_real_escape_string($start);
  101. $end = mysql_real_escape_string($end);
  102. $query = mysql_query("SELECT COUNT(*) AS votes FROM `votes` WHERE UNIX_TIMESTAMP(time) >=$start AND UNIX_TIMESTAMP(time) < $end");
  103. $result = mysql_fetch_assoc($query);
  104.  
  105. return $result['votes'];
  106. }
  107.  
  108. /**
  109. * gets the most popular vote rewards
  110. * @returns stack of data
  111. */
  112.  
  113. public function getPopularRewards() {
  114. $query = mysql_query("SELECT `item_id` , COUNT( `item_id` ) AS times FROM `items` GROUP BY `item_id`");
  115. $stack = array();
  116. while ($result = mysql_fetch_assoc($query)){
  117. array_push($stack, $result["item_id"], $result["times"]);
  118. }
  119.  
  120. return $stack;
  121. }
  122.  
  123. /**
  124. * deletes the temp id called back from RuneTopList
  125. * @returns amount of rows effected
  126. */
  127.  
  128. public function deleteTempID($callback_id) {
  129. $callback_id = mysql_real_escape_string($callback_id);
  130. $query = mysql_query("DELETE FROM `verifying_votes` WHERE callbackid='".$callback_id."'");
  131. return mysql_affected_rows();
  132. }
  133.  
  134. /**
  135. * adds the temp id to the database
  136. * @returns amount of rows effected
  137. */
  138.  
  139. public function addTempID($callback_id) {
  140. $callback_id = mysql_real_escape_string($callback_id);
  141. $query = mysql_query("INSERT INTO `verifying_votes` (callbackid) VALUES ('$callback_id')");
  142. return true;
  143. }
  144.  
  145. /**
  146. * adds item to the datebase to be checked/claimed/rewarded
  147. * @returns success
  148. */
  149.  
  150. public function addReward($reward, $username, $voterewards) {
  151. $reward = $this->getItemId(mysql_real_escape_string($reward), $voterewards);
  152. $username = mysql_real_escape_string($username);
  153. $amount = $this->getAmount($reward, $voterewards);
  154. $ip = gethostbyname($_SERVER['REMOTE_ADDR']);
  155. mysql_query("INSERT INTO `items` (`username`, `item_id`, `item_amount`) VALUES ('$username', '$reward', '$amount');");
  156. mysql_query("INSERT INTO `votes` (`ip`) VALUES ('$ip');");
  157. return true;
  158. }
  159.  
  160. public function getAmount($RewardId, $voterewards){
  161. for ($i = 0; $i < count($voterewards)/5; $i++) {
  162. if ($voterewards[($i*5+2)] == $RewardId) {
  163. return $voterewards[($i*5)+3];
  164. }
  165. }
  166. return 'item not found in array';
  167. }
  168.  
  169. public function getItemId($RewardId, $voterewards){
  170. for ($i = 0; $i < count($voterewards)/5; $i++) {
  171. if ($voterewards[($i*5)] == $RewardId) {
  172. return $voterewards[($i*5)+2];
  173. }
  174. }
  175. return 'item not found in array';
  176. }
  177.  
  178. function createRandomChars($length) {
  179. $chars = "abcdefghijkmnopqrstuvwxyz023456789";
  180. srand((double)microtime()*1000000);
  181. $i = 0;
  182. $pass = '' ;
  183. while ($i < $length) {
  184. $num = rand() % 33;
  185. $tmp = substr($chars, $num, 1);
  186. $pass = $pass . $tmp;
  187. $i++;
  188. }
  189. return $pass;
  190. }
  191. }
  192. ?>
Add Comment
Please, Sign In to add comment