Advertisement
Guest User

Untitled

a guest
May 30th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. <?
  2.  
  3. //Mysql connect info
  4. $servername = "removed";
  5. $username = "removed";
  6. $password = "removed";
  7. $database = "removed";
  8.  
  9. $link = new mysqli($servername, $username, $password, $database);
  10. if ($link->connect_error)
  11. {
  12. die("Connection failed: " . $link->connect_error);
  13. }
  14.  
  15. //Get or send the information from/to the game
  16. $func = $_GET['func'];
  17. $hash = mysqli_real_escape_string($link, $_GET['user']);
  18. $bonus = mysqli_real_escape_string($link, $_GET['bonus']);
  19.  
  20. class CheckUser
  21. {
  22. function CheckBonus($hash)
  23. {
  24. global $link;
  25. global $hash;
  26. $query = "SELECT bonustier, resettime, userid FROM members WHERE userid = ?";
  27. if ($stmt = $link->prepare($query))
  28. {
  29. $stmt->bind_param('s', $userid);
  30. $stmt->execute();
  31.  
  32. if($stmt->num_rows != 0) {
  33. $stmt->store_result();
  34. $stmt->bind_result($bonustier, $resettime, $userid);
  35.  
  36. while($stmt->fetch())
  37. {
  38. //Check if enough time has passed since last login bonus
  39. $time = time();
  40. $time2 = ((($time - $resettime) / 60) / 60);
  41. $time3 = substr($time2, 0, strpos($time2, "."));
  42.  
  43. if($time3 >= 24)
  44. {
  45. $connection = 1;
  46. $usergood = 1;
  47. $loginbonus = 1;
  48. $hoursince = $time3;
  49.  
  50. $bonusarray = array(
  51. 'BonusCheck' => array(
  52. 'connection' => $connection,
  53. 'usergood' => $usergood,
  54. 'loginbonus' => $loginbonus,
  55. 'bonustier' => $bonustier,
  56. 'hoursince' => $time3
  57. ),
  58. );
  59.  
  60. $bonusjson = json_encode($bonusarray, 128);
  61. echo $bonusjson;
  62. }
  63. else //If enough time has not passed, tell the game.
  64. {
  65. $connection = 1;
  66. $usergood = 1;
  67. $loginbonus = 0;
  68. $hoursince = $time3;
  69.  
  70. $bonusarray = array(
  71. 'BonusCheck' => array(
  72. 'connection' => $connection,
  73. 'usergood' => $usergood,
  74. 'loginbonus' => $loginbonus,
  75. 'bonustier' => $bonustier,
  76. 'hoursince' => $time3
  77. ),
  78. );
  79.  
  80. $bonusjson = json_encode($bonusarray, 128);
  81. echo $bonusjson;
  82. }
  83. }
  84. }
  85. else
  86. {
  87. $this->AddUser($hash);
  88. }
  89.  
  90. }
  91. $stmt->close();
  92. }
  93.  
  94. function UpdateBonus($hash, $bonus)
  95. {
  96. global $link;
  97. global $hash;
  98. global $bonus;
  99. if($stmt = $link->prepare("UPDATE members SET loginbonus = ?, bonustier = ?, resettime = ? WHERE userid=?"))
  100. {
  101. $stmt->bind_param('ssss', $loginbonus, $bonustier, $resettime, $hash);
  102.  
  103. switch($bonus)
  104. {
  105. case 0:
  106. $bonustier = 1;
  107. break;
  108. case 1:
  109. $bonustier = 2;
  110. break;
  111. case 2:
  112. $bonustier = 3;
  113. break;
  114. case 3:
  115. $bonustier = 4;
  116. break;
  117. case 4:
  118. $bonustier = 5;
  119. break;
  120. case 5:
  121. $bonustier = 0;
  122. break;
  123. }
  124.  
  125. $loginbonus = 0;
  126. $resettime = time();
  127. $success = '1';
  128.  
  129. $updatearray = array(
  130. 'UpdateBonus' => array(
  131. 'login' => $loginbonus,
  132. 'result' => $success
  133. ),
  134. );
  135.  
  136. $updatejson = json_encode($updatearray, 128);
  137. echo $updatejson;
  138.  
  139. $stmt->execute();
  140. $stmt->close();
  141. }
  142. }
  143.  
  144. function AddUser($hash)
  145. {
  146. global $link;
  147. global $hash;
  148. if($stmt = $link->prepare("INSERT INTO members (userid, loginbonus, bonustier, resettime) VALUES (?, ?, ?, ?)"))
  149. {
  150. $stmt->bind_param('ssss', $userid, $loginbonus, $bonustier, $resettime);
  151.  
  152. $userid = $hash;
  153. $loginbonus = 1;
  154. $bonustier = 1;
  155. $resettime = time();
  156.  
  157. $stmt->execute();
  158. $stmt->close();
  159.  
  160. $this->CheckBonus($hash);
  161. }
  162. }
  163.  
  164. function CheckFunc($func)
  165. {
  166. switch($func)
  167. {
  168. case cb:
  169. $this->CheckBonus($hash);
  170. break;
  171. case ub:
  172. $this->UpdateBonus($hash, $bonus);
  173. break;
  174. case au:
  175. $this->AddUser($hash);
  176. break;
  177. default:
  178. echo 'Function not found.';
  179. break;
  180. }
  181. }
  182. }
  183.  
  184. $newObject = new CheckUser();
  185. $newObject->CheckFunc($func);
  186.  
  187. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement