Guest User

Untitled

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