Dragon-Knight/src/bootstrap.php

61 lines
1.6 KiB
PHP

<?php
require_once 'lib.php';
require_once 'router.php';
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';
require_once 'models/model.php';
require_once 'models/user.php';
env_load('../.env');
$uri = uri();
$GLOBALS['cache'] = [];
$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");
}
$auth = new Auth;
// Login (or verify) if not logged in.
if (user() === false) {
if (!in_array($uri[0], ['login', 'register', 'verify', 'lostpassword', 'help'])) {
redirect('/login');
}
} else {
// Block user if he/she has been banned.
if (user()->authlevel === 2) {
exit("Your account has been banned.");
}
// Force verify if the user isn't verified yet.
if ($controlrow['verifyemail'] && user()->verify !== 'g2g' && !in_array($uri[0], ['verify', 'logout'])) {
redirect('/verify');
}
// Ensure the user can't use the admin panel.
if (user()->authlevel !== 1 && $uri[0] === 'admin') {
redirect('/');
}
}
}