Dragon-Knight/src/bootstrap.php

66 lines
1.8 KiB
PHP
Raw Normal View History

<?php
require_once 'lib.php';
require_once 'router.php';
2024-12-17 22:10:49 -06:00
require_once 'auth.php';
require_once 'mail.php';
require_once 'render.php';
require_once 'actions/explore.php';
require_once 'actions/heal.php';
require_once 'actions/users.php';
require_once 'actions/help.php';
require_once 'actions/towns.php';
require_once 'actions/fight.php';
require_once 'actions/forum.php';
require_once 'actions/install.php';
require_once 'actions/admin.php';
2024-12-17 22:10:49 -06:00
require_once 'models/model.php';
require_once 'models/user.php';
env_load('../.env');
$uri = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
2024-12-15 22:02:49 -06:00
$GLOBALS['cache'] = [];
2024-12-17 22:10:49 -06:00
$GLOBALS['state'] = [];
if (!file_exists('../.installed') && $uri[0] !== 'install') {
redirect('/install');
} elseif (file_exists(('../.installed')) && $uri[0] === 'install') {
redirect('/');
} elseif (file_exists(('../.installed')) && $uri[0] !== 'install') {
$controlrow = get_control_row();
if (!$controlrow["gameopen"]) {
display("The game is currently closed for maintanence. Please check back later.", "Game Closed");
}
2024-12-17 22:10:49 -06:00
$auth = new Auth;
// Login (or verify) if not logged in.
2024-12-17 22:10:49 -06:00
if (user() === false) {
if (!in_array($uri[0], ['login', 'register', 'verify', 'lostpassword', 'help'])) {
redirect('/login');
}
} elseif ($auth->good()) {
// Block user if he/she has been banned.
2024-12-17 22:10:49 -06:00
if (user()->authlevel === 2) {
exit("Your account has been banned.");
}
// Force verify if the user isn't verified yet.
2024-12-17 22:10:49 -06:00
if ($controlrow['verifyemail'] && user()->verify !== 'g2g' && !in_array($uri[0], ['verify', 'logout'])) {
redirect('/verify');
}
// Ensure the user can't use the admin panel.
2024-12-17 22:10:49 -06:00
if (user()->authlevel !== 1 && $uri[0] === 'admin') {
redirect('/');
}
2024-12-19 08:46:47 -06:00
user()->update_online_time();
} else {
$auth->logout();
redirect('/login');
}
}