', 'layouts/admin');
+ return $page;
}
/**
@@ -179,18 +163,280 @@ function edit_drop(int $id): string
$drop = get_drop($id);
if (is_post()) {
- $form = validate($_POST, [
+ $page = handle_edit_form($id, 'drops', validate($_POST, [
'name' => [],
'mlevel' => ['int', 'min:1'],
'attribute1' => [],
'attribute2' => ['default:X'],
+ ]));
+ } else {
+ $page = render('admin/edit_drop', ['drop' => $drop]);
+ }
+
+ page_title('Admin: Editing '.$drop['name']);
+ return $page;
+}
+
+/**
+ * Generate the list of towns that can be edited.
+ */
+function towns(): string
+{
+ $towns = db()->query('SELECT * FROM towns ORDER BY id;');
+ $page = "
Edit Towns
Click an town's name or ID to edit it.
\n";
+ $page .= build_bulk_table($towns, 'name', '/admin/towns');
+
+ page_title('Admin: Towns');
+ return $page;
+}
+
+/**
+ * Save any changes to the town made.
+ */
+function edit_town(int $id): string
+{
+ $town = get_town_by_id($id);
+
+ if (is_post()) {
+ $page = handle_edit_form($id, 'towns', validate($_POST, [
+ 'name' => [],
+ 'latitude' => ['int', 'min:0', 'max:'.env('game_size')],
+ 'longitude' => ['int', 'min:0', 'max:'.env('game_size')],
+ 'innprice' => ['int', 'min:0'],
+ 'mapprice' => ['int', 'min:0'],
+ 'travelpoints' => ['int', 'min:0'],
+ 'itemslist' => ['optional']
+ ]));
+ } else {
+ $page = render('admin/edit_town', ['town' => $town]);
+ }
+
+ page_title('Admin: Editing '.$town['name']);
+ return $page;
+}
+
+/**
+ * List the monsters available to edit.
+ */
+function monsters()
+{
+ $max_level = db()->query('SELECT level FROM monsters ORDER BY level DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC)['level'];
+ $monsters = db()->query('SELECT * FROM monsters ORDER BY id;');
+
+ $page = "
Edit Monsters
";
+
+ if ((env('game_size') / 5) !== $max_level) {
+ $page .= "Note: Your highest monster level does not match with your entered map size. Highest monster level should be ".(env('game_size') / 5).", yours is $max_level. Please fix this before opening the game to the public. ";
+ } else {
+ $page .= "Monster level and map size match. No further actions are required for map compatibility. ";
+ }
+
+ $page .= "Click an monster's name or ID to edit it.
", "Edit Towns");
-}
-
-function edittown($id)
-{
- global $controlrow;
-
- if (isset($_POST["submit"])) {
- $n = trim($_POST['name'] ?? '');
- $la = (int) trim($_POST['latitude'] ?? 0);
- $lo = (int) trim($_POST['longitude'] ?? 0);
- $ip = (int) trim($_POST['innprice'] ?? 0);
- $mp = (int) trim($_POST['mapprice'] ?? 0);
- $tp = (int) trim($_POST['travelpoints'] ?? 0);
- $il = trim($_POST['itemslist'] ?? '');
-
- $errors = [];
- if (empty($n)) $errors[] = 'Name is required.';
- if ($la > $controlrow['gamesize'] || $la < ($controlrow['gamesize'] * -1))
- $errors[] = "Latitude must be a number and within the bounds of the game size. ({$controlrow['gamesize']}";
- if ($lo > $controlrow['gamesize'] || $la < ($controlrow['gamesize'] * -1))
- $errors[] = "Longitude must be a number and within the bounds of the game size. ({$controlrow['gamesize']}";
- if ($ip < 0) $errors[] = "Inn price must be a number greater than or equal to 0.";
- if ($mp < 0) $errors[] = "Map price must be a number greater than or equal to 0.";
- if ($tp < 0) $errors[] = "Travel points must be a number greater than or equal to 0.";
-
- if (count($errors) === 0) {
- db()->query('UPDATE towns SET name=?, latitude=?, longitude=?, innprice=?, mapprice=?, travelpoints=?, itemslist=? WHERE id=?;', [
- $n, $la, $lo, $ip, $mp, $tp, $il, $id
- ]);
- display_admin("Town updated.", "Edit Towns");
- } else {
- $errorlist = implode(' ', $errors);
- display_admin("Errors:
$errorlist
Please go back and try again.", "Edit Towns");
- }
- }
-
- $row = get_town_by_id($id);
-
- $page = <<Edit Towns
-
- HTML;
-
- display_admin(parse($page, $row), "Edit Towns");
-}
-
-function monsters()
-{
- global $controlrow;
-
- $max_level = db()->query('SELECT level FROM monsters ORDER BY level DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC)['level'];
- $monsters = db()->query('SELECT id, name FROM monsters ORDER BY id;');
-
- $page = "Edit Monsters ";
-
- if (($controlrow['gamesize'] / 5) !== $max_level) {
- $page .= "Note: Your highest monster level does not match with your entered map size. Highest monster level should be ".($controlrow["gamesize"] / 5).", yours is $max_level. Please fix this before opening the game to the public. ";
- } else {
- $page .= "Monster level and map size match. No further actions are required for map compatibility. ";
- }
-
- $page .= "Click an monster's name to edit it.
", "Edit Monster");
-}
-
-function editmonster($id)
-{
- if (isset($_POST["submit"])) {
- $n = trim($_POST['name'] ?? '');
- $mh = (int) trim($_POST['maxhp'] ?? 0);
- $md = (int) trim($_POST['maxdam'] ?? 0);
- $a = (int) trim($_POST['armor'] ?? 0);
- $l = (int) trim($_POST['level'] ?? 0);
- $me = (int) trim($_POST['maxexp'] ?? 0);
- $mg = (int) trim($_POST['maxgold'] ?? 0);
-
- $errors = [];
- if (empty($n)) $errors[] = "Name is required.";
- if ($mh < 1) $errors[] = "Max HP must be a number greater than or equal to 1.";
- if ($md < 0) $errors[] = "Max Damage must be a number greater than or equal to 0.";
- if ($a < 0) $errors[] = "Armor must be a number greater than or equal to 0.";
- if ($l < 1) $errors[] = "Level must be a number greater than or equal to 1.";
- if ($me < 0) $errors[] = "Max Exp must be a number greater than or equal to 0.";
- if ($mg < 0) $errors[] = "Max Gold must be a number greater than or equal to 0.";
-
- if (count($errors) === 0) {
- db()->query('UPDATE monsters SET name=?, maxhp=?, maxdam=?, armor=?, level=?, maxexp=?, maxgold=?, immune=? WHERE id=?;', [
- $n, $mh, $md, $a, $l, $me, $mg, $_POST['immune'] ?? 0, $id
- ]);
- display_admin("Monster updated.", "Edit monsters");
- } else {
- $errorlist = implode(' ', $errors);
- display_admin("Errors:
$errorlist
Please go back and try again.", "Edit monsters");
- }
- }
-
- $row = get_monster($id);
-
- $page = <<Edit Monsters
", "Edit Spells");
-}
-
-function editspell($id)
-{
- if (isset($_POST["submit"])) {
- $n = trim($_POST['name'] ?? '');
- $mp = (int) trim($_POST['mp'] ?? 0);
- $a = (int) trim($_POST['attribute'] ?? 0);
-
- $errors = [];
- if (empty($n)) $errors[] = "Name is required.";
- if ($mp < 0) $errors[] = "MP must be a number greater than or equal to 0.";
- if ($a < 0) $errors[] = "Attribute must be a number greater than or equal to 0.";
-
- if (count($errors) === 0) {
- db()->query('UPDATE spells SET name=?, mp=?, attribute=?, type=? WHERE id=?;', [
- $n, $mp, $a, $_POST['type'] ?? 0, $id
- ]);
- display_admin("Spell updated.", "Edit Spells");
- } else {
- $errorlist = implode(' ', $errors);
- display_admin("Errors:
$errorlist
Please go back and try again.", "Edit Spells");
- }
- }
-
- $row = get_spell($id);
-
- $page = <<Edit Spells
-
- HTML;
-
- if ($row["type"] == 1) { $row["type1select"] = "selected=\"selected\" "; } else { $row["type1select"] = ""; }
- if ($row["type"] == 2) { $row["type2select"] = "selected=\"selected\" "; } else { $row["type2select"] = ""; }
- if ($row["type"] == 3) { $row["type3select"] = "selected=\"selected\" "; } else { $row["type3select"] = ""; }
- if ($row["type"] == 4) { $row["type4select"] = "selected=\"selected\" "; } else { $row["type4select"] = ""; }
- if ($row["type"] == 5) { $row["type5select"] = "selected=\"selected\" "; } else { $row["type5select"] = ""; }
-
- display_admin(parse($page, $row), "Edit Spells");
-}
-
-function levels()
-{
- $max_level = db()->query('SELECT id FROM levels ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC)['id'];
-
- $options = "";
- for ($i = 2; $i < $max_level; $i++) {
- $options .= "\n";
- }
-
- $page = <<Edit Levels
- Select a level number from the dropdown box to edit it.
-
- HTML;
-
- display_admin($page, "Edit Levels");
-}
-
-function editlevel()
-{
- if (!isset($_POST["level"])) display_admin("No level to edit.", "Edit Levels");
- $id = $_POST["level"];
-
- if (isset($_POST["submit"])) {
- unset($_POST['submit']);
- $errors = [];
- if ($_POST["one_exp"] == "") $errors[] = "Class 1 Experience is required.";
- if ($_POST["one_hp"] == "") $errors[] = "Class 1 HP is required.";
- if ($_POST["one_mp"] == "") $errors[] = "Class 1 MP is required.";
- if ($_POST["one_tp"] == "") $errors[] = "Class 1 TP is required.";
- if ($_POST["one_strength"] == "") $errors[] = "Class 1 Strength is required.";
- if ($_POST["one_dexterity"] == "") $errors[] = "Class 1 Dexterity is required.";
- if ($_POST["one_spells"] == "") $errors[] = "Class 1 Spells is required.";
- if (!is_numeric($_POST["one_exp"])) $errors[] = "Class 1 Experience must be a number.";
- if (!is_numeric($_POST["one_hp"])) $errors[] = "Class 1 HP must be a number.";
- if (!is_numeric($_POST["one_mp"])) $errors[] = "Class 1 MP must be a number.";
- if (!is_numeric($_POST["one_tp"])) $errors[] = "Class 1 TP must be a number.";
- if (!is_numeric($_POST["one_strength"])) $errors[] = "Class 1 Strength must be a number.";
- if (!is_numeric($_POST["one_dexterity"])) $errors[] = "Class 1 Dexterity must be a number.";
- if (!is_numeric($_POST["one_spells"])) $errors[] = "Class 1 Spells must be a number.";
-
- if ($_POST["two_exp"] == "") $errors[] = "Class 2 Experience is required.";
- if ($_POST["two_hp"] == "") $errors[] = "Class 2 HP is required.";
- if ($_POST["two_mp"] == "") $errors[] = "Class 2 MP is required.";
- if ($_POST["two_tp"] == "") $errors[] = "Class 2 TP is required.";
- if ($_POST["two_strength"] == "") $errors[] = "Class 2 Strength is required.";
- if ($_POST["two_dexterity"] == "") $errors[] = "Class 2 Dexterity is required.";
- if ($_POST["two_spells"] == "") $errors[] = "Class 2 Spells is required.";
- if (!is_numeric($_POST["two_exp"])) $errors[] = "Class 2 Experience must be a number.";
- if (!is_numeric($_POST["two_hp"])) $errors[] = "Class 2 HP must be a number.";
- if (!is_numeric($_POST["two_mp"])) $errors[] = "Class 2 MP must be a number.";
- if (!is_numeric($_POST["two_tp"])) $errors[] = "Class 2 TP must be a number.";
- if (!is_numeric($_POST["two_strength"])) $errors[] = "Class 2 Strength must be a number.";
- if (!is_numeric($_POST["two_dexterity"])) $errors[] = "Class 2 Dexterity must be a number.";
- if (!is_numeric($_POST["two_spells"])) $errors[] = "Class 2 Spells must be a number.";
-
- if ($_POST["three_exp"] == "") $errors[] = "Class 3 Experience is required.";
- if ($_POST["three_hp"] == "") $errors[] = "Class 3 HP is required.";
- if ($_POST["three_mp"] == "") $errors[] = "Class 3 MP is required.";
- if ($_POST["three_tp"] == "") $errors[] = "Class 3 TP is required.";
- if ($_POST["three_strength"] == "") $errors[] = "Class 3 Strength is required.";
- if ($_POST["three_dexterity"] == "") $errors[] = "Class 3 Dexterity is required.";
- if ($_POST["three_spells"] == "") $errors[] = "Class 3 Spells is required.";
- if (!is_numeric($_POST["three_exp"])) $errors[] = "Class 3 Experience must be a number.";
- if (!is_numeric($_POST["three_hp"])) $errors[] = "Class 3 HP must be a number.";
- if (!is_numeric($_POST["three_mp"])) $errors[] = "Class 3 MP must be a number.";
- if (!is_numeric($_POST["three_tp"])) $errors[] = "Class 3 TP must be a number.";
- if (!is_numeric($_POST["three_strength"])) $errors[] = "Class 3 Strength must be a number.";
- if (!is_numeric($_POST["three_dexterity"])) $errors[] = "Class 3 Dexterity must be a number.";
- if (!is_numeric($_POST["three_spells"])) $errors[] = "Class 3 Spells must be a number.";
-
- if (count($errors) === 0) {
- $updatequery = <<query($updatequery, [
- $one_exp, $one_hp, $one_mp, $one_tp, $one_strength, $one_dexterity, $one_spells,
- $two_exp, $two_hp, $two_mp, $two_tp, $two_strength, $two_dexterity, $two_spells,
- $three_exp, $three_hp, $three_mp, $three_tp, $three_strength, $three_dexterity, $three_spells,
- $id
- ]);
- display_admin("Level updated.", "Edit Levels");
- } else {
- $errorlist = implode(' ', $errors);
- display_admin("Errors:
$errorlist
Please go back and try again.", "Edit Spells");
- }
- }
-
-
- $row = db()->query('SELECT * FROM levels WHERE id=? LIMIT 1;', [$id])->fetchArray(SQLITE3_ASSOC);
-
- global $controlrow;
-
- $class1name = $controlrow["class1name"];
- $class2name = $controlrow["class2name"];
- $class3name = $controlrow["class3name"];
-
- $page = <<Edit Levels
- Experience values for each level should be the cumulative total amount of experience up to this point. All other values should be only the new amount to add this level.
-
- HTML;
-
- display_admin(parse($page, $row), "Edit Levels");
-}
-
-function users()
-{
- $page = "Edit Users Click a username to edit the account.
\n";
-
- $users = db()->query('SELECT id, username FROM users ORDER BY id;');
- $has_users = false;
-
- while ($row = $users->fetchArray(SQLITE3_ASSOC)) {
- $has_users = true;
- $page .= "
", "Edit Users");
-}
-
-function edituser($id)
-{
- if (isset($_POST["submit"])) {
- extract($_POST);
-
- $errors = [];
- if ($email == "") $errors[] = "Email is required.";
- if ($verify == "") $errors[] = "Verify is required.";
- if ($authlevel == "") $errors[] = "Auth Level is required.";
- if ($latitude == "") $errors[] = "Latitude is required.";
- if ($longitude == "") $errors[] = "Longitude is required.";
- if ($charclass == "") $errors[] = "Character Class is required.";
- if ($currentaction == "") $errors[] = "Current Action is required.";
- if ($currentfight == "") $errors[] = "Current Fight is required.";
-
- if ($currentmonster == "") $errors[] = "Current Monster is required.";
- if ($currentmonsterhp == "") $errors[] = "Current Monster HP is required.";
- if ($currentmonstersleep == "") $errors[] = "Current Monster Sleep is required.";
- if ($currentmonsterimmune == "") $errors[] = "Current Monster Immune is required.";
- if ($currentuberdamage == "") $errors[] = "Current Uber Damage is required.";
- if ($currentuberdefense == "") $errors[] = "Current Uber Defense is required.";
- if ($currenthp == "") $errors[] = "Current HP is required.";
- if ($currentmp == "") $errors[] = "Current MP is required.";
- if ($currenttp == "") $errors[] = "Current TP is required.";
- if ($maxhp == "") $errors[] = "Max HP is required.";
-
- if ($maxmp == "") $errors[] = "Max MP is required.";
- if ($maxtp == "") $errors[] = "Max TP is required.";
- if ($level == "") $errors[] = "Level is required.";
- if ($gold == "") $errors[] = "Gold is required.";
- if ($experience == "") $errors[] = "Experience is required.";
- if ($goldbonus == "") $errors[] = "Gold Bonus is required.";
- if ($expbonus == "") $errors[] = "Experience Bonus is required.";
- if ($strength == "") $errors[] = "Strength is required.";
- if ($dexterity == "") $errors[] = "Dexterity is required.";
- if ($attackpower == "") $errors[] = "Attack Power is required.";
-
- if ($defensepower == "") $errors[] = "Defense Power is required.";
- if ($weaponid == "") $errors[] = "Weapon ID is required.";
- if ($armorid == "") $errors[] = "Armor ID is required.";
- if ($shieldid == "") $errors[] = "Shield ID is required.";
- if ($slot1id == "") $errors[] = "Slot 1 ID is required.";
- if ($slot2id == "") $errors[] = "Slot 2 ID is required.";
- if ($slot3id == "") $errors[] = "Slot 3 ID is required.";
- if ($weaponname == "") $errors[] = "Weapon Name is required.";
- if ($armorname == "") $errors[] = "Armor Name is required.";
- if ($shieldname == "") $errors[] = "Shield Name is required.";
-
- if ($slot1name == "") $errors[] = "Slot 1 Name is required.";
- if ($slot2name == "") $errors[] = "Slot 2 Name is required.";
- if ($slot3name == "") $errors[] = "Slot 3 Name is required.";
- if ($dropcode == "") $errors[] = "Drop Code is required.";
- if ($spells == "") $errors[] = "Spells is required.";
- if ($towns == "") $errors[] = "Towns is required.";
-
- if (!is_numeric($authlevel)) $errors[] = "Auth Level must be a number.";
- if (!is_numeric($latitude)) $errors[] = "Latitude must be a number.";
- if (!is_numeric($longitude)) $errors[] = "Longitude must be a number.";
- if (!is_numeric($charclass)) $errors[] = "Character Class must be a number.";
- if (!is_numeric($currentfight)) $errors[] = "Current Fight must be a number.";
- if (!is_numeric($currentmonster)) $errors[] = "Current Monster must be a number.";
- if (!is_numeric($currentmonsterhp)) $errors[] = "Current Monster HP must be a number.";
- if (!is_numeric($currentmonstersleep)) $errors[] = "Current Monster Sleep must be a number.";
-
- if (!is_numeric($currentmonsterimmune)) $errors[] = "Current Monster Immune must be a number.";
- if (!is_numeric($currentuberdamage)) $errors[] = "Current Uber Damage must be a number.";
- if (!is_numeric($currentuberdefense)) $errors[] = "Current Uber Defense must be a number.";
- if (!is_numeric($currenthp)) $errors[] = "Current HP must be a number.";
- if (!is_numeric($currentmp)) $errors[] = "Current MP must be a number.";
- if (!is_numeric($currenttp)) $errors[] = "Current TP must be a number.";
- if (!is_numeric($maxhp)) $errors[] = "Max HP must be a number.";
- if (!is_numeric($maxmp)) $errors[] = "Max MP must be a number.";
- if (!is_numeric($maxtp)) $errors[] = "Max TP must be a number.";
- if (!is_numeric($level)) $errors[] = "Level must be a number.";
-
- if (!is_numeric($gold)) $errors[] = "Gold must be a number.";
- if (!is_numeric($experience)) $errors[] = "Experience must be a number.";
- if (!is_numeric($goldbonus)) $errors[] = "Gold Bonus must be a number.";
- if (!is_numeric($expbonus)) $errors[] = "Experience Bonus must be a number.";
- if (!is_numeric($strength)) $errors[] = "Strength must be a number.";
- if (!is_numeric($dexterity)) $errors[] = "Dexterity must be a number.";
- if (!is_numeric($attackpower)) $errors[] = "Attack Power must be a number.";
- if (!is_numeric($defensepower)) $errors[] = "Defense Power must be a number.";
- if (!is_numeric($weaponid)) $errors[] = "Weapon ID must be a number.";
- if (!is_numeric($armorid)) $errors[] = "Armor ID must be a number.";
-
- if (!is_numeric($shieldid)) $errors[] = "Shield ID must be a number.";
- if (!is_numeric($slot1id)) $errors[] = "Slot 1 ID must be a number.";
- if (!is_numeric($slot2id)) $errors[] = "Slot 2 ID must be a number.";
- if (!is_numeric($slot3id)) $errors[] = "Slot 3 ID must be a number.";
- if (!is_numeric($dropcode)) $errors[] = "Drop Code must be a number.";
-
- if (count($errors) === 0) {
- $updatequery = <<query($updatequery, [
- $email, $verify, $authlevel, $latitude, $longitude, $charclass, $currentaction,
- $currentfight, $currentmonster, $currentmonsterhp, $currentmonstersleep, $currentmonsterimmune,
- $currentuberdamage, $currentuberdefense, $currenthp, $currentmp, $currenttp, $maxhp,
- $maxmp, $maxtp, $level, $gold, $experience, $goldbonus, $expbonus, $strength,
- $dexterity, $attackpower, $defensepower, $weaponid, $armorid, $shieldid, $slot1id,
- $slot2id, $slot3id, $weaponname, $armorname, $shieldname, $slot1name, $slot2name,
- $slot3name, $dropcode, $spells, $towns, $id
- ]);
-
- display_admin("User updated.", "Edit Users");
- } else {
- $errorlist = implode(' ', $errors);
- display_admin("Errors:
$errorlist
Please go back and try again.", "Edit Users");
- }
- }
-
- $row = db()->query('SELECT * FROM users WHERE id = ? LIMIT 1;', [$id])->fetchArray(SQLITE3_ASSOC);
-
- global $controlrow;
- $class1name = $controlrow["class1name"];
- $class2name = $controlrow["class2name"];
- $class3name = $controlrow["class3name"];
-
- $page = <<Edit Users
Please go back and try again.", "Add News");
+ $error_list = implode(' ', $errors);
+ $page = "Errors:
$error_list
Please go back and try again.";
}
- }
-
- $page = <<Add A News Post
-
- HTML;
+ HTML;
+ }
- display_admin($page, "Add News");
+ page_title('Admin: Add News');
+ return $page;
}
/**
- * Build an HTML table containing all columns and rows of a given data structure. Takes a SQLiteResult3 of a SELECT *
+ * Build an HTML table containing all columns and rows of a given data structure. Takes a SQLiteResult3 of a SELECT
* query.
*/
function build_bulk_table(SQLite3Result $query_data, string $edit_column, string $edit_link): string
{
$data = [];
- while ($row = $query_data->fetchArray(SQLITE3_ASSOC)) $data[] = $row;
- if (empty($data)) return 'No data.';
+ $data_count = 0;
+ while ($row = $query_data->fetchArray(SQLITE3_ASSOC)) $data[$data_count++] = $row;
+ if ($data_count === 0) return 'No data.';
+
+ $columns = array_diff(array_keys($data[0]), ['password']);
+
+ $html_parts = [
+ '
';
+ return implode('', $html_parts);
+}
+
+/**
+ * Save a row of data to it's table from the data supplied.
+ */
+function save_data_row(string $table, array $data, int $id): SQLite3Result|false
+{
+ $data = array_filter($data, fn($value) => $value !== null && $value !== '');
+ if (empty($data)) return false;
+
+ $fields = implode(',', array_map(fn($key) => "`$key`=?", array_keys($data)));
+ $values = array_values($data);
+ $values[] = $id;
+
+ return db()->query("UPDATE $table SET $fields WHERE id=?", $values);
+}
+
+/**
+ * Handle the result of a generic edit form.
+ */
+function handle_edit_form(int $id, string $table, array $form, string $updated_message = ''): string
+{
+ if ($form['valid']) {
+ save_data_row($table, $form['data'], $id);
+ $page = $updated_message ?: ''.$form['data']['name'].' updated.';
+ } else {
+ $error_list = ul_from_validate_errors($form['errors']);
+ $page = <<Errors:
+
{$error_list}
+ Please go back and try again.
+ HTML;
+ }
+
+ return $page;
}
diff --git a/src/actions/explore.php b/src/actions/explore.php
index 30e2142..470a6fc 100644
--- a/src/actions/explore.php
+++ b/src/actions/explore.php
@@ -23,10 +23,7 @@ function move() {
// Validate direction
$form = validate($_POST, ['direction' => ['in:north,west,east,south']]);
- if (!$form['valid']) {
- $errors = ul_from_validate_errors($form['errors']);
- return \Render\content($errors);
- }
+ if (!$form['valid']) return ul_from_validate_errors($form['errors']);
// Current game state
$game_size = env('game_size');
diff --git a/src/actions/fight.php b/src/actions/fight.php
index b5352bf..0d8f494 100644
--- a/src/actions/fight.php
+++ b/src/actions/fight.php
@@ -120,15 +120,15 @@ function fight()
// Spell action
if (isset($_POST["spell"])) {
$pickedspell = $_POST["userspell"];
- if ($pickedspell == 0) return \Render\content('You must select a spell first. Please go back and try again.');
+ if ($pickedspell == 0) return 'You must select a spell first. Please go back and try again.';
$newspellrow = get_spell($pickedspell);
$spell = in_array($pickedspell, explode(',', user()->spells));
- if (!$spell) return \Render\content('You have not yet learned this spell. Please go back and try again.');
+ if (!$spell) return 'You have not yet learned this spell. Please go back and try again.';
if (user()->currentmp < $newspellrow["mp"]) {
- return \Render\content('You do not have enough Magic Points to cast this spell. Please go back and try again.');
+ return 'You do not have enough Magic Points to cast this spell. Please go back and try again.';
}
// Spell type handling (similar to original function)
@@ -177,7 +177,7 @@ function fight()
// Finalize page and display it
$page = render('fight', ['page' => $page]);
- return \Render\content($page);
+ return $page;
}
function victory()
@@ -251,7 +251,7 @@ function victory()
user()->save();
page_title($title);
- return \Render\content($page);
+ return $page;
}
function drop()
@@ -263,10 +263,7 @@ function drop()
if (isset($_POST["submit"])) {
$slot = $_POST["slot"];
- if ($slot == 0) {
- $page = 'Please go back and select an inventory slot to continue.';
- return \Render\content($page);
- }
+ if ($slot === 0) return 'Please go back and select an inventory slot to continue.';
$slotstr = 'slot'.$slot.'id';
if (user()->$slotstr != 0) {
@@ -321,8 +318,7 @@ function drop()
}
user()->save();
- $page = 'The item has been equipped. You can now continue exploring.';
- return \Render\content($page);
+ return 'The item has been equipped. You can now continue exploring.';
}
$attributearray = array("maxhp"=>"Max HP",
@@ -352,19 +348,18 @@ function drop()
$page .= "";
$page .= "You may also choose to just continue exploring and give up this item.";
- return \Render\content($page);
+ return $page;
}
function dead()
{
- $page = <<You have died.
As a consequence, you've lost half of your gold. However, you have been given back a portion of your hit points
to continue your journey.
You may now continue back to town, and we hope you fair better next time.
HTML;
- return \Render\content($page);
}
function handleMonsterTurn(&$userrow, $monsterrow)
diff --git a/src/actions/forum.php b/src/actions/forum.php
index 90c106b..aa50a1f 100644
--- a/src/actions/forum.php
+++ b/src/actions/forum.php
@@ -56,7 +56,7 @@ function donothing($start = 0)
$page .= '';
page_title('Forum');
- return \Render\content($page);
+ return $page;
}
function showthread($id, $start)
@@ -72,7 +72,7 @@ function showthread($id, $start)
$page .= "
You may now continue to the Login Page and start playing the game.
Thanks for playing!");
+ return "Your account was verified successfully.
You may now continue to the Login Page and start playing the game.
Thanks for playing!";
}
- return \Render\content(render('verify'));
+ return render('verify');
}
function lostpassword()
@@ -132,13 +132,13 @@ function lostpassword()
db()->query('UPDATE users SET password=? WHERE email=?;', [$hashed, $e]);
if (sendpassemail($e, $newpass)) {
- return \Render\content("Your new password was emailed to the address you provided.
Once you receive it, you may Log In and continue playing.
Thank you.");
+ return "Your new password was emailed to the address you provided.
Once you receive it, you may Log In and continue playing.
Thank you.";
} else {
- return \Render\content("There was an error sending your new password.
Please check with the game administrator for more information.
We apologize for the inconvience.");
+ return "There was an error sending your new password.
Please check with the game administrator for more information.
We apologize for the inconvience.";
}
}
- return \Render\content(render('lostpassword'));
+ return render('lostpassword');
}
function changepassword()
@@ -170,7 +170,7 @@ function changepassword()
$auth->logout();
- return \Render\content("Your password was changed successfully.
You have been logged out of the game to avoid errors.
Please log back in to continue playing.");
+ return "Your password was changed successfully.
You have been logged out of the game to avoid errors.
Please log back in to continue playing.";
}
}
@@ -187,10 +187,10 @@ function settings()
user()->save();
$alert = '
+Experience values for each level should be the cumulative total amount of experience up to this point. All other values should be only the new amount to add this level.