get('/', function() { global $userrow; if ($userrow["currentaction"] == "In Town") { $page = dotown(); $title = "In Town"; } elseif ($userrow["currentaction"] == "Exploring") { $page = doexplore(); $title = "Exploring"; } elseif ($userrow["currentaction"] == "Fighting") { redirect('/fight'); } display($page, $title); })->middleware('auth_only'); $r->get('/ninja', function() { exit('NINJA! 🥷'); }); 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); $r->post('/move', 'move'); $r->get('/spell/:id', 'healspells'); $r->get('/character', 'show_character_info'); $r->get('/character/:id', 'show_character_info'); $r->get('/showmap', 'showmap'); $r->form('/babblebox', 'babblebox'); // [code, handler, params, middleware] $l = $r->lookup($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']); if (is_int($l)) exit("Error: $l"); if (!empty($l['middleware'])) foreach ($l['middleware'] as $middleware) $middleware(); $l['handler'](...$l['params'] ?? []); function donothing() { global $userrow; if ($userrow["currentaction"] == "In Town") { $page = dotown(); $title = "In Town"; } elseif ($userrow["currentaction"] == "Exploring") { $page = doexplore(); $title = "Exploring"; } elseif ($userrow["currentaction"] == "Fighting") { redirect('/fight'); } display($page, $title); } /** * Spit out the main town page. */ function dotown() { global $userrow, $controlrow; $townrow = get_town_by_xy($userrow['longitude'], $userrow['latitude']); if ($townrow === false) display("There is an error with your user account, or with the town data. Please try again.","Error"); $townrow["news"] = ""; $townrow["whosonline"] = ""; $townrow["babblebox"] = ""; // News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe. if ($controlrow["shownews"] == 1) { $newsrow = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC); $townrow["news"] = '

'.$pos,
'title' => 'Map'
]);
}
/**
* Either render the latest 40 chats to the babblebox, or add a chat to it and redirect. This is used
* within an iframe.
*/
function babblebox()
{
global $userrow;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$safecontent = make_safe($_POST["babble"]);
if (!empty($safecontent)) {
db()->query('INSERT INTO babble (posttime, author, babble) VALUES (CURRENT_TIMESTAMP, ?, ?);',
[$userrow['username'], $safecontent]);
}
redirect('/babblebox');
}
$query = db()->query('SELECT * FROM babble ORDER BY id DESC LIMIT 40;');
echo render('babblebox', ['messages' => $query]);
}
/**
* NINJA! 🥷
*/
function ninja(): void
{
exit('NINJA! 🥷');
}