diff --git a/public/index.php b/public/index.php
index fb0acd4..cb9280b 100644
--- a/public/index.php
+++ b/public/index.php
@@ -1,63 +1,77 @@
-install.php from your Dragon Knight directory before continuing."); }
-include('lib.php');
-include('cookies.php');
-$link = opendb();
-$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");
-$controlrow = mysql_fetch_array($controlquery);
+// index.php :: Primary program script, evil alien overlord, you decide.
+
+if (!file_exists('../.installed')) {
+ header('Location: install.php');
+ exit;
+}
+
+require_once '../src/lib.php';
+
+$controlrow = get_control_row();
// Login (or verify) if not logged in.
-$userrow = checkcookies();
-if ($userrow == false) {
- if (isset($_GET["do"])) {
- if ($_GET["do"] == "verify") { header("Location: users.php?do=verify"); die(); }
+if (($userrow = checkcookies()) === false) {
+ if (isset($_GET['do']) && $_GET['do'] === 'verify') {
+ header("Location: users.php?do=verify");
+ exit;
}
- header("Location: login.php?do=login"); die();
+
+ header("Location: login.php?do=login");
+ exit;
}
+
// Close game.
-if ($controlrow["gameopen"] == 0) { display("The game is currently closed for maintanence. Please check back later.","Game Closed"); die(); }
+if ((bool) $controlrow["gameopen"] === false) {
+ display("The game is currently closed for maintanence. Please check back later.", "Game Closed");
+ exit;
+}
+
// Force verify if the user isn't verified yet.
-if ($controlrow["verifyemail"] == 1 && $userrow["verify"] != 1) { header("Location: users.php?do=verify"); die(); }
+if ((bool) $controlrow["verifyemail"] && (bool) $userrow["verify"] === false) {
+ header("Location: users.php?do=verify");
+ exit;
+}
+
// Block user if he/she has been banned.
-if ($userrow["authlevel"] == 2) { die("Your account has been blocked. Please try back later."); }
+if ($userrow["authlevel"] === 2) {
+ exit("Your account has been blocked.");
+}
-if (isset($_GET["do"])) {
- $do = explode(":",$_GET["do"]);
-
- // Town functions.
- if ($do[0] == "inn") { include('towns.php'); inn(); }
- elseif ($do[0] == "buy") { include('towns.php'); buy(); }
- elseif ($do[0] == "buy2") { include('towns.php'); buy2($do[1]); }
- elseif ($do[0] == "buy3") { include('towns.php'); buy3($do[1]); }
- elseif ($do[0] == "sell") { include('towns.php'); sell(); }
- elseif ($do[0] == "maps") { include('towns.php'); maps(); }
- elseif ($do[0] == "maps2") { include('towns.php'); maps2($do[1]); }
- elseif ($do[0] == "maps3") { include('towns.php'); maps3($do[1]); }
- elseif ($do[0] == "gotown") { include('towns.php'); travelto($do[1]); }
-
- // Exploring functions.
- elseif ($do[0] == "move") { include('explore.php'); move(); }
-
- // Fighting functions.
- elseif ($do[0] == "fight") { include('fight.php'); fight(); }
- elseif ($do[0] == "victory") { include('fight.php'); victory(); }
- elseif ($do[0] == "drop") { include('fight.php'); drop(); }
- elseif ($do[0] == "dead") { include('fight.php'); dead(); }
-
- // Misc functions.
- elseif ($do[0] == "verify") { header("Location: users.php?do=verify"); die(); }
- elseif ($do[0] == "spell") { include('heal.php'); healspells($do[1]); }
- elseif ($do[0] == "showchar") { showchar(); }
- elseif ($do[0] == "onlinechar") { onlinechar($do[1]); }
- elseif ($do[0] == "showmap") { showmap(); }
- elseif ($do[0] == "babblebox") { babblebox(); }
- elseif ($do[0] == "ninja") { ninja(); }
-
-} else { donothing(); }
+require_once '../src/towns.php';
+require_once '../src/explore.php';
+require_once '../src/fight.php';
+require_once '../src/heal.php';
-function donothing() {
-
+$do = explode(':', $_GET['do'] ?? '');
+match ($do[0]) {
+ 'inn' => inn(),
+ 'buy' => buy(),
+ 'buy2' => buy2($do[1]),
+ 'buy3' => buy3($do[1]),
+ // 'sell' => sell(),
+ 'maps' => maps(),
+ 'maps2' => maps2($do[1]),
+ 'maps3' => maps3($do[1]),
+ 'gotown' => travelto($do[1]),
+ 'move' => move(),
+ 'fight' => fight(),
+ 'victory' => victory(),
+ 'drop' => drop(),
+ 'dead' => dead(),
+ 'verify' => header("Location: users.php?do=verify"),
+ 'spell' => healspells($do[1]),
+ 'showchar' => showchar(),
+ 'onlinechar' => onlinechar($do[1]),
+ 'showmap' => showmap(),
+ 'babblebox' => babblebox(),
+ 'ninja' => ninja(),
+ default => donothing()
+};
+
+function donothing()
+{
global $userrow;
if ($userrow["currentaction"] == "In Town") {
@@ -70,92 +84,108 @@ function donothing() {
$page = dofight();
$title = "Fighting";
}
-
+
display($page, $title);
-
}
-function dotown() { // Spit out the main town page.
-
- global $userrow, $controlrow, $numqueries;
-
- $townquery = doquery("SELECT * FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
- if (mysql_num_rows($townquery) == 0) { display("There is an error with your user account, or with the town data. Please try again.","Error"); }
- $townrow = mysql_fetch_array($townquery);
-
+/**
+ * Spit out the main town page.
+ */
+function dotown()
+{
+ global $userrow, $controlrow;
+
+ $townquery = db()->query('SELECT * FROM towns WHERE latitude = ? AND longitude = ? LIMIT 1;', [$userrow["latitude"], $userrow["longitude"]]);
+ if ($townquery === false) display("There is an error with your user account, or with the town data. Please try again.", "Error");
+ $townrow = $townquery->fetchArray(SQLITE3_ASSOC);
+ if ($townrow === false) display("There is an error with your user account, or with the town data. Please try again.","Error");
+
// News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe.
- if ($controlrow["shownews"] == 1) {
- $newsquery = doquery("SELECT * FROM {{table}} ORDER BY id DESC LIMIT 1", "news");
- $newsrow = mysql_fetch_array($newsquery);
+ if ($controlrow["shownews"] == 1) {
+ $newsrow = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC);
$townrow["news"] = "
Latest News |
\n";
$townrow["news"] .= "[".prettydate($newsrow["postdate"])."] ".nl2br($newsrow["content"]);
$townrow["news"] .= " |
\n";
- } else { $townrow["news"] = ""; }
-
+ } else {
+ $townrow["news"] = "";
+ }
+
// Who's Online. Currently just members. Guests maybe later.
if ($controlrow["showonline"] == 1) {
- $onlinequery = doquery("SELECT * FROM {{table}} WHERE UNIX_TIMESTAMP(onlinetime) >= '".(time()-600)."' ORDER BY charname", "users");
+ $onlinequery = db()->query("SELECT * FROM news WHERE strftime('%s', onlinetime) >= strftime('%s', 'now') - 600 ORDER BY charname");
+
+ $online_count = 0;
+ $online_rows = [];
+
+ foreach ($onlinequery->fetchArray(SQLITE3_ASSOC) as $onlinerow) {
+ $online_count++;
+ $online_rows[] = "".$onlinerow["charname"]."" . ", ";
+ }
+
$townrow["whosonline"] = "Who's Online |
\n";
- $townrow["whosonline"] .= "There are " . mysql_num_rows($onlinequery) . " user(s) online within the last 10 minutes: ";
- while ($onlinerow = mysql_fetch_array($onlinequery)) { $townrow["whosonline"] .= "".$onlinerow["charname"]."" . ", "; }
- $townrow["whosonline"] = rtrim($townrow["whosonline"], ", ");
+ $townrow["whosonline"] .= "There are $online_count user(s) online within the last 10 minutes: ";
+ $townrow["whosonline"] .= rtrim(implode(', ', $online_rows), ', ');
$townrow["whosonline"] .= " |
\n";
- } else { $townrow["whosonline"] = ""; }
-
+ } else {
+ $townrow["whosonline"] = "";
+ }
+
if ($controlrow["showbabble"] == 1) {
$townrow["babblebox"] = "Babble Box |
\n";
$townrow["babblebox"] .= "";
$townrow["babblebox"] .= " |
\n";
- } else { $townrow["babblebox"] = ""; }
-
+ } else {
+ $townrow["babblebox"] = "";
+ }
+
$page = gettemplate("towns");
$page = parsetemplate($page, $townrow);
-
- return $page;
-
-}
-
-function doexplore() { // Just spit out a blank exploring page.
-
- // Exploring without a GET string is normally when they first log in, or when they've just finished fighting.
-
-$page = <<
- |
-
-You are exploring the map, and nothing has happened. Continue exploring using the direction buttons or the Travel To menus.
- |
-
-END;
return $page;
-
}
-function dofight() { // Redirect to fighting.
-
+/**
+ * Just spit out a blank exploring page. Exploring without a GET string is normally when they first log in, or when
+ * they've just finished fighting.
+ */
+function doexplore()
+{
+ return <<
+ |
+
+ You are exploring the map, and nothing has happened. Continue exploring using the direction buttons or the Travel To menus.
+ |
+
+ HTML;
+}
+
+/**
+ * Redirect to fighting.
+ */
+function dofight()
+{
header("Location: index.php?do=fight");
-
}
-function showchar() {
-
+function showchar()
+{
global $userrow, $controlrow;
-
+
// Format various userrow stuffs.
$userrow["experience"] = number_format($userrow["experience"]);
$userrow["gold"] = number_format($userrow["gold"]);
- if ($userrow["expbonus"] > 0) {
- $userrow["plusexp"] = "(+".$userrow["expbonus"]."%)";
+ if ($userrow["expbonus"] > 0) {
+ $userrow["plusexp"] = "(+".$userrow["expbonus"]."%)";
} elseif ($userrow["expbonus"] < 0) {
$userrow["plusexp"] = "(".$userrow["expbonus"]."%)";
} else { $userrow["plusexp"] = ""; }
- if ($userrow["goldbonus"] > 0) {
- $userrow["plusgold"] = "(+".$userrow["goldbonus"]."%)";
- } elseif ($userrow["goldbonus"] < 0) {
+ if ($userrow["goldbonus"] > 0) {
+ $userrow["plusgold"] = "(+".$userrow["goldbonus"]."%)";
+ } elseif ($userrow["goldbonus"] < 0) {
$userrow["plusgold"] = "(".$userrow["goldbonus"]."%)";
} else { $userrow["plusgold"] = ""; }
-
+
$levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels");
$levelrow = mysql_fetch_array($levelquery);
if ($userrow["level"] < 99) { $userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]); } else { $userrow["nextlevel"] = "None"; }
@@ -163,11 +193,11 @@ function showchar() {
if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; }
elseif ($userrow["charclass"] == 2) { $userrow["charclass"] = $controlrow["class2name"]; }
elseif ($userrow["charclass"] == 3) { $userrow["charclass"] = $controlrow["class3name"]; }
-
+
if ($userrow["difficulty"] == 1) { $userrow["difficulty"] = $controlrow["diff1name"]; }
elseif ($userrow["difficulty"] == 2) { $userrow["difficulty"] = $controlrow["diff2name"]; }
elseif ($userrow["difficulty"] == 3) { $userrow["difficulty"] = $controlrow["diff3name"]; }
-
+
$spellquery = doquery("SELECT id,name FROM {{table}}","spells");
$userspells = explode(",",$userrow["spells"]);
$userrow["magiclist"] = "";
@@ -181,40 +211,39 @@ function showchar() {
}
}
if ($userrow["magiclist"] == "") { $userrow["magiclist"] = "None"; }
-
+
// Make page tags for XHTML validation.
$xml = "\n"
. "\n"
. "\n";
-
+
$charsheet = gettemplate("showchar");
$page = $xml . gettemplate("minimal");
$array = array("content"=>parsetemplate($charsheet, $userrow), "title"=>"Character Information");
echo parsetemplate($page, $array);
die();
-
}
function onlinechar($id) {
-
+
global $controlrow;
$userquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "users");
if (mysql_num_rows($userquery) == 1) { $userrow = mysql_fetch_array($userquery); } else { display("No such user.", "Error"); }
-
+
// Format various userrow stuffs.
$userrow["experience"] = number_format($userrow["experience"]);
$userrow["gold"] = number_format($userrow["gold"]);
- if ($userrow["expbonus"] > 0) {
- $userrow["plusexp"] = "(+".$userrow["expbonus"]."%)";
+ if ($userrow["expbonus"] > 0) {
+ $userrow["plusexp"] = "(+".$userrow["expbonus"]."%)";
} elseif ($userrow["expbonus"] < 0) {
$userrow["plusexp"] = "(".$userrow["expbonus"]."%)";
} else { $userrow["plusexp"] = ""; }
- if ($userrow["goldbonus"] > 0) {
- $userrow["plusgold"] = "(+".$userrow["goldbonus"]."%)";
- } elseif ($userrow["goldbonus"] < 0) {
+ if ($userrow["goldbonus"] > 0) {
+ $userrow["plusgold"] = "(+".$userrow["goldbonus"]."%)";
+ } elseif ($userrow["goldbonus"] < 0) {
$userrow["plusgold"] = "(".$userrow["goldbonus"]."%)";
} else { $userrow["plusgold"] = ""; }
-
+
$levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels");
$levelrow = mysql_fetch_array($levelquery);
$userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]);
@@ -222,37 +251,37 @@ function onlinechar($id) {
if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; }
elseif ($userrow["charclass"] == 2) { $userrow["charclass"] = $controlrow["class2name"]; }
elseif ($userrow["charclass"] == 3) { $userrow["charclass"] = $controlrow["class3name"]; }
-
+
if ($userrow["difficulty"] == 1) { $userrow["difficulty"] = $controlrow["diff1name"]; }
elseif ($userrow["difficulty"] == 2) { $userrow["difficulty"] = $controlrow["diff2name"]; }
elseif ($userrow["difficulty"] == 3) { $userrow["difficulty"] = $controlrow["diff3name"]; }
-
+
$charsheet = gettemplate("onlinechar");
$page = parsetemplate($charsheet, $userrow);
display($page, "Character Information");
-
+
}
function showmap() {
-
- global $userrow;
-
+
+ global $userrow;
+
// Make page tags for XHTML validation.
$xml = "\n"
. "\n"
. "\n";
-
+
$page = $xml . gettemplate("minimal");
$array = array("content"=>"", "title"=>"Map");
echo parsetemplate($page, $array);
die();
-
+
}
function babblebox() {
-
+
global $userrow;
-
+
if (isset($_POST["babble"])) {
$safecontent = makesafe($_POST["babble"]);
if ($safecontent == "" || $safecontent == " ") { //blank post. do nothing.
@@ -260,17 +289,17 @@ function babblebox() {
header("Location: index.php?do=babblebox");
die();
}
-
+
$babblebox = array("content"=>"");
$bg = 1;
$babblequery = doquery("SELECT * FROM {{table}} ORDER BY id DESC LIMIT 20", "babble");
while ($babblerow = mysql_fetch_array($babblequery)) {
if ($bg == 1) { $new = "[".$babblerow["author"]."] ".$babblerow["babble"]."
\n"; $bg = 2; }
- else { $new = "[".$babblerow["author"]."] ".stripslashes($babblerow["babble"])."
\n"; $bg = 1; }
+ else { $new = "[".$babblerow["author"]."] ".stripslashes($babblerow["babble"])."
\n"; $bg = 1; }
$babblebox["content"] = $new . $babblebox["content"];
}
$babblebox["content"] .= "";
-
+
// Make page tags for XHTML validation.
$xml = "\n"
. "\n"
@@ -281,8 +310,10 @@ function babblebox() {
}
-function ninja() {
- header("Location: http://www.se7enet.com/img/shirtninja.jpg");
+/**
+ * NINJA! 🥷
+ */
+function ninja(): void
+{
+ exit('NINJA! 🥷');
}
-
-?>
\ No newline at end of file
diff --git a/public/install.php b/public/install.php
index c07334a..430274a 100644
--- a/public/install.php
+++ b/public/install.php
@@ -1,15 +1,13 @@
second(),
3 => third(),
4 => fourth(),
@@ -17,13 +15,12 @@ match ((int) $_GET['page'] ?? 0) {
default => first(),
};
-
/**
* First page - show warnings and gather info
*/
function first()
{
- echo <<
Dragon Knight Installation
@@ -44,7 +41,7 @@ function first()
- END;
+ HTML;
exit;
}
@@ -58,18 +55,18 @@ function second()
$full = isset($_POST["complete"]);
- $query = db()->exec(<<exec(<<' : 'Error creating Babble Box table.';
- $query = db()->exec(<<exec(<<' : 'Error creating Control table.';
@@ -101,7 +98,7 @@ function second()
echo $query === true ? 'Control table populated.
' : 'Error populating Control table.';
- $query = db()->exec(<<exec(<<' : 'Error creating Drops table.';
if ($full) {
- $query = db()->exec(<<exec(<<' : 'Error populating Drops table.';
}
- $query = db()->exec(<<exec(<<' : 'Error creating Forum table.';
- $query = db()->exec(<<exec(<<' : 'Error creating Items table.';
if ($full) {
- $query = db()->exec(<<exec(<<' : 'Error populating Items table.';
}
- $query = db()->exec(<<exec(<<' : 'Error creating Levels table.';
if ($full) {
- $query = db()->exec(<<exec(<<' : 'Error populating Levels table.';
}
- $query = db()->exec(<<exec(<<' : 'Error creating Monsters table.';
if ($full) {
- $query = db()->exec(<<exec(<<' : 'Error populating Monsters table.';
}
- $query = db()->exec(<<exec(<<' : 'Error creating News table.';
@@ -549,7 +546,7 @@ function second()
echo $query === true ? 'News table populated.
' : 'Error populating News table.';
- $query = db()->exec(<<exec(<<' : 'Error creating Spells table.';
if ($full) {
- $query = db()->exec(<<exec(<<' : 'Error populating Spells table.';
}
- $query = db()->exec(<<exec(<<' : 'Error creating Towns table.';
if ($full) {
- $query = db()->exec(<<exec(<<' : 'Error populating Towns table.';
}
- $query = db()->exec(<<exec(<<' : 'Error creating Users table.';
@@ -686,7 +683,7 @@ function second()
*/
function third()
{
- echo <<
Dragon Knight Installation
@@ -708,7 +705,7 @@ function third()
- END;
+ HTML;
exit;
}
@@ -764,7 +761,7 @@ function fourth()
file_put_contents('../.installed', date('Y-m-d H:i:s'));
- echo <<
Dragon Knight Installation
@@ -782,7 +779,7 @@ function fourth()
click here.
- END;
+ HTML;
exit;
}
@@ -796,7 +793,7 @@ function fifth()
die('Dragon Knight was unable to send your URL. Please go back and try again, or just continue on to the game.');
}
- echo <<
Dragon Knight Installation
@@ -807,7 +804,7 @@ function fifth()
You are now ready to play the game. Note that you must log in through the public section before being allowed into the control panel. Once logged in, an "Admin" link will appear in the Functions box of the left sidebar panel.