Advertisement
Guest User

Untitled

a guest
Feb 8th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. <?php
  2. date_default_timezone_set('America/Santiago');
  3. require_once 'engine/init.php';
  4. // Client 11 loginWebService
  5. if($_SERVER['HTTP_USER_AGENT'] == "Mozilla/5.0" && $config['TFSVersion'] === 'TFS_10') {
  6. function jsonError($message, $code = 3) {
  7. die(json_encode(array('errorCode' => $code, 'errorMessage' => $message)));
  8. }
  9. header("Content-Type: application/json");
  10. $input = file_get_contents("php://input");
  11. // Based on tests, input length should be at least 67+ chars.
  12. if (strlen($input) > 10) {
  13. /* {
  14. 'accountname' => 'username',
  15. 'password' => 'superpass',
  16. 'stayloggedin' => true,
  17. 'token' => '123123', (or not set)
  18. 'type' => 'login', (What other types do we have?)
  19. } */
  20. $jsonObject = json_decode($input);
  21. $result = json_decode($input, true);
  22. error_log( print_r($result, TRUE) );
  23. $username = sanitize($jsonObject->accountname);
  24. error_log("= user: " . $username);
  25. $password = SHA1($jsonObject->password);
  26. error_log("= pw: " . $password);
  27. $token = (isset($jsonObject->token)) ? sanitize($jsonObject->token) : false;
  28. if ($username === 'cast') {
  29. $casts = mysql_select_multi("SELECT `player_id`, `cast_version`, `cast_spectators`, `cast_password` FROM `players_online` WHERE `cast_on` = 1 LIMIT 256;");
  30. if ($casts === false) {
  31. jsonError('There are no live cast right now');
  32. }
  33. $passwd = $jsonObject->password;
  34. $available_casts = array();
  35. $i = 0;
  36. foreach ($casts as $cast) {
  37. if (empty($passwd) || $passwd === $cast['cast_password']) {
  38. $caster_data = mysql_select_single("SELECT `name`, `sex`, `world_id` FROM `players` WHERE `id` = ".$cast['player_id']." LIMIT 1;");
  39. if ($caster_data !== false) {
  40. $world = get_world_by_id($caster_data['world_id']);
  41. if ($world !== false) {
  42. $available_casts[] = array (
  43. 'world_id' => (int)$i,
  44. 'world_name' => $world['name'],
  45. 'world_ip' => $world['ip'],
  46. 'world_port' => (int)$world['cast_port'],
  47. 'caster_name' => $caster_data['name'],
  48. 'caster_ismale' => ($caster_data['sex'] === 1) ? true : false,
  49. 'caster_specs' => ($cast['cast_spectators'] < 10) ? '0'.$cast['cast_spectators'] : $cast['cast_spectators'],
  50. 'caster_version' => ((int)$cast['cast_version'] === 1100) ? "10" : "11"
  51. );
  52. $i++;
  53. }
  54. }
  55. }
  56. }
  57. if (empty($available_casts)) {
  58. jsonError('There is no live cast with this password');
  59. }
  60. $response = array(
  61. 'session' => array(
  62. 'fpstracking'=> false,
  63. 'isreturner' => true,
  64. 'returnernotification' => false,
  65. 'showrewardnews' => false,
  66. 'sessionkey' => $passwd,
  67. 'lastlogintime' => 0,
  68. 'ispremium' => false,
  69. 'premiumuntil' => 0,
  70. 'status' => 'active'
  71. ),
  72. 'playdata' => array(
  73. 'worlds' => array(
  74. ),
  75. 'characters' => array(
  76. )
  77. )
  78. );
  79. foreach ($available_casts as $cast) {
  80. $response['playdata']['worlds'][] = array(
  81. 'id' => $cast['world_id'],
  82. 'name' => $cast['caster_specs'].'/50 viewers, Client '.$cast['caster_version'].', '.$cast['world_name'],
  83. 'externaladdress' => $cast['world_ip'],
  84. 'externalport' => $cast['world_port'],
  85. 'previewstate' => 0,
  86. 'location' => 'ALL',
  87. 'anticheatprotection'=> false
  88. );
  89. $response['playdata']['characters'][] = array(
  90. 'worldid' => $cast['world_id'],
  91. 'name' => $cast['caster_name'],
  92. 'ismale' => $cast['caster_ismale'],
  93. 'tutorial' => false
  94. );
  95. }
  96. error_log("= SESSION KEY: " . $response['session']['sessionkey']);
  97. die(json_encode($response));
  98. }
  99.  
  100. $fields = '`id`, `premdays`, `secret`';
  101. if ($config['twoFactorAuthenticator']) $fields .= ', `secret`';
  102. $account = mysql_select_single("SELECT {$fields} FROM `accounts` WHERE `name`='{$username}' AND `password`='{$password}' LIMIT 1;");
  103. if ($account === false) {
  104. jsonError('Wrong username and/or password.');
  105. }
  106. if ($config['twoFactorAuthenticator'] === true && $account['secret'] !== null) {
  107. if ($token === false) {
  108. jsonError('Submit a valid two-factor authentication token.', 6);
  109. } else {
  110. require_once("engine/function/rfc6238.php");
  111. if (TokenAuth6238::verify($account['secret'], $token) !== true) {
  112. jsonError('Two-factor authentication failed, token is wrong.', 6);
  113. }
  114. }
  115. }
  116. $players = mysql_select_multi("SELECT `name`, `sex`, `world_id` FROM `players` WHERE `account_id`='".$account['id']."';");
  117. if ($players !== false) {
  118. $worlds = $config['worlds'];
  119. $sessionKey = $username."\n".$jsonObject->password."\n0\n0";
  120. if (strlen($account['secret']) > 5) $sessionKey = $username."\n".$jsonObject->password."\n".$token."\n".floor(time() / 30);
  121. $response = array(
  122. 'session' => array(
  123. 'fpstracking'=> false,
  124. 'isreturner' => true,
  125. 'returnernotification' => false,
  126. 'showrewardnews' => false,
  127. 'sessionkey' => $sessionKey,
  128. 'lastlogintime' => 0,
  129. 'ispremium' => ($account['premdays'] > 0) ? true : false,
  130. 'premiumuntil' => time() + ($account['premdays'] * 86400),
  131. 'status' => 'active'
  132. ),
  133. 'playdata' => array(
  134. 'worlds' => array(
  135. //array( 'world_id' => id, 'name' => 'asd', 'ip' => '127.0.0.1', 'port' => 7172, 'is_preview' = 0 ),
  136. ),
  137. 'characters' => array(
  138. //array( 'worldid' => ASD, 'name' => asd, 'ismale' => true, 'tutorial' => false ),
  139. )
  140. )
  141. );
  142. foreach ($worlds as $world) {
  143. $response['playdata']['worlds'][] = array(
  144. 'id' => $world['id'],
  145. 'name' => $world['name'],
  146. 'externaladdress' => $world['ip'],
  147. 'externalport' => $world['port'],
  148. 'previewstate' => $world['is_preview'],
  149. 'location' => 'ALL',
  150. 'anticheatprotection'=> false
  151. );
  152. }
  153. foreach ($players as $player) {
  154. $response['playdata']['characters'][] = array(
  155. 'worldid' => (int)$player['world_id'],
  156. 'name' => $player['name'],
  157. 'ismale' => ($player['sex'] === 1) ? true : false,
  158. 'tutorial' => false
  159. );
  160. }
  161. error_log("= SESSION KEY: " . $response['session']['sessionkey']);
  162. die(json_encode($response));
  163. } else {
  164. jsonError("Character list is empty.");
  165. }
  166. error_log("= SESSION KEY: " . $response['session']['sessionkey']);
  167. } else {
  168. jsonError("Unrecognized event.");
  169. }
  170. } // End client 11 loginWebService
  171. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement