Advertisement
Guest User

forphp7

a guest
May 1st, 2016
723
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.53 KB | None | 0 0
  1. <?php
  2. //really ugly script, feel free to release a better one :)
  3. // be aware that we don't even test the password in this script
  4.  
  5. define( 'MYSQL_HOST', 'localhost' );
  6. define( 'MYSQL_USER', 'root' );
  7. define( 'MYSQL_PASSWORD', '' );
  8. define( 'MYSQL_DB_NAME', 'tfs' );
  9. try
  10. {
  11.     $SQL = new PDO( 'mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB_NAME, MYSQL_USER, MYSQL_PASSWORD );
  12. }
  13. catch ( PDOException $e )
  14. {
  15.     echo 'Erro ao conectar com o MySQL: ' . $e->getMessage();
  16. }
  17.  
  18. $request_body = file_get_contents('php://input');
  19. $result = json_decode($request_body, true);
  20.  
  21. $acc = $result["accountname"];
  22. $password = $result["password"];
  23.  
  24. if ($password === "") {
  25.     die("failed to get account");
  26. }
  27.  
  28. $pass = sha1($password);
  29.  
  30. $dbResource = $SQL->query("SELECT `id` FROM `accounts` WHERE `name` = '$acc' and `password` = '$pass' LIMIT 1;")->fetch();
  31.  
  32. if(!$dbResource) {
  33.     die("failed to get account.");
  34. }
  35.  
  36. $accId = $dbResource["id"];
  37.  
  38. $dbResource = $SQL->query("SELECT * FROM `players` WHERE `account_id` = '$accId';")->fetchAll();
  39. if(!$dbResource) {
  40.     die("failed to get charactters.");
  41. }
  42.  
  43. $accArray = array();
  44.  
  45. foreach ($dbResource as $i) {
  46.     $dict = array("worldid" => 0, "name" => $i["name"]);
  47.     $accArray[] = $dict;   
  48. }
  49. $data = array();
  50.  
  51. $session = array(
  52.     "sessionkey" => $acc . "\n" . $password,
  53.     "lastlogintime" => 1461290246,
  54.     "ispremium" => true,
  55.     "premiumuntil" => 1463788913,
  56.     "status" => "active"   
  57. );
  58.  
  59. $data["session"] = $session;
  60.  
  61. $playerData = array();
  62.  
  63. $world = array(
  64.     "id" => 0,
  65.     "name" => "servername",
  66.     "externaladdress" => "127.0.0.1",
  67.     "externalport" => 7172,
  68.     "previewstate" => 0
  69. );
  70.  
  71. $worlds = array($world);
  72. $playerData["worlds"] = $worlds;
  73. $playerData["characters"] = $accArray;
  74.  
  75.  
  76. $data["playdata"] = $playerData;
  77.  
  78. echo json_encode($data);
  79.  
  80.  
  81. //echo '{   "session": {     "sessionkey": "DhZUxAPjDFQqwCy65z2JQKB145750y",     "lastlogintime": 1461290246,     "ispremium": true,     "premiumuntil": 1463788913,     "status": "active"   },   "playdata": {     "worlds": [       {         "id": 0,         "name": "Amera",         "externaladdress": "127.0.0.1",         "externalport": 7172,         "previewstate": 0       },       {         "id": 1,         "name": "Chrona",         "externaladdress": "127.0.0.1",         "externalport": 7172,         "previewstate": 0       },       {         "id": 2,         "name": "Eldera",         "externaladdress": "127.0.0.1",         "externalport": 7172,         "previewstate": 0       }     ],     "characters": [       {         "worldid": 0,         "name": "Paladin"       },       {         "worldid": 1,         "name": "Sorcerer"       },       {         "worldid": 2,         "name": "Druid"       }     ]   },   "survey": {     "id": 759822,     "invitationtext": "Dear Tibian! A few days ago, you have received an email invitation to join the Beta phase of Tibia 11. We\'d love to hear about your experiences with client version 11.0 so please help us with your feedback by completing this survey.",     "invitationtoken": "9ILillainoj7CsWxxoCRgOqSnGtt3L",     "endtimestamp": 1461535200   } }';
  82.  
  83. /*
  84. example json
  85. {
  86.   "session": {
  87.     "sessionkey": "DhZUxAPjDFQqwCy65z2JQKB145750y",
  88.     "lastlogintime": 1461290246,
  89.     "ispremium": true,
  90.     "premiumuntil": 1463788913,
  91.     "status": "active"
  92.   },
  93.   "playdata": {
  94.     //an array/list of worlds and theirs data
  95.     "worlds": [
  96.       {
  97.         "id": 0,
  98.         "name": "Amera",
  99.         "externaladdress": "66.150.54.19",
  100.         "externalport": 7171,
  101.         "previewstate": 0
  102.       },
  103.       {
  104.         "id": 1,
  105.         "name": "Chrona",
  106.         "externaladdress": "193.200.156.112",
  107.         "externalport": 7171,
  108.         "previewstate": 0
  109.       },
  110.       {
  111.         "id": 2,
  112.         "name": "Eldera",
  113.         "externaladdress": "66.150.54.94",
  114.         "externalport": 7171,
  115.         "previewstate": 0
  116.       }
  117.     ],
  118.     "characters": [
  119.       {
  120.         "worldid": 0,
  121.         "name": "Paladin"
  122.       },
  123.       {
  124.         "worldid": 1,
  125.         "name": "Sorcerer"
  126.       },
  127.       {
  128.         "worldid": 2,
  129.         "name": "Druid"
  130.       }
  131.     ]
  132.   },
  133.   //i believe this can just be removed, not needed
  134.   "survey": {
  135.     "id": 759822,
  136.     "invitationtext": "Dear Tibian! A few days ago, you have received an email invitation to join the Beta phase of Tibia 11. We'd love to hear about your experiences with client version 11.0 so please help us with your feedback by completing this survey.",
  137.     "invitationtoken": "9ILillainoj7CsWxxoCRgOqSnGtt3L",
  138.     "endtimestamp": 1461535200
  139.   }
  140. }
  141. */
  142. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement