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); })->middleware('auth_only'); $r->get('/ninja', function() { exit('NINJA! 🥷'); }); Towns\register_routes($r); Fights\register_routes($r); Users\register_routes($r); Help\register_routes($r); Forum\register_routes($r); Install\register_routes($r); $r->post('/move', 'move'); $r->get('/spell/:id', 'healspells'); $r->get('/showchar', 'showchar'); $r->get('/onlinechar/:id', 'onlinechar'); $r->get('/showmap', 'showmap'); $r->get('/babblebox', 'babblebox'); $r->post('/babblebox', 'babblebox'); // [code, handler, params, middleware] $l = $r->lookup($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']); if ($l['code'] !== 200) exit("Error: {$l['code']}"); if (!empty($l['middleware'])) foreach ($l['middleware'] as $middleware) $middleware(); $l['handler'](...$l['params'] ?? []); 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('/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"] = '
Latest News
'; $townrow["news"] .= "[".prettydate($newsrow["postdate"])."]
".nl2br($newsrow["content"]); } // 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[] = "".$onlinerow["username"].""; } $townrow["whosonline"] = '
Who\'s Online
'; $townrow["whosonline"] .= "There are $online_count user(s) online within the last 10 minutes: "; $townrow["whosonline"] .= rtrim(implode(', ', $online_rows), ', '); } if ($controlrow["showbabble"] == 1) { $townrow["babblebox"] = <<Babble Box 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 << Exploring You are exploring the map, and nothing has happened. Continue exploring using the direction buttons or the Travel To menus. HTML; } function showchar() { global $userrow, $controlrow; $userrow["experience"] = number_format($userrow["experience"]); $userrow["gold"] = number_format($userrow["gold"]); $userrow["plusexp"] = $userrow["expbonus"] != 0 ? "(" . ($userrow["expbonus"] > 0 ? "+" : "") . $userrow["expbonus"] . "%)" : ""; $userrow["plusgold"] = $userrow["goldbonus"] != 0 ? "(" . ($userrow["goldbonus"] > 0 ? "+" : "") . $userrow["goldbonus"] . "%)" : ""; $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"]) : 'None'; $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"]."
"; } if ($userrow["magiclist"] == "") $userrow["magiclist"] = "None"; $array = ["content" => parsetemplate(gettemplate("showchar"), $userrow), "title" => "Character Information"]; echo parsetemplate("\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 ? "(" . ($userrow["expbonus"] > 0 ? "+" : "") . $userrow["expbonus"] . "%)" : ""; $userrow["plusgold"] = $userrow["goldbonus"] != 0 ? "(" . ($userrow["goldbonus"] > 0 ? "+" : "") . $userrow["goldbonus"] . "%)" : ""; $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"]) : 'None'; $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" => "
\"Map\"
", "title" => "Map"]; echo parsetemplate("\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('/babblebox'); } $babblebox['content'] = ''; $query = db()->query('SELECT * FROM babble ORDER BY id DESC LIMIT 40;'); while ($babblerow = $query->fetchArray(SQLITE3_ASSOC)) { $new = "
[{$babblerow["author"]}] {$babblerow["babble"]}
\n"; $babblebox["content"] = $new . $babblebox["content"]; } $babblebox["content"] .= '

'; echo parsetemplate("\n" . gettemplate("babblebox"), $babblebox); } /** * NINJA! 🥷 */ function ninja(): void { exit('NINJA! 🥷'); }