DK2/public/index.php

99 lines
2.1 KiB
PHP
Raw Normal View History

2024-09-27 18:45:33 -05:00
<?php
/*
Setup
*/
2024-09-27 18:45:33 -05:00
define('SRC', __DIR__ . '/../src');
require_once SRC . '/bootstrap.php';
$r = [];
/*
Home
*/
2024-09-27 18:45:33 -05:00
router_get($r, '/', function () {
2024-10-03 12:36:49 -05:00
if (user()) must_have_character();
$GLOBALS['active_nav_tab'] = 'home';
echo render('layouts/basic', ['view' => 'pages/home']);
2024-09-27 18:45:33 -05:00
});
/*
Auth
*/
router_get($r, '/auth/register', 'auth_controller_register_get');
router_post($r, '/auth/register', 'auth_controller_register_post');
router_get($r, '/auth/login', 'auth_controller_login_get');
router_post($r, '/auth/login', 'auth_controller_login_post');
router_post($r, '/auth/logout', 'auth_controller_logout_post');
2024-09-27 18:45:33 -05:00
/*
Characters
*/
router_get($r, '/characters', 'char_controller_list_get');
router_post($r, '/characters', 'char_controller_list_post');
2024-10-03 12:02:32 -05:00
router_get($r, '/character/create-first', 'char_controller_create_first_get');
router_post($r, '/character/create', 'char_controller_create_post');
router_post($r, '/character/delete', 'char_controller_delete_post');
/*
World
*/
2024-10-10 19:14:14 -05:00
router_get($r, '/world', 'world_controller_get');
router_post($r, '/move', 'world_controller_move_post');
2024-10-16 22:55:47 -05:00
/*
Profile
*/
router_get($r, '/profile', 'profile_controller_get');
router_get($r, '/profile/:id', 'profile_controller_show_get');
2024-10-12 10:46:03 -05:00
/*
Settings
*/
router_get($r, '/settings', 'settings_controller_get');
/*
Auctions
*/
router_get($r, '/auctions', 'auctions_controller_get');
2024-10-23 17:39:48 -05:00
/*
Testing
*/
if (env('debug')) {
router_get($r, '/give_silver/:x', function (int $amt) {
auth_only_and_must_have_character();
wallet()->give(Currency::Silver, $amt);
redirect('/');
});
router_get($r, '/take_silver/:x', function (int $amt) {
auth_only_and_must_have_character();
wallet()->take(Currency::Silver, $amt);
redirect('/');
});
}
/*
Router
*/
2024-09-27 18:45:33 -05:00
// [code, handler, params]
stopwatch_start('router');
2024-09-27 18:45:33 -05:00
$l = router_lookup($r, $_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
stopwatch_stop('router');
stopwatch_start('handler');
2024-09-27 18:45:33 -05:00
if ($l['code'] !== 200) router_error($l['code']);
$l['handler'](...$l['params'] ?? []);
stopwatch_stop('handler');
/*
Cleanup
*/
2024-09-27 18:45:33 -05:00
clear_flashes();
/*
Stopwatch
*/
if (env('debug')) echo c_debug_stopwatch();