Dragon-Knight/public/index.php
Valithor Obsidion 4d5c345528 functions.php
2025-08-14 15:47:25 -04:00

61 lines
1.6 KiB
PHP

<?php
/*
* This file is a part of the Dragon-Knight project.
*
* Copyright (c) 2024-present Sharkk
*
* This file is subject to the MIT license that is bundled
* with this source code in the LICENSE.md file.
*/
namespace DragonKnight;
use DragonKnight\Actions\Fight;
use DragonKnight\Actions\Forum;
use DragonKnight\Actions\Help;
use DragonKnight\Actions\Install;
use DragonKnight\Actions\Towns;
use DragonKnight\Actions\Users;
use DragonKnight\Admin\Admin;
// Do an early return with babblebox data if that's what's being requested
if ($uri[0] === 'babblebox' && (isset($uri[1]) && $uri[1] === 'messages')) {
echo babblebox_messages();
exit;
}
$r = new Router;
$r->get('/', 'DragonKnight\index');
$r->post('/move', 'DragonKnight\Actions\Explore::move');
$r->get('/spell/:id', 'DragonKnight\Actions\Heal::healspells');
$r->get('/character', 'DragonKnight\show_character_info');
$r->get('/character/:id', 'DragonKnight\show_character_info');
$r->get('/showmap', 'DragonKnight\show_map');
$r->form('/babblebox', 'DragonKnight\babblebox');
$r->get('/babblebox/messages', 'DragonKnight\babblebox_messages');
Towns::register_routes($r);
Fight::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'] ?? []));