remove difficulty, finish index refactor
This commit is contained in:
parent
0511da22fb
commit
ea7e6e8646
|
@ -51,11 +51,6 @@ function main() {
|
|||
if ($class1name == "") { $errors++; $errorlist .= "Class 1 name is required.<br />"; }
|
||||
if ($class2name == "") { $errors++; $errorlist .= "Class 2 name is required.<br />"; }
|
||||
if ($class3name == "") { $errors++; $errorlist .= "Class 3 name is required.<br />"; }
|
||||
if ($diff1name == "") { $errors++; $errorlist .= "Difficulty 1 name is required.<br />"; }
|
||||
if ($diff2name == "") { $errors++; $errorlist .= "Difficulty 2 name is required.<br />"; }
|
||||
if ($diff3name == "") { $errors++; $errorlist .= "Difficulty 3 name is required.<br />"; }
|
||||
if ($diff2mod == "") { $errors++; $errorlist .= "Difficulty 2 value is required.<br />"; }
|
||||
if ($diff3mod == "") { $errors++; $errorlist .= "Difficulty 3 value is required.<br />"; }
|
||||
|
||||
if ($errors == 0) {
|
||||
$query = doquery("UPDATE {{table}} SET gamename='$gamename',gamesize='$gamesize',forumtype='$forumtype',forumaddress='$forumaddress',compression='$compression',class1name='$class1name',class2name='$class2name',class3name='$class3name',diff1name='$diff1name',diff2name='$diff2name',diff3name='$diff3name',diff2mod='$diff2mod',diff3mod='$diff3mod',gameopen='$gameopen',verifyemail='$verifyemail',gameurl='$gameurl',adminemail='$adminemail',shownews='$shownews',showonline='$showonline',showbabble='$showbabble' WHERE id='1' LIMIT 1", "control");
|
||||
|
@ -87,11 +82,6 @@ These options control several major settings for the overall game engine.<br /><
|
|||
<tr><td width="20%">Class 1 Name:</td><td><input type="text" name="class1name" size="20" maxlength="50" value="{{class1name}}" /><br /></td></tr>
|
||||
<tr><td width="20%">Class 2 Name:</td><td><input type="text" name="class2name" size="20" maxlength="50" value="{{class2name}}" /><br /></td></tr>
|
||||
<tr><td width="20%">Class 3 Name:</td><td><input type="text" name="class3name" size="20" maxlength="50" value="{{class3name}}" /><br /></td></tr>
|
||||
<tr><td width="20%">Difficulty 1 Name:</td><td><input type="text" name="diff1name" size="20" maxlength="50" value="{{diff1name}}" /><br /></td></tr>
|
||||
<tr><td width="20%">Difficulty 2 Name:</td><td><input type="text" name="diff2name" size="20" maxlength="50" value="{{diff2name}}" /><br /></td></tr>
|
||||
<tr><td width="20%">Difficulty 2 Value:</td><td><input type="text" name="diff2mod" size="3" maxlength="3" value="{{diff2mod}}" /><br /><span class="small">Default is 1.2. Specify factoral value for medium difficulty here.</span></td></tr>
|
||||
<tr><td width="20%">Difficulty 3 Name:</td><td><input type="text" name="diff3name" size="20" maxlength="50" value="{{diff3name}}" /><br /></td></tr>
|
||||
<tr><td width="20%">Difficulty 3 Value:</td><td><input type="text" name="diff3mod" size="3" maxlength="3" value="{{diff3mod}}" /><br /><span class="small">Default is 1.5. Specify factoral value for hard difficulty here.</span></td></tr>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
||||
</form>
|
||||
|
@ -666,11 +656,9 @@ function edituser($id) {
|
|||
$errorlist = "";
|
||||
if ($email == "") { $errors++; $errorlist .= "Email is required.<br />"; }
|
||||
if ($verify == "") { $errors++; $errorlist .= "Verify is required.<br />"; }
|
||||
if ($charname == "") { $errors++; $errorlist .= "Character Name is required.<br />"; }
|
||||
if ($authlevel == "") { $errors++; $errorlist .= "Auth Level is required.<br />"; }
|
||||
if ($latitude == "") { $errors++; $errorlist .= "Latitude is required.<br />"; }
|
||||
if ($longitude == "") { $errors++; $errorlist .= "Longitude is required.<br />"; }
|
||||
if ($difficulty == "") { $errors++; $errorlist .= "Difficulty is required.<br />"; }
|
||||
if ($charclass == "") { $errors++; $errorlist .= "Character Class is required.<br />"; }
|
||||
if ($currentaction == "") { $errors++; $errorlist .= "Current Action is required.<br />"; }
|
||||
if ($currentfight == "") { $errors++; $errorlist .= "Current Fight is required.<br />"; }
|
||||
|
@ -718,7 +706,6 @@ function edituser($id) {
|
|||
if (!is_numeric($authlevel)) { $errors++; $errorlist .= "Auth Level must be a number.<br />"; }
|
||||
if (!is_numeric($latitude)) { $errors++; $errorlist .= "Latitude must be a number.<br />"; }
|
||||
if (!is_numeric($longitude)) { $errors++; $errorlist .= "Longitude must be a number.<br />"; }
|
||||
if (!is_numeric($difficulty)) { $errors++; $errorlist .= "Difficulty must be a number.<br />"; }
|
||||
if (!is_numeric($charclass)) { $errors++; $errorlist .= "Character Class must be a number.<br />"; }
|
||||
if (!is_numeric($currentfight)) { $errors++; $errorlist .= "Current Fight must be a number.<br />"; }
|
||||
if (!is_numeric($currentmonster)) { $errors++; $errorlist .= "Current Monster must be a number.<br />"; }
|
||||
|
@ -756,8 +743,8 @@ function edituser($id) {
|
|||
if ($errors == 0) {
|
||||
$updatequery = <<<END
|
||||
UPDATE {{table}} SET
|
||||
email="$email", verify="$verify", charname="$charname", authlevel="$authlevel", latitude="$latitude",
|
||||
longitude="$longitude", difficulty="$difficulty", charclass="$charclass", currentaction="$currentaction", currentfight="$currentfight",
|
||||
email="$email", verify="$verify", authlevel="$authlevel", latitude="$latitude",
|
||||
longitude="$longitude", charclass="$charclass", currentaction="$currentaction", currentfight="$currentfight",
|
||||
currentmonster="$currentmonster", currentmonsterhp="$currentmonsterhp", currentmonstersleep="$currentmonstersleep", currentmonsterimmune="$currentmonsterimmune", currentuberdamage="$currentuberdamage",
|
||||
currentuberdefense="$currentuberdefense", currenthp="$currenthp", currentmp="$currentmp", currenttp="$currenttp", maxhp="$maxhp",
|
||||
maxmp="$maxmp", maxtp="$maxtp", level="$level", gold="$gold", experience="$experience",
|
||||
|
@ -793,7 +780,6 @@ $page = <<<END
|
|||
<tr><td width="20%">Username:</td><td>{{username}}</td></tr>
|
||||
<tr><td width="20%">Email:</td><td><input type="text" name="email" size="30" maxlength="100" value="{{email}}" /></td></tr>
|
||||
<tr><td width="20%">Verify:</td><td><input type="text" name="verify" size="30" maxlength="8" value="{{verify}}" /></td></tr>
|
||||
<tr><td width="20%">Character Name:</td><td><input type="text" name="charname" size="30" maxlength="30" value="{{charname}}" /></td></tr>
|
||||
<tr><td width="20%">Register Date:</td><td>{{regdate}}</td></tr>
|
||||
<tr><td width="20%">Last Online:</td><td>{{onlinetime}}</td></tr>
|
||||
<tr><td width="20%">Auth Level:</td><td><select name="authlevel"><option value="0" {{auth0select}}>User</option><option value="1" {{auth1select}}>Admin</option><option value="2" {{auth2select}}>Blocked</option></select><br /><span class="small">Set to "Blocked" to temporarily (or permanently) ban a user.</span></td></tr>
|
||||
|
@ -802,7 +788,6 @@ $page = <<<END
|
|||
|
||||
<tr><td width="20%">Latitude:</td><td><input type="text" name="latitude" size="5" maxlength="6" value="{{latitude}}" /></td></tr>
|
||||
<tr><td width="20%">Longitude:</td><td><input type="text" name="longitude" size="5" maxlength="6" value="{{longitude}}" /></td></tr>
|
||||
<tr><td width="20%">Difficulty:</td><td><select name="difficulty"><option value="1" {{diff1select}}>$diff1name</option><option value="2" {{diff2select}}>$diff2name</option><option value="3" {{diff3select}}>$diff3name</option></select></td></tr>
|
||||
<tr><td width="20%">Character Class:</td><td><select name="charclass"><option value="1" {{class1select}}>$class1name</option><option value="2" {{class2select}}>$class2name</option><option value="3" {{class3select}}>$class3name</option></select></td></tr>
|
||||
|
||||
<tr><td colspan="2" style="background-color:#cccccc;"> </td></tr>
|
||||
|
@ -869,9 +854,6 @@ END;
|
|||
if ($row["charclass"] == 1) { $row["class1select"] = "selected=\"selected\" "; } else { $row["class1select"] = ""; }
|
||||
if ($row["charclass"] == 2) { $row["class2select"] = "selected=\"selected\" "; } else { $row["class2select"] = ""; }
|
||||
if ($row["charclass"] == 3) { $row["class3select"] = "selected=\"selected\" "; } else { $row["class3select"] = ""; }
|
||||
if ($row["difficulty"] == 1) { $row["diff1select"] = "selected=\"selected\" "; } else { $row["diff1select"] = ""; }
|
||||
if ($row["difficulty"] == 2) { $row["diff2select"] = "selected=\"selected\" "; } else { $row["diff2select"] = ""; }
|
||||
if ($row["difficulty"] == 3) { $row["diff3select"] = "selected=\"selected\" "; } else { $row["diff3select"] = ""; }
|
||||
|
||||
$page = parsetemplate($page, $row);
|
||||
admindisplay($page, "Edit Users");
|
||||
|
|
|
@ -76,7 +76,7 @@ function reply() {
|
|||
|
||||
global $userrow;
|
||||
extract($_POST);
|
||||
$query = doquery("INSERT INTO {{table}} SET id='',postdate=NOW(),newpostdate=NOW(),author='".$userrow["charname"]."',parent='$parent',replies='0',title='$title',content='$content'", "forum");
|
||||
$query = doquery("INSERT INTO {{table}} SET id='',postdate=NOW(),newpostdate=NOW(),author='".$userrow["username"]."',parent='$parent',replies='0',title='$title',content='$content'", "forum");
|
||||
$query2 = doquery("UPDATE {{table}} SET newpostdate=NOW(),replies=replies+1 WHERE id='$parent' LIMIT 1", "forum");
|
||||
header("Location: forum.php?do=thread:$parent:0");
|
||||
die();
|
||||
|
@ -89,7 +89,7 @@ function newthread() {
|
|||
|
||||
if (isset($_POST["submit"])) {
|
||||
extract($_POST);
|
||||
$query = doquery("INSERT INTO {{table}} SET id='',postdate=NOW(),newpostdate=NOW(),author='".$userrow["charname"]."',parent='0',replies='0',title='$title',content='$content'", "forum");
|
||||
$query = doquery("INSERT INTO {{table}} SET id='',postdate=NOW(),newpostdate=NOW(),author='".$userrow["username"]."',parent='0',replies='0',title='$title',content='$content'", "forum");
|
||||
header("Location: forum.php");
|
||||
die();
|
||||
}
|
||||
|
|
|
@ -79,7 +79,6 @@ a:hover {
|
|||
<ul>
|
||||
<li /><a href="#intro">Introduction</a>
|
||||
<li /><a href="#classes">Character Classes</a>
|
||||
<li /><a href="#difficulties">Difficulty Levels</a>
|
||||
<li /><a href="#intown">Playing The Game: In Town</a>
|
||||
<li /><a href="#exploring">Playing The Game: Exploring & Fighting</a>
|
||||
<li /><a href="#status">Playing The Game: Status Panels</a>
|
||||
|
@ -163,22 +162,6 @@ for the game. If your administrator has used his/her own class setup, this infor
|
|||
|
||||
<br /><br /><hr />
|
||||
|
||||
<h3><a name="difficulties"></a>Difficulty Levels</h3>
|
||||
<i><? echo $controlrow["gamename"]; ?></i> includes the ability to play using one of three difficulty levels.
|
||||
All monster statistics in the game are set at a base number. However, using a difficulty multiplier, certain statistics
|
||||
are increased. The amount of hit points a monster has goes up, which means it will take longer to kill. But the amount
|
||||
of experience and gold you gain from killing it also goes up. So the game is a little bit harder, but it is also more
|
||||
rewarding. The following are the three difficulty levels and their statistic multiplier, which applies to the monster's
|
||||
HP, experience drop, and gold drop.
|
||||
<ul>
|
||||
<li /><? echo $controlrow["diff1name"] . ": <b>" . $controlrow["diff1mod"] . "</b>"; ?>
|
||||
<li /><? echo $controlrow["diff2name"] . ": <b>" . $controlrow["diff2mod"] . "</b>"; ?>
|
||||
<li /><? echo $controlrow["diff3name"] . ": <b>" . $controlrow["diff3mod"] . "</b>"; ?>
|
||||
</ul>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br /><br /><hr />
|
||||
|
||||
<h3><a name="intown"></a>Playing The Game: In Town</h3>
|
||||
When you begin a new game, the first thing you see is the Town screen. Towns serve four primary functions: healing, buying items,
|
||||
buying maps, and displaying game information.<br /><br />
|
||||
|
|
210
public/index.php
210
public/index.php
|
@ -2,10 +2,7 @@
|
|||
|
||||
// index.php :: Primary program script, evil alien overlord, you decide.
|
||||
|
||||
if (!file_exists('../.installed')) {
|
||||
header('Location: install.php');
|
||||
exit;
|
||||
}
|
||||
if (!file_exists('../.installed')) redirect('install.php');
|
||||
|
||||
require_once '../src/lib.php';
|
||||
|
||||
|
@ -81,8 +78,7 @@ function donothing()
|
|||
$page = doexplore();
|
||||
$title = "Exploring";
|
||||
} elseif ($userrow["currentaction"] == "Fighting") {
|
||||
$page = dofight();
|
||||
$title = "Fighting";
|
||||
redirect('index.php?do=fight');
|
||||
}
|
||||
|
||||
display($page, $title);
|
||||
|
@ -95,53 +91,53 @@ function dotown()
|
|||
{
|
||||
global $userrow, $controlrow;
|
||||
|
||||
$townquery = db()->query('SELECT * FROM towns WHERE latitude = ? AND longitude = ? LIMIT 1;', [$userrow["latitude"], $userrow["longitude"]]);
|
||||
if ($townquery === false) display("There is an error with your user account, or with the town data. Please try again.", "Error");
|
||||
$townrow = $townquery->fetchArray(SQLITE3_ASSOC);
|
||||
$townrow = get_town_by_xy($userrow['longitude'], $userrow['latitude']);
|
||||
if ($townrow === false) display("There is an error with your user account, or with the town data. Please try again.","Error");
|
||||
|
||||
$townrow["news"] = "";
|
||||
$townrow["whosonline"] = "";
|
||||
$townrow["babblebox"] = "";
|
||||
|
||||
// News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe.
|
||||
if ($controlrow["shownews"] == 1) {
|
||||
$newsrow = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC);
|
||||
$townrow["news"] = "<table width=\"95%\"><tr><td class=\"title\">Latest News</td></tr><tr><td>\n";
|
||||
$townrow["news"] .= "<span class=\"light\">[".prettydate($newsrow["postdate"])."]</span><br />".nl2br($newsrow["content"]);
|
||||
$townrow["news"] .= "</td></tr></table>\n";
|
||||
} else {
|
||||
$townrow["news"] = "";
|
||||
}
|
||||
|
||||
// Who's Online. Currently just members. Guests maybe later.
|
||||
if ($controlrow["showonline"] == 1) {
|
||||
$onlinequery = db()->query("SELECT * FROM news WHERE strftime('%s', onlinetime) >= strftime('%s', 'now') - 600 ORDER BY charname");
|
||||
$onlinequery = db()->query("SELECT id, username FROM users WHERE strftime('%s', onlinetime) >= strftime('%s', 'now') - 600 ORDER BY username");
|
||||
|
||||
$online_count = 0;
|
||||
$online_rows = [];
|
||||
|
||||
foreach ($onlinequery->fetchArray(SQLITE3_ASSOC) as $onlinerow) {
|
||||
while ($onlinerow = $onlinequery->fetchArray(SQLITE3_ASSOC)) {
|
||||
$online_count++;
|
||||
$online_rows[] = "<a href=\"index.php?do=onlinechar:".$onlinerow["id"]."\">".$onlinerow["charname"]."</a>" . ", ";
|
||||
$online_rows[] = "<a href=\"index.php?do=onlinechar:".$onlinerow["id"]."\">".$onlinerow["username"]."</a>" . ", ";
|
||||
}
|
||||
|
||||
$townrow["whosonline"] = "<table width=\"95%\"><tr><td class=\"title\">Who's Online</td></tr><tr><td>\n";
|
||||
$townrow["whosonline"] .= "There are <b>$online_count</b> user(s) online within the last 10 minutes: ";
|
||||
$townrow["whosonline"] .= rtrim(implode(', ', $online_rows), ', ');
|
||||
$townrow["whosonline"] .= "</td></tr></table>\n";
|
||||
} else {
|
||||
$townrow["whosonline"] = "";
|
||||
}
|
||||
|
||||
if ($controlrow["showbabble"] == 1) {
|
||||
$townrow["babblebox"] = "<table width=\"95%\"><tr><td class=\"title\">Babble Box</td></tr><tr><td>\n";
|
||||
$townrow["babblebox"] .= "<iframe src=\"index.php?do=babblebox\" name=\"sbox\" width=\"100%\" height=\"250\" frameborder=\"0\" id=\"bbox\">Your browser does not support inline frames! The Babble Box will not be available until you upgrade to a newer <a href=\"http://www.mozilla.org\" target=\"_new\">browser</a>.</iframe>";
|
||||
$townrow["babblebox"] .= "</td></tr></table>\n";
|
||||
} else {
|
||||
$townrow["babblebox"] = "";
|
||||
$townrow["babblebox"] = <<<HTML
|
||||
<table width="95%">
|
||||
<tr><td class="title">Babble Box</td></tr>
|
||||
<tr><td>
|
||||
<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>
|
||||
</td></tr>
|
||||
</table>
|
||||
HTML;
|
||||
}
|
||||
|
||||
$page = gettemplate("towns");
|
||||
$page = parsetemplate($page, $townrow);
|
||||
|
||||
return $page;
|
||||
return parsetemplate(gettemplate("towns"), $townrow);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,154 +156,104 @@ function doexplore()
|
|||
HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to fighting.
|
||||
*/
|
||||
function dofight()
|
||||
{
|
||||
header("Location: index.php?do=fight");
|
||||
}
|
||||
|
||||
function showchar()
|
||||
{
|
||||
global $userrow, $controlrow;
|
||||
|
||||
// Format various userrow stuffs.
|
||||
$userrow["experience"] = number_format($userrow["experience"]);
|
||||
$userrow["gold"] = number_format($userrow["gold"]);
|
||||
if ($userrow["expbonus"] > 0) {
|
||||
$userrow["plusexp"] = "<span class=\"light\">(+".$userrow["expbonus"]."%)</span>";
|
||||
} elseif ($userrow["expbonus"] < 0) {
|
||||
$userrow["plusexp"] = "<span class=\"light\">(".$userrow["expbonus"]."%)</span>";
|
||||
} else { $userrow["plusexp"] = ""; }
|
||||
if ($userrow["goldbonus"] > 0) {
|
||||
$userrow["plusgold"] = "<span class=\"light\">(+".$userrow["goldbonus"]."%)</span>";
|
||||
} elseif ($userrow["goldbonus"] < 0) {
|
||||
$userrow["plusgold"] = "<span class=\"light\">(".$userrow["goldbonus"]."%)</span>";
|
||||
} else { $userrow["plusgold"] = ""; }
|
||||
|
||||
$levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels");
|
||||
$levelrow = mysql_fetch_array($levelquery);
|
||||
if ($userrow["level"] < 99) { $userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]); } else { $userrow["nextlevel"] = "<span class=\"light\">None</span>"; }
|
||||
$userrow["plusexp"] = $userrow["expbonus"] != 0
|
||||
? "<span class=\"light\">(" . ($userrow["expbonus"] > 0 ? "+" : "") . $userrow["expbonus"] . "%)</span>"
|
||||
: "";
|
||||
|
||||
if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; }
|
||||
elseif ($userrow["charclass"] == 2) { $userrow["charclass"] = $controlrow["class2name"]; }
|
||||
elseif ($userrow["charclass"] == 3) { $userrow["charclass"] = $controlrow["class3name"]; }
|
||||
$userrow["plusgold"] = $userrow["goldbonus"] != 0
|
||||
? "<span class=\"light\">(" . ($userrow["goldbonus"] > 0 ? "+" : "") . $userrow["goldbonus"] . "%)</span>"
|
||||
: "";
|
||||
|
||||
if ($userrow["difficulty"] == 1) { $userrow["difficulty"] = $controlrow["diff1name"]; }
|
||||
elseif ($userrow["difficulty"] == 2) { $userrow["difficulty"] = $controlrow["diff2name"]; }
|
||||
elseif ($userrow["difficulty"] == 3) { $userrow["difficulty"] = $controlrow["diff3name"]; }
|
||||
$levelrow = db()->query("SELECT `{$userrow["charclass"]}_exp` FROM levels WHERE id=? LIMIT 1;", [$userrow['level'] + 1])->fetchArray(SQLITE3_ASSOC);
|
||||
$userrow["nextlevel"] = $userrow['level'] < 99 ? number_format($levelrow[$userrow["charclass"]."_exp"]) : '<span class="light">None</span>';
|
||||
|
||||
$spellquery = doquery("SELECT id,name FROM {{table}}","spells");
|
||||
$userspells = explode(",",$userrow["spells"]);
|
||||
$userrow["magiclist"] = "";
|
||||
while ($spellrow = mysql_fetch_array($spellquery)) {
|
||||
$userrow['charclass'] = match ((int) $userrow['charclass']) {
|
||||
1 => $controlrow["class1name"],
|
||||
2 => $controlrow["class2name"],
|
||||
3 => $controlrow["class3name"]
|
||||
};
|
||||
|
||||
$spells = db()->query('SELECT id, name FROM spells;');
|
||||
$userspells = explode(',', $userrow['spells']);
|
||||
$userrow["magiclist"] = '';
|
||||
while ($spellrow = $spells->fetchArray(SQLITE3_ASSOC)) {
|
||||
$spell = false;
|
||||
foreach($userspells as $a => $b) {
|
||||
if ($b == $spellrow["id"]) { $spell = true; }
|
||||
foreach($userspells as $b) if ($b == $spellrow["id"]) $spell = true;
|
||||
if ($spell == true) $userrow["magiclist"] .= $spellrow["name"]."<br />";
|
||||
}
|
||||
if ($spell == true) {
|
||||
$userrow["magiclist"] .= $spellrow["name"]."<br />";
|
||||
}
|
||||
}
|
||||
if ($userrow["magiclist"] == "") { $userrow["magiclist"] = "None"; }
|
||||
if ($userrow["magiclist"] == "") $userrow["magiclist"] = "None";
|
||||
|
||||
// Make page tags for XHTML validation.
|
||||
$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"
|
||||
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
|
||||
|
||||
$charsheet = gettemplate("showchar");
|
||||
$page = $xml . gettemplate("minimal");
|
||||
$array = array("content"=>parsetemplate($charsheet, $userrow), "title"=>"Character Information");
|
||||
echo parsetemplate($page, $array);
|
||||
die();
|
||||
$array = ["content" => parsetemplate(gettemplate("showchar"), $userrow), "title" => "Character Information"];
|
||||
echo parsetemplate("<html>\n" . gettemplate("minimal"), $array);
|
||||
}
|
||||
|
||||
function onlinechar($id) {
|
||||
|
||||
function onlinechar($id)
|
||||
{
|
||||
global $controlrow;
|
||||
$userquery = doquery("SELECT * FROM {{table}} WHERE id='$id' LIMIT 1", "users");
|
||||
if (mysql_num_rows($userquery) == 1) { $userrow = mysql_fetch_array($userquery); } else { display("No such user.", "Error"); }
|
||||
|
||||
// Format various userrow stuffs.
|
||||
$query = db()->query('SELECT * FROM users WHERE id=? LIMIT 1;', [$id]);
|
||||
if ($query !== false) { $userrow = $query->fetchArray(SQLITE3_ASSOC); } else { display("No such user.", "Error"); }
|
||||
unset($userrow['password']);
|
||||
|
||||
$userrow["experience"] = number_format($userrow["experience"]);
|
||||
$userrow["gold"] = number_format($userrow["gold"]);
|
||||
if ($userrow["expbonus"] > 0) {
|
||||
$userrow["plusexp"] = "<span class=\"light\">(+".$userrow["expbonus"]."%)</span>";
|
||||
} elseif ($userrow["expbonus"] < 0) {
|
||||
$userrow["plusexp"] = "<span class=\"light\">(".$userrow["expbonus"]."%)</span>";
|
||||
} else { $userrow["plusexp"] = ""; }
|
||||
if ($userrow["goldbonus"] > 0) {
|
||||
$userrow["plusgold"] = "<span class=\"light\">(+".$userrow["goldbonus"]."%)</span>";
|
||||
} elseif ($userrow["goldbonus"] < 0) {
|
||||
$userrow["plusgold"] = "<span class=\"light\">(".$userrow["goldbonus"]."%)</span>";
|
||||
} else { $userrow["plusgold"] = ""; }
|
||||
|
||||
$levelquery = doquery("SELECT ". $userrow["charclass"]."_exp FROM {{table}} WHERE id='".($userrow["level"]+1)."' LIMIT 1", "levels");
|
||||
$levelrow = mysql_fetch_array($levelquery);
|
||||
$userrow["nextlevel"] = number_format($levelrow[$userrow["charclass"]."_exp"]);
|
||||
$userrow["plusexp"] = $userrow["expbonus"] != 0
|
||||
? "<span class=\"light\">(" . ($userrow["expbonus"] > 0 ? "+" : "") . $userrow["expbonus"] . "%)</span>"
|
||||
: "";
|
||||
|
||||
if ($userrow["charclass"] == 1) { $userrow["charclass"] = $controlrow["class1name"]; }
|
||||
elseif ($userrow["charclass"] == 2) { $userrow["charclass"] = $controlrow["class2name"]; }
|
||||
elseif ($userrow["charclass"] == 3) { $userrow["charclass"] = $controlrow["class3name"]; }
|
||||
$userrow["plusgold"] = $userrow["goldbonus"] != 0
|
||||
? "<span class=\"light\">(" . ($userrow["goldbonus"] > 0 ? "+" : "") . $userrow["goldbonus"] . "%)</span>"
|
||||
: "";
|
||||
|
||||
if ($userrow["difficulty"] == 1) { $userrow["difficulty"] = $controlrow["diff1name"]; }
|
||||
elseif ($userrow["difficulty"] == 2) { $userrow["difficulty"] = $controlrow["diff2name"]; }
|
||||
elseif ($userrow["difficulty"] == 3) { $userrow["difficulty"] = $controlrow["diff3name"]; }
|
||||
$levelrow = db()->query("SELECT `{$userrow["charclass"]}_exp` FROM levels WHERE id=? LIMIT 1;", [$userrow['level'] + 1])->fetchArray(SQLITE3_ASSOC);
|
||||
$userrow["nextlevel"] = $userrow['level'] < 99 ? number_format($levelrow[$userrow["charclass"]."_exp"]) : '<span class="light">None</span>';
|
||||
|
||||
$charsheet = gettemplate("onlinechar");
|
||||
$page = parsetemplate($charsheet, $userrow);
|
||||
display($page, "Character Information");
|
||||
$userrow['charclass'] = match ((int) $userrow['charclass']) {
|
||||
1 => $controlrow["class1name"],
|
||||
2 => $controlrow["class2name"],
|
||||
3 => $controlrow["class3name"]
|
||||
};
|
||||
|
||||
display(parsetemplate(gettemplate("onlinechar"), $userrow), "Character Information");
|
||||
}
|
||||
|
||||
function showmap() {
|
||||
|
||||
global $userrow;
|
||||
|
||||
// Make page tags for XHTML validation.
|
||||
$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"
|
||||
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
|
||||
|
||||
$page = $xml . gettemplate("minimal");
|
||||
$array = array("content"=>"<center><img src=\"images/map.gif\" alt=\"Map\" /></center>", "title"=>"Map");
|
||||
echo parsetemplate($page, $array);
|
||||
die();
|
||||
|
||||
function showmap()
|
||||
{
|
||||
$array = ["content" => "<center><img src=\"images/map.gif\" alt=\"Map\" /></center>", "title" => "Map"];
|
||||
echo parsetemplate("<html>\n" . gettemplate("minimal"), $array);
|
||||
}
|
||||
|
||||
function babblebox() {
|
||||
|
||||
function babblebox()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
if (isset($_POST["babble"])) {
|
||||
$safecontent = makesafe($_POST["babble"]);
|
||||
if ($safecontent == "" || $safecontent == " ") { //blank post. do nothing.
|
||||
} else { $insert = doquery("INSERT INTO {{table}} SET id='',posttime=NOW(),author='".$userrow["charname"]."',babble='$safecontent'", "babble"); }
|
||||
header("Location: index.php?do=babblebox");
|
||||
die();
|
||||
if (!empty($safecontent)) {
|
||||
db()->query('INSERT INTO babble (posttime, author, babble) VALUES (CURRENT_TIMESTAMP, ?, ?);', [$userrow['username'], $safecontent]);
|
||||
}
|
||||
redirect('index.php?do=babblebox');
|
||||
}
|
||||
|
||||
$babblebox = array("content"=>"");
|
||||
$babblebox = ["content" => ""];
|
||||
$bg = 1;
|
||||
$babblequery = doquery("SELECT * FROM {{table}} ORDER BY id DESC LIMIT 20", "babble");
|
||||
while ($babblerow = mysql_fetch_array($babblequery)) {
|
||||
$query = db()->query('SELECT * FROM babble ORDER BY id DESC LIMIT 20;');
|
||||
while ($babblerow = $query->fetchArray(SQLITE3_ASSOC)) {
|
||||
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; }
|
||||
$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>";
|
||||
|
||||
// Make page tags for XHTML validation.
|
||||
$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"
|
||||
. "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">\n";
|
||||
$page = $xml . gettemplate("babblebox");
|
||||
echo parsetemplate($page, $babblebox);
|
||||
die();
|
||||
|
||||
echo parsetemplate("<html>\n" . gettemplate("babblebox"), $babblebox);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,7 +7,8 @@ if (file_exists('../.installed')) {
|
|||
|
||||
require_once '../src/lib.php';
|
||||
|
||||
match ((int) $_GET['page'] ?? 1) {
|
||||
$page = $_GET['page'] ?? 1;
|
||||
match ((int) $page) {
|
||||
2 => second(),
|
||||
3 => third(),
|
||||
4 => fourth(),
|
||||
|
@ -42,8 +43,6 @@ function first()
|
|||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -628,7 +627,6 @@ function second()
|
|||
`authlevel` INTEGER NOT NULL default 0,
|
||||
`latitude` INTEGER NOT NULL default 0,
|
||||
`longitude` INTEGER NOT NULL default 0,
|
||||
`difficulty` INTEGER NOT NULL default 0,
|
||||
`charclass` INTEGER NOT NULL default 0,
|
||||
`currentaction` TEXT NOT NULL default 'In Town',
|
||||
`currentfight` INTEGER NOT NULL default 0,
|
||||
|
@ -675,7 +673,6 @@ function second()
|
|||
|
||||
$time = round((microtime(true) - START), 4);
|
||||
echo "<br />Database setup complete in $time seconds.<br /><br /><a href=\"install.php?page=3\">Click here to continue with installation.</a></body></html>";
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -699,15 +696,12 @@ function third()
|
|||
<tr><td style="vertical-align:top;">Email Address:</td><td><input type="text" name="email1" size="30" maxlength="100" /></td></tr>
|
||||
<tr><td style="vertical-align:top;">Verify Email:</td><td><input type="text" name="email2" size="30" maxlength="100" /><br /><br /><br /></td></tr>
|
||||
<tr><td style="vertical-align:top;">Character Class:</td><td><select name="charclass"><option value="1">Mage</option><option value="2">Warrior</option><option value="3">Paladin</option></select></td></tr>
|
||||
<tr><td style="vertical-align:top;">Difficulty:</td><td><select name="difficulty"><option value="1">Easy</option><option value="2">Medium</option><option value="3">Hard</option></select></td></tr>
|
||||
<tr><td colspan="2"><input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -780,8 +774,6 @@ function fourth()
|
|||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -790,7 +782,7 @@ function fourth()
|
|||
function fifth()
|
||||
{
|
||||
if (mail("sky@sharkk.net", "Dragon Knight Call Home", $_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]) !== true) {
|
||||
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>.');
|
||||
exit('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 <<<HTML
|
||||
|
@ -805,6 +797,4 @@ function fifth()
|
|||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ function login()
|
|||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$u = trim($_POST['username'] ?? '');
|
||||
|
||||
$query = db()->query('SELECT * FROM users WHERE username = ? LIMIT 1;', [$u]);
|
||||
$query = db()->query('SELECT id, username, password 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.");
|
||||
|
|
|
@ -30,12 +30,6 @@ function register() { // Register a new account.
|
|||
$usernamequery = doquery("SELECT username FROM {{table}} WHERE username='$username' LIMIT 1","users");
|
||||
if (mysql_num_rows($usernamequery) > 0) { $errors++; $errorlist .= "Username already taken - unique username required.<br />"; }
|
||||
|
||||
// Process charname.
|
||||
if ($charname == "") { $errors++; $errorlist .= "Character Name field is required.<br />"; }
|
||||
if (preg_match("/[^A-z0-9_\-]/", $charname)==1) { $errors++; $errorlist .= "Character Name must be alphanumeric.<br />"; } // Thanks to "Carlos Pires" from php.net!
|
||||
$characternamequery = doquery("SELECT charname FROM {{table}} WHERE charname='$charname' LIMIT 1","users");
|
||||
if (mysql_num_rows($characternamequery) > 0) { $errors++; $errorlist .= "Character Name already taken - unique Character Name required.<br />"; }
|
||||
|
||||
// Process email address.
|
||||
if ($email1 == "" || $email2 == "") { $errors++; $errorlist .= "Email fields are required.<br />"; }
|
||||
if ($email1 != $email2) { $errors++; $errorlist .= "Emails don't match.<br />"; }
|
||||
|
@ -60,7 +54,7 @@ function register() { // Register a new account.
|
|||
$verifycode='1';
|
||||
}
|
||||
|
||||
$query = doquery("INSERT INTO {{table}} SET id='',regdate=NOW(),verify='$verifycode',username='$username',password='$password',email='$email1',charname='$charname',charclass='$charclass',difficulty='$difficulty'", "users") or die(mysql_error());
|
||||
$query = doquery("INSERT INTO {{table}} SET id='',regdate=NOW(),verify='$verifycode',username='$username',password='$password',email='$email1',charclass='$charclass'", "users") or die(mysql_error());
|
||||
|
||||
if ($controlrow["verifyemail"] == 1) {
|
||||
if (sendregmail($email1, $verifycode) == true) {
|
||||
|
|
|
@ -22,7 +22,6 @@ class Database extends SQLite3
|
|||
{
|
||||
$p = strpos($query, '?') !== false;
|
||||
$stmt = $this->prepare($query);
|
||||
|
||||
foreach ($params ?? [] as $k => $v) $stmt->bindValue($p ? $k + 1 : $k, $v, $this->getSQLiteType($v));
|
||||
|
||||
$start = microtime(true);
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
<?php // explore.php :: Handles all map exploring, chances to fight, etc.
|
||||
<?php
|
||||
|
||||
function move() {
|
||||
// explore.php :: Handles all map exploring, chances to fight, etc.
|
||||
|
||||
function move()
|
||||
{
|
||||
global $userrow, $controlrow;
|
||||
|
||||
if ($userrow["currentaction"] == "Fighting") { header("Location: index.php?do=fight"); die(); }
|
||||
|
@ -13,25 +15,17 @@ function move() {
|
|||
if (isset($_POST["east"])) { $longitude++; if ($longitude > $controlrow["gamesize"]) { $longitude = $controlrow["gamesize"]; } }
|
||||
if (isset($_POST["west"])) { $longitude--; if ($longitude < ($controlrow["gamesize"]*-1)) { $longitude = ($controlrow["gamesize"]*-1); } }
|
||||
|
||||
$townquery = doquery("SELECT id FROM {{table}} WHERE latitude='$latitude' AND longitude='$longitude' LIMIT 1", "towns");
|
||||
if (mysql_num_rows($townquery) > 0) {
|
||||
$townrow = mysql_fetch_array($townquery);
|
||||
include('towns.php');
|
||||
$townquery = db()->query('SELECT id FROM towns WHERE latitude = ? AND longitude = ? LIMIT 1;', [$latitude, $longitude]);
|
||||
if ($townquery !== false) {
|
||||
$townrow = $townquery->fetchArray(SQLITE3_ASSOC);
|
||||
require_once __DIR__ . '/towns.php';
|
||||
travelto($townrow["id"], false);
|
||||
die();
|
||||
exit;
|
||||
}
|
||||
|
||||
$chancetofight = rand(1,5);
|
||||
if ($chancetofight == 1) {
|
||||
$action = "currentaction='Fighting', currentfight='1',";
|
||||
} else {
|
||||
$action = "currentaction='Exploring',";
|
||||
}
|
||||
$chancetofight = rand(1, 5);
|
||||
$action = $chancetofight === 1 ? "currentaction='Fighting', currentfight='1'," : "currentaction='Exploring',";
|
||||
|
||||
|
||||
$updatequery = doquery("UPDATE {{table}} SET $action latitude='$latitude', longitude='$longitude', dropcode='0' WHERE id='".$userrow["id"]."' LIMIT 1", "users");
|
||||
db()->query("UPDATE users SET $action latitude = ?, longitude = ?, dropcode = 0 WHERE id = ?;", [$latitude, $longitude, $userrow['id']]);
|
||||
header("Location: index.php");
|
||||
|
||||
}
|
||||
|
||||
?>
|
|
@ -41,8 +41,6 @@ function fight() { // One big long function that determines the outcome of the f
|
|||
$monsterrow = mysql_fetch_array($monsterquery);
|
||||
$userrow["currentmonster"] = $monsterrow["id"];
|
||||
$userrow["currentmonsterhp"] = rand((($monsterrow["maxhp"]/5)*4),$monsterrow["maxhp"]);
|
||||
if ($userrow["difficulty"] == 2) { $userrow["currentmonsterhp"] = ceil($userrow["currentmonsterhp"] * $controlrow["diff2mod"]); }
|
||||
if ($userrow["difficulty"] == 3) { $userrow["currentmonsterhp"] = ceil($userrow["currentmonsterhp"] * $controlrow["diff3mod"]); }
|
||||
$userrow["currentmonstersleep"] = 0;
|
||||
$userrow["currentmonsterimmune"] = $monsterrow["immune"];
|
||||
|
||||
|
@ -80,8 +78,6 @@ function fight() { // One big long function that determines the outcome of the f
|
|||
}
|
||||
if ($userrow["currentmonstersleep"] == 0) { // Only do this if the monster is awake.
|
||||
$tohit = ceil(rand($monsterrow["maxdam"]*.5,$monsterrow["maxdam"]));
|
||||
if ($userrow["difficulty"] == 2) { $tohit = ceil($tohit * $controlrow["diff2mod"]); }
|
||||
if ($userrow["difficulty"] == 3) { $tohit = ceil($tohit * $controlrow["diff3mod"]); }
|
||||
$toblock = ceil(rand($userrow["defensepower"]*.75,$userrow["defensepower"])/4);
|
||||
$tododge = rand(1,150);
|
||||
if ($tododge <= sqrt($userrow["dexterity"])) {
|
||||
|
@ -152,8 +148,6 @@ function fight() { // One big long function that determines the outcome of the f
|
|||
}
|
||||
if ($userrow["currentmonstersleep"] == 0) { // Only do this if the monster is awake.
|
||||
$tohit = ceil(rand($monsterrow["maxdam"]*.5,$monsterrow["maxdam"]));
|
||||
if ($userrow["difficulty"] == 2) { $tohit = ceil($tohit * $controlrow["diff2mod"]); }
|
||||
if ($userrow["difficulty"] == 3) { $tohit = ceil($tohit * $controlrow["diff3mod"]); }
|
||||
$toblock = ceil(rand($userrow["defensepower"]*.75,$userrow["defensepower"])/4);
|
||||
$tododge = rand(1,150);
|
||||
if ($tododge <= sqrt($userrow["dexterity"])) {
|
||||
|
@ -246,8 +240,6 @@ function fight() { // One big long function that determines the outcome of the f
|
|||
}
|
||||
if ($userrow["currentmonstersleep"] == 0) { // Only do this if the monster is awake.
|
||||
$tohit = ceil(rand($monsterrow["maxdam"]*.5,$monsterrow["maxdam"]));
|
||||
if ($userrow["difficulty"] == 2) { $tohit = ceil($tohit * $controlrow["diff2mod"]); }
|
||||
if ($userrow["difficulty"] == 3) { $tohit = ceil($tohit * $controlrow["diff3mod"]); }
|
||||
$toblock = ceil(rand($userrow["defensepower"]*.75,$userrow["defensepower"])/4);
|
||||
$tododge = rand(1,150);
|
||||
if ($tododge <= sqrt($userrow["dexterity"])) {
|
||||
|
@ -287,8 +279,6 @@ function fight() { // One big long function that determines the outcome of the f
|
|||
}
|
||||
if ($userrow["currentmonstersleep"] == 0) { // Only do this if the monster is awake.
|
||||
$tohit = ceil(rand($monsterrow["maxdam"]*.5,$monsterrow["maxdam"]));
|
||||
if ($userrow["difficulty"] == 2) { $tohit = ceil($tohit * $controlrow["diff2mod"]); }
|
||||
if ($userrow["difficulty"] == 3) { $tohit = ceil($tohit * $controlrow["diff3mod"]); }
|
||||
$toblock = ceil(rand($userrow["defensepower"]*.75,$userrow["defensepower"])/4);
|
||||
$tododge = rand(1,150);
|
||||
if ($tododge <= sqrt($userrow["dexterity"])) {
|
||||
|
@ -363,13 +353,9 @@ function victory() {
|
|||
|
||||
$exp = rand((($monsterrow["maxexp"]/6)*5),$monsterrow["maxexp"]);
|
||||
if ($exp < 1) { $exp = 1; }
|
||||
if ($userrow["difficulty"] == 2) { $exp = ceil($exp * $controlrow["diff2mod"]); }
|
||||
if ($userrow["difficulty"] == 3) { $exp = ceil($exp * $controlrow["diff3mod"]); }
|
||||
if ($userrow["expbonus"] != 0) { $exp += ceil(($userrow["expbonus"]/100)*$exp); }
|
||||
$gold = rand((($monsterrow["maxgold"]/6)*5),$monsterrow["maxgold"]);
|
||||
if ($gold < 1) { $gold = 1; }
|
||||
if ($userrow["difficulty"] == 2) { $gold = ceil($gold * $controlrow["diff2mod"]); }
|
||||
if ($userrow["difficulty"] == 3) { $gold = ceil($gold * $controlrow["diff3mod"]); }
|
||||
if ($userrow["goldbonus"] != 0) { $gold += ceil(($userrow["goldbonus"]/100)*$exp); }
|
||||
if ($userrow["experience"] + $exp < 16777215) { $newexp = $userrow["experience"] + $exp; $warnexp = ""; } else { $newexp = $userrow["experience"]; $exp = 0; $warnexp = "You have maxed out your experience points."; }
|
||||
if ($userrow["gold"] + $gold < 16777215) { $newgold = $userrow["gold"] + $gold; $warngold = ""; } else { $newgold = $userrow["gold"]; $gold = 0; $warngold = "You have maxed out your experience points."; }
|
||||
|
|
27
src/lib.php
27
src/lib.php
|
@ -14,6 +14,15 @@ function db(): Database
|
|||
return $GLOBALS['database'] ??= new Database(__DIR__ . '/../database.db');
|
||||
}
|
||||
|
||||
/**
|
||||
* Redirect to a different URL, exit.
|
||||
*/
|
||||
function redirect(string $location): void
|
||||
{
|
||||
header("Location: $location");
|
||||
exit;
|
||||
}
|
||||
|
||||
function gettemplate($templatename) { // SQL query for the template.
|
||||
|
||||
$filename = __DIR__ . "/../templates/" . $templatename . ".php";
|
||||
|
@ -164,7 +173,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true,
|
|||
$spellquery = db()->query('SELECT id, name, type FROM spells;');
|
||||
$userspells = explode(",",$userrow["spells"]);
|
||||
$userrow["magiclist"] = "";
|
||||
foreach ($spellquery->fetchArray(SQLITE3_ASSOC) as $spellrow) {
|
||||
while ($spellrow = $spellquery->fetchArray(SQLITE3_ASSOC)) {
|
||||
$spell = false;
|
||||
foreach($userspells as $a => $b) {
|
||||
if ($b == $spellrow["id"] && $spellrow["type"] == 1) { $spell = true; }
|
||||
|
@ -179,7 +188,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true,
|
|||
$townslist = explode(",",$userrow["towns"]);
|
||||
$townquery2 = db()->query('SELECT * FROM towns ORDER BY id;');
|
||||
$userrow["townslist"] = "";
|
||||
foreach ($townquery2->fetchArray(SQLITE3_ASSOC) as $townrow2) {
|
||||
while ($townrow2 = $townquery2->fetchArray(SQLITE3_ASSOC)) {
|
||||
$town = false;
|
||||
foreach($townslist as $a => $b) {
|
||||
if ($b == $townrow2["id"]) { $town = true; }
|
||||
|
@ -217,14 +226,14 @@ function checkcookies()
|
|||
// COOKIE FORMAT:
|
||||
// {ID} {USERNAME} {PASSWORDHASH} {REMEMBERME}
|
||||
$theuser = explode(" ",$_COOKIE["dkgame"]);
|
||||
$query = db()->query('SELECT * FROM users WHERE id = ?, username = ?, password = ? LIMIT 1;', [$theuser[0], $theuser[1], $theuser[2]]);
|
||||
$query = db()->query('SELECT * FROM users WHERE id = ? AND username = ? AND password = ? LIMIT 1;', [$theuser[0], $theuser[1], $theuser[2]]);
|
||||
if ($query === false) {
|
||||
set_cookie('dkgame', '', -3600);
|
||||
die("Invalid cookie data. Please log in again.");
|
||||
}
|
||||
$row = $query->fetchArray(SQLITE3_ASSOC);
|
||||
set_cookie('dkgame', implode(" ", $theuser), (int) $theuser[3] === 1 ? time() + 31536000 : 0);
|
||||
db()->exec('UPDATE users SET onlinetime = CURRENT_TIMESTAMP WHERE id = ? LIMIT 1;', [$theuser[0]]);
|
||||
db()->exec('UPDATE users SET onlinetime = CURRENT_TIMESTAMP WHERE id = ?;', [$theuser[0]]);
|
||||
}
|
||||
|
||||
return $row;
|
||||
|
@ -254,3 +263,13 @@ function get_control_row(): array|false
|
|||
if ($query === false) return false;
|
||||
return $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a town's data by it's coordinates.
|
||||
*/
|
||||
function get_town_by_xy(int $x, int $y): array|false
|
||||
{
|
||||
$query = db()->query('SELECT * FROM towns WHERE longitude = ? AND latitude = ? LIMIT 1;', [$x, $y]);
|
||||
if ($query === false) return false;
|
||||
return $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
|
|
@ -1,39 +1,41 @@
|
|||
<?php // towns.php :: Handles all actions you can do in town.
|
||||
<?php
|
||||
|
||||
function inn() { // Staying at the inn resets all expendable stats to their max values.
|
||||
// towns.php :: Handles all actions you can do in town.
|
||||
|
||||
global $userrow, $numqueries;
|
||||
/**
|
||||
* Staying at the inn resets all expendable stats to their max values.
|
||||
*/
|
||||
function inn()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
$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"); }
|
||||
$townrow = mysql_fetch_array($townquery);
|
||||
$townrow = get_town_by_xy($userrow["longitude"], $userrow["latitude"]);
|
||||
if ($townrow === false) { display("Cheat attempt detected.<br /><br />Get a life, loser.", "Error"); }
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
|
||||
$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");
|
||||
db()->query(
|
||||
'UPDATE users SET gold=?, currenthp=?, currentmp=?, currenttp=? WHERE id=?',
|
||||
[$newgold, $userrow['maxhp'], $userrow['maxmp'], $userrow['maxtp'], $userrow['id']
|
||||
]);
|
||||
$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.";
|
||||
|
||||
} elseif (isset($_POST["cancel"])) {
|
||||
|
||||
header("Location: index.php"); die();
|
||||
|
||||
redirect('index.php');
|
||||
} else {
|
||||
|
||||
$title = "Inn";
|
||||
$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 .= "<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 .= "</form>\n";
|
||||
|
||||
}
|
||||
|
||||
display($page, $title);
|
||||
|
||||
}
|
||||
|
||||
function buy() { // Displays a list of available items for purchase.
|
||||
|
|
|
@ -1,41 +1,39 @@
|
|||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
Here is the character profile for <b>{{charname}}</b>.<br /><br />
|
||||
When you're finished, you may <a href="index.php">return to town</a>.<br /><br />
|
||||
<table width="200">
|
||||
<tr><td class="title"><img src="images/button_character.gif" alt="Character" title="Character" /></td></tr>
|
||||
<tr><td>
|
||||
<b>{{charname}}</b><br /><br />
|
||||
$template = <<<HTML
|
||||
Here is the character profile for <b>{{username}}</b>.<br /><br />
|
||||
When you're finished, you may <a href="index.php">return to town</a>.<br /><br />
|
||||
<table width="200">
|
||||
<tr><td class="title"><img src="images/button_character.gif" alt="Character" title="Character" /></td></tr>
|
||||
<tr><td>
|
||||
<b>{{username}}</b><br /><br />
|
||||
|
||||
Difficulty: {{difficulty}}<br />
|
||||
Class: {{charclass}}<br /><br />
|
||||
Class: {{charclass}}<br /><br />
|
||||
|
||||
Level: {{level}}<br />
|
||||
Experience: {{experience}}<br />
|
||||
Gold: {{gold}}<br />
|
||||
Hit Points: {{currenthp}} / {{maxhp}}<br />
|
||||
Magic Points: {{currentmp}} / {{maxmp}}<br />
|
||||
Travel Points: {{currenttp}} / {{maxtp}}<br /><br />
|
||||
Level: {{level}}<br />
|
||||
Experience: {{experience}}<br />
|
||||
Gold: {{gold}}<br />
|
||||
Hit Points: {{currenthp}} / {{maxhp}}<br />
|
||||
Magic Points: {{currentmp}} / {{maxmp}}<br />
|
||||
Travel Points: {{currenttp}} / {{maxtp}}<br /><br />
|
||||
|
||||
Strength: {{strength}}<br />
|
||||
Dexterity: {{dexterity}}<br />
|
||||
Attack Power: {{attackpower}}<br />
|
||||
Defense Power: {{defensepower}}<br />
|
||||
</td></tr>
|
||||
</table><br />
|
||||
Strength: {{strength}}<br />
|
||||
Dexterity: {{dexterity}}<br />
|
||||
Attack Power: {{attackpower}}<br />
|
||||
Defense Power: {{defensepower}}<br />
|
||||
</td></tr>
|
||||
</table><br />
|
||||
|
||||
<table width="200">
|
||||
<tr><td class="title"><img src="images/button_inventory.gif" alt="Inventory" title="Inventory" /></td></tr>
|
||||
<tr><td>
|
||||
<table width="100%">
|
||||
<tr><td><img src="images/icon_weapon.gif" alt="Weapon" title="Weapon" /></td><td width="100%">Weapon: {{weaponname}}</td></tr>
|
||||
<tr><td><img src="images/icon_armor.gif" alt="Armor" title="Armor" /></td><td width="100%">Armor: {{armorname}}</td></tr>
|
||||
<tr><td><img src="images/icon_shield.gif" alt="Shield" title="Shield" /></td><td width="100%">Shield: {{shieldname}}</td></tr>
|
||||
</table>
|
||||
Slot 1: {{slot1name}}<br />
|
||||
Slot 2: {{slot2name}}<br />
|
||||
Slot 3: {{slot3name}}
|
||||
</td></tr>
|
||||
</table><br />
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
||||
<table width="200">
|
||||
<tr><td class="title"><img src="images/button_inventory.gif" alt="Inventory" title="Inventory" /></td></tr>
|
||||
<tr><td>
|
||||
<table width="100%">
|
||||
<tr><td><img src="images/icon_weapon.gif" alt="Weapon" title="Weapon" /></td><td width="100%">Weapon: {{weaponname}}</td></tr>
|
||||
<tr><td><img src="images/icon_armor.gif" alt="Armor" title="Armor" /></td><td width="100%">Armor: {{armorname}}</td></tr>
|
||||
<tr><td><img src="images/icon_shield.gif" alt="Shield" title="Shield" /></td><td width="100%">Shield: {{shieldname}}</td></tr>
|
||||
</table>
|
||||
Slot 1: {{slot1name}}<br />
|
||||
Slot 2: {{slot2name}}<br />
|
||||
Slot 3: {{slot3name}}
|
||||
</td></tr>
|
||||
</table><br />
|
||||
HTML;
|
||||
|
|
|
@ -7,10 +7,8 @@ $template = <<<THEVERYENDOFYOU
|
|||
<tr><td>Verify Password:</td><td><input type="password" name="password2" size="30" maxlength="10" /><br />Passwords must be 10 alphanumeric characters or less.<br /><br /><br /></td></tr>
|
||||
<tr><td>Email Address:</td><td><input type="text" name="email1" size="30" maxlength="100" /></td></tr>
|
||||
<tr><td>Verify Email:</td><td><input type="text" name="email2" size="30" maxlength="100" />{{verifytext}}<br /><br /><br /></td></tr>
|
||||
<tr><td>Character Name:</td><td><input type="text" name="charname" size="30" maxlength="30" /></td></tr>
|
||||
<tr><td>Character Class:</td><td><select name="charclass"><option value="1">{{class1name}}</option><option value="2">{{class2name}}</option><option value="3">{{class3name}}</option></select></td></tr>
|
||||
<tr><td>Difficulty:</td><td><select name="difficulty"><option value="1">{{diff1name}}</option><option value="2">{{diff2name}}</option><option value="3">{{diff3name}}</option></select></td></tr>
|
||||
<tr><td colspan="2">See <a href="help.php">Help</a> for more information about character classes and difficulty levels.<br /><br /></td></tr>
|
||||
<tr><td colspan="2">See <a href="help.php">Help</a> for more information about character classes.<br /><br /></td></tr>
|
||||
<tr><td colspan="2"><input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
|
|
|
@ -3,7 +3,7 @@ $template = <<<THEVERYENDOFYOU
|
|||
<table width="100%">
|
||||
<tr><td class="title"><img src="images/button_character.gif" alt="Character" title="Character" /></td></tr>
|
||||
<tr><td>
|
||||
<b>{{charname}}</b><br />
|
||||
<b>{{username}}</b><br />
|
||||
Level: {{level}}<br />
|
||||
Exp: {{experience}}<br />
|
||||
Gold: {{gold}}<br />
|
||||
|
|
|
@ -3,9 +3,8 @@ $template = <<<THEVERYENDOFYOU
|
|||
<table width="100%">
|
||||
<tr><td class="title"><img src="images/button_character.gif" alt="Character" title="Character" /></td></tr>
|
||||
<tr><td>
|
||||
<b>{{charname}}</b><br /><br />
|
||||
<b>{{username}}</b><br /><br />
|
||||
|
||||
Difficulty: {{difficulty}}<br />
|
||||
Class: {{charclass}}<br /><br />
|
||||
|
||||
Level: {{level}}<br />
|
||||
|
|
Loading…
Reference in New Issue
Block a user