2024-12-11 22:05:45 -06:00
|
|
|
<?php
|
2017-02-05 10:49:37 -06:00
|
|
|
|
2024-12-11 22:05:45 -06:00
|
|
|
// index.php :: Primary program script, evil alien overlord, you decide.
|
|
|
|
|
2024-12-13 15:52:37 -06:00
|
|
|
require_once '../src/bootstrap.php';
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-13 11:42:22 -06:00
|
|
|
$r = new Router;
|
|
|
|
|
|
|
|
$r->get('/', function() {
|
|
|
|
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('/fight');
|
|
|
|
}
|
|
|
|
|
|
|
|
display($page, $title);
|
2024-12-13 14:57:48 -06:00
|
|
|
})->middleware('auth_only');
|
2024-12-13 11:42:22 -06:00
|
|
|
|
|
|
|
$r->get('/ninja', function() {
|
|
|
|
exit('NINJA! 🥷');
|
|
|
|
});
|
|
|
|
|
2024-12-13 14:57:48 -06:00
|
|
|
Towns\register_routes($r);
|
|
|
|
Fights\register_routes($r);
|
|
|
|
Users\register_routes($r);
|
|
|
|
Help\register_routes($r);
|
2024-12-13 15:35:06 -06:00
|
|
|
Forum\register_routes($r);
|
2024-12-13 15:52:37 -06:00
|
|
|
Install\register_routes($r);
|
2024-12-13 16:09:57 -06:00
|
|
|
Admin\register_routes($r);
|
2024-12-13 11:42:22 -06:00
|
|
|
|
|
|
|
$r->post('/move', 'move');
|
|
|
|
|
|
|
|
$r->get('/spell/:id', 'healspells');
|
|
|
|
$r->get('/showchar', 'showchar');
|
|
|
|
$r->get('/onlinechar/:id', 'onlinechar');
|
|
|
|
$r->get('/showmap', 'showmap');
|
2024-12-13 16:35:05 -06:00
|
|
|
$r->form('/babblebox', 'babblebox');
|
2024-12-13 11:42:22 -06:00
|
|
|
|
|
|
|
// [code, handler, params, middleware]
|
|
|
|
$l = $r->lookup($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
|
|
|
|
|
2024-12-13 15:35:06 -06:00
|
|
|
if ($l['code'] !== 200) exit("Error: {$l['code']}");
|
2024-12-13 11:42:22 -06:00
|
|
|
if (!empty($l['middleware'])) foreach ($l['middleware'] as $middleware) $middleware();
|
|
|
|
$l['handler'](...$l['params'] ?? []);
|
|
|
|
|
2024-12-11 22:05:45 -06:00
|
|
|
function donothing()
|
|
|
|
{
|
2017-02-05 10:49:37 -06:00
|
|
|
global $userrow;
|
|
|
|
|
|
|
|
if ($userrow["currentaction"] == "In Town") {
|
|
|
|
$page = dotown();
|
|
|
|
$title = "In Town";
|
|
|
|
} elseif ($userrow["currentaction"] == "Exploring") {
|
|
|
|
$page = doexplore();
|
|
|
|
$title = "Exploring";
|
|
|
|
} elseif ($userrow["currentaction"] == "Fighting") {
|
2024-12-13 11:42:22 -06:00
|
|
|
redirect('/fight');
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2017-02-05 10:49:37 -06:00
|
|
|
display($page, $title);
|
|
|
|
}
|
|
|
|
|
2024-12-11 22:05:45 -06:00
|
|
|
/**
|
|
|
|
* Spit out the main town page.
|
|
|
|
*/
|
|
|
|
function dotown()
|
|
|
|
{
|
|
|
|
global $userrow, $controlrow;
|
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$townrow = get_town_by_xy($userrow['longitude'], $userrow['latitude']);
|
2024-12-11 22:05:45 -06:00
|
|
|
if ($townrow === false) display("There is an error with your user account, or with the town data. Please try again.","Error");
|
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$townrow["news"] = "";
|
|
|
|
$townrow["whosonline"] = "";
|
|
|
|
$townrow["babblebox"] = "";
|
|
|
|
|
2017-02-05 10:49:37 -06:00
|
|
|
// News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe.
|
2024-12-11 22:05:45 -06:00
|
|
|
if ($controlrow["shownews"] == 1) {
|
|
|
|
$newsrow = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC);
|
2024-12-13 13:15:04 -06:00
|
|
|
$townrow["news"] = '<div class="title">Latest News</div>';
|
2024-12-12 11:28:19 -06:00
|
|
|
$townrow["news"] .= "<span class=\"light\">[".prettydate($newsrow["postdate"])."]</span><br>".nl2br($newsrow["content"]);
|
2024-12-12 09:33:17 -06:00
|
|
|
}
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2017-02-05 10:49:37 -06:00
|
|
|
// Who's Online. Currently just members. Guests maybe later.
|
2017-02-05 10:58:20 -06:00
|
|
|
if ($controlrow["showonline"] == 1) {
|
2024-12-12 09:33:17 -06:00
|
|
|
$onlinequery = db()->query("SELECT id, username FROM users WHERE strftime('%s', onlinetime) >= strftime('%s', 'now') - 600 ORDER BY username");
|
2024-12-11 22:05:45 -06:00
|
|
|
|
|
|
|
$online_count = 0;
|
|
|
|
$online_rows = [];
|
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
while ($onlinerow = $onlinequery->fetchArray(SQLITE3_ASSOC)) {
|
2024-12-11 22:05:45 -06:00
|
|
|
$online_count++;
|
2024-12-13 11:42:22 -06:00
|
|
|
$online_rows[] = "<a href=\"/onlinechar/{$onlinerow["id"]}\">".$onlinerow["username"]."</a>";
|
2024-12-11 22:05:45 -06:00
|
|
|
}
|
|
|
|
|
2024-12-13 13:15:04 -06:00
|
|
|
$townrow["whosonline"] = '<div class="title">Who\'s Online</div>';
|
2024-12-11 22:05:45 -06:00
|
|
|
$townrow["whosonline"] .= "There are <b>$online_count</b> user(s) online within the last 10 minutes: ";
|
|
|
|
$townrow["whosonline"] .= rtrim(implode(', ', $online_rows), ', ');
|
2024-12-12 09:33:17 -06:00
|
|
|
}
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2017-02-05 10:58:20 -06:00
|
|
|
if ($controlrow["showbabble"] == 1) {
|
2024-12-12 09:33:17 -06:00
|
|
|
$townrow["babblebox"] = <<<HTML
|
2024-12-13 13:15:04 -06:00
|
|
|
<div class="title">Babble Box</div>
|
|
|
|
<iframe src="/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>
|
2024-12-12 09:33:17 -06:00
|
|
|
HTML;
|
|
|
|
}
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
return parsetemplate(gettemplate("towns"), $townrow);
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|
|
|
|
|
2024-12-11 22:05:45 -06:00
|
|
|
/**
|
|
|
|
* 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%">
|
2024-12-13 11:42:22 -06:00
|
|
|
<tr><td class="title"><img src="/img/title_exploring.gif" alt="Exploring" /></td></tr>
|
2024-12-11 22:05:45 -06:00
|
|
|
<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;
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|
|
|
|
|
2024-12-11 22:05:45 -06:00
|
|
|
function showchar()
|
|
|
|
{
|
2017-02-05 10:49:37 -06:00
|
|
|
global $userrow, $controlrow;
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$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)) {
|
2017-02-05 10:58:20 -06:00
|
|
|
$spell = false;
|
2024-12-12 09:33:17 -06:00
|
|
|
foreach($userspells as $b) if ($b == $spellrow["id"]) $spell = true;
|
2024-12-12 11:28:19 -06:00
|
|
|
if ($spell == true) $userrow["magiclist"] .= $spellrow["name"]."<br>";
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|
2024-12-12 09:33:17 -06:00
|
|
|
if ($userrow["magiclist"] == "") $userrow["magiclist"] = "None";
|
2017-02-05 10:49:37 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$array = ["content" => parsetemplate(gettemplate("showchar"), $userrow), "title" => "Character Information"];
|
2024-12-13 17:28:51 -06:00
|
|
|
echo render('minimal', $array);
|
2024-12-12 09:33:17 -06:00
|
|
|
}
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
function onlinechar($id)
|
|
|
|
{
|
2017-02-05 10:49:37 -06:00
|
|
|
global $controlrow;
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$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']);
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$userrow["experience"] = number_format($userrow["experience"]);
|
|
|
|
$userrow["gold"] = number_format($userrow["gold"]);
|
2017-02-05 10:49:37 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$userrow["plusexp"] = $userrow["expbonus"] != 0
|
|
|
|
? "<span class=\"light\">(" . ($userrow["expbonus"] > 0 ? "+" : "") . $userrow["expbonus"] . "%)</span>"
|
|
|
|
: "";
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$userrow["plusgold"] = $userrow["goldbonus"] != 0
|
|
|
|
? "<span class=\"light\">(" . ($userrow["goldbonus"] > 0 ? "+" : "") . $userrow["goldbonus"] . "%)</span>"
|
|
|
|
: "";
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$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>';
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
$userrow['charclass'] = match ((int) $userrow['charclass']) {
|
|
|
|
1 => $controlrow["class1name"],
|
|
|
|
2 => $controlrow["class2name"],
|
|
|
|
3 => $controlrow["class3name"]
|
|
|
|
};
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
display(parsetemplate(gettemplate("onlinechar"), $userrow), "Character Information");
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|
|
|
|
|
2024-12-12 09:33:17 -06:00
|
|
|
function showmap()
|
|
|
|
{
|
2024-12-13 17:28:51 -06:00
|
|
|
global $userrow;
|
|
|
|
|
|
|
|
$pos = sprintf(
|
|
|
|
'<div style="position: absolute; width: 5px; height: 5px; border-radius: 1000px; border: solid 1px black; background-color: red; left: %dpx; top: %dpx;"></div>',
|
|
|
|
round(258 + $userrow['longitude'] * (500 / 500) - 3),
|
|
|
|
round(258 - $userrow['latitude'] * (500 / 500) - 3)
|
|
|
|
);
|
|
|
|
|
|
|
|
echo render('minimal', [
|
|
|
|
'content' => '<img src="/img/map.gif" alt="Map">'.$pos,
|
|
|
|
'title' => 'Map'
|
|
|
|
]);
|
2024-12-12 09:33:17 -06:00
|
|
|
}
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-13 17:28:51 -06:00
|
|
|
/**
|
|
|
|
* Either render the latest 40 chats to the babblebox, or add a chat to it and redirect. This is used
|
|
|
|
* within an iframe.
|
|
|
|
*/
|
2024-12-12 09:33:17 -06:00
|
|
|
function babblebox()
|
|
|
|
{
|
2017-02-05 10:49:37 -06:00
|
|
|
global $userrow;
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-13 17:28:51 -06:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
|
|
$safecontent = make_safe($_POST["babble"]);
|
2024-12-12 09:33:17 -06:00
|
|
|
if (!empty($safecontent)) {
|
2024-12-13 17:28:51 -06:00
|
|
|
db()->query('INSERT INTO babble (posttime, author, babble) VALUES (CURRENT_TIMESTAMP, ?, ?);',
|
|
|
|
[$userrow['username'], $safecontent]);
|
2024-12-12 09:33:17 -06:00
|
|
|
}
|
2024-12-13 11:42:22 -06:00
|
|
|
redirect('/babblebox');
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|
2024-12-11 22:05:45 -06:00
|
|
|
|
2024-12-13 13:15:04 -06:00
|
|
|
$query = db()->query('SELECT * FROM babble ORDER BY id DESC LIMIT 40;');
|
2024-12-13 17:28:51 -06:00
|
|
|
echo render('babblebox', ['messages' => $query]);
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|
|
|
|
|
2024-12-11 22:05:45 -06:00
|
|
|
/**
|
|
|
|
* NINJA! 🥷
|
|
|
|
*/
|
|
|
|
function ninja(): void
|
|
|
|
{
|
|
|
|
exit('NINJA! 🥷');
|
2017-02-05 10:49:37 -06:00
|
|
|
}
|