raf
Active Member
Could someone please point me the way, or just explain, how to use ZnoteAAC API ? I'm trying to get player information in json. But i have no idea how to correctly use that API.
$playername = getValue($_GET['name']);
if ($playername !== false) {
$player = mysql_select_single("SELECT `name` FROM `players` WHERE `name`='$playername';");
$response['player']['name'] = $player;
}
<?php require_once '../../module.php';
// Configure module version number
$response['version']['module'] = 1;
$playername = getValue($_GET['name']);
$player = mysql_select_single("SELECT `name`, `level` FROM `players` WHERE `name` = '$playername';");
if ($player !== false) {
$response['data']['player'] = $player;
} else {
// If no player is found, we send an error message
$response['error']['message'] = 'Could not find a player with that name.';
}
// Send the response through JSON API
SendResponse($response);
?>
// Player exixsts
{"version":{"znote":"1.5_SVN","ot":"TFS_10","module":1},"data":{"player":{"name":"Forgee","level":"8"}}}
// Player doesn't exixst
{"version":{"znote":"1.5_SVN","ot":"TFS_10","module":1},"error":{"message":"Could not find a player with that name."}}
Yes i did. I think it's outdated or not 100% working API, because there is player class to fetch info about players, but it doesn't seem to work.Are you sending the response (SendResponse($response))? The return of mysql_select_single is an array, even if you only fetch one field. The player name is in $player['name'].
<?php
require_once 'engine/init.php';
protect_page();
admin_only($user_data);
session_start();
ob_start();
$sessionPrefix = $config['session_prefix'];
if (isset($_SESSION['token'])) {
$_SESSION['old_token'] = $_SESSION['token'];
}
Token::generate();
function SendResponse($response) {
echo json_encode($response);
}
$playername = $_GET['name'];
$user_id = user_character_exist($playername);
if ($user_id !== false) {
$data = mysql_select_single("SELECT * FROM `players` WHERE `name` LIKE '$playername'");
$json['data']['player'] = $data;
$json['data']['player']['vocation'] = vocation_id_to_name($data['vocation']);
}
SendResponse($json);
?>
http://domain.name/api/modules/player/player.php?name=Raff
Yes I do.Do you call your module like this ?
Code:http://domain.name/api/modules/player/player.php?name=Raff
require_once '../../module.php';
I suppose the api is intended to be publicly accessible and he wanted to keep it as light as possible, but I don't know.