Advertisement
Guest User

test

a guest
May 30th, 2015
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. <?php
  2. //My login Script
  3. // mysql connection variables
  4. error_reporting(0);
  5. require_once('./class.rc4crypt.php');
  6. $host = 'localhost';
  7. $dbuser = 'root';
  8. $dbpass = 'root';
  9. $dbname = 'stickarena';
  10. $table = 'users';
  11. //
  12. // connect to db
  13. $db = @mysql_connect($host,$dbuser,$dbpass) or die("result=error");
  14. $db = mysql_select_db($dbname);
  15. if(!$db)
  16. {
  17. print "result=error";
  18. exit;
  19. }
  20.  
  21. // declare variables
  22. $username=sanitize($_POST['username']);
  23. $password=sanitize(md5($_POST['userpass']));
  24. $action=sanitize($_POST['action']);
  25. $usercol=sanitize($_POST['usercol']);
  26. $stats=$_POST['stats'];
  27.  
  28. if($action=="authenticate")
  29. {
  30. //
  31. // check table
  32. $query = mysql_query("SELECT * FROM $table WHERE USERname = '$username' AND USERpass = '$password'");
  33. $num = mysql_num_rows($query);
  34. if($num>0)
  35. {
  36. while ($row = mysql_fetch_array($query, MYSQL_BOTH)) {
  37. if($row["ban"] == 1)
  38. {
  39. echo "result=banned";
  40. exit;
  41. }
  42. printf("result=success&usercol=%s", colstring($row["red"]).colstring($row["green"]).colstring($row["blue"]));
  43. }
  44. } else {
  45. print "result=error";
  46. }
  47. }
  48.  
  49. if($action=="player_stats")
  50. {
  51. $query = mysql_query("SELECT * FROM users WHERE USERname = '$username'");
  52. while ($row = mysql_fetch_array($query, MYSQL_BOTH)) {
  53. printf ("rounds=%s&wins=%s&losses=%s&kills=%s&deaths=%s&user_level=%s&result=success", $row["rounds"], $row["wins"], $row["losses"], $row["kills"], $row["deaths"], $row["user_level"]);
  54. }
  55. }
  56.  
  57. if($action=="create")
  58. {
  59. if($usercol == "000000000")
  60. $usercol = "000000001";
  61.  
  62. $colour = str_split($usercol, 3);
  63. $querystring = sprintf("INSERT INTO `users` (USERname, USERpass, red, green, blue) VALUES('%s','%s','%s','%s','%s')", $username, $password, $colour[0], $colour[1], $colour[2]);
  64. $result = mysql_query($querystring);
  65.  
  66.  
  67. if (!$result) {
  68. $message = 'result=error';
  69. die($message);
  70. }
  71. echo "result=success";
  72. }
  73.  
  74. if($action=="start_round")
  75. {
  76. echo "result=success";
  77. }
  78.  
  79. if($action=="round_stats")
  80. {
  81. //$ = rc4Encrypt(hex2binary($stats), "8fJ3Ki8Fy6rX1l0J");
  82. $stats_decrypted = rc4crypt::decrypt("8fJ3Ki8Fy6rX1l0J", hex2binary($stats)); // Assuming the key is binary (what you typed)
  83. $kills = get_string_between($stats_decrypted, "KILLS=", "&DE");
  84. $deaths = sanitize(get_string_between($stats_decrypted, "DEATHS=", "&ROUNDSP"));
  85.  
  86. if($kills > 50)
  87. $kills = 0;
  88.  
  89. if($deaths < 0)
  90. $deaths = 0;
  91.  
  92. $kills = sanitize($kills);
  93. $deaths = sanitize($deaths);
  94.  
  95. $roundsplayed = sanitize(get_string_between($stats_decrypted, "PLAYED=", "&WIN"));
  96. $winner = get_string_between($stats_decrypted, "WINNER=", "X");
  97.  
  98. if($winner == "1")
  99. {
  100. $wins = "1";
  101. $losses = "0";
  102. } else if ($winner == "0")
  103. {
  104. $wins = "0";
  105. $losses = "1";
  106. }
  107.  
  108. $querystring = sprintf("UPDATE USERS set `kills` = `kills` + '%s', `deaths` = `deaths` + '%s', `rounds` = `rounds` + '%s', `wins` = `wins` + '%s', `losses` = `losses` + '%s' WHERE `USERname` = '%s' AND `USERpass` = '%s'", $kills, $deaths, $roundsplayed, $wins, $losses, $username, $password);
  109.  
  110. $result = mysql_query($querystring);
  111. if (!$result) {
  112. $message = 'result=error';
  113. die($message);
  114. }
  115. echo "result=success";
  116. }
  117.  
  118.  
  119. //------------------------------------------------------------------------------
  120. //Functions
  121. function colstring($col)
  122. {
  123. return str_pad($col, 3, "0", STR_PAD_LEFT);
  124. }
  125.  
  126. function cleanInput($input) {
  127.  
  128. $search = array(
  129. '@<script[^>]*?>.*?</script>@si', // Strip out javascript
  130. '@<[\/\!]*?[^<>]*?>@si', // Strip out HTML tags
  131. '@<style[^>]*?>.*?</style>@siU', // Strip style tags properly
  132. '@<![\s\S]*?--[ \t\n\r]*>@' // Strip multi-line comments
  133. );
  134.  
  135. $output = preg_replace($search, '', $input);
  136. return $output;
  137. }
  138.  
  139. function sanitize($input) {
  140. if (is_array($input)) {
  141. foreach($input as $var=>$val) {
  142. $output[$var] = sanitize($val);
  143. }
  144. }
  145. else {
  146. if (get_magic_quotes_gpc()) {
  147. $input = stripslashes($input);
  148. }
  149. $input = cleanInput($input);
  150. $output = mysql_real_escape_string($input);
  151. }
  152. return $output;
  153. }
  154.  
  155.  
  156.  
  157.  
  158. function get_string_between($string, $start, $end){
  159. $string = " ".$string;
  160. $ini = strpos($string,$start);
  161. if ($ini == 0) return "";
  162. $ini += strlen($start);
  163. $len = strpos($string,$end,$ini) - $ini;
  164. return substr($string,$ini,$len);
  165. }
  166.  
  167. function hex2binary($str) {
  168. $bin = "";
  169. $i = 0;
  170. do {
  171. $bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
  172. $i += 2;
  173. } while ($i < strlen($str));
  174. return $bin;
  175. }
  176.  
  177.  
  178. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement