more refactoring, add src dir, update index logic
This commit is contained in:
parent
ce06aecf84
commit
0511da22fb
201
public/index.php
201
public/index.php
|
@ -1,63 +1,77 @@
|
|||
<?php // index.php :: Primary program script, evil alien overlord, you decide.
|
||||
<?php
|
||||
|
||||
if (file_exists('install.php')) { die("Please delete <b>install.php</b> 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"]);
|
||||
require_once '../src/towns.php';
|
||||
require_once '../src/explore.php';
|
||||
require_once '../src/fight.php';
|
||||
require_once '../src/heal.php';
|
||||
|
||||
// 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(); }
|
||||
|
||||
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") {
|
||||
|
@ -72,74 +86,90 @@ function donothing() {
|
|||
}
|
||||
|
||||
display($page, $title);
|
||||
|
||||
}
|
||||
|
||||
function dotown() { // Spit out the main town page.
|
||||
/**
|
||||
* Spit out the main town page.
|
||||
*/
|
||||
function dotown()
|
||||
{
|
||||
global $userrow, $controlrow;
|
||||
|
||||
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);
|
||||
$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);
|
||||
$newsrow = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC);
|
||||
$townrow["news"] = "<table width=\"95%\"><tr><td class=\"title\">Latest News</td></tr><tr><td>\n";
|
||||
$townrow["news"] .= "<span class=\"light\">[".prettydate($newsrow["postdate"])."]</span><br />".nl2br($newsrow["content"]);
|
||||
$townrow["news"] .= "</td></tr></table>\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[] = "<a href=\"index.php?do=onlinechar:".$onlinerow["id"]."\">".$onlinerow["charname"]."</a>" . ", ";
|
||||
}
|
||||
|
||||
$townrow["whosonline"] = "<table width=\"95%\"><tr><td class=\"title\">Who's Online</td></tr><tr><td>\n";
|
||||
$townrow["whosonline"] .= "There are <b>" . mysql_num_rows($onlinequery) . "</b> user(s) online within the last 10 minutes: ";
|
||||
while ($onlinerow = mysql_fetch_array($onlinequery)) { $townrow["whosonline"] .= "<a href=\"index.php?do=onlinechar:".$onlinerow["id"]."\">".$onlinerow["charname"]."</a>" . ", "; }
|
||||
$townrow["whosonline"] = rtrim($townrow["whosonline"], ", ");
|
||||
$townrow["whosonline"] .= "There are <b>$online_count</b> user(s) online within the last 10 minutes: ";
|
||||
$townrow["whosonline"] .= rtrim(implode(', ', $online_rows), ', ');
|
||||
$townrow["whosonline"] .= "</td></tr></table>\n";
|
||||
} else { $townrow["whosonline"] = ""; }
|
||||
} else {
|
||||
$townrow["whosonline"] = "";
|
||||
}
|
||||
|
||||
if ($controlrow["showbabble"] == 1) {
|
||||
$townrow["babblebox"] = "<table width=\"95%\"><tr><td class=\"title\">Babble Box</td></tr><tr><td>\n";
|
||||
$townrow["babblebox"] .= "<iframe src=\"index.php?do=babblebox\" name=\"sbox\" width=\"100%\" height=\"250\" frameborder=\"0\" id=\"bbox\">Your browser does not support inline frames! The Babble Box will not be available until you upgrade to a newer <a href=\"http://www.mozilla.org\" target=\"_new\">browser</a>.</iframe>";
|
||||
$townrow["babblebox"] .= "</td></tr></table>\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 = <<<END
|
||||
/**
|
||||
* 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 <<<HTML
|
||||
<table width="100%">
|
||||
<tr><td class="title"><img src="images/title_exploring.gif" alt="Exploring" /></td></tr>
|
||||
<tr><td>
|
||||
You are exploring the map, and nothing has happened. Continue exploring using the direction buttons or the Travel To menus.
|
||||
</td></tr>
|
||||
</table>
|
||||
END;
|
||||
|
||||
return $page;
|
||||
|
||||
HTML;
|
||||
}
|
||||
|
||||
function dofight() { // Redirect to fighting.
|
||||
|
||||
/**
|
||||
* Redirect to fighting.
|
||||
*/
|
||||
function dofight()
|
||||
{
|
||||
header("Location: index.php?do=fight");
|
||||
|
||||
}
|
||||
|
||||
function showchar() {
|
||||
|
||||
function showchar()
|
||||
{
|
||||
global $userrow, $controlrow;
|
||||
|
||||
// Format various userrow stuffs.
|
||||
|
@ -192,7 +222,6 @@ function showchar() {
|
|||
$array = array("content"=>parsetemplate($charsheet, $userrow), "title"=>"Character Information");
|
||||
echo parsetemplate($page, $array);
|
||||
die();
|
||||
|
||||
}
|
||||
|
||||
function onlinechar($id) {
|
||||
|
@ -281,8 +310,10 @@ function babblebox() {
|
|||
|
||||
}
|
||||
|
||||
function ninja() {
|
||||
header("Location: http://www.se7enet.com/img/shirtninja.jpg");
|
||||
/**
|
||||
* NINJA! 🥷
|
||||
*/
|
||||
function ninja(): void
|
||||
{
|
||||
exit('NINJA! 🥷');
|
||||
}
|
||||
|
||||
?>
|
|
@ -1,15 +1,13 @@
|
|||
<?php
|
||||
|
||||
if (file_exists('../.installed')) {
|
||||
echo 'Game already installed.';
|
||||
header('Location: index.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
require_once '../lib.php';
|
||||
require_once '../src/lib.php';
|
||||
|
||||
define('START', microtime(true));
|
||||
|
||||
match ((int) $_GET['page'] ?? 0) {
|
||||
match ((int) $_GET['page'] ?? 1) {
|
||||
2 => 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 <<<END
|
||||
echo <<<HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Dragon Knight Installation</title>
|
||||
|
@ -44,7 +41,7 @@ function first()
|
|||
</form>
|
||||
</body>
|
||||
</html>
|
||||
END;
|
||||
HTML;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
@ -58,18 +55,18 @@ function second()
|
|||
|
||||
$full = isset($_POST["complete"]);
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE babble (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`posttime` TEXT NOT NULL DEFAULT '00:00:00',
|
||||
`author` TEXT NOT NULL DEFAULT '',
|
||||
`babble` TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Babble Box table created.<br />' : 'Error creating Babble Box table.';
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE control (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`gamename` TEXT NOT NULL DEFAULT '',
|
||||
|
@ -93,7 +90,7 @@ function second()
|
|||
`showbabble` INTEGER NOT NULL DEFAULT 0,
|
||||
`showonline` INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Control table created.<br />' : 'Error creating Control table.';
|
||||
|
||||
|
@ -101,7 +98,7 @@ function second()
|
|||
|
||||
echo $query === true ? 'Control table populated.<br />' : 'Error populating Control table.';
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE drops (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`name` TEXT NOT NULL DEFAULT '',
|
||||
|
@ -110,12 +107,12 @@ function second()
|
|||
`attribute1` TEXT NOT NULL DEFAULT '',
|
||||
`attribute2` TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query == true ? 'Drops table created.<br />' : 'Error creating Drops table.';
|
||||
|
||||
if ($full) {
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO drops VALUES
|
||||
(1, 'Life Pebble', 1, 1, 'maxhp,10', 'X'),
|
||||
(2, 'Life Stone', 10, 1, 'maxhp,25', 'X'),
|
||||
|
@ -149,12 +146,12 @@ function second()
|
|||
(30, 'Diamond', 50, 1, 'defensepower,150', 'X'),
|
||||
(31, 'Memory Drop', 5, 1, 'expbonus,10', 'X'),
|
||||
(32, 'Fortune Drop', 5, 1, 'goldbonus,10', 'X');
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Drops table populated.<br />' : 'Error populating Drops table.';
|
||||
}
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE forum (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`postdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
|
@ -165,11 +162,11 @@ function second()
|
|||
`title` TEXT NOT NULL DEFAULT '',
|
||||
`content` TEXT NOT NULL
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Forum table created.<br />' : 'Error creating Forum table.';
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE items (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`type` INTEGER NOT NULL DEFAULT 0,
|
||||
|
@ -178,12 +175,12 @@ function second()
|
|||
`attribute` INTEGER NOT NULL DEFAULT 0,
|
||||
`special` TEXT NOT NULL DEFAULT ''
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Items table created.<br />' : 'Error creating Items table.';
|
||||
|
||||
if ($full) {
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO items VALUES
|
||||
(1, 1, 'Stick', 10, 2, 'X'),
|
||||
(2, 1, 'Branch', 30, 4, 'X'),
|
||||
|
@ -218,12 +215,12 @@ function second()
|
|||
(31, 3, 'Large Shield', 2500, 30, 'X'),
|
||||
(32, 3, 'Silver Shield', 10000, 60, 'X'),
|
||||
(33, 3, 'Destiny Aegis', 25000, 100, 'maxhp,50');
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Items table populated.<br />' : 'Error populating Items table.';
|
||||
}
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE levels (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`1_exp` INTEGER NOT NULL DEFAULT 0,
|
||||
|
@ -248,12 +245,12 @@ function second()
|
|||
`3_dexterity` INTEGER NOT NULL DEFAULT 0,
|
||||
`3_spells` INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Levels table created.<br />' : 'Error creating Levels table.';
|
||||
|
||||
if ($full) {
|
||||
$query = db()->exec(<<<END
|
||||
$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),
|
||||
(2, 15, 2, 5, 1, 0, 1, 1, 18, 2, 4, 1, 2, 1, 1, 20, 2, 5, 1, 0, 2, 1),
|
||||
|
@ -355,12 +352,12 @@ function second()
|
|||
(98, 7837308, 4, 5, 5, 4, 3, 0, 8492119, 4, 3, 5, 7, 3, 0, 9461106, 4, 4, 5, 4, 4, 0),
|
||||
(99, 7964068, 50, 5, 5, 6, 5, 0, 8627330, 50, 3, 5, 9, 5, 0, 9609488, 50, 4, 5, 6, 6, 0),
|
||||
(100, 16777215, 0, 0, 0, 0, 0, 0, 16777215, 0, 0, 0, 0, 0, 0, 16777215, 0, 0, 0, 0, 0, 0);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Levels table populated.<br />' : 'Error populating Levels table.';
|
||||
}
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE monsters (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`name` TEXT NOT NULL DEFAULT '',
|
||||
|
@ -372,12 +369,12 @@ function second()
|
|||
`maxgold` INTEGER NOT NULL DEFAULT 0,
|
||||
`immune` INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Monsters table created.<br />' : 'Error creating Monsters table.';
|
||||
|
||||
if ($full) {
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO monsters VALUES
|
||||
(1, 'Blue Slime', 4, 3, 1, 1, 1, 1, 0),
|
||||
(2, 'Red Slime', 6, 5, 1, 1, 2, 1, 0),
|
||||
|
@ -530,18 +527,18 @@ function second()
|
|||
(149, 'Titan', 360, 340, 270, 50, 2400, 800, 0),
|
||||
(150, 'Black Daemon', 400, 400, 280, 50, 3000, 1000, 1),
|
||||
(151, 'Lucifuge', 600, 600, 400, 50, 10000, 10000, 2);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Monsters table populated.<br />' : 'Error populating Monsters table.';
|
||||
}
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE news (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`postdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
`content` TEXT NOT NULL
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'News table created.<br />' : 'Error creating News table.';
|
||||
|
||||
|
@ -549,7 +546,7 @@ function second()
|
|||
|
||||
echo $query === true ? 'News table populated.<br />' : 'Error populating News table.';
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE spells (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`name` TEXT NOT NULL,
|
||||
|
@ -557,12 +554,12 @@ function second()
|
|||
`attribute` INTEGER NOT NULL DEFAULT 0,
|
||||
`type` INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Spells table created.<br />' : 'Error creating Spells table.';
|
||||
|
||||
if ($full) {
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO spells VALUES
|
||||
(1, 'Heal', 5, 10, 1),
|
||||
(2, 'Revive', 10, 25, 1),
|
||||
|
@ -583,12 +580,12 @@ function second()
|
|||
(17, 'Ward', 10, 10, 5),
|
||||
(18, 'Fend', 20, 25, 5),
|
||||
(19, 'Barrier', 30, 50, 5);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Spells table populated.<br />' : 'Error populating Spells table.';
|
||||
}
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE towns (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`name` TEXT NOT NULL,
|
||||
|
@ -599,12 +596,12 @@ function second()
|
|||
`travelpoints` INTEGER NOT NULL DEFAULT 0,
|
||||
`itemslist` TEXT NOT NULL
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Towns table created.<br />' : 'Error creating Towns table.';
|
||||
|
||||
if ($full) {
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO towns VALUES
|
||||
(1, 'Midworld', 0, 0, 5, 0, 0, '1,2,3,17,18,19,28,29'),
|
||||
(2, 'Roma', 30, 30, 10, 25, 5, '2,3,4,18,19,29'),
|
||||
|
@ -614,12 +611,12 @@ function second()
|
|||
(6, 'Hambry', 170, 170, 90, 1000, 80, '10,11,12,13,14,23,24,30,31'),
|
||||
(7, 'Gilead', 200, -200, 100, 3000, 110, '12,13,14,15,24,25,26,32'),
|
||||
(8, 'Endworld', -250, -250, 125, 9000, 160, '16,27,33');
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Towns table populated.<br />' : 'Error populating Towns table.';
|
||||
}
|
||||
|
||||
$query = db()->exec(<<<END
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE users (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`username` TEXT NOT NULL,
|
||||
|
@ -672,7 +669,7 @@ function second()
|
|||
`spells` TEXT NOT NULL default '0',
|
||||
`towns` TEXT NOT NULL default '0'
|
||||
);
|
||||
END);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Users table created.<br />' : 'Error creating Users table.';
|
||||
|
||||
|
@ -686,7 +683,7 @@ function second()
|
|||
*/
|
||||
function third()
|
||||
{
|
||||
echo <<<END
|
||||
echo <<<HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Dragon Knight Installation</title>
|
||||
|
@ -708,7 +705,7 @@ function third()
|
|||
</form>
|
||||
</body>
|
||||
</html>
|
||||
END;
|
||||
HTML;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
@ -764,7 +761,7 @@ function fourth()
|
|||
|
||||
file_put_contents('../.installed', date('Y-m-d H:i:s'));
|
||||
|
||||
echo <<<END
|
||||
echo <<<HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Dragon Knight Installation</title>
|
||||
|
@ -782,7 +779,7 @@ function fourth()
|
|||
<a href="install.php?page=5">click here</a>.
|
||||
</body>
|
||||
</html>
|
||||
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 <a href=\"index.php\">the game</a>.');
|
||||
}
|
||||
|
||||
echo <<<END
|
||||
echo <<<HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Dragon Knight Installation</title>
|
||||
|
@ -807,7 +804,7 @@ function fifth()
|
|||
You are now ready to <a href="index.php">play the game</a>. 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.
|
||||
</body>
|
||||
</html>
|
||||
END;
|
||||
HTML;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
|
|
@ -1,42 +1,47 @@
|
|||
<?php // login.php :: Handles logins and cookies.
|
||||
<?php
|
||||
|
||||
include('lib.php');
|
||||
if (isset($_GET["do"])) {
|
||||
if ($_GET["do"] == "login") { login(); }
|
||||
elseif ($_GET["do"] == "logout") { logout(); }
|
||||
// login.php :: Handles logins and cookies.
|
||||
|
||||
if (!file_exists('../.installed')) {
|
||||
header('Location: install.php');
|
||||
exit;
|
||||
}
|
||||
|
||||
function login() {
|
||||
require_once '../src/lib.php';
|
||||
|
||||
include('config.php');
|
||||
$link = opendb();
|
||||
match ($_GET['do'] ?? 'login') {
|
||||
'login' => login(),
|
||||
'logout' => logout()
|
||||
};
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
function login()
|
||||
{
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$u = trim($_POST['username'] ?? '');
|
||||
|
||||
$query = doquery("SELECT * FROM {{table}} WHERE username='".$_POST["username"]."' AND password='".md5($_POST["password"])."' LIMIT 1", "users");
|
||||
if (mysql_num_rows($query) != 1) { die("Invalid username or password. Please go back and try again."); }
|
||||
$row = mysql_fetch_array($query);
|
||||
if (isset($_POST["rememberme"])) { $expiretime = time()+31536000; $rememberme = 1; } else { $expiretime = 0; $rememberme = 0; }
|
||||
$cookie = $row["id"] . " " . $row["username"] . " " . md5($row["password"] . "--" . $dbsettings["secretword"]) . " " . $rememberme;
|
||||
setcookie("dkgame", $cookie, $expiretime, "/", "", 0);
|
||||
$query = db()->query('SELECT * FROM users WHERE username = ? LIMIT 1;', [$u]);
|
||||
if ($query === false) die("Invalid username or password. Please go back and try again.");
|
||||
$row = $query->fetchArray(SQLITE3_ASSOC);
|
||||
if (!password_verify($_POST['password'] ?? '', $row['password'])) die("Invalid username or password. Please go back and try again.");
|
||||
|
||||
$expiretime = isset($_POST["rememberme"]) ? time() + 31536000 : 0;
|
||||
$rememberme = isset($_POST["rememberme"]) ? 1 : 0;
|
||||
$cookie = implode(' ', [$row['id'], $row['username'], $row['password'], $rememberme]);
|
||||
|
||||
set_cookie("dkgame", $cookie, $expiretime);
|
||||
header("Location: index.php");
|
||||
die();
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
$page = gettemplate("login");
|
||||
$title = "Log In";
|
||||
display($page, $title, false, false, false, false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
function logout() {
|
||||
|
||||
setcookie("dkgame", "", time()-100000, "/", "", 0);
|
||||
function logout()
|
||||
{
|
||||
set_cookie("dkgame", "", -3600);
|
||||
header("Location: login.php?do=login");
|
||||
die();
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -2,22 +2,21 @@
|
|||
|
||||
require_once __DIR__ . '/database.php';
|
||||
|
||||
$starttime = getmicrotime();
|
||||
$numqueries = 0;
|
||||
$version = "1.1.11";
|
||||
$build = "";
|
||||
define('VERSION', '1.1.11');
|
||||
define('BUILD', '');
|
||||
define('START', microtime(true));
|
||||
|
||||
/**
|
||||
* Open/get SQLite database connection.
|
||||
* Open or get SQLite database connection.
|
||||
*/
|
||||
function db(): Database
|
||||
{
|
||||
return $GLOBALS['database'] ??= new Database(__DIR__ . '/database.db');
|
||||
return $GLOBALS['database'] ??= new Database(__DIR__ . '/../database.db');
|
||||
}
|
||||
|
||||
function gettemplate($templatename) { // SQL query for the template.
|
||||
|
||||
$filename = "templates/" . $templatename . ".php";
|
||||
$filename = __DIR__ . "/../templates/" . $templatename . ".php";
|
||||
include("$filename");
|
||||
return $template;
|
||||
|
||||
|
@ -71,7 +70,7 @@ function makesafe($d) {
|
|||
|
||||
function admindisplay($content, $title) { // Finalize page and output to browser.
|
||||
|
||||
global $numqueries, $userrow, $controlrow, $starttime, $version, $build;
|
||||
global $userrow, $controlrow;
|
||||
if (!isset($controlrow)) {
|
||||
$query = db()->query('SELECT * FROM control WHERE id=1 LIMIT 1;');
|
||||
$controlrow = $query->fetchArray(SQLITE3_ASSOC);
|
||||
|
@ -80,10 +79,10 @@ function admindisplay($content, $title) { // Finalize page and output to browser
|
|||
$page = parsetemplate(gettemplate("admin"), [
|
||||
"title" => $title,
|
||||
"content" => $content,
|
||||
"totaltime"=>round(getmicrotime() - $starttime, 4),
|
||||
"numqueries"=>$numqueries,
|
||||
"version"=>$version,
|
||||
"build"=>$build
|
||||
"totaltime" => round(getmicrotime() - START, 4),
|
||||
"numqueries" => db()->count,
|
||||
"version" => VERSION,
|
||||
"build" => BUILD
|
||||
]);
|
||||
|
||||
echo "<html>\n" . $page;
|
||||
|
@ -200,10 +199,10 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true,
|
|||
"rightnav" => parsetemplate($rightnav, $userrow),
|
||||
"leftnav" => parsetemplate($leftnav, $userrow),
|
||||
"topnav" => $topnav,
|
||||
"totaltime"=>round(microtime(true) - $starttime, 4),
|
||||
"numqueries"=>$numqueries,
|
||||
"version"=>$version,
|
||||
"build"=>$build
|
||||
"totaltime" => round(getmicrotime() - START, 4),
|
||||
"numqueries" => db()->count,
|
||||
"version" => VERSION,
|
||||
"build" => BUILD
|
||||
]);
|
||||
|
||||
echo "<html>\n" . $page;
|
||||
|
@ -245,3 +244,13 @@ function set_cookie($name, $value, $expires)
|
|||
'samesite' => 'Strict' // Enforce SameSite=Strict
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current control row from the database.
|
||||
*/
|
||||
function get_control_row(): array|false
|
||||
{
|
||||
$query = db()->query('SELECT * FROM control WHERE id = 1 LIMIT 1;');
|
||||
if ($query === false) return false;
|
||||
return $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
|
@ -388,6 +388,3 @@ function travelto($id, $usepoints=true) { // Send a user to a town from the Trav
|
|||
display($page, "Travel To");
|
||||
|
||||
}
|
||||
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user