get('/', 'index');
$r->post('/move', 'Explore\move');
$r->get('/spell/:id', 'healspells');
$r->get('/character', 'show_character_info');
$r->get('/character/:id', 'show_character_info');
$r->get('/showmap', 'show_map');
$r->form('/babblebox', 'babblebox');
$r->get('/babblebox/messages', 'babblebox_messages');
Towns\register_routes($r);
Fights\register_routes($r);
Users\register_routes($r);
Help\register_routes($r);
Forum\register_routes($r);
Install\register_routes($r);
Admin\register_routes($r);
/*
NINJA! 🥷
*/
$r->get('/ninja', function() {
exit('NINJA! 🥷');
});
// [code, handler, params, middleware]
$l = $r->lookup($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
if (is_int($l)) exit("Error: $l");
echo render_response($uri, $l['handler'](...$l['params'] ?? []));
exit;
/**
* Return a page for a couple generic actions.
*/
function index(): string
{
if (user()->currentaction === "In Town") {
$page = Towns\town();
} elseif (user()->currentaction === "Exploring") {
$page = Explore\explore();
} elseif (user()->currentaction === "Fighting") {
redirect('/fight');
}
return $page;
}
/**
* Show a character's info. Defaults to the currently logged in user.
*/
function show_character_info(int $id = 0): string
{
$user = $id !== 0 ? User::find($id) : user();
if ($user === false) exit('Failed to show info for user ID '.$id);
$level = db()->query("SELECT `{$user->charclass}_exp` FROM levels WHERE id=? LIMIT 1;", [$user->level + 1])->fetchArray(SQLITE3_ASSOC);
$spells = $user->spells();
$magic_list = 'None';
if (!empty($spells)) {
$magic_list = '';
foreach ($spells as $spell) $magic_list .= $spell['name'].'
';
}
$showchar = render('show_char', [
'char' => $user,
'level' => $level,
'magic_list' => $magic_list
]);
return render('layouts/minimal', ['content' => $showchar, 'title' => $user->username.' Information']);
}
/**
* Show the user their position on the current world map. Only works with a game size of 250 and the default towns 😅
*/
function show_map()
{
$pos = sprintf(
'