Advertisement
Guest User

Untitled

a guest
Feb 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.60 KB | None | 0 0
  1. <?php
  2. /**
  3. * Created by Notepad++.
  4. * User: Malucooo - Erick Nunes
  5. * Remaked of login.php by JLCVP and parts of login.php by Monteiro. Thanks for both!
  6. * Date: 18/09/17
  7. * Time: 03:01
  8. */
  9.  
  10. require 'config/config.php';
  11.  
  12. // comment to show E_NOTICE [undefinied variable etc.], comment if you want make script and see all errors
  13. error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE);
  14.  
  15. // true = show sent queries and SQL queries status/status code/error message
  16. define('DEBUG_DATABASE', false);
  17.  
  18. define('INITIALIZED', true);
  19.  
  20. if (!defined('ONLY_PAGE'))
  21. define('ONLY_PAGE', true);
  22.  
  23. // check if site is disabled/requires installation
  24. include_once('./system/load.loadCheck.php');
  25.  
  26. // fix user data, load config, enable class auto loader
  27. include_once('./system/load.init.php');
  28.  
  29. // DATABASE
  30. include_once('./system/load.database.php');
  31. if (DEBUG_DATABASE)
  32. Website::getDBHandle()->setPrintQueries(true);
  33. // DATABASE END
  34.  
  35. /*error example:
  36. {
  37. "errorCode":3,
  38. "errorMessage":"Account name or password is not correct."
  39. }*/
  40.  
  41. # Declare variables with array structure
  42. $characters = array();
  43. $playerData = array();
  44. $data = array();
  45. $isCasting = false;
  46.  
  47. # error function
  48. function sendError($msg){
  49. $ret = array();
  50. $ret["errorCode"] = 3;
  51. $ret["errorMessage"] = $msg;
  52.  
  53. die(json_encode($ret));
  54. }
  55.  
  56. # getting infos
  57. $request = file_get_contents('php://input');
  58. $result = json_decode($request, true);
  59.  
  60. # account infos
  61. $accountName = $result["accountname"];
  62. $password = $result["password"];
  63.  
  64. # game port
  65. $port = 7172;
  66.  
  67. # check if player wanna see cast list
  68. if (strtolower($accountName) == "cast")
  69. $isCasting = true;
  70.  
  71. if ($isCasting) {
  72. $casts = $SQL->query("SELECT `player_id` FROM `live_casts`")->fetchAll();
  73. if (count($casts[0]) == 0)
  74. sendError("There is no live casts right now!");
  75. foreach($casts as $cast) {
  76. $character = new Player();
  77. $character->load($cast['player_id']);
  78.  
  79. if ($character->isLoaded()) {
  80. $char = array("worldid" => 0, "name" => $character->getName(), "ismale" => (($character->getSex() == 1) ? true : false), "tutorial" => false);
  81. $characters[] = $char;
  82. }
  83. }
  84.  
  85. $port = 7173;
  86. $lastLogin = 0;
  87. } else {
  88. $account = new Account();
  89. $account->find($accountName);
  90.  
  91. if (!$account->isLoaded())
  92. sendError("Failed to get account. Try again!");
  93.  
  94. if ($account->getPassword() != Website::encryptPassword($password))
  95. sendError("The password for this account is wrong. Try again!");
  96.  
  97. foreach($account->getPlayersList() as $character) {
  98. $char = array("worldid" => 0, "name" => $character->getName(), "ismale" => (($character->getSex() == 1) ? true : false), "tutorial" => false);
  99. $characters[] = $char;
  100. }
  101.  
  102. $lastLogin = $account->getLastLogin();
  103. }
  104.  
  105. $session = array(
  106. "sessionkey" => $accountName . "\n" . $password,
  107. "lastlogintime" => $lastLogin,
  108. "ispremium" => true,
  109. "premiumuntil" => 0,
  110. "status" => "active"
  111. );
  112.  
  113. $world = array(
  114. "id" => 0,
  115. "name" => $config['server']['serverName'],
  116. "externaladdress" => gethostbyname($config['server']['ip']),
  117. "externalport" => $port,
  118. "previewstate" => 0,
  119. "location" => "BRA",
  120. "externaladdressunprotected" => gethostbyname($config["server"]["ip"]),
  121. "externaladdressprotected" => gethostbyname($config["server"]["ip"])
  122. );
  123.  
  124. $worlds = array($world);
  125.  
  126. $data["session"] = $session;
  127. $playerData["worlds"] = $worlds;
  128. $playerData["characters"] = $characters;
  129. $data["playdata"] = $playerData;
  130.  
  131. echo json_encode($data);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement