Guest User

Untitled

a guest
Oct 28th, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. <?php
  2. require('../config.php');
  3. $mode = $_GET['mode'];
  4. if($mode == 'verify') {
  5. // Verify mode variables
  6. $api = mysql_real_escape_string($_GET['key']);
  7. $email = mysql_real_escape_string($_GET['email']);
  8. $userpass = mysql_real_escape_string($_GET['pass']); // The password is already in MD5
  9. // MySQL query to look for the apikey
  10. $q = 'SELECT * FROM `games` WHERE `apikey`=\''.$api.'\'';
  11. $res = mysql_query($q) or die(mysql_error());
  12. $resc = mysql_num_rows($res);
  13. if($resc == 1) {
  14. $game = mysql_fetch_array($res);
  15. // Found the what game it is. Let's verify the user's password.
  16. $q = "SELECT * FROM `users` WHERE `email`='".$email."' AND `password`='".$userpass."'";
  17. $res = mysql_query($q) or die(mysql_error());
  18. $resc = mysql_num_rows($res);
  19. if($resc == 1) {
  20. // Verified the user's password. Now to check if the user bought the application.
  21. $user = mysql_fetch_array($res);
  22. $games = explode(',', $user['gameid']);
  23. $v = 0;
  24. foreach($games as $g) {
  25. if($g == $game['gameid']) {
  26. // The user bought the application, let's output the XML code
  27. $xml = new SimpleXMLElement('<info></info>');
  28. $xml->addChild('mode', 'verify');
  29. $xml->addChild('API_key', $api);
  30. $xml->addChild('secret_key', $game['secretkey']);
  31. $xml->addChild('user_firstname', $user['firstname']);
  32. $xml->addChild('user_lastname', $user['lastname']);
  33. $xml->addChild('status', 'verified');
  34. $v = 1;
  35. }
  36. // End foreach loop
  37. }
  38. if($v == 0) {
  39. // The user hasn't bought the game.
  40. $xml = new SimpleXMLElement('<info></info>');
  41. $xml->addChild('mode', 'verify');
  42. $xml->addChild('API_key', $api);
  43. $xml->addChild('secret_key', $game['secretkey']);
  44. $xml->addChild('user_firstname', $user['firstname']);
  45. $xml->addChild('user_lastname', $user['lastname']);
  46. $xml->addChild('status', 'error 1');
  47. $xml->addChild('error', 'The user hasn\'t bought the application.');
  48. }
  49. } else {
  50. // The user's data doesn't match up.
  51. $xml = new SimpleXMLElement('<info></info>');
  52. $xml->addChild('mode', 'verify');
  53. $xml->addChild('API_key', $api);
  54. $xml->addChild('secret_key', $game['secretkey']);
  55. $xml->addChild('status', 'error 2');
  56. $xml->addChild('error', 'The user\'s data doesn\'t match up.');
  57. }
  58. } else {
  59. // No application with that API key found.
  60. $xml = new SimpleXMLElement('<info></info>');
  61. $xml->addChild('mode', 'verify');
  62. $xml->addChild('status', 'error 3');
  63. $xml->addChild('error', 'No application with that API key found.');
  64. }
  65. // End verify if
  66. }
  67. if($mode == 'register') {
  68. // Register a bought app with ExiaApps
  69. $apikey = mysql_real_escape_string($_GET['key']);
  70. $userkey = mysql_real_escape_string($_GET['userkey']);
  71. $q = 'SELECT * FROM `games` WHERE `apikey`=\''.$apikey.'\'';
  72. $res = mysql_query($q) or die(mysql_error());
  73. $resc = mysql_num_rows($res);
  74. if($resc == 1) {
  75. $game = mysql_fetch_array($res);
  76. // The app exists and we have the variables, now to check if the user exists.
  77. $q = 'SELECT * FROM `users` WHERE `key`=\''.$userkey.'\'';
  78. $res = mysql_query($q) or die(mysql_error());
  79. $resc = mysql_num_rows($res);
  80. if($resc == 1) {
  81. $user = mysql_fetch_array($res);
  82. // The user exists and we have the variables, now to check if the user hasn't already bought the app.
  83. $games = explode(',', $user['gameid']);
  84. foreach($games as $g) {
  85. if($g == $game['gameid']) {
  86. // The user has already bought the game, abort.
  87. $xml = new SimpleXMLElement('<info></info>');
  88. $xml->addChild('api_key', $apikey);
  89. $xml->addChild('secret_key', $game['secretkey']);
  90. $xml->addChild('status', 'error 1');
  91. $xml->addChild('error', 'The user has already bought the application');
  92. header('Content-type: text/xml');
  93. echo $xml->asXML();
  94. die();
  95. }
  96. }
  97. // The user hasn't bought the app before, now to register the app.
  98. $games = $user['gameid'];
  99. if($games == '') {
  100. $g = $game['gameid'];
  101. } else {
  102. $g = $games + ',' + $game['gameid'];
  103. }
  104. $q = "UPDATE `users` SET `gameid`='".$g."' WHERE `id`=".$user['id'].";";
  105. mysql_query($q) or die(mysql_error());
  106. // The app has been registered as being bought by the user, now to output the success XML
  107. $xml = new SimpleXMLElement('<info></info>');
  108. $xml->addChild('api_key', $apikey);
  109. $xml->addChild('secret_key', $game['secretkey']);
  110. $xml->addChild('firstname', $user['firstname']);
  111. $xml->addChild('lastname', $user['lastname']);
  112. $xml->addChild('email', $user['email']);
  113. $xml->addChild('status', 'success');
  114. } else {
  115. // This application doesn't exist.
  116. $xml = new SimpleXMLElement('<info></info>');
  117. $xml->addChild('api_key', $apikey);
  118. $xml->addChild('secret_key', $game['secretkey']);
  119. $xml->addChild('status', 'error 2');
  120. $xml->addChild('error', 'The user doesn\'t exist');
  121. }
  122. } else {
  123. // This application doesn't exist.
  124. $xml = new SimpleXMLElement('<info></info>');
  125. $xml->addChild('api_key', $apikey);
  126. $xml->addChild('secret_key', $game['secretkey']);
  127. $xml->addChild('status', 'error 3');
  128. $xml->addChild('error', 'This application doesn\'t exist');
  129. }
  130. }
  131. header('Content-type: text/xml');
  132. echo $xml->asXML();
Add Comment
Please, Sign In to add comment