mirror of
https://github.com/Znote/ZnoteAAC.git
synced 2025-10-14 02:14:53 +02:00
Started with JSON API module system
This commit is contained in:
23
api/modules/highscores/topExperience.php
Normal file
23
api/modules/highscores/topExperience.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php require_once '../../module.php';
|
||||
|
||||
// Configure module version number
|
||||
$response['version']['module'] = 1;
|
||||
|
||||
// Fetch number of rows
|
||||
$rows = getValue($_GET['rows']);
|
||||
if (!$rows || $rows == 0) $rows = 10;
|
||||
else $rows = (int)$rows;
|
||||
|
||||
// Show which configuration is used
|
||||
$response['config']['rows'] = $rows;
|
||||
|
||||
// Fetch top 10 players
|
||||
$players = mysql_select_multi("SELECT `p`.`name`, `p`.`level`, `p`.`experience`, `p`.`vocation`, `p`.`lastlogin`, `z`.`created` FROM `players` AS `p` INNER JOIN `znote_players` AS `z` ON `p`.`id` = `z`.`player_id` WHERE `p`.`group_id`<'2' ORDER BY `p`.`experience` DESC LIMIT $rows;");
|
||||
for ($i = 0; $i < count($players); $i++) {
|
||||
$players[$i]['vocation_name'] = $config['vocations'][$players[$i]['vocation']];
|
||||
}
|
||||
$response['data']['players'] = $players;
|
||||
|
||||
|
||||
SendResponse($response);
|
||||
?>
|
44
api/modules/samples/blank.php
Normal file
44
api/modules/samples/blank.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php require_once '../../module.php';
|
||||
// Blank/empty module, nice code to start with when making custom stuff.
|
||||
|
||||
// Configure module version number
|
||||
$response['version']['module'] = 1;
|
||||
|
||||
/* Do PHP logic, you got access to:
|
||||
-Znote AAC sql functions:
|
||||
:mysql_select_single("QUERY");
|
||||
:mysql_select_multi("QUERY");
|
||||
:mysql_update("QUERY"), mysql_insert("QUERY"), mysql_delete("QUERY")
|
||||
|
||||
-Config values
|
||||
:etc $config['vocations']
|
||||
|
||||
-Cache system
|
||||
:Sample:
|
||||
$cache = new Cache('engine/cache/api/ApiModuleName');
|
||||
if ($cache->hasExpired()) {
|
||||
$players = mysql_select_multi("SELECT `name`, `level`, `experience` FROM `players` ORDER BY `experience` DESC LIMIT 5;");
|
||||
|
||||
$cache->setContent($players);
|
||||
$cache->save();
|
||||
} else {
|
||||
$players = $cache->load();
|
||||
}
|
||||
|
||||
-Functions found in general.php
|
||||
:When fetching GET or POST from parameters, ALWAYS use getValue($value)
|
||||
:Etc if you want to fetch character name from url, do it like this:
|
||||
$playername = getValue($_GET['name']);
|
||||
if ($playername !== false) {
|
||||
// $playername either contains player name, or false if failed to fetch name from GET.
|
||||
}
|
||||
:getValue is often used in 3 ways: Fetch GET and POST values, or sanitize/secure any value you wish.
|
||||
:Check ZnoteAAC\engine\function\general.php for full list of available functions.
|
||||
*/
|
||||
|
||||
// Save the results of previous logic to the response
|
||||
$response['data']['title'] = "The fabulous blank page!";
|
||||
|
||||
// Send the response through JSON API
|
||||
SendResponse($response);
|
||||
?>
|
15
api/modules/towns/getTownNames.php
Normal file
15
api/modules/towns/getTownNames.php
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php require_once '../../module.php';
|
||||
|
||||
// Configure module version number
|
||||
$response['version']['module'] = 1;
|
||||
|
||||
// Fetch towns
|
||||
$response['data']['towns'] = $config['towns'];
|
||||
|
||||
// Fetch towns available under character creation
|
||||
foreach ($config['available_towns'] as $id) {
|
||||
$response['data']['available'][$id] = $response['data']['towns'][$id];
|
||||
}
|
||||
|
||||
SendResponse($response);
|
||||
?>
|
Reference in New Issue
Block a user