Compare commits

...

2 Commits

Author SHA1 Message Date
98204ee9f1 Repair most of fight 2024-12-12 18:52:12 -06:00
9348c17179 Completely repair admin panel 2024-12-12 18:36:30 -06:00
10 changed files with 1202 additions and 1182 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. // forum.php :: Internal forums script for the game.
if (!file_exists('../.installed')) redirect('install.php');
require_once '../src/lib.php'; require_once '../src/lib.php';
if (!file_exists('../.installed')) redirect('install.php');
$controlrow = get_control_row(); $controlrow = get_control_row();
// Login (or verify) if not logged in. // Login (or verify) if not logged in.

View File

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

View File

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

View File

@ -1,12 +1,9 @@
<?php <?php
if (file_exists('../.installed')) {
header('Location: index.php');
exit;
}
require_once '../src/lib.php'; require_once '../src/lib.php';
if (file_exists('../.installed')) redirect('index.php');
$page = $_GET['page'] ?? 1; $page = $_GET['page'] ?? 1;
match ((int) $page) { match ((int) $page) {
2 => second(), 2 => second(),
@ -29,17 +26,8 @@ function first()
<body> <body>
<b>Dragon Knight Installation: Page One</b><br><br> <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> 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. <a href="install.php?page=2"><button>Install</button></a>
<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>
</body> </body>
</html> </html>
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>"; 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 $query = db()->exec(<<<SQL
CREATE TABLE babble ( CREATE TABLE babble (
`id` INTEGER PRIMARY KEY AUTOINCREMENT, `id` INTEGER PRIMARY KEY AUTOINCREMENT,
@ -68,20 +54,14 @@ function second()
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
CREATE TABLE control ( CREATE TABLE control (
`id` INTEGER PRIMARY KEY AUTOINCREMENT, `id` INTEGER PRIMARY KEY AUTOINCREMENT,
`gamename` TEXT NOT NULL DEFAULT '', `gamename` TEXT NOT NULL DEFAULT 'Dragon Knight',
`gamesize` INTEGER NOT NULL DEFAULT 0, `gamesize` INTEGER NOT NULL DEFAULT 250,
`gameopen` INTEGER NOT NULL DEFAULT 0, `gameopen` INTEGER NOT NULL DEFAULT 1,
`gameurl` TEXT NOT NULL DEFAULT '', `gameurl` TEXT NOT NULL DEFAULT '',
`adminemail` TEXT NOT NULL DEFAULT '', `adminemail` TEXT NOT NULL DEFAULT '',
`class1name` TEXT NOT NULL DEFAULT '', `class1name` TEXT NOT NULL DEFAULT '',
`class2name` TEXT NOT NULL DEFAULT '', `class2name` TEXT NOT NULL DEFAULT '',
`class3name` 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, `verifyemail` INTEGER NOT NULL DEFAULT 0,
`shownews` INTEGER NOT NULL DEFAULT 0, `shownews` INTEGER NOT NULL DEFAULT 0,
`showbabble` 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.'; 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.'; 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.'; echo $query == true ? 'Drops table created.<br>' : 'Error creating Drops table.';
if ($full) {
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
INSERT INTO drops VALUES INSERT INTO drops VALUES
(1, 'Life Pebble', 1, 1, 'maxhp,10', 'X'), (1, 'Life Pebble', 1, 1, 'maxhp,10', 'X'),
@ -146,7 +125,6 @@ function second()
SQL); SQL);
echo $query === true ? 'Drops table populated.<br>' : 'Error populating Drops table.'; echo $query === true ? 'Drops table populated.<br>' : 'Error populating Drops table.';
}
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
CREATE TABLE forum ( CREATE TABLE forum (
@ -176,7 +154,6 @@ function second()
echo $query === true ? 'Items table created.<br>' : 'Error creating Items table.'; echo $query === true ? 'Items table created.<br>' : 'Error creating Items table.';
if ($full) {
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
INSERT INTO items VALUES INSERT INTO items VALUES
(1, 1, 'Stick', 10, 2, 'X'), (1, 1, 'Stick', 10, 2, 'X'),
@ -215,7 +192,6 @@ function second()
SQL); SQL);
echo $query === true ? 'Items table populated.<br>' : 'Error populating Items table.'; echo $query === true ? 'Items table populated.<br>' : 'Error populating Items table.';
}
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
CREATE TABLE levels ( CREATE TABLE levels (
@ -246,7 +222,6 @@ function second()
echo $query === true ? 'Levels table created.<br>' : 'Error creating Levels table.'; echo $query === true ? 'Levels table created.<br>' : 'Error creating Levels table.';
if ($full) {
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
INSERT INTO levels VALUES 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), (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); SQL);
echo $query === true ? 'Levels table populated.<br>' : 'Error populating Levels table.'; echo $query === true ? 'Levels table populated.<br>' : 'Error populating Levels table.';
}
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
CREATE TABLE monsters ( CREATE TABLE monsters (
@ -370,7 +344,6 @@ function second()
echo $query === true ? 'Monsters table created.<br>' : 'Error creating Monsters table.'; echo $query === true ? 'Monsters table created.<br>' : 'Error creating Monsters table.';
if ($full) {
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
INSERT INTO monsters VALUES INSERT INTO monsters VALUES
(1, 'Blue Slime', 4, 3, 1, 1, 1, 1, 0), (1, 'Blue Slime', 4, 3, 1, 1, 1, 1, 0),
@ -527,11 +500,11 @@ function second()
SQL); SQL);
echo $query === true ? 'Monsters table populated.<br>' : 'Error populating Monsters table.'; echo $query === true ? 'Monsters table populated.<br>' : 'Error populating Monsters table.';
}
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
CREATE TABLE news ( CREATE TABLE news (
`id` INTEGER PRIMARY KEY AUTOINCREMENT, `id` INTEGER PRIMARY KEY AUTOINCREMENT,
`author` TEXT NOT NULL DEFAULT 'Guild Master',
`postdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, `postdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`content` TEXT NOT NULL `content` TEXT NOT NULL
); );
@ -539,7 +512,7 @@ function second()
echo $query === true ? 'News table created.<br>' : 'Error creating News table.'; 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.'; 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.'; echo $query === true ? 'Spells table created.<br>' : 'Error creating Spells table.';
if ($full) {
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
INSERT INTO spells VALUES INSERT INTO spells VALUES
(1, 'Heal', 5, 10, 1), (1, 'Heal', 5, 10, 1),
@ -580,7 +552,6 @@ function second()
SQL); SQL);
echo $query === true ? 'Spells table populated.<br>' : 'Error populating Spells table.'; echo $query === true ? 'Spells table populated.<br>' : 'Error populating Spells table.';
}
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
CREATE TABLE towns ( CREATE TABLE towns (
@ -597,7 +568,6 @@ function second()
echo $query === true ? 'Towns table created.<br>' : 'Error creating Towns table.'; echo $query === true ? 'Towns table created.<br>' : 'Error creating Towns table.';
if ($full) {
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
INSERT INTO towns VALUES INSERT INTO towns VALUES
(1, 'Midworld', 0, 0, 5, 0, 0, '1,2,3,17,18,19,28,29'), (1, 'Midworld', 0, 0, 5, 0, 0, '1,2,3,17,18,19,28,29'),
@ -611,7 +581,6 @@ function second()
SQL); SQL);
echo $query === true ? 'Towns table populated.<br>' : 'Error populating Towns table.'; echo $query === true ? 'Towns table populated.<br>' : 'Error populating Towns table.';
}
$query = db()->exec(<<<SQL $query = db()->exec(<<<SQL
CREATE TABLE users ( CREATE TABLE users (

View File

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

View File

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

View File

@ -1,26 +1,27 @@
<?php // fight.php :: Handles all fighting action. <?php
function fight() { // One big long function that determines the outcome of the fight. // fight.php :: Handles all fighting action.
global $userrow, $controlrow; /**
if ($userrow["currentaction"] != "Fighting") { display("Cheat attempt detected.<br><br>Get a life, loser.", "Error"); } * One big long function that determines the outcome of the fight.
*/
function fight()
{
global $userrow;
if ($userrow["currentaction"] != "Fighting") display("Cheat attempt detected.<br><br>Get a life, loser.", "Error");
$pagearray = array(); $pagearray = array();
$playerisdead = 0; $playerisdead = 0;
$pagearray["magiclist"] = ""; $pagearray["magiclist"] = "";
$userspells = explode(",", $userrow["spells"]); $userspells = explode(",", $userrow["spells"]);
$spellquery = doquery("SELECT id,name FROM {{table}}", "spells"); $spellquery = db()->query('SELECT id, name FROM spells ORDER BY id;');
while ($spellrow = mysql_fetch_array($spellquery)) { while ($spellrow = $spellquery->fetchArray(SQLITE3_ASSOC)) {
$spell = false; $spell = false;
foreach ($userspells as $a => $b) { foreach ($userspells as $b) if ($b == $spellrow["id"]) $spell = true;
if ($b == $spellrow["id"]) { $spell = true; } if ($spell == true) $pagearray["magiclist"] .= "<option value=\"".$spellrow["id"]."\">".$spellrow["name"]."</option>\n";
}
if ($spell == true) {
$pagearray["magiclist"] .= "<option value=\"".$spellrow["id"]."\">".$spellrow["name"]."</option>\n";
}
unset($spell); unset($spell);
} }
if ($pagearray["magiclist"] == "") { $pagearray["magiclist"] = "<option value=\"0\">None</option>\n"; } if ($pagearray["magiclist"] == "") $pagearray["magiclist"] = "<option value=\"0\">None</option>\n";
$magiclist = $pagearray["magiclist"]; $magiclist = $pagearray["magiclist"];
$chancetoswingfirst = 1; $chancetoswingfirst = 1;
@ -37,8 +38,9 @@ function fight() { // One big long function that determines the outcome of the f
// Pick a monster. // Pick a monster.
$monsterquery = doquery("SELECT * FROM {{table}} WHERE level>='$minlevel' AND level<='$maxlevel' ORDER BY RAND() LIMIT 1", "monsters"); $monsterrow = db()->query('SELECT * FROM monsters WHERE level >= ? AND level <= ? ORDER BY RANDOM() LIMIT 1;', [
$monsterrow = mysql_fetch_array($monsterquery); $minlevel, $maxlevel
])->fetchArray(SQLITE3_ASSOC);
$userrow["currentmonster"] = $monsterrow["id"]; $userrow["currentmonster"] = $monsterrow["id"];
$userrow["currentmonsterhp"] = rand((($monsterrow["maxhp"]/5)*4),$monsterrow["maxhp"]); $userrow["currentmonsterhp"] = rand((($monsterrow["maxhp"]/5)*4),$monsterrow["maxhp"]);
$userrow["currentmonstersleep"] = 0; $userrow["currentmonstersleep"] = 0;
@ -49,12 +51,10 @@ function fight() { // One big long function that determines the outcome of the f
unset($monsterquery); unset($monsterquery);
unset($monsterrow); unset($monsterrow);
} }
// Next, get the monster statistics. // Next, get the monster statistics.
$monsterquery = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["currentmonster"]."' LIMIT 1", "monsters"); $monsterrow = get_monster($userrow['currentmonster']);
$monsterrow = mysql_fetch_array($monsterquery);
$pagearray["monstername"] = $monsterrow["name"]; $pagearray["monstername"] = $monsterrow["name"];
// Do run stuff. // Do run stuff.
@ -96,15 +96,16 @@ function fight() { // One big long function that determines the outcome of the f
if ($userrow["currenthp"] <= 0) { if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2); $newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4); $newhp = ceil($userrow["maxhp"]/4);
$updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users"); db()->query("UPDATE users SET currenthp=?, currentaction='In Town', currentmonster=0, currentmonsterhp=0, currentmonstersleep=0, currentmonsterimmune=0, currentfight=0, latitude=0, longitude=0, gold=? WHERE id=?;", [
$newhp, $newgold, $userrow['id']
]);
$playerisdead = 1; $playerisdead = 1;
} }
} }
} }
$updatequery = doquery("UPDATE {{table}} SET currentaction='Exploring' WHERE id='".$userrow["id"]."' LIMIT 1", "users"); db()->query("UPDATE users SET currentaction='Exploring' WHERE id=?;", [$userrow['id']]);
header("Location: index.php"); redirect('index.php');
die();
// Do fight stuff. // Do fight stuff.
} elseif (isset($_POST["fight"])) { } elseif (isset($_POST["fight"])) {
@ -130,9 +131,8 @@ function fight() { // One big long function that determines the outcome of the f
$userrow["currentmonsterhp"] -= $monsterdamage; $userrow["currentmonsterhp"] -= $monsterdamage;
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>"; $pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
if ($userrow["currentmonsterhp"] <= 0) { if ($userrow["currentmonsterhp"] <= 0) {
$updatequery = doquery("UPDATE {{table}} SET currentmonsterhp='0' WHERE id='".$userrow["id"]."' LIMIT 1", "users"); db()->query('UPDATE users SET currentmonsterhp=0 WHERE id=?;', [$userrow['id']]);
header("Location: index.php?do=victory"); redirect('index.php?do=victory');
die();
} }
// Monster's turn. // Monster's turn.
@ -166,7 +166,9 @@ function fight() { // One big long function that determines the outcome of the f
if ($userrow["currenthp"] <= 0) { if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2); $newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4); $newhp = ceil($userrow["maxhp"]/4);
$updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users"); db()->query("UPDATE users SET currenthp=?, currentaction='In Town', currentmonster=0, currentmonsterhp=0, currentmonstersleep=0, currentmonsterimmune=0, currentfight=0, latitude=0, longitude=0, gold=? WHERE id=?;", [
$newhp, $newgold, $userrow['id']
]);
$playerisdead = 1; $playerisdead = 1;
} }
} }
@ -178,8 +180,7 @@ function fight() { // One big long function that determines the outcome of the f
$pickedspell = $_POST["userspell"]; $pickedspell = $_POST["userspell"];
if ($pickedspell == 0) { display("You must select a spell first. Please go back and try again.", "Error"); die(); } if ($pickedspell == 0) { display("You must select a spell first. Please go back and try again.", "Error"); die(); }
$newspellquery = doquery("SELECT * FROM {{table}} WHERE id='$pickedspell' LIMIT 1", "spells"); $newspellrow = get_spell($pickedspell);
$newspellrow = mysql_fetch_array($newspellquery);
$spell = false; $spell = false;
foreach($userspells as $a => $b) { foreach($userspells as $a => $b) {
if ($b == $pickedspell) { $spell = true; } if ($b == $pickedspell) { $spell = true; }
@ -222,9 +223,10 @@ function fight() { // One big long function that determines the outcome of the f
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>"; $pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
if ($userrow["currentmonsterhp"] <= 0) { if ($userrow["currentmonsterhp"] <= 0) {
$updatequery = doquery("UPDATE {{table}} SET currentmonsterhp='0',currenthp='".$userrow["currenthp"]."',currentmp='".$userrow["currentmp"]."' WHERE id='".$userrow["id"]."' LIMIT 1", "users"); db()->query('UPDATE users SET currentmonsterhp=0, currenthp=?, currentmp=? WHERE id=?;', [
header("Location: index.php?do=victory"); $userrow['currenthp'], $userrow['currentmp'], $userrow['id']
die(); ]);
redirect('index.php?do=victory');
} }
// Monster's turn. // Monster's turn.
@ -258,7 +260,9 @@ function fight() { // One big long function that determines the outcome of the f
if ($userrow["currenthp"] <= 0) { if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2); $newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4); $newhp = ceil($userrow["maxhp"]/4);
$updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users"); db()->query("UPDATE users SET currenthp=?, currentaction='In Town', currentmonster=0, currentmonsterhp=0, currentmonstersleep=0, currentmonsterimmune=0, currentfight=0, latitude=0, longitude=0, gold=? WHERE id=?;", [
$newhp, $newgold, $userrow['id']
]);
$playerisdead = 1; $playerisdead = 1;
} }
} }
@ -297,7 +301,9 @@ function fight() { // One big long function that determines the outcome of the f
if ($userrow["currenthp"] <= 0) { if ($userrow["currenthp"] <= 0) {
$newgold = ceil($userrow["gold"]/2); $newgold = ceil($userrow["gold"]/2);
$newhp = ceil($userrow["maxhp"]/4); $newhp = ceil($userrow["maxhp"]/4);
$updatequery = doquery("UPDATE {{table}} SET currenthp='$newhp',currentaction='In Town',currentmonster='0',currentmonsterhp='0',currentmonstersleep='0',currentmonsterimmune='0',currentfight='0',latitude='0',longitude='0',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users"); db()->query("UPDATE users SET currenthp=?, currentaction='In Town', currentmonster=0, currentmonsterhp=0, currentmonstersleep=0, currentmonsterimmune=0, currentfight=0, latitude=0, longitude=0, gold=? WHERE id=?;", [
$newhp, $newgold, $userrow['id']
]);
$playerisdead = 1; $playerisdead = 1;
} }
} }
@ -320,25 +326,24 @@ function fight() { // One big long function that determines the outcome of the f
$newmp = $userrow["currentmp"]; $newmp = $userrow["currentmp"];
if ($playerisdead != 1) { if ($playerisdead != 1) {
$pagearray["command"] = <<<END $pagearray["command"] = <<<HTML
Command?<br><br> Command?<br><br>
<form action="index.php?do=fight" method="post"> <form action="index.php?do=fight" method="post">
<input type="submit" name="fight" value="Fight" /><br><br> <input type="submit" name="fight" value="Fight" /><br><br>
<select name="userspell"><option value="0">Choose One</option>$magiclist</select> <input type="submit" name="spell" value="Spell" /><br><br> <select name="userspell"><option value="0">Choose One</option>$magiclist</select> <input type="submit" name="spell" value="Spell" /><br><br>
<input type="submit" name="run" value="Run" /><br><br> <input type="submit" name="run" value="Run" /><br><br>
</form> </form>
END; HTML;
$updatequery = doquery("UPDATE {{table}} SET currentaction='Fighting',currenthp='$newhp',currentmp='$newmp',currentfight='$newfight',currentmonster='$newmonster',currentmonsterhp='$newmonsterhp',currentmonstersleep='$newmonstersleep',currentmonsterimmune='$newmonsterimmune',currentuberdamage='$newuberdamage',currentuberdefense='$newuberdefense' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
db()->query("UPDATE users SET currentaction='Fighting', currenthp=?, currentmp=?, currentfight=?, currentmonster=?, currentmonsterhp=?, currentmonstersleep=?, currentmonsterimmune=?, currentuberdamage=?, currentuberdefense=? WHERE id=?;", [
$newhp, $newmp, $newfight, $newmonster, $newmonsterhp, $newmonstersleep, $newmonsterimmune, $newuberdamage, $newuberdefense, $userrow['id']
]);
} else { } else {
$pagearray["command"] = "<b>You have died.</b><br><br>As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br><br>You may now continue back to <a href=\"index.php\">town</a>, and we hope you fair better next time."; $pagearray["command"] = "<b>You have died.</b><br><br>As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br><br>You may now continue back to <a href=\"index.php\">town</a>, and we hope you fair better next time.";
} }
// Finalize page and display it. // Finalize page and display it.
$template = gettemplate("fight"); display(parsetemplate(gettemplate("fight"), $pagearray), "Fighting");
$page = parsetemplate($template,$pagearray);
display($page, "Fighting");
} }
function victory() { function victory() {
@ -515,12 +520,12 @@ function drop() {
} }
function dead() { function dead()
{
$page = "<b>You have died.</b><br><br>As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points to continue your journey.<br><br>You may now continue back to <a href=\"index.php\">town</a>, and we hope you fair better next time."; return <<<HTML
<b>You have died.</b><br><br>
As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points
to continue your journey.<br><br>
You may now continue back to <a href="index.php">town</a>, and we hope you fair better next time.
HTML;
} }
?>

View File

@ -66,19 +66,14 @@ function is_email($email) { // Thanks to "mail(at)philipp-louis.de" from php.net
} }
function makesafe($d) { function makesafe($d) {
return htmlentities($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;
} }
function admindisplay($content, $title) { // Finalize page and output to browser. /**
* Finalize page and output to browser.
*/
function admindisplay($content, $title)
{
global $userrow, $controlrow; global $userrow, $controlrow;
if (!isset($controlrow)) { if (!isset($controlrow)) {
$query = db()->query('SELECT * FROM control WHERE id=1 LIMIT 1;'); $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); 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. * Get a spell by it's ID.
*/ */
@ -302,6 +307,16 @@ function get_spell(int $id): array|false
return $query->fetchArray(SQLITE3_ASSOC); 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. * Translate a Specials keyword to it's string.
*/ */

View File

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