From 9ce0bab60651510dd3acb500f7effff613aab6fb Mon Sep 17 00:00:00 2001 From: Sky Johnson Date: Fri, 13 Dec 2024 15:52:37 -0600 Subject: [PATCH] Move install to new router model, fix bootstrap checks --- public/index.php | 46 ++--------------------------- {public => src/actions}/install.php | 31 ++++++++++--------- src/bootstrap.php | 45 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 58 deletions(-) rename {public => src/actions}/install.php (98%) create mode 100644 src/bootstrap.php diff --git a/public/index.php b/public/index.php index 8210b13..ec4a7a2 100644 --- a/public/index.php +++ b/public/index.php @@ -2,50 +2,7 @@ // index.php :: Primary program script, evil alien overlord, you decide. -require_once '../src/lib.php'; -require_once '../src/router.php'; -require_once '../src/explore.php'; -require_once '../src/heal.php'; -require_once '../src/actions/users.php'; -require_once '../src/actions/help.php'; -require_once '../src/actions/towns.php'; -require_once '../src/actions/fight.php'; -require_once '../src/actions/forum.php'; - -if (!file_exists('../.installed')) redirect('install.php'); - -$controlrow = get_control_row(); - -if (!$controlrow["gameopen"]) { - display("The game is currently closed for maintanence. Please check back later.", "Game Closed"); - exit; -} - -// Login (or verify) if not logged in. -if (($userrow = checkcookies()) === false) { - $uri = uri(); - if (!in_array($uri[0], ['login', 'register', 'verify', 'lostpassword', 'help'])) { - redirect('/login'); - } -} else { - // Block user if he/she has been banned. - if ($userrow["authlevel"] === 2) { - exit("Your account has been banned."); - } - - // Force verify if the user isn't verified yet. - if ($controlrow["verifyemail"] && (bool) $userrow["verify"] === false) { - redirect('/verify'); - header("Location: users.php?do=verify"); - exit; - } -} - -// Close game. -if (!$controlrow["gameopen"]) { - display("The game is currently closed for maintanence. Please check back later.", "Game Closed"); - exit; -} +require_once '../src/bootstrap.php'; $r = new Router; @@ -74,6 +31,7 @@ Fights\register_routes($r); Users\register_routes($r); Help\register_routes($r); Forum\register_routes($r); +Install\register_routes($r); $r->post('/move', 'move'); diff --git a/public/install.php b/src/actions/install.php similarity index 98% rename from public/install.php rename to src/actions/install.php index 8edaa69..d7e2bed 100644 --- a/public/install.php +++ b/src/actions/install.php @@ -1,17 +1,20 @@ second(), - 3 => third(), - 4 => fourth(), - 5 => fifth(), - default => first(), -}; +function register_routes(Router $r): Router +{ + if (!file_exists('../.installed')) { + $r->get('/install', 'Install\first'); + $r->get('/install/second', 'Install\second'); + $r->get('/install/third', 'Install\third'); + $r->post('/install/fourth', 'Install\fourth'); + $r->get('/install/fifth', 'Install\fifth'); + } + return $r; +} /** * First page - show warnings and gather info @@ -27,7 +30,7 @@ function first() Dragon Knight Installation: Page One

Installation for Dragon Knight is a simple two-step process: set up the database tables, then create the admin user. After that, you're done.

- + HTML; @@ -639,7 +642,7 @@ function second() echo $query === true ? 'Users table created.
' : 'Error creating Users table.'; $time = round((microtime(true) - START), 4); - echo "
Database setup complete in $time seconds.

Click here to continue with installation."; + echo "
Database setup complete in $time seconds.

Click here to continue with installation."; } /** @@ -655,7 +658,7 @@ function third() Dragon Knight Installation: Page Three

Now you must create an administrator account so you can use the control panel. Fill out the form below to create your account. You will be able to customize the class names through the control panel once your admin account is created.

-
+ @@ -711,7 +714,7 @@ function fourth() optional "call home" function in the installer, which notifies the author of your game installation. The ONLY information transmitted with this function is the URL to your game. This is included mainly to satisfy the author's curiosity about how many copies of the game are being installed and used. If you choose to submit your URL to the author, please - click here. + click here. HTML; diff --git a/src/bootstrap.php b/src/bootstrap.php new file mode 100644 index 0000000..d11fa0d --- /dev/null +++ b/src/bootstrap.php @@ -0,0 +1,45 @@ +
Username:


Password: