<?php
//really ugly script, feel free to release a better one :)
// be aware that we don't even test the password in this script
$host = "server.com";
$user = "root";
$passwd = "root";
$db = "otserv";
$lnk = mysql_connect("$host", "$user", "$passwd") or die ('ERROR MySql: ' . mysql_error());
mysql_select_db("$db", $lnk) or die ('ERROR MySql: ' . mysql_error());
$request_body = file_get_contents('php://input');
$result = json_decode($request_body, true);
$acc = $result["accountname"];
$password = $result["password"];
$dbResource = mysql_query("SELECT `id` FROM `accounts` WHERE `name` = '$acc' LIMIT 1;");
if(!$dbResource) {
die("failed to get account.");
}
$dbRet = mysql_fetch_array($dbResource);
$accId = $dbRet[0];
$dbResource = mysql_query("SELECT `name` FROM `players` WHERE `account_id` = '$accId';");
if(!$dbResource) {
die("failed to get charactters.");
}
$accArray = array();
while ($dbRet = mysql_fetch_array($dbResource, MYSQL_BOTH)) {
$dict = array("worldid" => 0, "name" => $dbRet["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" => "Server",
"externaladdress" => "149.56.98.00", // masked ;>
"externalport" => 7172,
"previewstate" => 1
);
$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
}
*/
?>