266 lines
9.3 KiB
PHP
266 lines
9.3 KiB
PHP
<?php
|
|
|
|
// index.php :: Primary program script, evil alien overlord, you decide.
|
|
|
|
if (!file_exists('../.installed')) redirect('install.php');
|
|
|
|
require_once '../src/lib.php';
|
|
|
|
$controlrow = get_control_row();
|
|
|
|
// Login (or verify) if not logged in.
|
|
if (($userrow = checkcookies()) === false) {
|
|
if (isset($_GET['do']) && $_GET['do'] === 'verify') {
|
|
header("Location: users.php?do=verify");
|
|
exit;
|
|
}
|
|
|
|
header("Location: login.php?do=login");
|
|
exit;
|
|
}
|
|
|
|
// Close game.
|
|
if ((bool) $controlrow["gameopen"] === false) {
|
|
display("The game is currently closed for maintanence. Please check back later.", "Game Closed");
|
|
exit;
|
|
}
|
|
|
|
// Force verify if the user isn't verified yet.
|
|
if ((bool) $controlrow["verifyemail"] && (bool) $userrow["verify"] === false) {
|
|
header("Location: users.php?do=verify");
|
|
exit;
|
|
}
|
|
|
|
// Block user if he/she has been banned.
|
|
if ($userrow["authlevel"] === 2) {
|
|
exit("Your account has been blocked.");
|
|
}
|
|
|
|
require_once '../src/towns.php';
|
|
require_once '../src/explore.php';
|
|
require_once '../src/fight.php';
|
|
require_once '../src/heal.php';
|
|
|
|
$do = explode(':', $_GET['do'] ?? '');
|
|
match ($do[0]) {
|
|
'inn' => inn(),
|
|
'buy' => buy(),
|
|
'buy2' => buy2($do[1]),
|
|
'buy3' => buy3($do[1]),
|
|
// 'sell' => sell(),
|
|
'maps' => maps(),
|
|
'maps2' => maps2($do[1]),
|
|
'maps3' => maps3($do[1]),
|
|
'gotown' => travelto($do[1]),
|
|
'move' => move(),
|
|
'fight' => fight(),
|
|
'victory' => victory(),
|
|
'drop' => drop(),
|
|
'dead' => dead(),
|
|
'verify' => header("Location: users.php?do=verify"),
|
|
'spell' => healspells($do[1]),
|
|
'showchar' => showchar(),
|
|
'onlinechar' => onlinechar($do[1]),
|
|
'showmap' => showmap(),
|
|
'babblebox' => babblebox(),
|
|
'ninja' => ninja(),
|
|
default => donothing()
|
|
};
|
|
|
|
function donothing()
|
|
{
|
|
global $userrow;
|
|
|
|
if ($userrow["currentaction"] == "In Town") {
|
|
$page = dotown();
|
|
$title = "In Town";
|
|
} elseif ($userrow["currentaction"] == "Exploring") {
|
|
$page = doexplore();
|
|
$title = "Exploring";
|
|
} elseif ($userrow["currentaction"] == "Fighting") {
|
|
redirect('index.php?do=fight');
|
|
}
|
|
|
|
display($page, $title);
|
|
}
|
|
|
|
/**
|
|
* Spit out the main town page.
|
|
*/
|
|
function dotown()
|
|
{
|
|
global $userrow, $controlrow;
|
|
|
|
$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";
|
|
}
|
|
|
|
// Who's Online. Currently just members. Guests maybe later.
|
|
if ($controlrow["showonline"] == 1) {
|
|
$onlinequery = db()->query("SELECT id, username FROM users WHERE strftime('%s', onlinetime) >= strftime('%s', 'now') - 600 ORDER BY username");
|
|
|
|
$online_count = 0;
|
|
$online_rows = [];
|
|
|
|
while ($onlinerow = $onlinequery->fetchArray(SQLITE3_ASSOC)) {
|
|
$online_count++;
|
|
$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";
|
|
}
|
|
|
|
if ($controlrow["showbabble"] == 1) {
|
|
$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;
|
|
}
|
|
|
|
return parsetemplate(gettemplate("towns"), $townrow);
|
|
}
|
|
|
|
/**
|
|
* 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;
|
|
}
|
|
|
|
function showchar()
|
|
{
|
|
global $userrow, $controlrow;
|
|
|
|
$userrow["experience"] = number_format($userrow["experience"]);
|
|
$userrow["gold"] = number_format($userrow["gold"]);
|
|
|
|
$userrow["plusexp"] = $userrow["expbonus"] != 0
|
|
? "<span class=\"light\">(" . ($userrow["expbonus"] > 0 ? "+" : "") . $userrow["expbonus"] . "%)</span>"
|
|
: "";
|
|
|
|
$userrow["plusgold"] = $userrow["goldbonus"] != 0
|
|
? "<span class=\"light\">(" . ($userrow["goldbonus"] > 0 ? "+" : "") . $userrow["goldbonus"] . "%)</span>"
|
|
: "";
|
|
|
|
$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>';
|
|
|
|
$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 $b) if ($b == $spellrow["id"]) $spell = true;
|
|
if ($spell == true) $userrow["magiclist"] .= $spellrow["name"]."<br>";
|
|
}
|
|
if ($userrow["magiclist"] == "") $userrow["magiclist"] = "None";
|
|
|
|
$array = ["content" => parsetemplate(gettemplate("showchar"), $userrow), "title" => "Character Information"];
|
|
echo parsetemplate("<html>\n" . gettemplate("minimal"), $array);
|
|
}
|
|
|
|
function onlinechar($id)
|
|
{
|
|
global $controlrow;
|
|
|
|
$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"]);
|
|
|
|
$userrow["plusexp"] = $userrow["expbonus"] != 0
|
|
? "<span class=\"light\">(" . ($userrow["expbonus"] > 0 ? "+" : "") . $userrow["expbonus"] . "%)</span>"
|
|
: "";
|
|
|
|
$userrow["plusgold"] = $userrow["goldbonus"] != 0
|
|
? "<span class=\"light\">(" . ($userrow["goldbonus"] > 0 ? "+" : "") . $userrow["goldbonus"] . "%)</span>"
|
|
: "";
|
|
|
|
$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>';
|
|
|
|
$userrow['charclass'] = match ((int) $userrow['charclass']) {
|
|
1 => $controlrow["class1name"],
|
|
2 => $controlrow["class2name"],
|
|
3 => $controlrow["class3name"]
|
|
};
|
|
|
|
display(parsetemplate(gettemplate("onlinechar"), $userrow), "Character Information");
|
|
}
|
|
|
|
function showmap()
|
|
{
|
|
$array = ["content" => "<center><img src=\"images/map.gif\" alt=\"Map\" /></center>", "title" => "Map"];
|
|
echo parsetemplate("<html>\n" . gettemplate("minimal"), $array);
|
|
}
|
|
|
|
function babblebox()
|
|
{
|
|
global $userrow;
|
|
|
|
if (isset($_POST["babble"])) {
|
|
$safecontent = makesafe($_POST["babble"]);
|
|
if (!empty($safecontent)) {
|
|
db()->query('INSERT INTO babble (posttime, author, babble) VALUES (CURRENT_TIMESTAMP, ?, ?);', [$userrow['username'], $safecontent]);
|
|
}
|
|
redirect('index.php?do=babblebox');
|
|
}
|
|
|
|
$babblebox = ["content" => ""];
|
|
$bg = 1;
|
|
$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>";
|
|
|
|
echo parsetemplate("<html>\n" . gettemplate("babblebox"), $babblebox);
|
|
}
|
|
|
|
/**
|
|
* NINJA! 🥷
|
|
*/
|
|
function ninja(): void
|
|
{
|
|
exit('NINJA! 🥷');
|
|
}
|