Advertisement
Guest User

Untitled

a guest
Oct 19th, 2016
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.36 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. $host = "localhost";
  5. $user = "root";
  6. $passwd = "";
  7. $db = "tfs10";
  8.  
  9. $lnk = mysql_connect("$host", "$user", "$passwd") or die ('ERROR MySql: ' . mysql_error());
  10. mysql_select_db("$db", $lnk) or die ('ERROR MySql: ' . mysql_error());    
  11.  
  12. $request_body = file_get_contents('php://input');
  13. $result = json_decode($request_body, true);
  14.  
  15. $acc = $result["accountname"];
  16. $password = $result["password"];
  17.  
  18. $dbResource = mysql_query("SELECT `id` FROM `accounts` WHERE `name` = '$acc' LIMIT 1;");
  19.  
  20. if(!$dbResource) {
  21.     die("failed to get account.");
  22. }
  23.  
  24. $dbRet = mysql_fetch_array($dbResource);
  25.  
  26. $accId = $dbRet[0];
  27.  
  28. $dbResource = mysql_query("SELECT `name` FROM `players` WHERE `account_id` = '$accId';");
  29. if(!$dbResource) {
  30.     die("failed to get charactters.");
  31. }
  32.  
  33. $accArray = array();
  34.  
  35. while ($dbRet = mysql_fetch_array($dbResource, MYSQL_BOTH)) {
  36.     $dict = array("worldid" => 0, "name" => $dbRet["name"]);
  37.     $accArray[] = $dict;
  38. }
  39.  
  40. $data = array();
  41.  
  42. $session = array(
  43.     "sessionkey" => $acc . "\n" . $password,
  44.     "lastlogintime" => 1461290246,
  45.     "ispremium" => true,
  46.     "premiumuntil" => 1463788913,
  47.     "status" => "active"   
  48. );
  49.  
  50. $data["session"] = $session;
  51.  
  52. $playerData = array();
  53.  
  54. $world = array(
  55.     "id" => 0,
  56.     "name" => "servername",
  57.     "externaladdress" => "localhost",
  58.     "externalport" => 7172,
  59.     "previewstate" => 0
  60. );
  61.  
  62. $worlds = array($world);
  63. $playerData["worlds"] = $worlds;
  64. $playerData["characters"] = $accArray;
  65.  
  66.  
  67. $data["playdata"] = $playerData;
  68.  
  69. echo json_encode($data);
  70.  
  71.  
  72. //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   } }';
  73.  
  74. /*
  75. example json
  76. {
  77.   "session": {
  78.     "sessionkey": "DhZUxAPjDFQqwCy65z2JQKB145750y",
  79.     "lastlogintime": 1461290246,
  80.     "ispremium": true,
  81.     "premiumuntil": 1463788913,
  82.     "status": "active"
  83.   },
  84.   "playdata": {
  85.     //an array/list of worlds and theirs data
  86.     "worlds": [
  87.       {
  88.         "id": 0,
  89.         "name": "Amera",
  90.         "externaladdress": "66.150.54.19",
  91.         "externalport": 7171,
  92.         "previewstate": 0
  93.       },
  94.       {
  95.         "id": 1,
  96.         "name": "Chrona",
  97.         "externaladdress": "193.200.156.112",
  98.         "externalport": 7171,
  99.         "previewstate": 0
  100.       },
  101.       {
  102.         "id": 2,
  103.         "name": "Eldera",
  104.         "externaladdress": "66.150.54.94",
  105.         "externalport": 7171,
  106.         "previewstate": 0
  107.       }
  108.     ],
  109.     "characters": [
  110.       {
  111.         "worldid": 0,
  112.         "name": "Paladin"
  113.       },
  114.       {
  115.         "worldid": 1,
  116.         "name": "Sorcerer"
  117.       },
  118.       {
  119.         "worldid": 2,
  120.         "name": "Druid"
  121.       }
  122.     ]
  123.   },
  124.   //i believe this can just be removed, not needed
  125.   "survey": {
  126.     "id": 759822,
  127.     "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.",
  128.     "invitationtoken": "9ILillainoj7CsWxxoCRgOqSnGtt3L",
  129.     "endtimestamp": 1461535200
  130.   }
  131. }
  132. */
  133. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement