more refactoring, add src dir, update index logic
This commit is contained in:
parent
ce06aecf84
commit
0511da22fb
297
public/index.php
297
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."); }
|
// index.php :: Primary program script, evil alien overlord, you decide.
|
||||||
include('lib.php');
|
|
||||||
include('cookies.php');
|
if (!file_exists('../.installed')) {
|
||||||
$link = opendb();
|
header('Location: install.php');
|
||||||
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");
|
exit;
|
||||||
$controlrow = mysql_fetch_array($controlquery);
|
}
|
||||||
|
|
||||||
|
require_once '../src/lib.php';
|
||||||
|
|
||||||
|
$controlrow = get_control_row();
|
||||||
|
|
||||||
// Login (or verify) if not logged in.
|
// Login (or verify) if not logged in.
|
||||||
$userrow = checkcookies();
|
if (($userrow = checkcookies()) === false) {
|
||||||
if ($userrow == false) {
|
if (isset($_GET['do']) && $_GET['do'] === 'verify') {
|
||||||
if (isset($_GET["do"])) {
|
header("Location: users.php?do=verify");
|
||||||
if ($_GET["do"] == "verify") { header("Location: users.php?do=verify"); die(); }
|
exit;
|
||||||
}
|
}
|
||||||
header("Location: login.php?do=login"); die();
|
|
||||||
|
header("Location: login.php?do=login");
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close game.
|
// 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.
|
// 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.
|
// 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"])) {
|
require_once '../src/towns.php';
|
||||||
$do = explode(":",$_GET["do"]);
|
require_once '../src/explore.php';
|
||||||
|
require_once '../src/fight.php';
|
||||||
// Town functions.
|
require_once '../src/heal.php';
|
||||||
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;
|
global $userrow;
|
||||||
|
|
||||||
if ($userrow["currentaction"] == "In Town") {
|
if ($userrow["currentaction"] == "In Town") {
|
||||||
|
@ -70,92 +84,108 @@ function donothing() {
|
||||||
$page = dofight();
|
$page = dofight();
|
||||||
$title = "Fighting";
|
$title = "Fighting";
|
||||||
}
|
}
|
||||||
|
|
||||||
display($page, $title);
|
display($page, $title);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function dotown() { // Spit out the main town page.
|
/**
|
||||||
|
* Spit out the main town page.
|
||||||
global $userrow, $controlrow, $numqueries;
|
*/
|
||||||
|
function dotown()
|
||||||
$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"); }
|
global $userrow, $controlrow;
|
||||||
$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.
|
// News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe.
|
||||||
if ($controlrow["shownews"] == 1) {
|
if ($controlrow["shownews"] == 1) {
|
||||||
$newsquery = doquery("SELECT * FROM {{table}} ORDER BY id DESC LIMIT 1", "news");
|
$newsrow = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC);
|
||||||
$newsrow = mysql_fetch_array($newsquery);
|
|
||||||
$townrow["news"] = "<table width=\"95%\"><tr><td class=\"title\">Latest News</td></tr><tr><td>\n";
|
$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"] .= "<span class=\"light\">[".prettydate($newsrow["postdate"])."]</span><br />".nl2br($newsrow["content"]);
|
||||||
$townrow["news"] .= "</td></tr></table>\n";
|
$townrow["news"] .= "</td></tr></table>\n";
|
||||||
} else { $townrow["news"] = ""; }
|
} else {
|
||||||
|
$townrow["news"] = "";
|
||||||
|
}
|
||||||
|
|
||||||
// Who's Online. Currently just members. Guests maybe later.
|
// Who's Online. Currently just members. Guests maybe later.
|
||||||
if ($controlrow["showonline"] == 1) {
|
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"] = "<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: ";
|
$townrow["whosonline"] .= "There are <b>$online_count</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(implode(', ', $online_rows), ', ');
|
||||||
$townrow["whosonline"] = rtrim($townrow["whosonline"], ", ");
|
|
||||||
$townrow["whosonline"] .= "</td></tr></table>\n";
|
$townrow["whosonline"] .= "</td></tr></table>\n";
|
||||||
} else { $townrow["whosonline"] = ""; }
|
} else {
|
||||||
|
$townrow["whosonline"] = "";
|
||||||
|
}
|
||||||
|
|
||||||
if ($controlrow["showbabble"] == 1) {
|
if ($controlrow["showbabble"] == 1) {
|
||||||
$townrow["babblebox"] = "<table width=\"95%\"><tr><td class=\"title\">Babble Box</td></tr><tr><td>\n";
|
$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"] .= "<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";
|
$townrow["babblebox"] .= "</td></tr></table>\n";
|
||||||
} else { $townrow["babblebox"] = ""; }
|
} else {
|
||||||
|
$townrow["babblebox"] = "";
|
||||||
|
}
|
||||||
|
|
||||||
$page = gettemplate("towns");
|
$page = gettemplate("towns");
|
||||||
$page = parsetemplate($page, $townrow);
|
$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
|
|
||||||
<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;
|
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 <<<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>
|
||||||
|
HTML;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirect to fighting.
|
||||||
|
*/
|
||||||
|
function dofight()
|
||||||
|
{
|
||||||
header("Location: index.php?do=fight");
|
header("Location: index.php?do=fight");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showchar() {
|
function showchar()
|
||||||
|
{
|
||||||
global $userrow, $controlrow;
|
global $userrow, $controlrow;
|
||||||
|
|
||||||
// Format various userrow stuffs.
|
// Format various userrow stuffs.
|
||||||
$userrow["experience"] = number_format($userrow["experience"]);
|
$userrow["experience"] = number_format($userrow["experience"]);
|
||||||
$userrow["gold"] = number_format($userrow["gold"]);
|
$userrow["gold"] = number_format($userrow["gold"]);
|
||||||
if ($userrow["expbonus"] > 0) {
|
if ($userrow["expbonus"] > 0) {
|
||||||
$userrow["plusexp"] = "<span class=\"light\">(+".$userrow["expbonus"]."%)</span>";
|
$userrow["plusexp"] = "<span class=\"light\">(+".$userrow["expbonus"]."%)</span>";
|
||||||
} elseif ($userrow["expbonus"] < 0) {
|
} elseif ($userrow["expbonus"] < 0) {
|
||||||
$userrow["plusexp"] = "<span class=\"light\">(".$userrow["expbonus"]."%)</span>";
|
$userrow["plusexp"] = "<span class=\"light\">(".$userrow["expbonus"]."%)</span>";
|
||||||
} else { $userrow["plusexp"] = ""; }
|
} else { $userrow["plusexp"] = ""; }
|
||||||
if ($userrow["goldbonus"] > 0) {
|
if ($userrow["goldbonus"] > 0) {
|
||||||
$userrow["plusgold"] = "<span class=\"light\">(+".$userrow["goldbonus"]."%)</span>";
|
$userrow["plusgold"] = "<span class=\"light\">(+".$userrow["goldbonus"]."%)</span>";
|
||||||
} elseif ($userrow["goldbonus"] < 0) {
|
} elseif ($userrow["goldbonus"] < 0) {
|
||||||
$userrow["plusgold"] = "<span class=\"light\">(".$userrow["goldbonus"]."%)</span>";
|
$userrow["plusgold"] = "<span class=\"light\">(".$userrow["goldbonus"]."%)</span>";
|
||||||
} else { $userrow["plusgold"] = ""; }
|
} else { $userrow["plusgold"] = ""; }
|
||||||
|
|
||||||
$levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels");
|
$levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels");
|
||||||
$levelrow = mysql_fetch_array($levelquery);
|
$levelrow = mysql_fetch_array($levelquery);
|
||||||
if ($userrow["level"] < 99) { $userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]); } else { $userrow["nextlevel"] = "<span class=\"light\">None</span>"; }
|
if ($userrow["level"] < 99) { $userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]); } else { $userrow["nextlevel"] = "<span class=\"light\">None</span>"; }
|
||||||
|
@ -163,11 +193,11 @@ function showchar() {
|
||||||
if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; }
|
if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; }
|
||||||
elseif ($userrow["charclass"] == 2) { $userrow["charclass"] = $controlrow["class2name"]; }
|
elseif ($userrow["charclass"] == 2) { $userrow["charclass"] = $controlrow["class2name"]; }
|
||||||
elseif ($userrow["charclass"] == 3) { $userrow["charclass"] = $controlrow["class3name"]; }
|
elseif ($userrow["charclass"] == 3) { $userrow["charclass"] = $controlrow["class3name"]; }
|
||||||
|
|
||||||
if ($userrow["difficulty"] == 1) { $userrow["difficulty"] = $controlrow["diff1name"]; }
|
if ($userrow["difficulty"] == 1) { $userrow["difficulty"] = $controlrow["diff1name"]; }
|
||||||
elseif ($userrow["difficulty"] == 2) { $userrow["difficulty"] = $controlrow["diff2name"]; }
|
elseif ($userrow["difficulty"] == 2) { $userrow["difficulty"] = $controlrow["diff2name"]; }
|
||||||
elseif ($userrow["difficulty"] == 3) { $userrow["difficulty"] = $controlrow["diff3name"]; }
|
elseif ($userrow["difficulty"] == 3) { $userrow["difficulty"] = $controlrow["diff3name"]; }
|
||||||
|
|
||||||
$spellquery = doquery("SELECT id,name FROM {{table}}","spells");
|
$spellquery = doquery("SELECT id,name FROM {{table}}","spells");
|
||||||
$userspells = explode(",",$userrow["spells"]);
|
$userspells = explode(",",$userrow["spells"]);
|
||||||
$userrow["magiclist"] = "";
|
$userrow["magiclist"] = "";
|
||||||
|
@ -181,40 +211,39 @@ function showchar() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($userrow["magiclist"] == "") { $userrow["magiclist"] = "None"; }
|
if ($userrow["magiclist"] == "") { $userrow["magiclist"] = "None"; }
|
||||||
|
|
||||||
// Make page tags for XHTML validation.
|
// Make page tags for XHTML validation.
|
||||||
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
|
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
|
||||||
. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n"
|
. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n"
|
||||||
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
|
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
|
||||||
|
|
||||||
$charsheet = gettemplate("showchar");
|
$charsheet = gettemplate("showchar");
|
||||||
$page = $xml . gettemplate("minimal");
|
$page = $xml . gettemplate("minimal");
|
||||||
$array = array("content"=>parsetemplate($charsheet, $userrow), "title"=>"Character Information");
|
$array = array("content"=>parsetemplate($charsheet, $userrow), "title"=>"Character Information");
|
||||||
echo parsetemplate($page, $array);
|
echo parsetemplate($page, $array);
|
||||||
die();
|
die();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function onlinechar($id) {
|
function onlinechar($id) {
|
||||||
|
|
||||||
global $controlrow;
|
global $controlrow;
|
||||||
$userquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "users");
|
$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"); }
|
if (mysql_num_rows($userquery) == 1) { $userrow = mysql_fetch_array($userquery); } else { display("No such user.", "Error"); }
|
||||||
|
|
||||||
// Format various userrow stuffs.
|
// Format various userrow stuffs.
|
||||||
$userrow["experience"] = number_format($userrow["experience"]);
|
$userrow["experience"] = number_format($userrow["experience"]);
|
||||||
$userrow["gold"] = number_format($userrow["gold"]);
|
$userrow["gold"] = number_format($userrow["gold"]);
|
||||||
if ($userrow["expbonus"] > 0) {
|
if ($userrow["expbonus"] > 0) {
|
||||||
$userrow["plusexp"] = "<span class=\"light\">(+".$userrow["expbonus"]."%)</span>";
|
$userrow["plusexp"] = "<span class=\"light\">(+".$userrow["expbonus"]."%)</span>";
|
||||||
} elseif ($userrow["expbonus"] < 0) {
|
} elseif ($userrow["expbonus"] < 0) {
|
||||||
$userrow["plusexp"] = "<span class=\"light\">(".$userrow["expbonus"]."%)</span>";
|
$userrow["plusexp"] = "<span class=\"light\">(".$userrow["expbonus"]."%)</span>";
|
||||||
} else { $userrow["plusexp"] = ""; }
|
} else { $userrow["plusexp"] = ""; }
|
||||||
if ($userrow["goldbonus"] > 0) {
|
if ($userrow["goldbonus"] > 0) {
|
||||||
$userrow["plusgold"] = "<span class=\"light\">(+".$userrow["goldbonus"]."%)</span>";
|
$userrow["plusgold"] = "<span class=\"light\">(+".$userrow["goldbonus"]."%)</span>";
|
||||||
} elseif ($userrow["goldbonus"] < 0) {
|
} elseif ($userrow["goldbonus"] < 0) {
|
||||||
$userrow["plusgold"] = "<span class=\"light\">(".$userrow["goldbonus"]."%)</span>";
|
$userrow["plusgold"] = "<span class=\"light\">(".$userrow["goldbonus"]."%)</span>";
|
||||||
} else { $userrow["plusgold"] = ""; }
|
} else { $userrow["plusgold"] = ""; }
|
||||||
|
|
||||||
$levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels");
|
$levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels");
|
||||||
$levelrow = mysql_fetch_array($levelquery);
|
$levelrow = mysql_fetch_array($levelquery);
|
||||||
$userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]);
|
$userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]);
|
||||||
|
@ -222,37 +251,37 @@ function onlinechar($id) {
|
||||||
if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; }
|
if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; }
|
||||||
elseif ($userrow["charclass"] == 2) { $userrow["charclass"] = $controlrow["class2name"]; }
|
elseif ($userrow["charclass"] == 2) { $userrow["charclass"] = $controlrow["class2name"]; }
|
||||||
elseif ($userrow["charclass"] == 3) { $userrow["charclass"] = $controlrow["class3name"]; }
|
elseif ($userrow["charclass"] == 3) { $userrow["charclass"] = $controlrow["class3name"]; }
|
||||||
|
|
||||||
if ($userrow["difficulty"] == 1) { $userrow["difficulty"] = $controlrow["diff1name"]; }
|
if ($userrow["difficulty"] == 1) { $userrow["difficulty"] = $controlrow["diff1name"]; }
|
||||||
elseif ($userrow["difficulty"] == 2) { $userrow["difficulty"] = $controlrow["diff2name"]; }
|
elseif ($userrow["difficulty"] == 2) { $userrow["difficulty"] = $controlrow["diff2name"]; }
|
||||||
elseif ($userrow["difficulty"] == 3) { $userrow["difficulty"] = $controlrow["diff3name"]; }
|
elseif ($userrow["difficulty"] == 3) { $userrow["difficulty"] = $controlrow["diff3name"]; }
|
||||||
|
|
||||||
$charsheet = gettemplate("onlinechar");
|
$charsheet = gettemplate("onlinechar");
|
||||||
$page = parsetemplate($charsheet, $userrow);
|
$page = parsetemplate($charsheet, $userrow);
|
||||||
display($page, "Character Information");
|
display($page, "Character Information");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function showmap() {
|
function showmap() {
|
||||||
|
|
||||||
global $userrow;
|
global $userrow;
|
||||||
|
|
||||||
// Make page tags for XHTML validation.
|
// Make page tags for XHTML validation.
|
||||||
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
|
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
|
||||||
. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n"
|
. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n"
|
||||||
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
|
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
|
||||||
|
|
||||||
$page = $xml . gettemplate("minimal");
|
$page = $xml . gettemplate("minimal");
|
||||||
$array = array("content"=>"<center><img src=\"images/map.gif\" alt=\"Map\" /></center>", "title"=>"Map");
|
$array = array("content"=>"<center><img src=\"images/map.gif\" alt=\"Map\" /></center>", "title"=>"Map");
|
||||||
echo parsetemplate($page, $array);
|
echo parsetemplate($page, $array);
|
||||||
die();
|
die();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function babblebox() {
|
function babblebox() {
|
||||||
|
|
||||||
global $userrow;
|
global $userrow;
|
||||||
|
|
||||||
if (isset($_POST["babble"])) {
|
if (isset($_POST["babble"])) {
|
||||||
$safecontent = makesafe($_POST["babble"]);
|
$safecontent = makesafe($_POST["babble"]);
|
||||||
if ($safecontent == "" || $safecontent == " ") { //blank post. do nothing.
|
if ($safecontent == "" || $safecontent == " ") { //blank post. do nothing.
|
||||||
|
@ -260,17 +289,17 @@ function babblebox() {
|
||||||
header("Location: index.php?do=babblebox");
|
header("Location: index.php?do=babblebox");
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
$babblebox = array("content"=>"");
|
$babblebox = array("content"=>"");
|
||||||
$bg = 1;
|
$bg = 1;
|
||||||
$babblequery = doquery("SELECT * FROM {{table}} ORDER BY id DESC LIMIT 20", "babble");
|
$babblequery = doquery("SELECT * FROM {{table}} ORDER BY id DESC LIMIT 20", "babble");
|
||||||
while ($babblerow = mysql_fetch_array($babblequery)) {
|
while ($babblerow = mysql_fetch_array($babblequery)) {
|
||||||
if ($bg == 1) { $new = "<div style=\"width:98%; background-color:#eeeeee;\">[<b>".$babblerow["author"]."</b>] ".$babblerow["babble"]."</div>\n"; $bg = 2; }
|
if ($bg == 1) { $new = "<div style=\"width:98%; background-color:#eeeeee;\">[<b>".$babblerow["author"]."</b>] ".$babblerow["babble"]."</div>\n"; $bg = 2; }
|
||||||
else { $new = "<div style=\"width:98%; background-color:#ffffff;\">[<b>".$babblerow["author"]."</b>] ".stripslashes($babblerow["babble"])."</div>\n"; $bg = 1; }
|
else { $new = "<div style=\"width:98%; background-color:#ffffff;\">[<b>".$babblerow["author"]."</b>] ".stripslashes($babblerow["babble"])."</div>\n"; $bg = 1; }
|
||||||
$babblebox["content"] = $new . $babblebox["content"];
|
$babblebox["content"] = $new . $babblebox["content"];
|
||||||
}
|
}
|
||||||
$babblebox["content"] .= "<center><form action=\"index.php?do=babblebox\" method=\"post\"><input type=\"text\" name=\"babble\" size=\"15\" maxlength=\"120\" /><br /><input type=\"submit\" name=\"submit\" value=\"Babble\" /> <input type=\"reset\" name=\"reset\" value=\"Clear\" /></form></center>";
|
$babblebox["content"] .= "<center><form action=\"index.php?do=babblebox\" method=\"post\"><input type=\"text\" name=\"babble\" size=\"15\" maxlength=\"120\" /><br /><input type=\"submit\" name=\"submit\" value=\"Babble\" /> <input type=\"reset\" name=\"reset\" value=\"Clear\" /></form></center>";
|
||||||
|
|
||||||
// Make page tags for XHTML validation.
|
// Make page tags for XHTML validation.
|
||||||
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
|
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"
|
||||||
. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n"
|
. "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"DTD/xhtml1-transitional.dtd\">\n"
|
||||||
|
@ -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
|
<?php
|
||||||
|
|
||||||
if (file_exists('../.installed')) {
|
if (file_exists('../.installed')) {
|
||||||
echo 'Game already installed.';
|
header('Location: index.php');
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
require_once '../lib.php';
|
require_once '../src/lib.php';
|
||||||
|
|
||||||
define('START', microtime(true));
|
match ((int) $_GET['page'] ?? 1) {
|
||||||
|
|
||||||
match ((int) $_GET['page'] ?? 0) {
|
|
||||||
2 => second(),
|
2 => second(),
|
||||||
3 => third(),
|
3 => third(),
|
||||||
4 => fourth(),
|
4 => fourth(),
|
||||||
|
@ -17,13 +15,12 @@ match ((int) $_GET['page'] ?? 0) {
|
||||||
default => first(),
|
default => first(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* First page - show warnings and gather info
|
* First page - show warnings and gather info
|
||||||
*/
|
*/
|
||||||
function first()
|
function first()
|
||||||
{
|
{
|
||||||
echo <<<END
|
echo <<<HTML
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Dragon Knight Installation</title>
|
<title>Dragon Knight Installation</title>
|
||||||
|
@ -44,7 +41,7 @@ function first()
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
END;
|
HTML;
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -58,18 +55,18 @@ function second()
|
||||||
|
|
||||||
$full = isset($_POST["complete"]);
|
$full = isset($_POST["complete"]);
|
||||||
|
|
||||||
$query = db()->exec(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE babble (
|
CREATE TABLE babble (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`posttime` TEXT NOT NULL DEFAULT '00:00:00',
|
`posttime` TEXT NOT NULL DEFAULT '00:00:00',
|
||||||
`author` TEXT NOT NULL DEFAULT '',
|
`author` TEXT NOT NULL DEFAULT '',
|
||||||
`babble` TEXT NOT NULL DEFAULT ''
|
`babble` TEXT NOT NULL DEFAULT ''
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query === true ? 'Babble Box table created.<br />' : 'Error creating Babble Box table.';
|
echo $query === true ? 'Babble Box table created.<br />' : 'Error creating Babble Box table.';
|
||||||
|
|
||||||
$query = db()->exec(<<<END
|
$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 '',
|
||||||
|
@ -93,7 +90,7 @@ function second()
|
||||||
`showbabble` INTEGER NOT NULL DEFAULT 0,
|
`showbabble` INTEGER NOT NULL DEFAULT 0,
|
||||||
`showonline` INTEGER NOT NULL DEFAULT 0
|
`showonline` INTEGER NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query === true ? 'Control table created.<br />' : 'Error creating Control table.';
|
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.';
|
echo $query === true ? 'Control table populated.<br />' : 'Error populating Control table.';
|
||||||
|
|
||||||
$query = db()->exec(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE drops (
|
CREATE TABLE drops (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`name` TEXT NOT NULL DEFAULT '',
|
`name` TEXT NOT NULL DEFAULT '',
|
||||||
|
@ -110,12 +107,12 @@ function second()
|
||||||
`attribute1` TEXT NOT NULL DEFAULT '',
|
`attribute1` TEXT NOT NULL DEFAULT '',
|
||||||
`attribute2` TEXT NOT NULL DEFAULT ''
|
`attribute2` TEXT NOT NULL DEFAULT ''
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query == true ? 'Drops table created.<br />' : 'Error creating Drops table.';
|
echo $query == true ? 'Drops table created.<br />' : 'Error creating Drops table.';
|
||||||
|
|
||||||
if ($full) {
|
if ($full) {
|
||||||
$query = db()->exec(<<<END
|
$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'),
|
||||||
(2, 'Life Stone', 10, 1, 'maxhp,25', 'X'),
|
(2, 'Life Stone', 10, 1, 'maxhp,25', 'X'),
|
||||||
|
@ -149,12 +146,12 @@ function second()
|
||||||
(30, 'Diamond', 50, 1, 'defensepower,150', 'X'),
|
(30, 'Diamond', 50, 1, 'defensepower,150', 'X'),
|
||||||
(31, 'Memory Drop', 5, 1, 'expbonus,10', 'X'),
|
(31, 'Memory Drop', 5, 1, 'expbonus,10', 'X'),
|
||||||
(32, 'Fortune Drop', 5, 1, 'goldbonus,10', 'X');
|
(32, 'Fortune Drop', 5, 1, 'goldbonus,10', 'X');
|
||||||
END);
|
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(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE forum (
|
CREATE TABLE forum (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`postdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`postdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
@ -165,11 +162,11 @@ function second()
|
||||||
`title` TEXT NOT NULL DEFAULT '',
|
`title` TEXT NOT NULL DEFAULT '',
|
||||||
`content` TEXT NOT NULL
|
`content` TEXT NOT NULL
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query === true ? 'Forum table created.<br />' : 'Error creating Forum table.';
|
echo $query === true ? 'Forum table created.<br />' : 'Error creating Forum table.';
|
||||||
|
|
||||||
$query = db()->exec(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE items (
|
CREATE TABLE items (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`type` INTEGER NOT NULL DEFAULT 0,
|
`type` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
@ -178,12 +175,12 @@ function second()
|
||||||
`attribute` INTEGER NOT NULL DEFAULT 0,
|
`attribute` INTEGER NOT NULL DEFAULT 0,
|
||||||
`special` TEXT NOT NULL DEFAULT ''
|
`special` TEXT NOT NULL DEFAULT ''
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query === true ? 'Items table created.<br />' : 'Error creating Items table.';
|
echo $query === true ? 'Items table created.<br />' : 'Error creating Items table.';
|
||||||
|
|
||||||
if ($full) {
|
if ($full) {
|
||||||
$query = db()->exec(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
INSERT INTO items VALUES
|
INSERT INTO items VALUES
|
||||||
(1, 1, 'Stick', 10, 2, 'X'),
|
(1, 1, 'Stick', 10, 2, 'X'),
|
||||||
(2, 1, 'Branch', 30, 4, 'X'),
|
(2, 1, 'Branch', 30, 4, 'X'),
|
||||||
|
@ -218,12 +215,12 @@ function second()
|
||||||
(31, 3, 'Large Shield', 2500, 30, 'X'),
|
(31, 3, 'Large Shield', 2500, 30, 'X'),
|
||||||
(32, 3, 'Silver Shield', 10000, 60, 'X'),
|
(32, 3, 'Silver Shield', 10000, 60, 'X'),
|
||||||
(33, 3, 'Destiny Aegis', 25000, 100, 'maxhp,50');
|
(33, 3, 'Destiny Aegis', 25000, 100, 'maxhp,50');
|
||||||
END);
|
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(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE levels (
|
CREATE TABLE levels (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`1_exp` INTEGER NOT NULL DEFAULT 0,
|
`1_exp` INTEGER NOT NULL DEFAULT 0,
|
||||||
|
@ -248,12 +245,12 @@ function second()
|
||||||
`3_dexterity` INTEGER NOT NULL DEFAULT 0,
|
`3_dexterity` INTEGER NOT NULL DEFAULT 0,
|
||||||
`3_spells` 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.';
|
echo $query === true ? 'Levels table created.<br />' : 'Error creating Levels table.';
|
||||||
|
|
||||||
if ($full) {
|
if ($full) {
|
||||||
$query = db()->exec(<<<END
|
$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),
|
||||||
(2, 15, 2, 5, 1, 0, 1, 1, 18, 2, 4, 1, 2, 1, 1, 20, 2, 5, 1, 0, 2, 1),
|
(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),
|
(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),
|
(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);
|
(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.';
|
echo $query === true ? 'Levels table populated.<br />' : 'Error populating Levels table.';
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = db()->exec(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE monsters (
|
CREATE TABLE monsters (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`name` TEXT NOT NULL DEFAULT '',
|
`name` TEXT NOT NULL DEFAULT '',
|
||||||
|
@ -372,12 +369,12 @@ function second()
|
||||||
`maxgold` INTEGER NOT NULL DEFAULT 0,
|
`maxgold` INTEGER NOT NULL DEFAULT 0,
|
||||||
`immune` INTEGER NOT NULL DEFAULT 0
|
`immune` INTEGER NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query === true ? 'Monsters table created.<br />' : 'Error creating Monsters table.';
|
echo $query === true ? 'Monsters table created.<br />' : 'Error creating Monsters table.';
|
||||||
|
|
||||||
if ($full) {
|
if ($full) {
|
||||||
$query = db()->exec(<<<END
|
$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),
|
||||||
(2, 'Red Slime', 6, 5, 1, 1, 2, 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),
|
(149, 'Titan', 360, 340, 270, 50, 2400, 800, 0),
|
||||||
(150, 'Black Daemon', 400, 400, 280, 50, 3000, 1000, 1),
|
(150, 'Black Daemon', 400, 400, 280, 50, 3000, 1000, 1),
|
||||||
(151, 'Lucifuge', 600, 600, 400, 50, 10000, 10000, 2);
|
(151, 'Lucifuge', 600, 600, 400, 50, 10000, 10000, 2);
|
||||||
END);
|
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(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE news (
|
CREATE TABLE news (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`postdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
`postdate` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
`content` TEXT NOT NULL
|
`content` TEXT NOT NULL
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query === true ? 'News table created.<br />' : 'Error creating News table.';
|
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.';
|
echo $query === true ? 'News table populated.<br />' : 'Error populating News table.';
|
||||||
|
|
||||||
$query = db()->exec(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE spells (
|
CREATE TABLE spells (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`name` TEXT NOT NULL,
|
`name` TEXT NOT NULL,
|
||||||
|
@ -557,12 +554,12 @@ function second()
|
||||||
`attribute` INTEGER NOT NULL DEFAULT 0,
|
`attribute` INTEGER NOT NULL DEFAULT 0,
|
||||||
`type` INTEGER NOT NULL DEFAULT 0
|
`type` INTEGER NOT NULL DEFAULT 0
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query === true ? 'Spells table created.<br />' : 'Error creating Spells table.';
|
echo $query === true ? 'Spells table created.<br />' : 'Error creating Spells table.';
|
||||||
|
|
||||||
if ($full) {
|
if ($full) {
|
||||||
$query = db()->exec(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
INSERT INTO spells VALUES
|
INSERT INTO spells VALUES
|
||||||
(1, 'Heal', 5, 10, 1),
|
(1, 'Heal', 5, 10, 1),
|
||||||
(2, 'Revive', 10, 25, 1),
|
(2, 'Revive', 10, 25, 1),
|
||||||
|
@ -583,12 +580,12 @@ function second()
|
||||||
(17, 'Ward', 10, 10, 5),
|
(17, 'Ward', 10, 10, 5),
|
||||||
(18, 'Fend', 20, 25, 5),
|
(18, 'Fend', 20, 25, 5),
|
||||||
(19, 'Barrier', 30, 50, 5);
|
(19, 'Barrier', 30, 50, 5);
|
||||||
END);
|
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(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE towns (
|
CREATE TABLE towns (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`name` TEXT NOT NULL,
|
`name` TEXT NOT NULL,
|
||||||
|
@ -599,12 +596,12 @@ function second()
|
||||||
`travelpoints` INTEGER NOT NULL DEFAULT 0,
|
`travelpoints` INTEGER NOT NULL DEFAULT 0,
|
||||||
`itemslist` TEXT NOT NULL
|
`itemslist` TEXT NOT NULL
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query === true ? 'Towns table created.<br />' : 'Error creating Towns table.';
|
echo $query === true ? 'Towns table created.<br />' : 'Error creating Towns table.';
|
||||||
|
|
||||||
if ($full) {
|
if ($full) {
|
||||||
$query = db()->exec(<<<END
|
$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'),
|
||||||
(2, 'Roma', 30, 30, 10, 25, 5, '2,3,4,18,19,29'),
|
(2, 'Roma', 30, 30, 10, 25, 5, '2,3,4,18,19,29'),
|
||||||
|
@ -614,65 +611,65 @@ function second()
|
||||||
(6, 'Hambry', 170, 170, 90, 1000, 80, '10,11,12,13,14,23,24,30,31'),
|
(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'),
|
(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');
|
(8, 'Endworld', -250, -250, 125, 9000, 160, '16,27,33');
|
||||||
END);
|
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(<<<END
|
$query = db()->exec(<<<SQL
|
||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
`username` TEXT NOT NULL,
|
`username` TEXT NOT NULL,
|
||||||
`password` TEXT NOT NULL,
|
`password` TEXT NOT NULL,
|
||||||
`email` TEXT NOT NULL,
|
`email` TEXT NOT NULL,
|
||||||
`verify` INTEGER NOT NULL default 0,
|
`verify` INTEGER NOT NULL default 0,
|
||||||
`regdate` datetime NOT NULL default CURRENT_TIMESTAMP,
|
`regdate` datetime NOT NULL default CURRENT_TIMESTAMP,
|
||||||
`onlinetime` datetime NOT NULL default CURRENT_TIMESTAMP,
|
`onlinetime` datetime NOT NULL default CURRENT_TIMESTAMP,
|
||||||
`authlevel` INTEGER NOT NULL default 0,
|
`authlevel` INTEGER NOT NULL default 0,
|
||||||
`latitude` INTEGER NOT NULL default 0,
|
`latitude` INTEGER NOT NULL default 0,
|
||||||
`longitude` INTEGER NOT NULL default 0,
|
`longitude` INTEGER NOT NULL default 0,
|
||||||
`difficulty` INTEGER NOT NULL default 0,
|
`difficulty` INTEGER NOT NULL default 0,
|
||||||
`charclass` INTEGER NOT NULL default 0,
|
`charclass` INTEGER NOT NULL default 0,
|
||||||
`currentaction` TEXT NOT NULL default 'In Town',
|
`currentaction` TEXT NOT NULL default 'In Town',
|
||||||
`currentfight` INTEGER NOT NULL default 0,
|
`currentfight` INTEGER NOT NULL default 0,
|
||||||
`currentmonster` INTEGER NOT NULL default 0,
|
`currentmonster` INTEGER NOT NULL default 0,
|
||||||
`currentmonsterhp` INTEGER NOT NULL default 0,
|
`currentmonsterhp` INTEGER NOT NULL default 0,
|
||||||
`currentmonstersleep` INTEGER NOT NULL default 0,
|
`currentmonstersleep` INTEGER NOT NULL default 0,
|
||||||
`currentmonsterimmune` INTEGER NOT NULL default 0,
|
`currentmonsterimmune` INTEGER NOT NULL default 0,
|
||||||
`currentuberdamage` INTEGER NOT NULL default 0,
|
`currentuberdamage` INTEGER NOT NULL default 0,
|
||||||
`currentuberdefense` INTEGER NOT NULL default 0,
|
`currentuberdefense` INTEGER NOT NULL default 0,
|
||||||
`currenthp` INTEGER NOT NULL default 15,
|
`currenthp` INTEGER NOT NULL default 15,
|
||||||
`currentmp` INTEGER NOT NULL default 0,
|
`currentmp` INTEGER NOT NULL default 0,
|
||||||
`currenttp` INTEGER NOT NULL default 10,
|
`currenttp` INTEGER NOT NULL default 10,
|
||||||
`maxhp` INTEGER NOT NULL default 15,
|
`maxhp` INTEGER NOT NULL default 15,
|
||||||
`maxmp` INTEGER NOT NULL default 0,
|
`maxmp` INTEGER NOT NULL default 0,
|
||||||
`maxtp` INTEGER NOT NULL default 10,
|
`maxtp` INTEGER NOT NULL default 10,
|
||||||
`level` INTEGER NOT NULL default 1,
|
`level` INTEGER NOT NULL default 1,
|
||||||
`gold` INTEGER NOT NULL default 100,
|
`gold` INTEGER NOT NULL default 100,
|
||||||
`experience` INTEGER NOT NULL default 0,
|
`experience` INTEGER NOT NULL default 0,
|
||||||
`goldbonus` INTEGER NOT NULL default 0,
|
`goldbonus` INTEGER NOT NULL default 0,
|
||||||
`expbonus` INTEGER NOT NULL default 0,
|
`expbonus` INTEGER NOT NULL default 0,
|
||||||
`strength` INTEGER NOT NULL default 5,
|
`strength` INTEGER NOT NULL default 5,
|
||||||
`dexterity` INTEGER NOT NULL default 5,
|
`dexterity` INTEGER NOT NULL default 5,
|
||||||
`attackpower` INTEGER NOT NULL default 5,
|
`attackpower` INTEGER NOT NULL default 5,
|
||||||
`defensepower` INTEGER NOT NULL default 5,
|
`defensepower` INTEGER NOT NULL default 5,
|
||||||
`weaponid` INTEGER NOT NULL default 0,
|
`weaponid` INTEGER NOT NULL default 0,
|
||||||
`armorid` INTEGER NOT NULL default 0,
|
`armorid` INTEGER NOT NULL default 0,
|
||||||
`shieldid` INTEGER NOT NULL default 0,
|
`shieldid` INTEGER NOT NULL default 0,
|
||||||
`slot1id` INTEGER NOT NULL default 0,
|
`slot1id` INTEGER NOT NULL default 0,
|
||||||
`slot2id` INTEGER NOT NULL default 0,
|
`slot2id` INTEGER NOT NULL default 0,
|
||||||
`slot3id` INTEGER NOT NULL default 0,
|
`slot3id` INTEGER NOT NULL default 0,
|
||||||
`weaponname` TEXT NOT NULL default 'None',
|
`weaponname` TEXT NOT NULL default 'None',
|
||||||
`armorname` TEXT NOT NULL default 'None',
|
`armorname` TEXT NOT NULL default 'None',
|
||||||
`shieldname` TEXT NOT NULL default 'None',
|
`shieldname` TEXT NOT NULL default 'None',
|
||||||
`slot1name` TEXT NOT NULL default 'None',
|
`slot1name` TEXT NOT NULL default 'None',
|
||||||
`slot2name` TEXT NOT NULL default 'None',
|
`slot2name` TEXT NOT NULL default 'None',
|
||||||
`slot3name` TEXT NOT NULL default 'None',
|
`slot3name` TEXT NOT NULL default 'None',
|
||||||
`dropcode` INTEGER NOT NULL default 0,
|
`dropcode` INTEGER NOT NULL default 0,
|
||||||
`spells` TEXT NOT NULL default '0',
|
`spells` TEXT NOT NULL default '0',
|
||||||
`towns` TEXT NOT NULL default '0'
|
`towns` TEXT NOT NULL default '0'
|
||||||
);
|
);
|
||||||
END);
|
SQL);
|
||||||
|
|
||||||
echo $query === true ? 'Users table created.<br />' : 'Error creating Users table.';
|
echo $query === true ? 'Users table created.<br />' : 'Error creating Users table.';
|
||||||
|
|
||||||
|
@ -686,7 +683,7 @@ function second()
|
||||||
*/
|
*/
|
||||||
function third()
|
function third()
|
||||||
{
|
{
|
||||||
echo <<<END
|
echo <<<HTML
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Dragon Knight Installation</title>
|
<title>Dragon Knight Installation</title>
|
||||||
|
@ -708,7 +705,7 @@ function third()
|
||||||
</form>
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
END;
|
HTML;
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -764,7 +761,7 @@ function fourth()
|
||||||
|
|
||||||
file_put_contents('../.installed', date('Y-m-d H:i:s'));
|
file_put_contents('../.installed', date('Y-m-d H:i:s'));
|
||||||
|
|
||||||
echo <<<END
|
echo <<<HTML
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Dragon Knight Installation</title>
|
<title>Dragon Knight Installation</title>
|
||||||
|
@ -782,7 +779,7 @@ function fourth()
|
||||||
<a href="install.php?page=5">click here</a>.
|
<a href="install.php?page=5">click here</a>.
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
END;
|
HTML;
|
||||||
|
|
||||||
exit;
|
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>.');
|
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>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Dragon Knight Installation</title>
|
<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.
|
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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
END;
|
HTML;
|
||||||
|
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,42 +1,47 @@
|
||||||
<?php // login.php :: Handles logins and cookies.
|
<?php
|
||||||
|
|
||||||
include('lib.php');
|
// login.php :: Handles logins and cookies.
|
||||||
if (isset($_GET["do"])) {
|
|
||||||
if ($_GET["do"] == "login") { login(); }
|
if (!file_exists('../.installed')) {
|
||||||
elseif ($_GET["do"] == "logout") { logout(); }
|
header('Location: install.php');
|
||||||
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
function login() {
|
require_once '../src/lib.php';
|
||||||
|
|
||||||
include('config.php');
|
match ($_GET['do'] ?? 'login') {
|
||||||
$link = opendb();
|
'login' => login(),
|
||||||
|
'logout' => logout()
|
||||||
if (isset($_POST["submit"])) {
|
};
|
||||||
|
|
||||||
$query = doquery("SELECT * FROM {{table}} WHERE username='".$_POST["username"]."' AND password='".md5($_POST["password"])."' LIMIT 1", "users");
|
function login()
|
||||||
if (mysql_num_rows($query) != 1) { die("Invalid username or password. Please go back and try again."); }
|
{
|
||||||
$row = mysql_fetch_array($query);
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
if (isset($_POST["rememberme"])) { $expiretime = time()+31536000; $rememberme = 1; } else { $expiretime = 0; $rememberme = 0; }
|
$u = trim($_POST['username'] ?? '');
|
||||||
$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");
|
header("Location: index.php");
|
||||||
die();
|
exit;
|
||||||
|
}
|
||||||
}
|
|
||||||
|
|
||||||
$page = gettemplate("login");
|
$page = gettemplate("login");
|
||||||
$title = "Log In";
|
$title = "Log In";
|
||||||
display($page, $title, false, false, false, false);
|
display($page, $title, false, false, false, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function logout() {
|
|
||||||
|
function logout()
|
||||||
setcookie("dkgame", "", time()-100000, "/", "", 0);
|
{
|
||||||
|
set_cookie("dkgame", "", -3600);
|
||||||
header("Location: login.php?do=login");
|
header("Location: login.php?do=login");
|
||||||
die();
|
die();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
|
@ -2,22 +2,21 @@
|
||||||
|
|
||||||
require_once __DIR__ . '/database.php';
|
require_once __DIR__ . '/database.php';
|
||||||
|
|
||||||
$starttime = getmicrotime();
|
define('VERSION', '1.1.11');
|
||||||
$numqueries = 0;
|
define('BUILD', '');
|
||||||
$version = "1.1.11";
|
define('START', microtime(true));
|
||||||
$build = "";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open/get SQLite database connection.
|
* Open or get SQLite database connection.
|
||||||
*/
|
*/
|
||||||
function db(): Database
|
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.
|
function gettemplate($templatename) { // SQL query for the template.
|
||||||
|
|
||||||
$filename = "templates/" . $templatename . ".php";
|
$filename = __DIR__ . "/../templates/" . $templatename . ".php";
|
||||||
include("$filename");
|
include("$filename");
|
||||||
return $template;
|
return $template;
|
||||||
|
|
||||||
|
@ -71,19 +70,19 @@ function makesafe($d) {
|
||||||
|
|
||||||
function admindisplay($content, $title) { // Finalize page and output to browser.
|
function admindisplay($content, $title) { // Finalize page and output to browser.
|
||||||
|
|
||||||
global $numqueries, $userrow, $controlrow, $starttime, $version, $build;
|
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;');
|
||||||
$controlrow = $query->fetchArray(SQLITE3_ASSOC);
|
$controlrow = $query->fetchArray(SQLITE3_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = parsetemplate(gettemplate("admin"), [
|
$page = parsetemplate(gettemplate("admin"), [
|
||||||
"title"=>$title,
|
"title" => $title,
|
||||||
"content"=>$content,
|
"content" => $content,
|
||||||
"totaltime"=>round(getmicrotime() - $starttime, 4),
|
"totaltime" => round(getmicrotime() - START, 4),
|
||||||
"numqueries"=>$numqueries,
|
"numqueries" => db()->count,
|
||||||
"version"=>$version,
|
"version" => VERSION,
|
||||||
"build"=>$build
|
"build" => BUILD
|
||||||
]);
|
]);
|
||||||
|
|
||||||
echo "<html>\n" . $page;
|
echo "<html>\n" . $page;
|
||||||
|
@ -194,16 +193,16 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true,
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = parsetemplate(gettemplate("primary"), [
|
$page = parsetemplate(gettemplate("primary"), [
|
||||||
"dkgamename"=>$controlrow["gamename"],
|
"dkgamename" => $controlrow["gamename"],
|
||||||
"title"=>$title,
|
"title" => $title,
|
||||||
"content"=>$content,
|
"content" => $content,
|
||||||
"rightnav"=>parsetemplate($rightnav,$userrow),
|
"rightnav" => parsetemplate($rightnav, $userrow),
|
||||||
"leftnav"=>parsetemplate($leftnav,$userrow),
|
"leftnav" => parsetemplate($leftnav, $userrow),
|
||||||
"topnav"=>$topnav,
|
"topnav" => $topnav,
|
||||||
"totaltime"=>round(microtime(true) - $starttime, 4),
|
"totaltime" => round(getmicrotime() - START, 4),
|
||||||
"numqueries"=>$numqueries,
|
"numqueries" => db()->count,
|
||||||
"version"=>$version,
|
"version" => VERSION,
|
||||||
"build"=>$build
|
"build" => BUILD
|
||||||
]);
|
]);
|
||||||
|
|
||||||
echo "<html>\n" . $page;
|
echo "<html>\n" . $page;
|
||||||
|
@ -245,3 +244,13 @@ function set_cookie($name, $value, $expires)
|
||||||
'samesite' => 'Strict' // Enforce SameSite=Strict
|
'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);
|
||||||
|
}
|
|
@ -1,56 +1,56 @@
|
||||||
<?php // towns.php :: Handles all actions you can do in town.
|
<?php // towns.php :: Handles all actions you can do in town.
|
||||||
|
|
||||||
function inn() { // Staying at the inn resets all expendable stats to their max values.
|
function inn() { // Staying at the inn resets all expendable stats to their max values.
|
||||||
|
|
||||||
global $userrow, $numqueries;
|
global $userrow, $numqueries;
|
||||||
|
|
||||||
$townquery = doquery("SELECT name,innprice FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
|
$townquery = doquery("SELECT name,innprice FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
|
||||||
if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
||||||
$townrow = mysql_fetch_array($townquery);
|
$townrow = mysql_fetch_array($townquery);
|
||||||
|
|
||||||
if ($userrow["gold"] < $townrow["innprice"]) { display("You do not have enough gold to stay at this Inn tonight.<br /><br />You may return to <a href=\"index.php\">town</a>, or use the direction buttons on the left to start exploring.", "Inn"); die(); }
|
if ($userrow["gold"] < $townrow["innprice"]) { display("You do not have enough gold to stay at this Inn tonight.<br /><br />You may return to <a href=\"index.php\">town</a>, or use the direction buttons on the left to start exploring.", "Inn"); die(); }
|
||||||
|
|
||||||
if (isset($_POST["submit"])) {
|
if (isset($_POST["submit"])) {
|
||||||
|
|
||||||
$newgold = $userrow["gold"] - $townrow["innprice"];
|
$newgold = $userrow["gold"] - $townrow["innprice"];
|
||||||
$query = doquery("UPDATE {{table}} SET gold='$newgold',currenthp='".$userrow["maxhp"]."',currentmp='".$userrow["maxmp"]."',currenttp='".$userrow["maxtp"]."' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
|
$query = doquery("UPDATE {{table}} SET gold='$newgold',currenthp='".$userrow["maxhp"]."',currentmp='".$userrow["maxmp"]."',currenttp='".$userrow["maxtp"]."' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
|
||||||
$title = "Inn";
|
$title = "Inn";
|
||||||
$page = "You wake up feeling refreshed and ready for action.<br /><br />You may return to <a href=\"index.php\">town</a>, or use the direction buttons on the left to start exploring.";
|
$page = "You wake up feeling refreshed and ready for action.<br /><br />You may return to <a href=\"index.php\">town</a>, or use the direction buttons on the left to start exploring.";
|
||||||
|
|
||||||
} elseif (isset($_POST["cancel"])) {
|
} elseif (isset($_POST["cancel"])) {
|
||||||
|
|
||||||
header("Location: index.php"); die();
|
header("Location: index.php"); die();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
$title = "Inn";
|
$title = "Inn";
|
||||||
$page = "Resting at the inn will refill your current HP, MP, and TP to their maximum levels.<br /><br />\n";
|
$page = "Resting at the inn will refill your current HP, MP, and TP to their maximum levels.<br /><br />\n";
|
||||||
$page .= "A night's sleep at this Inn will cost you <b>" . $townrow["innprice"] . " gold</b>. Is that ok?<br /><br />\n";
|
$page .= "A night's sleep at this Inn will cost you <b>" . $townrow["innprice"] . " gold</b>. Is that ok?<br /><br />\n";
|
||||||
$page .= "<form action=\"index.php?do=inn\" method=\"post\">\n";
|
$page .= "<form action=\"index.php?do=inn\" method=\"post\">\n";
|
||||||
$page .= "<input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" />\n";
|
$page .= "<input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" />\n";
|
||||||
$page .= "</form>\n";
|
$page .= "</form>\n";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
display($page, $title);
|
display($page, $title);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function buy() { // Displays a list of available items for purchase.
|
function buy() { // Displays a list of available items for purchase.
|
||||||
|
|
||||||
global $userrow, $numqueries;
|
global $userrow, $numqueries;
|
||||||
|
|
||||||
$townquery = doquery("SELECT name,itemslist FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
|
$townquery = doquery("SELECT name,itemslist FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
|
||||||
if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
||||||
$townrow = mysql_fetch_array($townquery);
|
$townrow = mysql_fetch_array($townquery);
|
||||||
|
|
||||||
$itemslist = explode(",",$townrow["itemslist"]);
|
$itemslist = explode(",",$townrow["itemslist"]);
|
||||||
$querystring = "";
|
$querystring = "";
|
||||||
foreach($itemslist as $a=>$b) {
|
foreach($itemslist as $a=>$b) {
|
||||||
$querystring .= "id='$b' OR ";
|
$querystring .= "id='$b' OR ";
|
||||||
}
|
}
|
||||||
$querystring = rtrim($querystring, " OR ");
|
$querystring = rtrim($querystring, " OR ");
|
||||||
|
|
||||||
$itemsquery = doquery("SELECT * FROM {{table}} WHERE $querystring ORDER BY id", "items");
|
$itemsquery = doquery("SELECT * FROM {{table}} WHERE $querystring ORDER BY id", "items");
|
||||||
$page = "Buying weapons will increase your Attack Power. Buying armor and shields will increase your Defense Power.<br /><br />Click an item name to purchase it.<br /><br />The following items are available at this town:<br /><br />\n";
|
$page = "Buying weapons will increase your Attack Power. Buying armor and shields will increase your Defense Power.<br /><br />Click an item name to purchase it.<br /><br />The following items are available at this town:<br /><br />\n";
|
||||||
$page .= "<table width=\"80%\">\n";
|
$page .= "<table width=\"80%\">\n";
|
||||||
|
@ -70,28 +70,28 @@ function buy() { // Displays a list of available items for purchase.
|
||||||
$page .= "</table><br />\n";
|
$page .= "</table><br />\n";
|
||||||
$page .= "If you've changed your mind, you may also return back to <a href=\"index.php\">town</a>.\n";
|
$page .= "If you've changed your mind, you may also return back to <a href=\"index.php\">town</a>.\n";
|
||||||
$title = "Buy Items";
|
$title = "Buy Items";
|
||||||
|
|
||||||
display($page, $title);
|
display($page, $title);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function buy2($id) { // Confirm user's intent to purchase item.
|
function buy2($id) { // Confirm user's intent to purchase item.
|
||||||
|
|
||||||
global $userrow, $numqueries;
|
global $userrow, $numqueries;
|
||||||
|
|
||||||
$townquery = doquery("SELECT name,itemslist FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
|
$townquery = doquery("SELECT name,itemslist FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
|
||||||
if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
||||||
$townrow = mysql_fetch_array($townquery);
|
$townrow = mysql_fetch_array($townquery);
|
||||||
$townitems = explode(",",$townrow["itemslist"]);
|
$townitems = explode(",",$townrow["itemslist"]);
|
||||||
if (! in_array($id, $townitems)) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
if (! in_array($id, $townitems)) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
||||||
|
|
||||||
$itemsquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "items");
|
$itemsquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "items");
|
||||||
$itemsrow = mysql_fetch_array($itemsquery);
|
$itemsrow = mysql_fetch_array($itemsquery);
|
||||||
|
|
||||||
if ($userrow["gold"] < $itemsrow["buycost"]) { display("You do not have enough gold to buy this item.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=buy\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Items"); die(); }
|
if ($userrow["gold"] < $itemsrow["buycost"]) { display("You do not have enough gold to buy this item.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=buy\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Items"); die(); }
|
||||||
|
|
||||||
if ($itemsrow["type"] == 1) {
|
if ($itemsrow["type"] == 1) {
|
||||||
if ($userrow["weaponid"] != 0) {
|
if ($userrow["weaponid"] != 0) {
|
||||||
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["weaponid"]."' LIMIT 1", "items");
|
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["weaponid"]."' LIMIT 1", "items");
|
||||||
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
||||||
$page = "If you are buying the ".$itemsrow["name"].", then I will buy your ".$itemsrow2["name"]." for ".ceil($itemsrow2["buycost"]/2)." gold. Is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
$page = "If you are buying the ".$itemsrow["name"].", then I will buy your ".$itemsrow2["name"]." for ".ceil($itemsrow2["buycost"]/2)." gold. Is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||||
|
@ -99,7 +99,7 @@ function buy2($id) { // Confirm user's intent to purchase item.
|
||||||
$page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
$page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||||
}
|
}
|
||||||
} elseif ($itemsrow["type"] == 2) {
|
} elseif ($itemsrow["type"] == 2) {
|
||||||
if ($userrow["armorid"] != 0) {
|
if ($userrow["armorid"] != 0) {
|
||||||
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["armorid"]."' LIMIT 1", "items");
|
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["armorid"]."' LIMIT 1", "items");
|
||||||
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
||||||
$page = "If you are buying the ".$itemsrow["name"].", then I will buy your ".$itemsrow2["name"]." for ".ceil($itemsrow2["buycost"]/2)." gold. Is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
$page = "If you are buying the ".$itemsrow["name"].", then I will buy your ".$itemsrow2["name"]." for ".ceil($itemsrow2["buycost"]/2)." gold. Is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||||
|
@ -107,7 +107,7 @@ function buy2($id) { // Confirm user's intent to purchase item.
|
||||||
$page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
$page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||||
}
|
}
|
||||||
} elseif ($itemsrow["type"] == 3) {
|
} elseif ($itemsrow["type"] == 3) {
|
||||||
if ($userrow["shieldid"] != 0) {
|
if ($userrow["shieldid"] != 0) {
|
||||||
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["shieldid"]."' LIMIT 1", "items");
|
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["shieldid"]."' LIMIT 1", "items");
|
||||||
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
||||||
$page = "If you are buying the ".$itemsrow["name"].", then I will buy your ".$itemsrow2["name"]." for ".ceil($itemsrow2["buycost"]/2)." gold. Is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
$page = "If you are buying the ".$itemsrow["name"].", then I will buy your ".$itemsrow2["name"]." for ".ceil($itemsrow2["buycost"]/2)." gold. Is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||||
|
@ -115,39 +115,39 @@ function buy2($id) { // Confirm user's intent to purchase item.
|
||||||
$page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
$page = "You are buying the ".$itemsrow["name"].", is that ok?<br /><br /><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$title = "Buy Items";
|
$title = "Buy Items";
|
||||||
display($page, $title);
|
display($page, $title);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function buy3($id) { // Update user profile with new item & stats.
|
function buy3($id) { // Update user profile with new item & stats.
|
||||||
|
|
||||||
if (isset($_POST["cancel"])) { header("Location: index.php"); die(); }
|
if (isset($_POST["cancel"])) { header("Location: index.php"); die(); }
|
||||||
|
|
||||||
global $userrow;
|
global $userrow;
|
||||||
|
|
||||||
$townquery = doquery("SELECT name,itemslist FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
|
$townquery = doquery("SELECT name,itemslist FROM {{table}} WHERE latitude='".$userrow["latitude"]."' AND longitude='".$userrow["longitude"]."' LIMIT 1", "towns");
|
||||||
if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
if (mysql_num_rows($townquery) != 1) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
||||||
$townrow = mysql_fetch_array($townquery);
|
$townrow = mysql_fetch_array($townquery);
|
||||||
$townitems = explode(",",$townrow["itemslist"]);
|
$townitems = explode(",",$townrow["itemslist"]);
|
||||||
if (! in_array($id, $townitems)) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
if (! in_array($id, $townitems)) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
||||||
|
|
||||||
$itemsquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "items");
|
$itemsquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "items");
|
||||||
$itemsrow = mysql_fetch_array($itemsquery);
|
$itemsrow = mysql_fetch_array($itemsquery);
|
||||||
|
|
||||||
if ($userrow["gold"] < $itemsrow["buycost"]) { display("You do not have enough gold to buy this item.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=buy\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Items"); die(); }
|
if ($userrow["gold"] < $itemsrow["buycost"]) { display("You do not have enough gold to buy this item.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=buy\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Items"); die(); }
|
||||||
|
|
||||||
if ($itemsrow["type"] == 1) { // weapon
|
if ($itemsrow["type"] == 1) { // weapon
|
||||||
|
|
||||||
// Check if they already have an item in the slot.
|
// Check if they already have an item in the slot.
|
||||||
if ($userrow["weaponid"] != 0) {
|
if ($userrow["weaponid"] != 0) {
|
||||||
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["weaponid"]."' LIMIT 1", "items");
|
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["weaponid"]."' LIMIT 1", "items");
|
||||||
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
||||||
} else {
|
} else {
|
||||||
$itemsrow2 = array("attribute"=>0,"buycost"=>0,"special"=>"X");
|
$itemsrow2 = array("attribute"=>0,"buycost"=>0,"special"=>"X");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special item fields.
|
// Special item fields.
|
||||||
$specialchange1 = "";
|
$specialchange1 = "";
|
||||||
$specialchange2 = "";
|
$specialchange2 = "";
|
||||||
|
@ -167,7 +167,7 @@ function buy3($id) { // Update user profile with new item & stats.
|
||||||
if ($tochange2 == "strength") { $userrow["attackpower"] -= $special2[1]; }
|
if ($tochange2 == "strength") { $userrow["attackpower"] -= $special2[1]; }
|
||||||
if ($tochange2 == "dexterity") { $userrow["defensepower"] -= $special2[1]; }
|
if ($tochange2 == "dexterity") { $userrow["defensepower"] -= $special2[1]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// New stats.
|
// New stats.
|
||||||
$newgold = $userrow["gold"] + ceil($itemsrow2["buycost"]/2) - $itemsrow["buycost"];
|
$newgold = $userrow["gold"] + ceil($itemsrow2["buycost"]/2) - $itemsrow["buycost"];
|
||||||
$newattack = $userrow["attackpower"] + $itemsrow["attribute"] - $itemsrow2["attribute"];
|
$newattack = $userrow["attackpower"] + $itemsrow["attribute"] - $itemsrow2["attribute"];
|
||||||
|
@ -177,20 +177,20 @@ function buy3($id) { // Update user profile with new item & stats.
|
||||||
if ($userrow["currenthp"] > $userrow["maxhp"]) { $newhp = $userrow["maxhp"]; } else { $newhp = $userrow["currenthp"]; }
|
if ($userrow["currenthp"] > $userrow["maxhp"]) { $newhp = $userrow["maxhp"]; } else { $newhp = $userrow["currenthp"]; }
|
||||||
if ($userrow["currentmp"] > $userrow["maxmp"]) { $newmp = $userrow["maxmp"]; } else { $newmp = $userrow["currentmp"]; }
|
if ($userrow["currentmp"] > $userrow["maxmp"]) { $newmp = $userrow["maxmp"]; } else { $newmp = $userrow["currentmp"]; }
|
||||||
if ($userrow["currenttp"] > $userrow["maxtp"]) { $newtp = $userrow["maxtp"]; } else { $newtp = $userrow["currenttp"]; }
|
if ($userrow["currenttp"] > $userrow["maxtp"]) { $newtp = $userrow["maxtp"]; } else { $newtp = $userrow["currenttp"]; }
|
||||||
|
|
||||||
// Final update.
|
// Final update.
|
||||||
$updatequery = doquery("UPDATE {{table}} SET $specialchange1 $specialchange2 gold='$newgold', attackpower='$newattack', weaponid='$newid', weaponname='$newname', currenthp='$newhp', currentmp='$newmp', currenttp='$newtp' WHERE id='$userid' LIMIT 1", "users");
|
$updatequery = doquery("UPDATE {{table}} SET $specialchange1 $specialchange2 gold='$newgold', attackpower='$newattack', weaponid='$newid', weaponname='$newname', currenthp='$newhp', currentmp='$newmp', currenttp='$newtp' WHERE id='$userid' LIMIT 1", "users");
|
||||||
|
|
||||||
} elseif ($itemsrow["type"] == 2) { // Armor
|
} elseif ($itemsrow["type"] == 2) { // Armor
|
||||||
|
|
||||||
// Check if they already have an item in the slot.
|
// Check if they already have an item in the slot.
|
||||||
if ($userrow["armorid"] != 0) {
|
if ($userrow["armorid"] != 0) {
|
||||||
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["armorid"]."' LIMIT 1", "items");
|
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["armorid"]."' LIMIT 1", "items");
|
||||||
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
||||||
} else {
|
} else {
|
||||||
$itemsrow2 = array("attribute"=>0,"buycost"=>0,"special"=>"X");
|
$itemsrow2 = array("attribute"=>0,"buycost"=>0,"special"=>"X");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special item fields.
|
// Special item fields.
|
||||||
$specialchange1 = "";
|
$specialchange1 = "";
|
||||||
$specialchange2 = "";
|
$specialchange2 = "";
|
||||||
|
@ -210,7 +210,7 @@ function buy3($id) { // Update user profile with new item & stats.
|
||||||
if ($tochange2 == "strength") { $userrow["attackpower"] -= $special2[1]; }
|
if ($tochange2 == "strength") { $userrow["attackpower"] -= $special2[1]; }
|
||||||
if ($tochange2 == "dexterity") { $userrow["defensepower"] -= $special2[1]; }
|
if ($tochange2 == "dexterity") { $userrow["defensepower"] -= $special2[1]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// New stats.
|
// New stats.
|
||||||
$newgold = $userrow["gold"] + ceil($itemsrow2["buycost"]/2) - $itemsrow["buycost"];
|
$newgold = $userrow["gold"] + ceil($itemsrow2["buycost"]/2) - $itemsrow["buycost"];
|
||||||
$newdefense = $userrow["defensepower"] + $itemsrow["attribute"] - $itemsrow2["attribute"];
|
$newdefense = $userrow["defensepower"] + $itemsrow["attribute"] - $itemsrow2["attribute"];
|
||||||
|
@ -220,20 +220,20 @@ function buy3($id) { // Update user profile with new item & stats.
|
||||||
if ($userrow["currenthp"] > $userrow["maxhp"]) { $newhp = $userrow["maxhp"]; } else { $newhp = $userrow["currenthp"]; }
|
if ($userrow["currenthp"] > $userrow["maxhp"]) { $newhp = $userrow["maxhp"]; } else { $newhp = $userrow["currenthp"]; }
|
||||||
if ($userrow["currentmp"] > $userrow["maxmp"]) { $newmp = $userrow["maxmp"]; } else { $newmp = $userrow["currentmp"]; }
|
if ($userrow["currentmp"] > $userrow["maxmp"]) { $newmp = $userrow["maxmp"]; } else { $newmp = $userrow["currentmp"]; }
|
||||||
if ($userrow["currenttp"] > $userrow["maxtp"]) { $newtp = $userrow["maxtp"]; } else { $newtp = $userrow["currenttp"]; }
|
if ($userrow["currenttp"] > $userrow["maxtp"]) { $newtp = $userrow["maxtp"]; } else { $newtp = $userrow["currenttp"]; }
|
||||||
|
|
||||||
// Final update.
|
// Final update.
|
||||||
$updatequery = doquery("UPDATE {{table}} SET $specialchange1 $specialchange2 gold='$newgold', defensepower='$newdefense', armorid='$newid', armorname='$newname', currenthp='$newhp', currentmp='$newmp', currenttp='$newtp' WHERE id='$userid' LIMIT 1", "users");
|
$updatequery = doquery("UPDATE {{table}} SET $specialchange1 $specialchange2 gold='$newgold', defensepower='$newdefense', armorid='$newid', armorname='$newname', currenthp='$newhp', currentmp='$newmp', currenttp='$newtp' WHERE id='$userid' LIMIT 1", "users");
|
||||||
|
|
||||||
} elseif ($itemsrow["type"] == 3) { // Shield
|
} elseif ($itemsrow["type"] == 3) { // Shield
|
||||||
|
|
||||||
// Check if they already have an item in the slot.
|
// Check if they already have an item in the slot.
|
||||||
if ($userrow["shieldid"] != 0) {
|
if ($userrow["shieldid"] != 0) {
|
||||||
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["shieldid"]."' LIMIT 1", "items");
|
$itemsquery2 = doquery("SELECT * FROM {{table}} WHERE id='".$userrow["shieldid"]."' LIMIT 1", "items");
|
||||||
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
$itemsrow2 = mysql_fetch_array($itemsquery2);
|
||||||
} else {
|
} else {
|
||||||
$itemsrow2 = array("attribute"=>0,"buycost"=>0,"special"=>"X");
|
$itemsrow2 = array("attribute"=>0,"buycost"=>0,"special"=>"X");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Special item fields.
|
// Special item fields.
|
||||||
$specialchange1 = "";
|
$specialchange1 = "";
|
||||||
$specialchange2 = "";
|
$specialchange2 = "";
|
||||||
|
@ -253,7 +253,7 @@ function buy3($id) { // Update user profile with new item & stats.
|
||||||
if ($tochange2 == "strength") { $userrow["attackpower"] -= $special2[1]; }
|
if ($tochange2 == "strength") { $userrow["attackpower"] -= $special2[1]; }
|
||||||
if ($tochange2 == "dexterity") { $userrow["defensepower"] -= $special2[1]; }
|
if ($tochange2 == "dexterity") { $userrow["defensepower"] -= $special2[1]; }
|
||||||
}
|
}
|
||||||
|
|
||||||
// New stats.
|
// New stats.
|
||||||
$newgold = $userrow["gold"] + ceil($itemsrow2["buycost"]/2) - $itemsrow["buycost"];
|
$newgold = $userrow["gold"] + ceil($itemsrow2["buycost"]/2) - $itemsrow["buycost"];
|
||||||
$newdefense = $userrow["defensepower"] + $itemsrow["attribute"] - $itemsrow2["attribute"];
|
$newdefense = $userrow["defensepower"] + $itemsrow["attribute"] - $itemsrow2["attribute"];
|
||||||
|
@ -263,32 +263,32 @@ function buy3($id) { // Update user profile with new item & stats.
|
||||||
if ($userrow["currenthp"] > $userrow["maxhp"]) { $newhp = $userrow["maxhp"]; } else { $newhp = $userrow["currenthp"]; }
|
if ($userrow["currenthp"] > $userrow["maxhp"]) { $newhp = $userrow["maxhp"]; } else { $newhp = $userrow["currenthp"]; }
|
||||||
if ($userrow["currentmp"] > $userrow["maxmp"]) { $newmp = $userrow["maxmp"]; } else { $newmp = $userrow["currentmp"]; }
|
if ($userrow["currentmp"] > $userrow["maxmp"]) { $newmp = $userrow["maxmp"]; } else { $newmp = $userrow["currentmp"]; }
|
||||||
if ($userrow["currenttp"] > $userrow["maxtp"]) { $newtp = $userrow["maxtp"]; } else { $newtp = $userrow["currenttp"]; }
|
if ($userrow["currenttp"] > $userrow["maxtp"]) { $newtp = $userrow["maxtp"]; } else { $newtp = $userrow["currenttp"]; }
|
||||||
|
|
||||||
// Final update.
|
// Final update.
|
||||||
$updatequery = doquery("UPDATE {{table}} SET $specialchange1 $specialchange2 gold='$newgold', defensepower='$newdefense', shieldid='$newid', shieldname='$newname', currenthp='$newhp', currentmp='$newmp', currenttp='$newtp' WHERE id='$userid' LIMIT 1", "users");
|
$updatequery = doquery("UPDATE {{table}} SET $specialchange1 $specialchange2 gold='$newgold', defensepower='$newdefense', shieldid='$newid', shieldname='$newname', currenthp='$newhp', currentmp='$newmp', currenttp='$newtp' WHERE id='$userid' LIMIT 1", "users");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
display("Thank you for purchasing this item.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=buy\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Items");
|
display("Thank you for purchasing this item.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=buy\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Items");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function maps() { // List maps the user can buy.
|
function maps() { // List maps the user can buy.
|
||||||
|
|
||||||
global $userrow, $numqueries;
|
global $userrow, $numqueries;
|
||||||
|
|
||||||
$mappedtowns = explode(",",$userrow["towns"]);
|
$mappedtowns = explode(",",$userrow["towns"]);
|
||||||
|
|
||||||
$page = "Buying maps will put the town in your Travel To box, and it won't cost you as many TP to get there.<br /><br />\n";
|
$page = "Buying maps will put the town in your Travel To box, and it won't cost you as many TP to get there.<br /><br />\n";
|
||||||
$page .= "Click a town name to purchase its map.<br /><br />\n";
|
$page .= "Click a town name to purchase its map.<br /><br />\n";
|
||||||
$page .= "<table width=\"90%\">\n";
|
$page .= "<table width=\"90%\">\n";
|
||||||
|
|
||||||
$townquery = doquery("SELECT * FROM {{table}} ORDER BY id", "towns");
|
$townquery = doquery("SELECT * FROM {{table}} ORDER BY id", "towns");
|
||||||
while ($townrow = mysql_fetch_array($townquery)) {
|
while ($townrow = mysql_fetch_array($townquery)) {
|
||||||
|
|
||||||
if ($townrow["latitude"] >= 0) { $latitude = $townrow["latitude"] . "N,"; } else { $latitude = ($townrow["latitude"]*-1) . "S,"; }
|
if ($townrow["latitude"] >= 0) { $latitude = $townrow["latitude"] . "N,"; } else { $latitude = ($townrow["latitude"]*-1) . "S,"; }
|
||||||
if ($townrow["longitude"] >= 0) { $longitude = $townrow["longitude"] . "E"; } else { $longitude = ($townrow["longitude"]*-1) . "W"; }
|
if ($townrow["longitude"] >= 0) { $longitude = $townrow["longitude"] . "E"; } else { $longitude = ($townrow["longitude"]*-1) . "W"; }
|
||||||
|
|
||||||
$mapped = false;
|
$mapped = false;
|
||||||
foreach($mappedtowns as $a => $b) {
|
foreach($mappedtowns as $a => $b) {
|
||||||
if ($b == $townrow["id"]) { $mapped = true; }
|
if ($b == $townrow["id"]) { $mapped = true; }
|
||||||
|
@ -298,76 +298,76 @@ function maps() { // List maps the user can buy.
|
||||||
} else {
|
} else {
|
||||||
$page .= "<tr><td width=\"25%\"><span class=\"light\">".$townrow["name"]."</span></td><td width=\"25%\"><span class=\"light\">Already mapped.</span></td><td width=\"35%\"><span class=\"light\">Location: $latitude $longitude</span></td><td width=\"15%\"><span class=\"light\">TP: ".$townrow["travelpoints"]."</span></td></tr>\n";
|
$page .= "<tr><td width=\"25%\"><span class=\"light\">".$townrow["name"]."</span></td><td width=\"25%\"><span class=\"light\">Already mapped.</span></td><td width=\"35%\"><span class=\"light\">Location: $latitude $longitude</span></td><td width=\"15%\"><span class=\"light\">TP: ".$townrow["travelpoints"]."</span></td></tr>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$page .= "</table><br />\n";
|
$page .= "</table><br />\n";
|
||||||
$page .= "If you've changed your mind, you may also return back to <a href=\"index.php\">town</a>.\n";
|
$page .= "If you've changed your mind, you may also return back to <a href=\"index.php\">town</a>.\n";
|
||||||
|
|
||||||
display($page, "Buy Maps");
|
display($page, "Buy Maps");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function maps2($id) { // Confirm user's intent to purchase map.
|
function maps2($id) { // Confirm user's intent to purchase map.
|
||||||
|
|
||||||
global $userrow, $numqueries;
|
global $userrow, $numqueries;
|
||||||
|
|
||||||
$townquery = doquery("SELECT name,mapprice FROM {{table}} WHERE id='$id' LIMIT 1", "towns");
|
$townquery = doquery("SELECT name,mapprice FROM {{table}} WHERE id='$id' LIMIT 1", "towns");
|
||||||
$townrow = mysql_fetch_array($townquery);
|
$townrow = mysql_fetch_array($townquery);
|
||||||
|
|
||||||
if ($userrow["gold"] < $townrow["mapprice"]) { display("You do not have enough gold to buy this map.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=maps\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Maps"); die(); }
|
if ($userrow["gold"] < $townrow["mapprice"]) { display("You do not have enough gold to buy this map.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=maps\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Maps"); die(); }
|
||||||
|
|
||||||
$page = "You are buying the ".$townrow["name"]." map. Is that ok?<br /><br /><form action=\"index.php?do=maps3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
$page = "You are buying the ".$townrow["name"]." map. Is that ok?<br /><br /><form action=\"index.php?do=maps3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||||
|
|
||||||
display($page, "Buy Maps");
|
display($page, "Buy Maps");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function maps3($id) { // Add new map to user's profile.
|
function maps3($id) { // Add new map to user's profile.
|
||||||
|
|
||||||
if (isset($_POST["cancel"])) { header("Location: index.php"); die(); }
|
if (isset($_POST["cancel"])) { header("Location: index.php"); die(); }
|
||||||
|
|
||||||
global $userrow, $numqueries;
|
global $userrow, $numqueries;
|
||||||
|
|
||||||
$townquery = doquery("SELECT name,mapprice FROM {{table}} WHERE id='$id' LIMIT 1", "towns");
|
$townquery = doquery("SELECT name,mapprice FROM {{table}} WHERE id='$id' LIMIT 1", "towns");
|
||||||
$townrow = mysql_fetch_array($townquery);
|
$townrow = mysql_fetch_array($townquery);
|
||||||
|
|
||||||
if ($userrow["gold"] < $townrow["mapprice"]) { display("You do not have enough gold to buy this map.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=maps\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Maps"); die(); }
|
if ($userrow["gold"] < $townrow["mapprice"]) { display("You do not have enough gold to buy this map.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=maps\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Maps"); die(); }
|
||||||
|
|
||||||
$mappedtowns = $userrow["towns"].",$id";
|
$mappedtowns = $userrow["towns"].",$id";
|
||||||
$newgold = $userrow["gold"] - $townrow["mapprice"];
|
$newgold = $userrow["gold"] - $townrow["mapprice"];
|
||||||
|
|
||||||
$updatequery = doquery("UPDATE {{table}} SET towns='$mappedtowns',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
|
$updatequery = doquery("UPDATE {{table}} SET towns='$mappedtowns',gold='$newgold' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
|
||||||
|
|
||||||
display("Thank you for purchasing this map.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=maps\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Maps");
|
display("Thank you for purchasing this map.<br /><br />You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=maps\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Maps");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function travelto($id, $usepoints=true) { // Send a user to a town from the Travel To menu.
|
function travelto($id, $usepoints=true) { // Send a user to a town from the Travel To menu.
|
||||||
|
|
||||||
global $userrow, $numqueries;
|
global $userrow, $numqueries;
|
||||||
|
|
||||||
if ($userrow["currentaction"] == "Fighting") { header("Location: index.php?do=fight"); die(); }
|
if ($userrow["currentaction"] == "Fighting") { header("Location: index.php?do=fight"); die(); }
|
||||||
|
|
||||||
$townquery = doquery("SELECT name,travelpoints,latitude,longitude FROM {{table}} WHERE id='$id' LIMIT 1", "towns");
|
$townquery = doquery("SELECT name,travelpoints,latitude,longitude FROM {{table}} WHERE id='$id' LIMIT 1", "towns");
|
||||||
$townrow = mysql_fetch_array($townquery);
|
$townrow = mysql_fetch_array($townquery);
|
||||||
|
|
||||||
if ($usepoints==true) {
|
if ($usepoints==true) {
|
||||||
if ($userrow["currenttp"] < $townrow["travelpoints"]) {
|
if ($userrow["currenttp"] < $townrow["travelpoints"]) {
|
||||||
display("You do not have enough TP to travel here. Please go back and try again when you get more TP.", "Travel To"); die();
|
display("You do not have enough TP to travel here. Please go back and try again when you get more TP.", "Travel To"); die();
|
||||||
}
|
}
|
||||||
$mapped = explode(",",$userrow["towns"]);
|
$mapped = explode(",",$userrow["towns"]);
|
||||||
if (!in_array($id, $mapped)) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
if (!in_array($id, $mapped)) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($userrow["latitude"] == $townrow["latitude"]) && ($userrow["longitude"] == $townrow["longitude"])) { display("You are already in this town. <a href=\"index.php\">Click here</a> to return to the main town screen.", "Travel To"); die(); }
|
if (($userrow["latitude"] == $townrow["latitude"]) && ($userrow["longitude"] == $townrow["longitude"])) { display("You are already in this town. <a href=\"index.php\">Click here</a> to return to the main town screen.", "Travel To"); die(); }
|
||||||
|
|
||||||
if ($usepoints == true) { $newtp = $userrow["currenttp"] - $townrow["travelpoints"]; } else { $newtp = $userrow["currenttp"]; }
|
if ($usepoints == true) { $newtp = $userrow["currenttp"] - $townrow["travelpoints"]; } else { $newtp = $userrow["currenttp"]; }
|
||||||
|
|
||||||
$newlat = $townrow["latitude"];
|
$newlat = $townrow["latitude"];
|
||||||
$newlon = $townrow["longitude"];
|
$newlon = $townrow["longitude"];
|
||||||
$newid = $userrow["id"];
|
$newid = $userrow["id"];
|
||||||
|
|
||||||
// If they got here by exploring, add this town to their map.
|
// If they got here by exploring, add this town to their map.
|
||||||
$mapped = explode(",",$userrow["towns"]);
|
$mapped = explode(",",$userrow["towns"]);
|
||||||
$town = false;
|
$town = false;
|
||||||
|
@ -375,19 +375,16 @@ function travelto($id, $usepoints=true) { // Send a user to a town from the Trav
|
||||||
if ($b == $id) { $town = true; }
|
if ($b == $id) { $town = true; }
|
||||||
}
|
}
|
||||||
$mapped = implode(",",$mapped);
|
$mapped = implode(",",$mapped);
|
||||||
if ($town == false) {
|
if ($town == false) {
|
||||||
$mapped .= ",$id";
|
$mapped .= ",$id";
|
||||||
$mapped = "towns='".$mapped."',";
|
$mapped = "towns='".$mapped."',";
|
||||||
} else {
|
} else {
|
||||||
$mapped = "towns='".$mapped."',";
|
$mapped = "towns='".$mapped."',";
|
||||||
}
|
}
|
||||||
|
|
||||||
$updatequery = doquery("UPDATE {{table}} SET currentaction='In Town',$mapped currenttp='$newtp',latitude='$newlat',longitude='$newlon' WHERE id='$newid' LIMIT 1", "users");
|
$updatequery = doquery("UPDATE {{table}} SET currentaction='In Town',$mapped currenttp='$newtp',latitude='$newlat',longitude='$newlon' WHERE id='$newid' LIMIT 1", "users");
|
||||||
|
|
||||||
$page = "You have travelled to ".$townrow["name"].". You may now <a href=\"index.php\">enter this town</a>.";
|
$page = "You have travelled to ".$townrow["name"].". You may now <a href=\"index.php\">enter this town</a>.";
|
||||||
display($page, "Travel To");
|
display($page, "Travel To");
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
}
|
Loading…
Reference in New Issue
Block a user