Completely repair admin panel

This commit is contained in:
Sky Johnson 2024-12-12 18:36:30 -06:00
parent 7e9ce285e0
commit 9348c17179
9 changed files with 1134 additions and 1119 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2,10 +2,10 @@
// forum.php :: Internal forums script for the game.
if (!file_exists('../.installed')) redirect('install.php');
require_once '../src/lib.php';
if (!file_exists('../.installed')) redirect('install.php');
$controlrow = get_control_row();
// Login (or verify) if not logged in.

View File

@ -1,8 +1,9 @@
<?php
if (!file_exists('../.installed')) redirect('install.php');
require_once '../src/lib.php';
if (!file_exists('../.installed')) redirect('install.php');
$controlrow = get_control_row();
$page = $_GET['page'] ?? '';

View File

@ -2,10 +2,10 @@
// index.php :: Primary program script, evil alien overlord, you decide.
if (!file_exists('../.installed')) redirect('install.php');
require_once '../src/lib.php';
if (!file_exists('../.installed')) redirect('install.php');
$controlrow = get_control_row();
// Login (or verify) if not logged in.

View File

@ -1,12 +1,9 @@
<?php
if (file_exists('../.installed')) {
header('Location: index.php');
exit;
}
require_once '../src/lib.php';
if (file_exists('../.installed')) redirect('index.php');
$page = $_GET['page'] ?? 1;
match ((int) $page) {
2 => second(),
@ -29,17 +26,8 @@ function first()
<body>
<b>Dragon Knight Installation: Page One</b><br><br>
<b>NOTE:</b> Please ensure you have filled in the correct values in config.php before continuing. Installation will fail if these values are not correct. Also, the MySQL database needs to already exist. This installer script will take care of setting up its structure and content, but the database itself must already exist on your MySQL server before the installer will work.<br><br>
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.<br><br>
You have two options for database setup: complete or partial.
<ul>
<li><b>Complete Setup</b> includes table structure and all default data (items, drops, monsters, levels, spells, towns) - after complete setup, the game is totally ready to run.</li>
<li><b>Partial Setup</b> only creates the table structure, it does not populate the tables - use this if you are going to be creating and importing your own customized game data later.</li>
</ul>
Click the appropriate button below for your preferred installation method.<br><br>
<form action="install.php?page=2" method="post">
<input type="submit" name="complete" value="Complete Setup" /><br> - OR - <br><input type="submit" name="partial" value="Partial Setup" />
</form>
<a href="install.php?page=2"><button>Install</button></a>
</body>
</html>
HTML;
@ -52,8 +40,6 @@ function second()
{
echo "<html><head><title>Dragon Knight Installation</title></head><body><b>Dragon Knight Installation: Page Two</b><br><br>";
$full = isset($_POST["complete"]);
$query = db()->exec(<<<SQL
CREATE TABLE babble (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
@ -68,20 +54,14 @@ function second()
$query = db()->exec(<<<SQL
CREATE TABLE control (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`gamename` TEXT NOT NULL DEFAULT '',
`gamesize` INTEGER NOT NULL DEFAULT 0,
`gameopen` INTEGER NOT NULL DEFAULT 0,
`gamename` TEXT NOT NULL DEFAULT 'Dragon Knight',
`gamesize` INTEGER NOT NULL DEFAULT 250,
`gameopen` INTEGER NOT NULL DEFAULT 1,
`gameurl` TEXT NOT NULL DEFAULT '',
`adminemail` TEXT NOT NULL DEFAULT '',
`class1name` TEXT NOT NULL DEFAULT '',
`class2name` TEXT NOT NULL DEFAULT '',
`class3name` TEXT NOT NULL DEFAULT '',
`diff1name` TEXT NOT NULL DEFAULT '',
`diff1mod` REAL NOT NULL DEFAULT 0,
`diff2name` TEXT NOT NULL DEFAULT '',
`diff2mod` REAL NOT NULL DEFAULT 0,
`diff3name` TEXT NOT NULL DEFAULT '',
`diff3mod` REAL NOT NULL DEFAULT 0,
`verifyemail` INTEGER NOT NULL DEFAULT 0,
`shownews` INTEGER NOT NULL DEFAULT 0,
`showbabble` INTEGER NOT NULL DEFAULT 0,
@ -91,7 +71,7 @@ function second()
echo $query === true ? 'Control table created.<br>' : 'Error creating Control table.';
$query = db()->exec("INSERT INTO control VALUES (1, 'Dragon Knight', 250, 1, '', '', 1, '', 'Mage', 'Warrior', 'Paladin', 'Easy', 1, 'Medium', 1.2, 'Hard', 1.5, 1, 1, 1, 1);");
$query = db()->exec("INSERT INTO control VALUES (1, 'Dragon Knight', 250, 1, '', '', 'Mage', 'Warrior', 'Paladin', 1, 1, 1, 1);");
echo $query === true ? 'Control table populated.<br>' : 'Error populating Control table.';
@ -108,7 +88,6 @@ function second()
echo $query == true ? 'Drops table created.<br>' : 'Error creating Drops table.';
if ($full) {
$query = db()->exec(<<<SQL
INSERT INTO drops VALUES
(1, 'Life Pebble', 1, 1, 'maxhp,10', 'X'),
@ -146,7 +125,6 @@ function second()
SQL);
echo $query === true ? 'Drops table populated.<br>' : 'Error populating Drops table.';
}
$query = db()->exec(<<<SQL
CREATE TABLE forum (
@ -176,7 +154,6 @@ function second()
echo $query === true ? 'Items table created.<br>' : 'Error creating Items table.';
if ($full) {
$query = db()->exec(<<<SQL
INSERT INTO items VALUES
(1, 1, 'Stick', 10, 2, 'X'),
@ -215,7 +192,6 @@ function second()
SQL);
echo $query === true ? 'Items table populated.<br>' : 'Error populating Items table.';
}
$query = db()->exec(<<<SQL
CREATE TABLE levels (
@ -246,7 +222,6 @@ function second()
echo $query === true ? 'Levels table created.<br>' : 'Error creating Levels table.';
if ($full) {
$query = db()->exec(<<<SQL
INSERT INTO levels VALUES
(1, 0, 15, 0, 5, 5, 5, 0, 0, 15, 0, 5, 5, 5, 0, 0, 15, 0, 5, 5, 5, 0),
@ -352,7 +327,6 @@ function second()
SQL);
echo $query === true ? 'Levels table populated.<br>' : 'Error populating Levels table.';
}
$query = db()->exec(<<<SQL
CREATE TABLE monsters (
@ -370,7 +344,6 @@ function second()
echo $query === true ? 'Monsters table created.<br>' : 'Error creating Monsters table.';
if ($full) {
$query = db()->exec(<<<SQL
INSERT INTO monsters VALUES
(1, 'Blue Slime', 4, 3, 1, 1, 1, 1, 0),
@ -527,11 +500,11 @@ function second()
SQL);
echo $query === true ? 'Monsters table populated.<br>' : 'Error populating Monsters table.';
}
$query = db()->exec(<<<SQL
CREATE TABLE news (
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
`author` TEXT NOT NULL DEFAULT 'Guild Master',
`postdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`content` TEXT NOT NULL
);
@ -539,7 +512,7 @@ function second()
echo $query === true ? 'News table created.<br>' : 'Error creating News table.';
$query = db()->exec("INSERT INTO news VALUES (1, '2004-01-01 12:00:00', 'This is the first news post. Please use the admin control panel to add another one and make this one go away.');");
$query = db()->exec("INSERT INTO news (content) VALUES ('This is the first news post. Please use the admin control panel to add another one and make this one go away.');");
echo $query === true ? 'News table populated.<br>' : 'Error populating News table.';
@ -555,7 +528,6 @@ function second()
echo $query === true ? 'Spells table created.<br>' : 'Error creating Spells table.';
if ($full) {
$query = db()->exec(<<<SQL
INSERT INTO spells VALUES
(1, 'Heal', 5, 10, 1),
@ -580,7 +552,6 @@ function second()
SQL);
echo $query === true ? 'Spells table populated.<br>' : 'Error populating Spells table.';
}
$query = db()->exec(<<<SQL
CREATE TABLE towns (
@ -597,7 +568,6 @@ function second()
echo $query === true ? 'Towns table created.<br>' : 'Error creating Towns table.';
if ($full) {
$query = db()->exec(<<<SQL
INSERT INTO towns VALUES
(1, 'Midworld', 0, 0, 5, 0, 0, '1,2,3,17,18,19,28,29'),
@ -611,7 +581,6 @@ function second()
SQL);
echo $query === true ? 'Towns table populated.<br>' : 'Error populating Towns table.';
}
$query = db()->exec(<<<SQL
CREATE TABLE users (

View File

@ -2,10 +2,10 @@
// login.php :: Handles logins and cookies.
if (!file_exists('../.installed')) redirect('install.php');
require_once '../src/lib.php';
if (!file_exists('../.installed')) redirect('install.php');
match ($_GET['do'] ?? 'login') {
'login' => login(),
'logout' => logout()

View File

@ -2,10 +2,10 @@
// users.php :: Handles user account functions.
if (!file_exists('../.installed')) redirect('install.php');
require_once '../src/lib.php';
if (!file_exists('../.installed')) redirect('install.php');
$controlrow = get_control_row();
$do = $_GET['do'] ?? 'register';

View File

@ -66,19 +66,14 @@ function is_email($email) { // Thanks to "mail(at)philipp-louis.de" from php.net
}
function makesafe($d) {
$d = str_replace("\t","",$d);
$d = str_replace("<","&#60;",$d);
$d = str_replace(">","&#62;",$d);
$d = str_replace("\n","",$d);
$d = str_replace("|","??",$d);
$d = str_replace(" "," &nbsp;",$d);
return $d;
return htmlentities($d);
}
function admindisplay($content, $title) { // Finalize page and output to browser.
/**
* Finalize page and output to browser.
*/
function admindisplay($content, $title)
{
global $userrow, $controlrow;
if (!isset($controlrow)) {
$query = db()->query('SELECT * FROM control WHERE id=1 LIMIT 1;');
@ -292,6 +287,16 @@ function get_item(int $id): array|false
return $query->fetchArray(SQLITE3_ASSOC);
}
/**
* Get a drop by it's ID.
*/
function get_drop(int $id): array|false
{
$query = db()->query('SELECT * FROM drops WHERE id=? LIMIT 1;', [$id]);
if ($query === false) return false;
return $query->fetchArray(SQLITE3_ASSOC);
}
/**
* Get a spell by it's ID.
*/
@ -302,6 +307,16 @@ function get_spell(int $id): array|false
return $query->fetchArray(SQLITE3_ASSOC);
}
/**
* Get a monster by it's ID.
*/
function get_monster(int $id): array|false
{
$query = db()->query('SELECT * FROM monsters WHERE id=? LIMIT 1;', [$id]);
if ($query === false) return false;
return $query->fetchArray(SQLITE3_ASSOC);
}
/**
* Translate a Specials keyword to it's string.
*/

View File

@ -1,5 +1,5 @@
<?php
$template = <<<THEVERYENDOFYOU
$template = <<<HTML
<table width="100%">
<tr><td class="title"><img src="images/button_location.gif" alt="Location" title="Location" /></td></tr>
<tr><td>
@ -15,7 +15,9 @@ Longitude: {{longitude}}<br>
</center>
</form>
</td></tr>
</table><br>
</table>
<br>
<table width="100%">
<tr><td class="title"><img src="images/button_towns.gif" alt="Towns" title="Towns" /></td></tr>
@ -24,17 +26,19 @@ Longitude: {{longitude}}<br>
Travel To:<br>
{{townslist}}
</td></tr>
</table><br>
</table>
<br>
<table width="100%">
<tr><td class="title"><img src="images/button_functions.gif" alt="Functions" title="Functions" /></td></tr>
<tr><td>
<a href="/index.php">Home</a><br>
{{forumslink}}
{{adminlink}}
<a href="users.php?do=changepassword">Change Password</a><br>
<a href="login.php?do=logout">Log Out</a><br>
<a href="help.php">Help</a>
</td></tr>
</table><br>
THEVERYENDOFYOU;
?>
</table>
HTML;