Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //really ugly script, feel free to release a better one :)
- // be aware that we don't even test the password in this script
- define( 'MYSQL_HOST', 'localhost' );
- define( 'MYSQL_USER', 'root' );
- define( 'MYSQL_PASSWORD', '' );
- define( 'MYSQL_DB_NAME', 'tfs' );
- try
- {
- $SQL = new PDO( 'mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB_NAME, MYSQL_USER, MYSQL_PASSWORD );
- }
- catch ( PDOException $e )
- {
- echo 'Erro ao conectar com o MySQL: ' . $e->getMessage();
- }
- $request_body = file_get_contents('php://input');
- $result = json_decode($request_body, true);
- $acc = $result["accountname"];
- $password = $result["password"];
- if ($password === "") {
- die("failed to get account");
- }
- $pass = sha1($password);
- $dbResource = $SQL->query("SELECT `id` FROM `accounts` WHERE `name` = '$acc' and `password` = '$pass' LIMIT 1;")->fetch();
- if(!$dbResource) {
- die("failed to get account.");
- }
- $accId = $dbResource["id"];
- $dbResource = $SQL->query("SELECT * FROM `players` WHERE `account_id` = '$accId';")->fetchAll();
- if(!$dbResource) {
- die("failed to get charactters.");
- }
- $accArray = array();
- foreach ($dbResource as $i) {
- $dict = array("worldid" => 0, "name" => $i["name"]);
- $accArray[] = $dict;
- }
- $data = array();
- $session = array(
- "sessionkey" => $acc . "\n" . $password,
- "lastlogintime" => 1461290246,
- "ispremium" => true,
- "premiumuntil" => 1463788913,
- "status" => "active"
- );
- $data["session"] = $session;
- $playerData = array();
- $world = array(
- "id" => 0,
- "name" => "servername",
- "externaladdress" => "127.0.0.1",
- "externalport" => 7172,
- "previewstate" => 0
- );
- $worlds = array($world);
- $playerData["worlds"] = $worlds;
- $playerData["characters"] = $accArray;
- $data["playdata"] = $playerData;
- echo json_encode($data);
- //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 } }';
- /*
- example json
- {
- "session": {
- "sessionkey": "DhZUxAPjDFQqwCy65z2JQKB145750y",
- "lastlogintime": 1461290246,
- "ispremium": true,
- "premiumuntil": 1463788913,
- "status": "active"
- },
- "playdata": {
- //an array/list of worlds and theirs data
- "worlds": [
- {
- "id": 0,
- "name": "Amera",
- "externaladdress": "66.150.54.19",
- "externalport": 7171,
- "previewstate": 0
- },
- {
- "id": 1,
- "name": "Chrona",
- "externaladdress": "193.200.156.112",
- "externalport": 7171,
- "previewstate": 0
- },
- {
- "id": 2,
- "name": "Eldera",
- "externaladdress": "66.150.54.94",
- "externalport": 7171,
- "previewstate": 0
- }
- ],
- "characters": [
- {
- "worldid": 0,
- "name": "Paladin"
- },
- {
- "worldid": 1,
- "name": "Sorcerer"
- },
- {
- "worldid": 2,
- "name": "Druid"
- }
- ]
- },
- //i believe this can just be removed, not needed
- "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
- }
- }
- */
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement