Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!
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.
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'].
Edit: I'm a bit intrigued with the API myself, so I wrote a simple test module to fetch player name and level.
It looks like this:
Code:
<?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);
?>
Response:
Code:
// 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."}}
To parse the response back into an array in PHP you would use json_parse. For ajax you can set the dataType as json and it will return a JS object.
It could probably do with some toughening up to prevent excessive SQL load, perhaps cache players and check if the player has been loaded recently (is in cache) before running the query. Maybe someone will find it useful as an example.
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'].
You should not need to set up the session, have a look at api/api.php, it handles that. It also includes config.php, engine/function/users.php, general.php, database/connect.php. https://github.com/Znote/ZnoteAAC/blob/master/api/api.php#L9-L12
Just include module.php in your script and you should be good.
Code:
require_once '../../module.php';
I'm a bit curious as to why it doesn't just include init.php, as we loose out on the "spam protection" and user data. 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.
I will probably experiment with it a bit more later.
Alright, that helps me already I hope Znote will come back to developing this AAC. And improve some stuff! If i do something cool with API, i will post it here. Thank you
This is correct, I originally got the idea of creating a json api for the purpose of letting third party services access OT related data. For instance if otservlist wanted to fetch the highscores and show it on their site.
But then I got a bit over ambitious and wanted to make a single page application template with etc Angularjs. This requires that I make lots of modules for all kinds of ajax calls. I got off to a nice start preparing to create a player class but reality kicked in and well.. RIP spare time. I am still dreaming of completing it, but who knows if /& when I'll have time to do that.