Compare commits
No commits in common. "master" and "retro" have entirely different histories.
23
.env.example
|
@ -1,23 +0,0 @@
|
|||
# Game
|
||||
game_name = 'Dragon Knight'
|
||||
game_size = 250
|
||||
game_open = true
|
||||
game_url = 'localhost:8080'
|
||||
admin_email = 'noreply@localhost'
|
||||
class_1_name = 'Mage'
|
||||
class_2_name = 'Warrior'
|
||||
class_3_name = 'Paladin'
|
||||
verify_email = false
|
||||
show_news = true
|
||||
show_babble = true
|
||||
show_online = true
|
||||
|
||||
# Environment
|
||||
debug = false
|
||||
|
||||
# Email
|
||||
smtp_host = smtp.foobar.com
|
||||
smtp_port = 546
|
||||
smtp_encryption = tls
|
||||
smtp_username = foo
|
||||
smtp_password = bar123
|
2
.gitignore
vendored
|
@ -1,5 +1,3 @@
|
|||
.installed
|
||||
database.db
|
||||
database.db-*
|
||||
.env
|
||||
logs
|
||||
|
|
47
README.md
|
@ -1,16 +1,51 @@
|
|||
# Dragon Knight
|
||||
@todo
|
||||
- See also: [Dragon Scourge](https://github.com/renderse7en/dragon-scourge)
|
||||
- [Live Demo](http://dragon.se7enet.com/)
|
||||
|
||||
Many years ago, when I was young and dumb, I wrote a simple little game based on the game *Dragon Warrior* for the NES. It was fun, it helped me learn how to code, and a lot of people liked it.
|
||||
I am now turning it over to the open source community. Fork it, do what you want, make it your own.
|
||||
Couple things to keep in mind though:
|
||||
- It's super old. It may not even work on modern versions of PHP. It may have security issues. I have no idea.
|
||||
- I have moved on with my life, and am no longer changing or doing anything with this game.
|
||||
- I am not providing help or support. You're on your own.
|
||||
- I am not accepting pull requests. If you fork this, you are welcome to do whatever you want, but no changes will be merged back into this.
|
||||
- Quite frankly, I don't really suggest that you use this as is. It's probably better as an inspiration for your own project.
|
||||
- Have fun with this. I gave it a lot of love a long time ago. I hope it inspires you to give something a lot of love as well.
|
||||
- This Git repo represents the final released version, 1.1.11, originally released 3/26/2006.
|
||||
|
||||
# System Requirements
|
||||
- PHP 8.3+
|
||||
- PHP SQLite3 Extension
|
||||
- PHP (4.1 and higher)
|
||||
- MySQL
|
||||
- zlib compression enabled on your server (optional)
|
||||
|
||||
# Installation Instructions
|
||||
1. Clone this repo or download the zip.
|
||||
3. Duplicate `.env.example` as `.env` and change the settings you want.
|
||||
2. Create a new database for Dragon Knight to use, if you don't already have one set up.
|
||||
3. Edit `config.php` to include the correct values for your database setup.
|
||||
4. Upload the contents of the Dragon Knight folder to your site.
|
||||
5. In your browser, go to `/install` and follow the instructions.
|
||||
5. In your browser, run `install.php` and follow the instructions.
|
||||
6. After completing installation, delete `install.php` from your Dragon Knight directory for security.
|
||||
7. Enjoy the game.
|
||||
|
||||
# License
|
||||
See the [license](LICENSE).
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 renderse7en
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
911
public/admin.php
Normal file
|
@ -0,0 +1,911 @@
|
|||
<?php
|
||||
|
||||
// admin.php :: primary administration script.
|
||||
|
||||
require_once '../src/lib.php';
|
||||
|
||||
if (!file_exists('../.installed')) redirect('install.php');
|
||||
|
||||
$controlrow = get_control_row();
|
||||
|
||||
// Login (or verify) if not logged in.
|
||||
if (($userrow = checkcookies()) === false) {
|
||||
if (isset($_GET['do']) && $_GET['do'] === 'verify') redirect('users.php?do=verify');
|
||||
redirect('login.php?do=login');
|
||||
}
|
||||
|
||||
if ($userrow["authlevel"] !== 1) exit("You must have administrator privileges to use the control panel.");
|
||||
|
||||
$do = explode(':', $_GET['do'] ?? '');
|
||||
match ($do[0]) {
|
||||
'main' => primary(),
|
||||
'items' => items(),
|
||||
'edititem' => edititem($do[1]),
|
||||
'drops' => drops(),
|
||||
'editdrop' => editdrop($do[1]),
|
||||
'towns' => towns(),
|
||||
'edittown' => edittown($do[1]),
|
||||
'monsters' => monsters(),
|
||||
'editmonster' => editmonster($do[1]),
|
||||
'levels' => levels(),
|
||||
'editlevel' => editlevel(),
|
||||
'spells' => spells(),
|
||||
'editspell' => editspell($do[1]),
|
||||
'users' => users(),
|
||||
'edituser' => edituser($do[1]),
|
||||
'news' => addnews(),
|
||||
default => donothing()
|
||||
};
|
||||
|
||||
function donothing()
|
||||
{
|
||||
$page = <<<HTML
|
||||
Welcome to the Dragon Knight Administration section. Use the links on the left bar to control and edit various
|
||||
elements of the game.
|
||||
<br><br>
|
||||
Please note that the control panel has been created mostly as a shortcut for certain individual settings. It is
|
||||
meant for use primarily with editing one thing at a time. If you need to completely replace an entire table
|
||||
(say, to replace all stock monsters with your own new ones), it is suggested that you use a more in-depth
|
||||
database tool such as <a href="http://www.phpmyadmin.net" target="_new">phpMyAdmin</a>. Also, you may want
|
||||
to have a copy of the Dragon Knight development kit, available from the
|
||||
<a href="http://dragon.se7enet.com/dev.php">Dragon Knight homepage</a>.
|
||||
<br><br>
|
||||
Also, you should be aware that certain portions of the DK code are dependent on the formatting of certain
|
||||
database results (for example, the special attributes on item drops). While I have attempted to point these out
|
||||
throughout the admin script, you should definitely pay attention and be careful when editing some fields,
|
||||
because mistakes in the database content may result in script errors or your game breaking completely.
|
||||
HTML;
|
||||
|
||||
admindisplay($page, "Admin Home");
|
||||
}
|
||||
|
||||
function primary()
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$errors = [];
|
||||
|
||||
$gn = trim($_POST['gamename'] ?? 'Dragon Knight');
|
||||
$gs = (int) trim($_POST['gamesize'] ?? 250);
|
||||
$c1n = trim($_POST['class1name'] ?? 'Mage');
|
||||
$c2n = trim($_POST['class2name'] ?? 'Warrior');
|
||||
$c3n = trim($_POST['class3name'] ?? 'Paladin');
|
||||
|
||||
if (empty($gn)) $errors[] = "Game name is required.";
|
||||
if (!is_int($gs) || !($gs > 0) || ($gs % 5) != 0) $errors[] = "Map size must be a number greater than 0 and divisible by five.";
|
||||
if (empty($c1n) || empty($c2n) || empty($c3n)) $errors[] = "Class names are required.";
|
||||
|
||||
if (count($errors) === 0) {
|
||||
db()->query('UPDATE control SET gamename=?, gamesize=?, class1name=?, class2name=?, class3name=?, gameopen=?, verifyemail=?, gameurl=?, adminemail=?, shownews=?, showonline=?, showbabble=? WHERE id=1;', [
|
||||
$gn, $gs, $c1n, $c2n, $c3n, $_POST['gameopen'] ?? 1, $_POST['verifyemail'] ?? 1, $_POST['gameurl'] ?? '', $_POST['adminemail'] ?? '', $_POST['shownews'] ?? 1, $_POST['showonline'] ?? 1, $_POST['showbabble'] ?? 1
|
||||
]);
|
||||
|
||||
admindisplay("Settings updated.", "Main Settings");
|
||||
} else {
|
||||
$errorlist = implode('<br>', $errors);
|
||||
admindisplay("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>Please go back and try again.", "Main Settings");
|
||||
}
|
||||
}
|
||||
|
||||
global $controlrow;
|
||||
|
||||
$page = <<<HTML
|
||||
<b><u>Main Settings</u></b><br>
|
||||
These options control several major settings for the overall game engine.<br><br>
|
||||
<form action="admin.php?do=main" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%"><span class="highlight">Game Open:</span></td><td><select name="gameopen"><option value="1" {{open1select}}>Open</option><option value="0" {{open0select}}>Closed</option></select><br><span class="small">Close the game if you are upgrading or working on settings and don't want to cause odd errors for end-users. Closing the game will completely halt all activity.</span></td></tr>
|
||||
<tr><td width="20%">Game Name:</td><td><input type="text" name="gamename" value="{{gamename}}" /><br><span class="small">Default is "Dragon Knight". Change this if you want to change to call your game something different.</span></td></tr>
|
||||
<tr><td width="20%">Game URL:</td><td><input type="text" name="gameurl" value="{{gameurl}}" /><br><span class="small">Please specify the full URL to your game installation ("http://www.server.com/dkpath/index.php"). This gets used in the registration email sent to users. If you leave this field blank or incorrect, users may not be able to register correctly.</span></td></tr>
|
||||
<tr><td width="20%">Admin Email:</td><td><input type="text" name="adminemail" value="{{adminemail}}" /><br><span class="small">Please specify your email address. This gets used when the game has to send an email to users.</span></td></tr>
|
||||
<tr><td width="20%">Map Size:</td><td><input type="text" name="gamesize" value="{{gamesize}}" /><br><span class="small">Default is 250. This is the size of each map quadrant. Note that monster levels increase every 5 spaces, so you should ensure that you have at least (map size / 5) monster levels total, otherwise there will be parts of the map without any monsters, or some monsters won't ever get used. Ex: with a map size of 250, you should have 50 monster levels total.</span></td></tr>
|
||||
<tr><td width="20%">Email Verification:</td><td><select name="verifyemail"><option value="0" {{selectverify0}}>Disabled</option><option value="1" {{selectverify1}}>Enabled</option></select><br><span class="small">Make users verify their email address for added security.</span></td></tr>
|
||||
<tr><td width="20%">Show News:</td><td><select name="shownews"><option value="0" {{selectnews0}}>No</option><option value="1" {{selectnews1}}>Yes</option></select><br><span class="small">Toggle display of the Latest News box in towns.</td></tr>
|
||||
<tr><td width="20%">Show Who's Online:</td><td><select name="showonline"><option value="0" {{selectonline0}}>No</option><option value="1" {{selectonline1}}>Yes</option></select><br><span class="small">Toggle display of the Who's Online box in towns.</span></td></tr>
|
||||
<tr><td width="20%">Show Babblebox:</td><td><select name="showbabble"><option value="0" {{selectbabble0}}>No</option><option value="1" {{selectbabble1}}>Yes</option></select><br><span class="small">Toggle display of the Babble Box in towns.</span></td></tr>
|
||||
<tr><td width="20%">Class 1 Name:</td><td><input type="text" name="class1name" value="{{class1name}}" /><br></td></tr>
|
||||
<tr><td width="20%">Class 2 Name:</td><td><input type="text" name="class2name" value="{{class2name}}" /><br></td></tr>
|
||||
<tr><td width="20%">Class 3 Name:</td><td><input type="text" name="class3name" value="{{class3name}}" /><br></td></tr>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset">
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
if ($controlrow["verifyemail"] == 0) { $controlrow["selectverify0"] = "selected=\"selected\" "; } else { $controlrow["selectverify0"] = ""; }
|
||||
if ($controlrow["verifyemail"] == 1) { $controlrow["selectverify1"] = "selected=\"selected\" "; } else { $controlrow["selectverify1"] = ""; }
|
||||
if ($controlrow["shownews"] == 0) { $controlrow["selectnews0"] = "selected=\"selected\" "; } else { $controlrow["selectnews0"] = ""; }
|
||||
if ($controlrow["shownews"] == 1) { $controlrow["selectnews1"] = "selected=\"selected\" "; } else { $controlrow["selectnews1"] = ""; }
|
||||
if ($controlrow["showonline"] == 0) { $controlrow["selectonline0"] = "selected=\"selected\" "; } else { $controlrow["selectonline0"] = ""; }
|
||||
if ($controlrow["showonline"] == 1) { $controlrow["selectonline1"] = "selected=\"selected\" "; } else { $controlrow["selectonline1"] = ""; }
|
||||
if ($controlrow["showbabble"] == 0) { $controlrow["selectbabble0"] = "selected=\"selected\" "; } else { $controlrow["selectbabble0"] = ""; }
|
||||
if ($controlrow["showbabble"] == 1) { $controlrow["selectbabble1"] = "selected=\"selected\" "; } else { $controlrow["selectbabble1"] = ""; }
|
||||
if ($controlrow["gameopen"] == 1) { $controlrow["open1select"] = "selected=\"selected\" "; } else { $controlrow["open1select"] = ""; }
|
||||
if ($controlrow["gameopen"] == 0) { $controlrow["open0select"] = "selected=\"selected\" "; } else { $controlrow["open0select"] = ""; }
|
||||
|
||||
admindisplay(parsetemplate($page, $controlrow), "Main Settings");
|
||||
}
|
||||
|
||||
function items()
|
||||
{
|
||||
$items = db()->query('SELECT id, name FROM items ORDER BY id;');
|
||||
$page = "<b><u>Edit Items</u></b><br>Click an item's name to edit it.<br><br><table width=\"50%\">\n";
|
||||
|
||||
$hasItems = false;
|
||||
while ($row = $items->fetchArray(SQLITE3_BOTH)) {
|
||||
$hasItems = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=edititem:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$hasItems) $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No items found.</td></tr>\n";
|
||||
admindisplay($page . "</table>", "Edit Items");
|
||||
}
|
||||
|
||||
function edititem($id)
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$errors = [];
|
||||
$n = trim($_POST['name'] ?? '');
|
||||
$bc = (int) trim($_POST['buycost'] ?? 0);
|
||||
$a = (int) trim($_POST['attribute'] ?? 0);
|
||||
$s = trim($_POST['special'] ?? 'X');
|
||||
|
||||
if (empty($n)) $errors[] = "Name is required.";
|
||||
if (!is_int($bc) || !($bc >= 0)) $errors[] = 'Cost must be a number greater than or equal to 0.';
|
||||
if (!is_int($a)) $errors[] = 'Attribute must be a number.';
|
||||
|
||||
if (count($errors) === 0) {
|
||||
db()->query('UPDATE items SET name=?, type=?, buycost=?, attribute=?, special=? WHERE id=?;', [
|
||||
$n, $_POST['type'] ?? 0, $bc, $a, $s, $id
|
||||
]);
|
||||
admindisplay("Item updated.","Edit Items");
|
||||
} else {
|
||||
$errorlist = implode('<br>', $errors);
|
||||
admindisplay("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>Please go back and try again.", "Edit Items");
|
||||
}
|
||||
}
|
||||
|
||||
$item = get_item($id);
|
||||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Items</u></b><br><br>
|
||||
<form action="admin.php?do=edititem:$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" value="{{name}}" /></td></tr>
|
||||
<tr><td width="20%">Type:</td><td><select name="type"><option value="1" {{type1select}}>Weapon</option><option value="2" {{type2select}}>Armor</option><option value="3" {{type3select}}>Shield</option></select></td></tr>
|
||||
<tr><td width="20%">Cost:</td><td><input type="text" name="buycost" value="{{buycost}}" /> gold</td></tr>
|
||||
<tr><td width="20%">Attribute:</td><td><input type="text" name="attribute" value="{{attribute}}" /><br><span class="small">How much the item adds to total attackpower (weapons) or defensepower (armor/shields).</span></td></tr>
|
||||
<tr><td width="20%">Special:</td><td><input type="text" name="special" value="{{special}}" /><br><span class="small">Should be either a special code or <span class="highlight">X</span> to disable. Edit this field very carefully because mistakes to formatting or field names can create problems in the game.</span></td></tr>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
||||
</form>
|
||||
<b>Special Codes:</b><br>
|
||||
Special codes can be added in the item's Special field to give it extra user attributes. Special codes are in the format <span class="highlight">attribute,value</span>. <span class="highlight">Attribute</span> can be any database field from the Users table - however, it is suggested that you only use the ones from the list below, otherwise things can get freaky. <span class="highlight">Value</span> may be any positive or negative whole number. For example, if you want a weapon to give an additional 50 max hit points, the special code would be <span class="highlight">maxhp,50</span>.<br><br>
|
||||
Suggested user fields for special codes:<br>
|
||||
maxhp - max hit points<br>
|
||||
maxmp - max magic points<br>
|
||||
maxtp - max travel points<br>
|
||||
goldbonus - gold bonus, in percent<br>
|
||||
expbonus - experience bonus, in percent<br>
|
||||
strength - strength (which also adds to attackpower)<br>
|
||||
dexterity - dexterity (which also adds to defensepower)<br>
|
||||
attackpower - total attack power<br>
|
||||
defensepower - total defense power
|
||||
HTML;
|
||||
|
||||
if ($item["type"] == 1) { $item["type1select"] = "selected=\"selected\" "; } else { $item["type1select"] = ""; }
|
||||
if ($item["type"] == 2) { $item["type2select"] = "selected=\"selected\" "; } else { $item["type2select"] = ""; }
|
||||
if ($item["type"] == 3) { $item["type3select"] = "selected=\"selected\" "; } else { $item["type3select"] = ""; }
|
||||
|
||||
admindisplay(parsetemplate($page, $item), "Edit Items");
|
||||
}
|
||||
|
||||
function drops()
|
||||
{
|
||||
$page = "<b><u>Edit Drops</u></b><br>Click an item's name to edit it.<br><br><table width=\"50%\">\n";
|
||||
|
||||
$drops = db()->query('SELECT id, name FROM drops ORDER BY id;');
|
||||
$has_drops = false;
|
||||
while ($row = $drops->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_drops = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=editdrop:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_drops) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No drops found.</td></tr>\n"; }
|
||||
|
||||
admindisplay($page . "</table>", "Edit Drops");
|
||||
}
|
||||
|
||||
function editdrop($id)
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$errors = [];
|
||||
|
||||
$n = trim($_POST['name'] ?? '');
|
||||
$ml = (int) trim($_POST['mlevel'] ?? 0);
|
||||
$a = trim($_POST['attribute1'] ?? 'X');
|
||||
$a2 = trim($_POST['attribute2'] ?? 'X');
|
||||
|
||||
if (empty($n)) $errors[] = "Name is required.";
|
||||
if (!is_int($ml) || $ml < 1) $errors[] = "Monster level is required, and must be higher than 0.";
|
||||
if (empty($a) || $a === 'X') $errors[] = 'First attribute is required.';
|
||||
if (empty($a2)) $a2 = 'X';
|
||||
|
||||
if (count($errors) === 0) {
|
||||
db()->query('UPDATE drops SET name=?, mlevel=?, attribute1=?, attribute2=? WHERE id=?;', [
|
||||
$n, $ml, $a, $a2, $id
|
||||
]);
|
||||
admindisplay("Item updated.","Edit Drops");
|
||||
} else {
|
||||
$errorlist = implode('<br>', $errors);
|
||||
admindisplay("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>Please go back and try again.", "Edit Drops");
|
||||
}
|
||||
}
|
||||
|
||||
$drop = get_drop($id);
|
||||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Drops</u></b><br><br>
|
||||
<form action="admin.php?do=editdrop:$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" value="{{name}}" /></td></tr>
|
||||
<tr><td width="20%">Monster Level:</td><td><input type="number" name="mlevel" value="{{mlevel}}" /><br><span class="small">Minimum monster level that will drop this item.</span></td></tr>
|
||||
<tr><td width="20%">Attribute 1:</td><td><input type="text" name="attribute1" value="{{attribute1}}" /><br><span class="small">Must be a special code. First attribute cannot be disabled. Edit this field very carefully because mistakes to formatting or field names can create problems in the game.</span></td></tr>
|
||||
<tr><td width="20%">Attribute 2:</td><td><input type="text" name="attribute2" value="{{attribute2}}" /><br><span class="small">Should be either a special code or <span class="highlight">X</span> to disable. Edit this field very carefully because mistakes to formatting or field names can create problems in the game.</span></td></tr>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
||||
</form>
|
||||
<b>Special Codes:</b><br>
|
||||
Special codes are used in the two attribute fields to give the item properties. The first attribute field must contain a special code, but the second one may be left empty ("X") if you wish. Special codes are in the format <span class="highlight">attribute,value</span>. <span class="highlight">Attribute</span> can be any database field from the Users table - however, it is suggested that you only use the ones from the list below, otherwise things can get freaky. <span class="highlight">Value</span> may be any positive or negative whole number. For example, if you want a weapon to give an additional 50 max hit points, the special code would be <span class="highlight">maxhp,50</span>.<br><br>
|
||||
Suggested user fields for special codes:<br>
|
||||
maxhp - max hit points<br>
|
||||
maxmp - max magic points<br>
|
||||
maxtp - max travel points<br>
|
||||
goldbonus - gold bonus, in percent<br>
|
||||
expbonus - experience bonus, in percent<br>
|
||||
strength - strength (which also adds to attackpower)<br>
|
||||
dexterity - dexterity (which also adds to defensepower)<br>
|
||||
attackpower - total attack power<br>
|
||||
defensepower - total defense power
|
||||
HTML;
|
||||
|
||||
admindisplay(parsetemplate($page, $drop), "Edit Drops");
|
||||
}
|
||||
|
||||
function towns()
|
||||
{
|
||||
$page = "<b><u>Edit Towns</u></b><br>Click an town's name to edit it.<br><br><table width=\"50%\">\n";
|
||||
|
||||
$towns = db()->query('SELECT id, name FROM towns ORDER BY id;');
|
||||
$has_towns = false;
|
||||
while ($row = $towns->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_towns = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=edittown:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_towns) $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No towns found.</td></tr>\n";
|
||||
|
||||
admindisplay($page . "</table>", "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 ($errors == 0) {
|
||||
db()->query('UPDATE towns SET name=?, latitude=?, longitude=?, innprice=?, mapprice=?, travelpoints=?, itemslist=? WHERE id=?;', [
|
||||
$n, $la, $lo, $ip, $mp, $tp, $il, $id
|
||||
]);
|
||||
admindisplay("Town updated.", "Edit Towns");
|
||||
} else {
|
||||
$errorlist = implode('<br>', $errors);
|
||||
admindisplay("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>Please go back and try again.", "Edit Towns");
|
||||
}
|
||||
}
|
||||
|
||||
$row = get_town_by_id($id);
|
||||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Towns</u></b><br><br>
|
||||
<form action="admin.php?do=edittown:$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" value="{{name}}" /></td></tr>
|
||||
<tr><td width="20%">Latitude:</td><td><input type="text" name="latitude" value="{{latitude}}" /><br><span class="small">Positive or negative integer.</span></td></tr>
|
||||
<tr><td width="20%">Longitude:</td><td><input type="text" name="longitude" value="{{longitude}}" /><br><span class="small">Positive or negative integer.</span></td></tr>
|
||||
<tr><td width="20%">Inn Price:</td><td><input type="text" name="innprice" value="{{innprice}}" /> gold</td></tr>
|
||||
<tr><td width="20%">Map Price:</td><td><input type="text" name="mapprice" value="{{mapprice}}" /> gold<br><span class="small">How much it costs to buy the map to this town.</span></td></tr>
|
||||
<tr><td width="20%">Travel Points:</td><td><input type="text" name="travelpoints" value="{{travelpoints}}" /><br><span class="small">How many TP are consumed when travelling to this town.</span></td></tr>
|
||||
<tr><td width="20%">Items List:</td><td><input type="text" name="itemslist" value="{{itemslist}}" /><br><span class="small">Comma-separated list of item ID numbers available for purchase at this town. (Example: <span class="highlight">1,2,3,6,9,10,13,20</span>)</span></td></tr>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
admindisplay(parsetemplate($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 = "<b><u>Edit Monsters</u></b><br>";
|
||||
|
||||
if (($controlrow['gamesize'] / 5) !== $max_level) {
|
||||
$page .= "<span class=\"highlight\">Note:</span> 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.<br>";
|
||||
} else {
|
||||
$page .= "Monster level and map size match. No further actions are required for map compatibility.<br>";
|
||||
}
|
||||
|
||||
$page .= "Click an monster's name to edit it.<br><br><table width=\"50%\">\n";
|
||||
|
||||
$has_monsters = false;
|
||||
while ($row = $monsters->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_monsters = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=editmonster:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_monsters) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No monsters found.</td></tr>\n"; }
|
||||
|
||||
admindisplay($page."</table>", "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
|
||||
]);
|
||||
admindisplay("Monster updated.", "Edit monsters");
|
||||
} else {
|
||||
$errorlist = implode('<br>', $errors);
|
||||
admindisplay("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>Please go back and try again.", "Edit monsters");
|
||||
}
|
||||
}
|
||||
|
||||
$row = get_monster($id);
|
||||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Monsters</u></b><br><br>
|
||||
<form action="admin.php?do=editmonster:$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" size="30" maxlength="30" value="{{name}}" /></td></tr>
|
||||
<tr><td width="20%">Max Hit Points:</td><td><input type="text" name="maxhp" size="5" maxlength="10" value="{{maxhp}}" /></td></tr>
|
||||
<tr><td width="20%">Max Damage:</td><td><input type="text" name="maxdam" size="5" maxlength="10" value="{{maxdam}}" /><br><span class="small">Compares to player's attackpower.</span></td></tr>
|
||||
<tr><td width="20%">Armor:</td><td><input type="text" name="armor" size="5" maxlength="10" value="{{armor}}" /><br><span class="small">Compares to player's defensepower.</span></td></tr>
|
||||
<tr><td width="20%">Monster Level:</td><td><input type="text" name="level" size="5" maxlength="10" value="{{level}}" /><br><span class="small">Determines spawn location and item drops.</span></td></tr>
|
||||
<tr><td width="20%">Max Experience:</td><td><input type="text" name="maxexp" size="5" maxlength="10" value="{{maxexp}}" /><br><span class="small">Max experience gained from defeating monster.</span></td></tr>
|
||||
<tr><td width="20%">Max Gold:</td><td><input type="text" name="maxgold" size="5" maxlength="10" value="{{maxgold}}" /><br><span class="small">Max gold gained from defeating monster.</span></td></tr>
|
||||
<tr><td width="20%">Immunity:</td><td><select name="immune"><option value="0" {{immune0select}}>None</option><option value="1" {{immune1select}}>Hurt Spells</option><option value="2" {{immune2select}}>Hurt & Sleep Spells</option></select><br><span class="small">Some monsters may not be hurt by certain spells.</span></td></tr>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
if ($row["immune"] == 1) { $row["immune1select"] = "selected=\"selected\" "; } else { $row["immune1select"] = ""; }
|
||||
if ($row["immune"] == 2) { $row["immune2select"] = "selected=\"selected\" "; } else { $row["immune2select"] = ""; }
|
||||
if ($row["immune"] == 3) { $row["immune3select"] = "selected=\"selected\" "; } else { $row["immune3select"] = ""; }
|
||||
|
||||
admindisplay(parsetemplate($page, $row), "Edit Monsters");
|
||||
}
|
||||
|
||||
function spells()
|
||||
{
|
||||
$page = "<b><u>Edit Spells</u></b><br>Click an spell's name to edit it.<br><br><table width=\"50%\">\n";
|
||||
|
||||
$spells = db()->query('SELECT id, name FROM spells ORDER BY id;');
|
||||
$has_spells = false;
|
||||
|
||||
while ($row = $spells->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_spells = true;
|
||||
$page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=editspell:".$row["id"]."\">".$row["name"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_spells) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No spells found.</td></tr>\n"; }
|
||||
|
||||
admindisplay($page."</table>", "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
|
||||
]);
|
||||
admindisplay("Spell updated.", "Edit Spells");
|
||||
} else {
|
||||
$errorlist = implode('<br>', $errors);
|
||||
admindisplay("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>Please go back and try again.", "Edit Spells");
|
||||
}
|
||||
}
|
||||
|
||||
$row = get_spell($id);
|
||||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Spells</u></b><br><br>
|
||||
<form action="admin.php?do=editspell:$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" size="30" maxlength="30" value="{{name}}" /></td></tr>
|
||||
<tr><td width="20%">Magic Points:</td><td><input type="text" name="mp" size="5" maxlength="10" value="{{mp}}" /><br><span class="small">MP required to cast spell.</span></td></tr>
|
||||
<tr><td width="20%">Attribute:</td><td><input type="text" name="attribute" size="5" maxlength="10" value="{{attribute}}" /><br><span class="small">Numeric value of the spell's effect. Ties with type, below.</span></td></tr>
|
||||
<tr><td width="20%">Type:</td><td><select name="type"><option value="1" {{type1select}}>Heal</option><option value="2" {{type2select}}>Hurt</option><option value="3" {{type3select}}>Sleep</option><option value="4" {{type4select}}>Uber Attack</option><option value="5" {{type5select}}>Uber Defense</option></select><br><span class="small">- Heal gives player back [attribute] hit points.<br>- Hurt deals [attribute] damage to monster.<br>- Sleep keeps monster from attacking ([attribute] is monster's chance out of 15 to stay asleep each turn).<br>- Uber Attack increases total attack damage by [attribute] percent.<br>- Uber Defense increases total defense from attack by [attribute] percent.</span></td></tr>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
||||
</form>
|
||||
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"] = ""; }
|
||||
|
||||
admindisplay(parsetemplate($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 .= "<option value=\"$i\">$i</option>\n";
|
||||
}
|
||||
|
||||
$page = <<<HTML
|
||||
<b><u>Edit Levels</u></b><br>
|
||||
Select a level number from the dropdown box to edit it.<br><br>
|
||||
<form action="admin.php?do=editlevel" method="post">
|
||||
<select name="level">
|
||||
$options
|
||||
</select>
|
||||
<input type="submit" name="go" value="Edit" />
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
admindisplay($page, "Edit Levels");
|
||||
}
|
||||
|
||||
function editlevel()
|
||||
{
|
||||
if (!isset($_POST["level"])) admindisplay("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 = <<<SQL
|
||||
UPDATE levels SET
|
||||
"1_exp" = ?, "1_hp" = ?, "1_mp" = ?, "1_tp" = ?, "1_strength" = ?, "1_dexterity" = ?, "1_spells" = ?,
|
||||
"2_exp" = ?, "2_hp" = ?, "2_mp" = ?, "2_tp" = ?, "2_strength" = ?, "2_dexterity" = ?, "2_spells" = ?,
|
||||
"3_exp" = ?, "3_hp" = ?, "3_mp" = ?, "3_tp" = ?, "3_strength" = ?, "3_dexterity" = ?, "3_spells" = ?
|
||||
WHERE id = ?
|
||||
SQL;
|
||||
|
||||
extract($_POST);
|
||||
db()->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
|
||||
]);
|
||||
admindisplay("Level updated.", "Edit Levels");
|
||||
} else {
|
||||
$errorlist = implode('<br>', $errors);
|
||||
admindisplay("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>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 = <<<HTML
|
||||
<b><u>Edit Levels</u></b><br><br>
|
||||
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.<br><br>
|
||||
<form action="admin.php?do=editlevel" method="post">
|
||||
<input type="hidden" name="level" value="$id" />
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
|
||||
<tr><td colspan="2" style="background-color:#cccccc;"> </td></tr>
|
||||
|
||||
<tr><td width="20%">$class1name Experience:</td><td><input type="text" name="one_exp" size="10" maxlength="8" value="{{1_exp}}" /></td></tr>
|
||||
<tr><td width="20%">$class1name HP:</td><td><input type="text" name="one_hp" size="5" maxlength="5" value="{{1_hp}}" /></td></tr>
|
||||
<tr><td width="20%">$class1name MP:</td><td><input type="text" name="one_mp" size="5" maxlength="5" value="{{1_mp}}" /></td></tr>
|
||||
<tr><td width="20%">$class1name TP:</td><td><input type="text" name="one_tp" size="5" maxlength="5" value="{{1_tp}}" /></td></tr>
|
||||
<tr><td width="20%">$class1name Strength:</td><td><input type="text" name="one_strength" size="5" maxlength="5" value="{{1_strength}}" /></td></tr>
|
||||
<tr><td width="20%">$class1name Dexterity:</td><td><input type="text" name="one_dexterity" size="5" maxlength="5" value="{{1_dexterity}}" /></td></tr>
|
||||
<tr><td width="20%">$class1name Spells:</td><td><input type="text" name="one_spells" size="5" maxlength="3" value="{{1_spells}}" /></td></tr>
|
||||
|
||||
<tr><td colspan="2" style="background-color:#cccccc;"> </td></tr>
|
||||
|
||||
<tr><td width="20%">$class2name Experience:</td><td><input type="text" name="two_exp" size="10" maxlength="8" value="{{2_exp}}" /></td></tr>
|
||||
<tr><td width="20%">$class2name HP:</td><td><input type="text" name="two_hp" size="5" maxlength="5" value="{{2_hp}}" /></td></tr>
|
||||
<tr><td width="20%">$class2name MP:</td><td><input type="text" name="two_mp" size="5" maxlength="5" value="{{2_mp}}" /></td></tr>
|
||||
<tr><td width="20%">$class2name TP:</td><td><input type="text" name="two_tp" size="5" maxlength="5" value="{{2_tp}}" /></td></tr>
|
||||
<tr><td width="20%">$class2name Strength:</td><td><input type="text" name="two_strength" size="5" maxlength="5" value="{{2_strength}}" /></td></tr>
|
||||
<tr><td width="20%">$class2name Dexterity:</td><td><input type="text" name="two_dexterity" size="5" maxlength="5" value="{{2_dexterity}}" /></td></tr>
|
||||
<tr><td width="20%">$class2name Spells:</td><td><input type="text" name="two_spells" size="5" maxlength="3" value="{{2_spells}}" /></td></tr>
|
||||
|
||||
<tr><td colspan="2" style="background-color:#cccccc;"> </td></tr>
|
||||
|
||||
<tr><td width="20%">$class3name Experience:</td><td><input type="text" name="three_exp" size="10" maxlength="8" value="{{3_exp}}" /></td></tr>
|
||||
<tr><td width="20%">$class3name HP:</td><td><input type="text" name="three_hp" size="5" maxlength="5" value="{{3_hp}}" /></td></tr>
|
||||
<tr><td width="20%">$class3name MP:</td><td><input type="text" name="three_mp" size="5" maxlength="5" value="{{3_mp}}" /></td></tr>
|
||||
<tr><td width="20%">$class3name TP:</td><td><input type="text" name="three_tp" size="5" maxlength="5" value="{{3_tp}}" /></td></tr>
|
||||
<tr><td width="20%">$class3name Strength:</td><td><input type="text" name="three_strength" size="5" maxlength="5" value="{{3_strength}}" /></td></tr>
|
||||
<tr><td width="20%">$class3name Dexterity:</td><td><input type="text" name="three_dexterity" size="5" maxlength="5" value="{{3_dexterity}}" /></td></tr>
|
||||
<tr><td width="20%">$class3name Spells:</td><td><input type="text" name="three_spells" size="5" maxlength="3" value="{{3_spells}}" /></td></tr>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
admindisplay(parsetemplate($page, $row), "Edit Levels");
|
||||
}
|
||||
|
||||
function users()
|
||||
{
|
||||
$page = "<b><u>Edit Users</u></b><br>Click a username to edit the account.<br><br><table width=\"50%\">\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 .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">".$row["id"]."</td><td style=\"background-color: #eeeeee;\"><a href=\"admin.php?do=edituser:".$row["id"]."\">".$row["username"]."</a></td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$has_users) { $page .= "<tr><td width=\"8%\" style=\"background-color: #eeeeee;\">No spells found.</td></tr>\n"; }
|
||||
|
||||
admindisplay($page."</table>", "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 = <<<SQL
|
||||
UPDATE users SET
|
||||
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 = ?
|
||||
WHERE id = ?
|
||||
SQL;
|
||||
|
||||
db()->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
|
||||
]);
|
||||
|
||||
admindisplay("User updated.", "Edit Users");
|
||||
} else {
|
||||
$errorlist = implode('<br>', $errors);
|
||||
admindisplay("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>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 = <<<HTML
|
||||
<b><u>Edit Users</u></b><br><br>
|
||||
<form action="admin.php?do=edituser:$id" method="post">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td>{{id}}</td></tr>
|
||||
<tr><td width="20%">Username:</td><td>{{username}}</td></tr>
|
||||
<tr><td width="20%">Email:</td><td><input type="text" name="email" value="{{email}}" /></td></tr>
|
||||
<tr><td width="20%">Verify:</td><td><input type="text" name="verify" value="{{verify}}" /></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>
|
||||
|
||||
<tr><td colspan="2" style="background-color:#cccccc;"> </td></tr>
|
||||
|
||||
<tr><td width="20%">Latitude:</td><td><input type="text" name="latitude" value="{{latitude}}" /></td></tr>
|
||||
<tr><td width="20%">Longitude:</td><td><input type="text" name="longitude" value="{{longitude}}" /></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>
|
||||
|
||||
<tr><td width="20%">Current Action:</td><td><input type="text" name="currentaction" value="{{currentaction}}" /></td></tr>
|
||||
<tr><td width="20%">Current Fight:</td><td><input type="text" name="currentfight" value="{{currentfight}}" /></td></tr>
|
||||
<tr><td width="20%">Current Monster:</td><td><input type="text" name="currentmonster" value="{{currentmonster}}" /></td></tr>
|
||||
<tr><td width="20%">Current Monster HP:</td><td><input type="text" name="currentmonsterhp" value="{{currentmonsterhp}}" /></td></tr>
|
||||
<tr><td width="20%">Current Monster Sleep:</td><td><input type="text" name="currentmonsterimmune" value="{{currentmonsterimmune}}" /></td></tr>
|
||||
<tr><td width="20%">Current Monster Immune:</td><td><input type="text" name="currentmonstersleep" value="{{currentmonstersleep}}" /></td></tr>
|
||||
<tr><td width="20%">Current Uber Damage:</td><td><input type="text" name="currentuberdamage" value="{{currentuberdamage}}" /></td></tr>
|
||||
<tr><td width="20%">Current Uber Defense:</td><td><input type="text" name="currentuberdefense" value="{{currentuberdefense}}" /></td></tr>
|
||||
|
||||
<tr><td colspan="2" style="background-color:#cccccc;"> </td></tr>
|
||||
|
||||
<tr><td width="20%">Current HP:</td><td><input type="text" name="currenthp" value="{{currenthp}}" /></td></tr>
|
||||
<tr><td width="20%">Current MP:</td><td><input type="text" name="currentmp" value="{{currentmp}}" /></td></tr>
|
||||
<tr><td width="20%">Current TP:</td><td><input type="text" name="currenttp" value="{{currenttp}}" /></td></tr>
|
||||
<tr><td width="20%">Max HP:</td><td><input type="text" name="maxhp" value="{{maxhp}}" /></td></tr>
|
||||
<tr><td width="20%">Max MP:</td><td><input type="text" name="maxmp" value="{{maxmp}}" /></td></tr>
|
||||
<tr><td width="20%">Max TP:</td><td><input type="text" name="maxtp" value="{{maxtp}}" /></td></tr>
|
||||
|
||||
<tr><td colspan="2" style="background-color:#cccccc;"> </td></tr>
|
||||
|
||||
<tr><td width="20%">Level:</td><td><input type="text" name="level" value="{{level}}" /></td></tr>
|
||||
<tr><td width="20%">Gold:</td><td><input type="text" name="gold" value="{{gold}}" /></td></tr>
|
||||
<tr><td width="20%">Experience:</td><td><input type="text" name="experience" value="{{experience}}" /></td></tr>
|
||||
<tr><td width="20%">Gold Bonus:</td><td><input type="text" name="goldbonus" value="{{goldbonus}}" /></td></tr>
|
||||
<tr><td width="20%">Experience Bonus:</td><td><input type="text" name="expbonus" value="{{expbonus}}" /></td></tr>
|
||||
<tr><td width="20%">Strength:</td><td><input type="text" name="strength" value="{{strength}}" /></td></tr>
|
||||
<tr><td width="20%">Dexterity:</td><td><input type="text" name="dexterity" value="{{dexterity}}" /></td></tr>
|
||||
<tr><td width="20%">Attack Power:</td><td><input type="text" name="attackpower" value="{{attackpower}}" /></td></tr>
|
||||
<tr><td width="20%">Defense Power:</td><td><input type="text" name="defensepower" value="{{defensepower}}" /></td></tr>
|
||||
|
||||
<tr><td colspan="2" style="background-color:#cccccc;"> </td></tr>
|
||||
|
||||
<tr><td width="20%">Weapon ID:</td><td><input type="text" name="weaponid" value="{{weaponid}}" /></td></tr>
|
||||
<tr><td width="20%">Armor ID:</td><td><input type="text" name="armorid" value="{{armorid}}" /></td></tr>
|
||||
<tr><td width="20%">Shield ID:</td><td><input type="text" name="shieldid" value="{{shieldid}}" /></td></tr>
|
||||
<tr><td width="20%">Slot 1 ID:</td><td><input type="text" name="slot1id" value="{{slot1id}}" /></td></tr>
|
||||
<tr><td width="20%">Slot 2 ID:</td><td><input type="text" name="slot2id" value="{{slot2id}}" /></td></tr>
|
||||
<tr><td width="20%">Slot 3 ID:</td><td><input type="text" name="slot3id" value="{{slot3id}}" /></td></tr>
|
||||
<tr><td width="20%">Weapon Name:</td><td><input type="text" name="weaponname" value="{{weaponname}}" /></td></tr>
|
||||
<tr><td width="20%">Armor Name:</td><td><input type="text" name="armorname" value="{{armorname}}" /></td></tr>
|
||||
<tr><td width="20%">Shield Name:</td><td><input type="text" name="shieldname" value="{{shieldname}}" /></td></tr>
|
||||
<tr><td width="20%">Slot 1 Name:</td><td><input type="text" name="slot1name" value="{{slot1name}}" /></td></tr>
|
||||
<tr><td width="20%">Slot 2 Name:</td><td><input type="text" name="slot2name" value="{{slot2name}}" /></td></tr>
|
||||
<tr><td width="20%">Slot 3 Name:</td><td><input type="text" name="slot3name" value="{{slot3name}}" /></td></tr>
|
||||
|
||||
<tr><td colspan="2" style="background-color:#cccccc;"> </td></tr>
|
||||
|
||||
<tr><td width="20%">Drop Code:</td><td><input type="text" name="dropcode" value="{{dropcode}}" /></td></tr>
|
||||
<tr><td width="20%">Spells:</td><td><input type="text" name="spells" value="{{spells}}" /></td></tr>
|
||||
<tr><td width="20%">Towns:</td><td><input type="text" name="towns" value="{{towns}}" /></td></tr>
|
||||
</table>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
if ($row["authlevel"] == 0) { $row["auth0select"] = "selected=\"selected\" "; } else { $row["auth0select"] = ""; }
|
||||
if ($row["authlevel"] == 1) { $row["auth1select"] = "selected=\"selected\" "; } else { $row["auth1select"] = ""; }
|
||||
if ($row["authlevel"] == 2) { $row["auth2select"] = "selected=\"selected\" "; } else { $row["auth2select"] = ""; }
|
||||
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"] = ""; }
|
||||
|
||||
admindisplay(parsetemplate($page, $row), "Edit Users");
|
||||
}
|
||||
|
||||
function addnews()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$c = trim($_POST['content'] ?? '');
|
||||
|
||||
$errors = [];
|
||||
if (empty($c)) $errors[] = "Content is required.";
|
||||
|
||||
if (count($errors) === 0) {
|
||||
db()->query('INSERT INTO news (author, content) VALUES (?, ?);', [$userrow['username'], $c]);
|
||||
admindisplay("News post added.", "Add News");
|
||||
} else {
|
||||
$errorlist = implode('<br>', $errors);
|
||||
admindisplay("<b>Errors:</b><br><div style=\"color:red;\">$errorlist</div><br>Please go back and try again.", "Add News");
|
||||
}
|
||||
}
|
||||
|
||||
$page = <<<HTML
|
||||
<b><u>Add A News Post</u></b><br><br>
|
||||
<form action="admin.php?do=news" method="post">
|
||||
Type your post below and then click Submit to add it.<br>
|
||||
<textarea name="content" rows="5" cols="50"></textarea><br>
|
||||
<input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" />
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
admindisplay($page, "Add News");
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
:root {
|
||||
--font-size: 16px;
|
||||
--font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
||||
}
|
||||
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: var(--font-size);
|
||||
font-family: var(--font-family);
|
||||
}
|
||||
|
||||
body {
|
||||
padding: 2rem;
|
||||
color: rgb(108, 108, 108);
|
||||
background-color: rgb(245, 245, 245);
|
||||
}
|
||||
|
||||
h1, h2, h3, h4, h5 {
|
||||
color: rgb(30, 30, 30);
|
||||
}
|
||||
|
||||
div#admin-container {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
header {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
main {
|
||||
display: flex;
|
||||
gap: 2rem;
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
main > nav {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
main > section {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
outline-width: none;
|
||||
font-family: var(--font-family);
|
||||
border: 1px solid rgba(0, 0, 0, 0.1);
|
||||
|
||||
& > caption {
|
||||
margin: 1rem;
|
||||
}
|
||||
|
||||
& :is(td,th) {
|
||||
border: 1px solid rgba(0, 0, 0, 0.4);
|
||||
padding: 0.5rem 1rem;
|
||||
}
|
||||
|
||||
& thead tr {
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
& tbody tr:nth-of-type(even) {
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
&:hover { background: rgba(0, 0, 0, 0.2); }
|
||||
}
|
||||
|
||||
td:hover {
|
||||
color: white;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
tr:hover {
|
||||
background: rgba(0, 0, 0, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
.table-wrapper {
|
||||
width: 100%; /* Ensure the wrapper takes 100% of the parent's width */
|
||||
max-height: 300px; /* Set the desired height limit */
|
||||
overflow-x: auto; /* Enable horizontal scrolling if the table overflows */
|
||||
overflow-y: auto; /* Enable vertical scrolling if needed */
|
||||
display: block; /* Ensure block-level behavior */
|
||||
-webkit-overflow-scrolling: touch; /* Smooth scrolling on touch devices */
|
||||
}
|
||||
|
||||
a {
|
||||
color: #015df7;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover {
|
||||
color: hsl(218, 99%, 29%);
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.small {
|
||||
font: 10px verdana;
|
||||
}
|
||||
.highlight {
|
||||
color: red;
|
||||
}
|
||||
.light {
|
||||
color: #999999;
|
||||
}
|
||||
.title {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font-weight: bold;
|
||||
padding: 5px;
|
||||
margin: 3px;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
font-size: 0.8rem;
|
||||
padding: 0.5rem;
|
||||
margin: 2rem 0;
|
||||
}
|
|
@ -1,219 +0,0 @@
|
|||
:root {
|
||||
--font-size: 12px;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: var(--font-size);
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
background-image: url('/img/backgrounds/classic.jpg');
|
||||
scrollbar-gutter: stable both-edges;
|
||||
|
||||
&.skin-1 {
|
||||
background-image: url('/img/backgrounds/snowstorm.jpg');
|
||||
}
|
||||
}
|
||||
|
||||
div#game-container {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 1rem;
|
||||
}
|
||||
|
||||
header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
border-bottom: solid 2px black;
|
||||
padding-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
main {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
main > section {
|
||||
padding: 0.75rem;
|
||||
}
|
||||
|
||||
main > section > section {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
main section#left {
|
||||
width: 180px;
|
||||
flex-shrink: 0;
|
||||
border-right: solid 2px black;
|
||||
}
|
||||
|
||||
main section#middle {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
main section#right {
|
||||
width: 180px;
|
||||
flex-shrink: 0;
|
||||
border-left: solid 2px black;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font-size: 0.8rem;
|
||||
padding: 0.5rem;
|
||||
}
|
||||
|
||||
table {
|
||||
border-style: none;
|
||||
padding: 0px;
|
||||
font-size: var(--font-size);
|
||||
}
|
||||
|
||||
td {
|
||||
border-style: none;
|
||||
padding: 3px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
a {
|
||||
color: #663300;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
a:hover {
|
||||
color: #330000;
|
||||
}
|
||||
|
||||
.small {
|
||||
font-size: 0.8rem;
|
||||
}
|
||||
|
||||
.highlight {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.light {
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
.title {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font-weight: bold;
|
||||
padding: 5px;
|
||||
font-size: 1.2rem;
|
||||
font-family: serif;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
|
||||
.copyright {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font: 10px verdana;
|
||||
}
|
||||
|
||||
.move-compass {
|
||||
width: 128px;
|
||||
height: 128px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background-image: url('/img/compass.webp');
|
||||
margin: 0.5rem auto;
|
||||
}
|
||||
|
||||
.move-compass div.mid {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.move-compass button {
|
||||
background-color: transparent;
|
||||
border: none;
|
||||
color: transparent; /* Hide the text */
|
||||
background-size: cover; /* Ensure the background image fills the button */
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.move-compass button:hover {
|
||||
background-color: rgba(225, 16, 16, 0.5);
|
||||
}
|
||||
|
||||
.move-compass button.north {
|
||||
width: 128px;
|
||||
height: 40px;
|
||||
}
|
||||
|
||||
.move-compass button.west {
|
||||
width: 63px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.move-compass button.east {
|
||||
width: 63px;
|
||||
height: 50px;
|
||||
}
|
||||
|
||||
.move-compass button.south {
|
||||
width: 128px;
|
||||
height: 38px;
|
||||
}
|
||||
|
||||
div.town-content {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 1rem;
|
||||
}
|
||||
|
||||
div.town-content div.options, div.town-content div.news {
|
||||
grid-column: span 2;
|
||||
}
|
||||
|
||||
div.stat-table div.stat-row {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
div.stat-bar {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
div.stat-bar > div {
|
||||
width: 100%;
|
||||
position: absolute;
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
#babblebox > .messages {
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
#babblebox > .messages .message {
|
||||
padding: 0.25rem;
|
||||
background-color: #eee;
|
||||
|
||||
&:nth-child(even) {
|
||||
background-color: white;
|
||||
}
|
||||
}
|
||||
|
||||
#babblebox > form {
|
||||
margin-top: 0 !important;
|
||||
|
||||
& > input[type="text"] {
|
||||
width: 100%;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
:root {
|
||||
--font-size: 14px;
|
||||
}
|
||||
|
||||
html {
|
||||
font-size: var(--font-size);
|
||||
font-family: sans-serif;
|
||||
}
|
||||
|
||||
body {
|
||||
background-image: url('/img/backgrounds/classic.jpg');
|
||||
padding: 2rem;
|
||||
}
|
||||
table {
|
||||
border-style: none;
|
||||
padding: 0px;
|
||||
}
|
||||
tr:nth-child(even) {
|
||||
background-color: white;
|
||||
}
|
||||
td {
|
||||
border-style: none;
|
||||
padding: 3px;
|
||||
vertical-align: top;
|
||||
}
|
||||
td.top {
|
||||
border-bottom: solid 2px black;
|
||||
}
|
||||
td.left {
|
||||
width: 150px;
|
||||
border-right: solid 2px black;
|
||||
}
|
||||
td.right {
|
||||
width: 150px;
|
||||
border-left: solid 2px black;
|
||||
}
|
||||
a {
|
||||
color: #663300;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
}
|
||||
a:hover {
|
||||
color: #330000;
|
||||
}
|
||||
.small {
|
||||
font: 10px verdana;
|
||||
}
|
||||
.highlight {
|
||||
color: red;
|
||||
}
|
||||
.light {
|
||||
color: #999999;
|
||||
}
|
||||
.title {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font-weight: bold;
|
||||
padding: 5px;
|
||||
margin: 3px;
|
||||
}
|
||||
.copyright {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font: 10px verdana;
|
||||
}
|
||||
|
||||
footer {
|
||||
display: flex;
|
||||
justify-content: space-around;
|
||||
font-size: 0.8rem;
|
||||
padding: 0.5rem;
|
||||
margin-top: 2rem;
|
||||
}
|
111
public/forum.php
Normal file
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
|
||||
// forum.php :: Internal forums script for the game.
|
||||
|
||||
require_once '../src/lib.php';
|
||||
|
||||
if (!file_exists('../.installed')) redirect('install.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.");
|
||||
}
|
||||
|
||||
$do = explode(':', $_GET['do'] ?? '');
|
||||
match ($do[0]) {
|
||||
'thread' => showthread($do[1], $do[2]),
|
||||
'new' => newthread(),
|
||||
'reply' => reply(),
|
||||
'list' => donothing($do[1]),
|
||||
default => donothing()
|
||||
};
|
||||
|
||||
function donothing($start = 0)
|
||||
{
|
||||
$query = db()->query('SELECT * FROM forum WHERE parent=0 ORDER BY newpostdate DESC LIMIT 20 OFFSET ?;', [20 * $start]);
|
||||
$page = "<table width=\"100%\"><tr><td style=\"padding:1px; background-color:black;\"><table width=\"100%\" style=\"margins:0px;\" cellspacing=\"1\" cellpadding=\"3\"><tr><th colspan=\"3\" style=\"background-color:#dddddd;\"><center><a href=\"forum.php?do=new\">New Thread</a></center></th></tr><tr><th width=\"50%\" style=\"background-color:#dddddd;\">Thread</th><th width=\"10%\" style=\"background-color:#dddddd;\">Replies</th><th style=\"background-color:#dddddd;\">Last Post</th></tr>\n";
|
||||
|
||||
$hasRows = false;
|
||||
|
||||
while ($row = $query->fetchArray(SQLITE3_ASSOC)) {
|
||||
$hasRows = true;
|
||||
$page .= "<tr><td style=\"background-color:#ffffff;\"><a href=\"forum.php?do=thread:".$row["id"].":0\">".$row["title"]."</a></td><td style=\"background-color:#ffffff;\">".$row["replies"]."</td><td style=\"background-color:#ffffff;\">".$row["newpostdate"]."</td></tr>\n";
|
||||
}
|
||||
|
||||
if (!$hasRows) {
|
||||
$page .= "<tr><td style=\"background-color:#ffffff;\" colspan=\"3\"><b>No threads in forum.</b></td></tr>\n";
|
||||
}
|
||||
|
||||
$page .= "</table></td></tr></table>";
|
||||
|
||||
display($page, "Forum");
|
||||
}
|
||||
|
||||
function showthread($id, $start)
|
||||
{
|
||||
$posts = db()->query('SELECT * FROM forum WHERE id=? OR parent=? ORDER BY id LIMIT 15 OFFSET ?;', [$id, $id, $start * 15]);
|
||||
$title = db()->query('SELECT title FROM forum WHERE id=? LIMIT 1;', [$id])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$page = "<table width=\"100%\"><tr><td style=\"padding:1px; background-color:black;\"><table width=\"100%\" style=\"margins:0px;\" cellspacing=\"1\" cellpadding=\"3\"><tr><td colspan=\"2\" style=\"background-color:#dddddd;\"><b><a href=\"forum.php\">Forum</a> :: ".$title['title']."</b></td></tr>\n";
|
||||
while ($row = $posts->fetchArray(SQLITE3_ASSOC)) {
|
||||
$page .= "<tr><td width=\"25%\" style=\"background-color:#ffffff; vertical-align:top;\"><span class=\"small\"><b>".$row["author"]."</b><br><br>".prettyforumdate($row["postdate"])."</td><td style=\"background-color:#ffffff; vertical-align:top;\">".nl2br($row["content"])."</td></tr>\n";
|
||||
}
|
||||
$page .= "</table></td></tr></table><br>";
|
||||
$page .= "<table width=\"100%\"><tr><td><b>Reply To This Thread:</b><br><form action=\"forum.php?do=reply\" method=\"post\"><input type=\"hidden\" name=\"parent\" value=\"$id\" /><input type=\"hidden\" name=\"title\" value=\"Re: ".$title["title"]."\" /><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
|
||||
|
||||
display($page, "Forum");
|
||||
}
|
||||
|
||||
function reply()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
$p = $_POST['parent'] ?? 0;
|
||||
$t = trim($_POST['title'] ?? '');
|
||||
$c = trim($_POST['content'] ?? '');
|
||||
|
||||
db()->query('INSERT INTO forum (author, title, content, parent) VALUES (?, ?, ?, ?);', [$userrow['username'], $t, $c, $p]);
|
||||
db()->query('UPDATE forum SET newpostdate=CURRENT_TIMESTAMP, replies=replies + 1 WHERE id=?;', [$p]);
|
||||
redirect("forum.php?do=thread:$p:0");
|
||||
}
|
||||
|
||||
function newthread()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
extract($_POST);
|
||||
$t = trim($_POST['title'] ?? '');
|
||||
$c = trim($_POST['content'] ?? '');
|
||||
db()->query('INSERT INTO forum (author, title, content) VALUES (?, ?, ?);', [$userrow['username'], $t, $c]);
|
||||
redirect('forum.php');
|
||||
}
|
||||
|
||||
$page = "<table width=\"100%\"><tr><td><b>Make A New Post:</b><br><br/ ><form action=\"forum.php?do=new\" method=\"post\">Title:<br><input type=\"text\" name=\"title\" size=\"50\" maxlength=\"50\" /><br><br>Message:<br><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
|
||||
display($page, "Forum");
|
||||
}
|
568
public/help.php
Normal file
|
@ -0,0 +1,568 @@
|
|||
<?php
|
||||
|
||||
require_once '../src/lib.php';
|
||||
|
||||
if (!file_exists('../.installed')) redirect('install.php');
|
||||
|
||||
$controlrow = get_control_row();
|
||||
|
||||
$page = $_GET['page'] ?? '';
|
||||
if (!in_array($page, ['main', 'items', 'levels', 'monsters', 'spells'])) $page = 'main';
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title><?= $controlrow["gamename"] ?> Help</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
background-image: url('images/background.jpg');
|
||||
color: black;
|
||||
font: 11px verdana;
|
||||
}
|
||||
table {
|
||||
border-style: none;
|
||||
padding: 0px;
|
||||
font: 11px verdana;
|
||||
}
|
||||
tr:nth-child(even) {
|
||||
background-color: white;
|
||||
}
|
||||
td {
|
||||
border-style: none;
|
||||
padding: 3px;
|
||||
vertical-align: top;
|
||||
}
|
||||
td.top {
|
||||
border-bottom: solid 2px black;
|
||||
}
|
||||
td.left {
|
||||
width: 150px;
|
||||
border-right: solid 2px black;
|
||||
}
|
||||
td.right {
|
||||
width: 150px;
|
||||
border-left: solid 2px black;
|
||||
}
|
||||
a {
|
||||
color: #663300;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
}
|
||||
a:hover {
|
||||
color: #330000;
|
||||
}
|
||||
.small {
|
||||
font: 10px verdana;
|
||||
}
|
||||
.highlight {
|
||||
color: red;
|
||||
}
|
||||
.light {
|
||||
color: #999999;
|
||||
}
|
||||
.title {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font-weight: bold;
|
||||
padding: 5px;
|
||||
margin: 3px;
|
||||
}
|
||||
.copyright {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font: 10px verdana;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<a name="top"></a>
|
||||
<h1><?= $controlrow["gamename"] ?> Help</h1>
|
||||
[ <a href="/index.php">Return to the game</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<?php
|
||||
// @MAIN
|
||||
if ($page === 'main'):
|
||||
?>
|
||||
<h3>Table of Contents</h3>
|
||||
<ul>
|
||||
<li /><a href="#intro">Introduction</a>
|
||||
<li /><a href="#classes">Character Classes</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>
|
||||
<li /><a href="#items">Spoilers: Items & Drops</a>
|
||||
<li /><a href="#monsters">Spoilers: Monsters</a>
|
||||
<li /><a href="#spells">Spoilers: Spells</a>
|
||||
<li /><a href="#levels">Spoilers: Levels</a>
|
||||
<li /><a href="#credits">Credits</a>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3><a name="intro"></a>Introduction</h3>
|
||||
Firstly, I'd like to say thank you for playing my game. The <i>Dragon Knight</i> game engine is the result of several months of
|
||||
planning, coding and testing. The original idea was to create a web-based tribute to the NES game, <i>Dragon
|
||||
Warrior</i>. In its current iteration, only the underlying fighting system really resembles that game, as almost
|
||||
everything else in DK has been made bigger and better. But you should still recognize bits and pieces as stemming
|
||||
from <i>Dragon Warrior</i> and other RPGs of old.<br><br>
|
||||
This is the first game I've ever written, and it has definitely been a positive experience. It got difficult at
|
||||
times, admittedly, but it was still a lot of fun to write, and even more fun to play. And I hope to use this
|
||||
experience so that if I ever want to create another game it will be even better than this one.<br><br>
|
||||
If you are a site administrator, and would like to install a copy of DK on your own server, you may visit the
|
||||
<a href="http://dragon.se7enet.com/dev.php" target="_new">development site</a> for <i>Dragon Knight</i>. This page
|
||||
includes the downloadable game souce code, as well as some other resources that developers and administrators may
|
||||
find valuable.<br><br>
|
||||
Once again, thanks for playing!<br><br>
|
||||
<i>Jamin Seven</i><br>
|
||||
<i>Dragon Knight creator</i><br>
|
||||
<a href="http://www.se7enet.com" target="_new">My Homepage</a><br>
|
||||
<a href="http://dragon.se7enet.com/dev.php" target="_new">Dragon Knight Homepage</a><br ><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="classes"></a>Character Classes</h3>
|
||||
There are three character classes in the game. The main differences between the classes are what spells you get
|
||||
access to, the speed with which you level up, and the amount of HP/MP/strength/dexterity you gain per level. Below
|
||||
is a basic outline of each of the character classes. For more detailed information about the characters, please
|
||||
view the Levels table at the bottom of this page. Also, note that the outline below refers to the stock class setup
|
||||
for the game. If your administrator has used his/her own class setup, this information may not be accurate.<br><br>
|
||||
<b><?= $controlrow["class1name"] ?></b>
|
||||
<ul>
|
||||
<li>Fast level-ups</li>
|
||||
<li>High hit points</li>
|
||||
<li>High magic points</li>
|
||||
<li>Low strength</li>
|
||||
<li>Low dexterity</li>
|
||||
<li>5 heal spells</li>
|
||||
<li>5 hurt spells</li>
|
||||
<li>3 sleep spells</li>
|
||||
<li>3 +defense spells</li>
|
||||
<li>0 +attack spells</li>
|
||||
</ul>
|
||||
<b><?= $controlrow["class2name"] ?></b>
|
||||
<ul>
|
||||
<li>Medium level-ups</li>
|
||||
<li>Medium hit points</li>
|
||||
<li>Low magic points</li>
|
||||
<li>High strength</li>
|
||||
<li>Low dexterity</li>
|
||||
<li>3 heal spells</li>
|
||||
<li>3 hurt spells</li>
|
||||
<li>2 sleep spells</li>
|
||||
<li>3 +defense spells</li>
|
||||
<li>3 +attack spells</li>
|
||||
</ul>
|
||||
<b><?= $controlrow["class3name"] ?></b>
|
||||
<ul>
|
||||
<li>Slow level-ups</li>
|
||||
<li>Medium hit points</li>
|
||||
<li>Medium magic points</li>
|
||||
<li>Low strength</li>
|
||||
<li>High dexterity</li>
|
||||
<li>4 heal spells</li>
|
||||
<li>4 hurt spells</li>
|
||||
<li>3 sleep spells</li>
|
||||
<li>2 +defense spells</li>
|
||||
<li>2 +attack spells</li>
|
||||
</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>
|
||||
To heal yourself, click the "Rest at the Inn" link at the top of the town screen. Each town's Inn has a different price - some towns
|
||||
are cheap, others are expensive. No matter what town you're in, the Inns always serve the same function: they restore your current
|
||||
hit points, magic points, and travel points to their maximum amounts. Out in the field, you are free to use healing spells to restore
|
||||
your hit points, but when you run low on magic points, the only way to restore them is at an Inn.<br><br>
|
||||
Buying weapons and armor is accomplished through the appropriately-named "Buy Weapons/Armor" link. Not every item is available in
|
||||
every town, so in order to get the most powerful items, you'll need to explore some of the outer towns. Once you've clicked the link,
|
||||
you are presented with a list of items available in this town's store. To the left of each item is an icon that represents its type:
|
||||
weapon, armor or shield. The amount of attack/defense power, as well as the item's price, are displayed to the right of the item name.
|
||||
You'll notice that some items have a red asterisk (<span class="highlight">*</span>) next to their names. These are items that come
|
||||
with special attributes that modify other parts of your character profile. See the Items & Drops table at the bottom of this page for
|
||||
more information about special items.<br><br>
|
||||
Maps are the third function in towns. Buying a map to a town places the town in your Travel To box in the left status panel. Once
|
||||
you've purchased a town's map, you can click its name from your Travel To box and you will jump to that town. Travelling this way
|
||||
costs travel points, though, and you'll only be able to visit towns if you have enough travel points.<br><br>
|
||||
The final function in towns is displaying game information and statistics. This includes the latest news post made by the game
|
||||
administrator, a list of players who have been online recently, and the Babble Box.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="exploring"></a>Playing The Game: Exploring & Fighting</h3>
|
||||
Once you're done in town, you are free to start exploring the world. Use the compass buttons on the left status panel to move around.
|
||||
The game world is basically a big square, divided into four quadrants. Each quadrant is <?= $controlrow["gamesize"] ?> spaces
|
||||
square. The first town is usually located at (0N,0E). Click the North button from the first town, and now you'll be at (1N,0E).
|
||||
Likewise, if you now click the West button, you'll be at (1N,1W). Monster levels increase with every 5 spaces you move outward
|
||||
from (0N,0E).<br><br>
|
||||
While you're exploring, you will occasionally run into monsters. As in pretty much any other RPG game, you and the monster take turns
|
||||
hitting each other in an attempt to reduce each other's hit points to zero. Once you run into a monster, the Exploring screen changes
|
||||
to the Fighting screen.<br><br>
|
||||
When a fight begins, you'll see the monster's name and hit points, and the game will ask you for your first command. You then get to
|
||||
pick whether you want to fight, use a spell, or run away. Note, though, that sometimes the monster has the chance to hit you
|
||||
first.<br><br>
|
||||
The Fight button is pretty straightforward: you attack the monster, and the amount of damage dealt is based on your attack power and
|
||||
the monster's armor. On top of that, there are two other things that can happen: an Excellent Hit, which doubles your total attack
|
||||
damage; and a monster dodge, which results in you doing no damage to the monster.<br><br>
|
||||
The Spell button allows you to pick an available spell and cast it. See the Spells list at the bottom of this page for more information
|
||||
about spells.<br><br>
|
||||
Finally, there is the Run button, which lets you run away from a fight if the monster is too powerful. Be warned, though: it is
|
||||
possible for the monster to block you from running and attack you. So if your hit points are low, you may fare better by staying
|
||||
around monsters that you know can't do much damage to you.<br><br>
|
||||
Once you've had your turn, the monster also gets his turn. It is also possible for you to dodge the monster's attack and take no
|
||||
damage.<br><br>
|
||||
The end result of a fight is either you or the monster being knocked down to zero hit points. If you win, the monster dies and will
|
||||
give you a certain amount of experience and gold. There is also a chance that the monster will drop an item, which you can put into
|
||||
one of the three inventory slots to give you extra points in your character profile. If you lose and die, half of your gold is taken
|
||||
away - however, you are given back a few hit points to help you make it back to town (for example, if you don't have enough gold to
|
||||
pay for an Inn, and need to kill a couple low-level monsters to get the money).<br><br>
|
||||
When the fight is over, you can continue exploring until you find another monster to beat into submission.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="status"></a>Playing The Game: Status Panels</h3>
|
||||
There are two status panels on the game screen: left and right.<br><br>
|
||||
The left panel inclues your current location and play status (In Town, Exploring, Fighting), compass buttons for movement, and the
|
||||
Travel To list for jumping between towns. At the bottom of the left panel is also a list of game functions.<br><br>
|
||||
The right panel displays some character statistics, your inventory, and quick spells.<br><br>
|
||||
The Character section shows the most important character statistics. It also displays the status bars for your current hit points,
|
||||
magic points and travel points. These status bars are colored either green, yellow or red depending on your current amount of each
|
||||
stat. There is also a link to pop up your list of extended statistics, which shows more detailed character information.<br><br>
|
||||
The Fast Spells section lists any Heal spells you've learned. You may use these links any time you are in town or exploring to cast
|
||||
the heal spell. These may not be used during fights, however - you have to use the Spells box on the fight screen for that.
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="items"></a>Spoilers: Items & Drops</h3>
|
||||
<a href="help.php?page=items">Click here</a> for the Items & Drops spoiler page.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="monsters"></a>Spoilers: Monsters</h3>
|
||||
<a href="help.php?page=monsters">Click here</a> for the Monsters spoiler page.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="spells"></a>Spoilers: Spells</h3>
|
||||
<a href="help.php?page=spells">Click here</a> for the Spells spoiler page.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="levels"></a>Spoilers: Levels</h3>
|
||||
<a href="help.php?page=levels">Click here</a> for the Levels spoiler page.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="credits"></a>Credits</h3>
|
||||
<ul>
|
||||
<li><b>All program code and stock graphics for the game were created by Jamin Seven</b>.<br><br></li>
|
||||
<li>Major props go to a few people on the PHP manual site, for help with various chunks of code. The specific people are listed in the source code.<br><br></li>
|
||||
<li>Super monkey love goes to Enix and the developers of <i>Dragon Warrior</i>. If it weren't for you guys, my game never would have been made.<br><br></li>
|
||||
<li>Mega props go to Dalez from GameFAQs for his DW3 experience chart, which was where I got my experience levels from.<br><br></li>
|
||||
<li>
|
||||
Mad crazy ninja love goes to the following people for help and support throughout the development process:<br><br>
|
||||
<b>Ideas:</b> (whether they got used or not)
|
||||
<ul>
|
||||
<li>kushet</li>
|
||||
<li>lghtning</li>
|
||||
<li>Ebolamonkey3000</li>
|
||||
<li>Crimson Scythe</li>
|
||||
<li>SilDeath</li>
|
||||
</ul>
|
||||
<b>Beta Testing:</b> (forums name if applicable, character name otherwise)
|
||||
<ul>
|
||||
<li>Ebolamonkey3000</li>
|
||||
<li>lisi</li>
|
||||
<li>Junglist</li>
|
||||
<li>Crimson Scythe</li>
|
||||
<li>Sk8erpunk69</li>
|
||||
<li>lghtning</li>
|
||||
<li>kushet</li>
|
||||
<li>SilDeath</li>
|
||||
<li>lowrider4life</li>
|
||||
<li>dubiin</li>
|
||||
<li>Sam Wise The Great</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
Apologies and lots of happy naked love to anyone I forgot. <br><br>
|
||||
And of course, thanks to <b>you</b> for playing my game! <br><br>
|
||||
<a href="/index.php?do=ninja">NINJA!</a> <br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr><br>
|
||||
|
||||
Please visit the following sites for more information:<br>
|
||||
<a href="http://www.se7enet.com" target="_new">Se7enet</a> (Jamin's homepage)<br>
|
||||
<a href="http://dragon.se7enet.com/dev.php" target="_new">Dragon Knight</a> (official DK homepage)<br>
|
||||
<a href="http://se7enet.com/forums" target="_new">Forums</a> (official DK forums)<br><br>
|
||||
All original coding and graphics for the <i>Dragon Knight</i> game engine are © 2003-2005 by Jamin Seven.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<?php
|
||||
endif;
|
||||
// @MAIN END
|
||||
?>
|
||||
|
||||
<?php
|
||||
// @ITEMS
|
||||
if ($page === 'items'):
|
||||
?>
|
||||
|
||||
<table width="60%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="5" bgcolor="#ffffff"><center><b>Items</b></center></td></tr>
|
||||
<tr><td><b>Type</b></td><td><b>Name</b></td><td><b>Cost</b></td><td><b>Attribute</b></td><td><b>Special</b></td></tr>
|
||||
<?php
|
||||
$items = db()->query('SELECT * FROM items ORDER BY id;');
|
||||
$item_types = [1 => ['weapon', 'Attack'], 2 => ['armor', 'Defense'], 3 => ['shield', 'Defense']];
|
||||
|
||||
while ($item = $items->fetchArray(SQLITE3_ASSOC)) {
|
||||
$image = $item_types[$item['type']][0];
|
||||
$power = $item_types[$item['type']][1];
|
||||
|
||||
if ($item['special'] !== 'X') {
|
||||
$special = explode(',', $item['special']);
|
||||
$attr = special_to_string($special[0]);
|
||||
$stat = (($special[1] > 0) ? '+' : '') . $special[1];
|
||||
$bigspecial = "$attr $stat";
|
||||
} else {
|
||||
$bigspecial = '<span class="light">None</span>';
|
||||
}
|
||||
|
||||
echo "<tr><td width=\"5%\"><img src=\"images/icon_$image.gif\" alt=\"$image\"></td><td width=\"30%\">".$item["name"]."</td><td width=\"20%\">".$item["buycost"]." Gold</td><td width=\"20%\">".$item["attribute"]." $power Power</td><td width=\"25%\">$bigspecial</td></tr>\n";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<br><br>
|
||||
|
||||
<table width="60%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="4" bgcolor="#ffffff"><center><b>Drops</b></center></td></tr>
|
||||
<tr><td><b>Name</b></td><td><b>Monster Level</b></td><td><b>Attribute 1</b></td><td><b>Attribute 2</b></td></tr>
|
||||
<?php
|
||||
$drops = db()->query('SELECT * FROM drops ORDER BY id;');
|
||||
|
||||
while ($drop = $drops->fetchArray(SQLITE3_ASSOC)) {
|
||||
if ($drop["attribute1"] !== "X") {
|
||||
$special = explode(',', $drop['attribute1']);
|
||||
$attr = special_to_string($special[0]);
|
||||
$stat = (($special[1] > 0) ? '+' : '') . $special[1];
|
||||
$bigspecial1 = "$attr $stat";
|
||||
} else {
|
||||
$bigspecial1 = '<span class="light">None</span>';
|
||||
}
|
||||
|
||||
if ($drop["attribute2"] !== "X") {
|
||||
$special = explode(',', $drop['attribute2']);
|
||||
$attr = special_to_string($special[0]);
|
||||
$stat = (($special[1] > 0) ? '+' : '') . $special[1];
|
||||
$bigspecial2 = "$attr $stat";
|
||||
} else {
|
||||
$bigspecial2 = '<span class="light">None</span>';
|
||||
}
|
||||
|
||||
echo "<tr><td width=\"25%\">".$drop["name"]."</td><td width=\"15%\">".$drop["mlevel"]."</td><td width=\"30%\">$bigspecial1</td><td width=\"30%\">$bigspecial2</td></tr>\n";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
// @ITEMS END
|
||||
?>
|
||||
|
||||
<?php
|
||||
// @SPELLS
|
||||
if ($page === 'spells'):
|
||||
?>
|
||||
|
||||
<table width="50%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b>Spells</b></center></td></tr>
|
||||
<tr><td><b>Name</b></td><td><b>Cost</b></td><td><b>Type</b></td><td><b>Attribute</b></td></tr>
|
||||
<?php
|
||||
$spells = db()->query('SELECT * FROM spells ORDER BY id;');
|
||||
$spell_types = ['None', 'Heal', 'Hurt', 'Sleep', '+Damage (%)', '+Defense (%)'];
|
||||
while ($spell = $spells->fetchArray(SQLITE3_ASSOC)) {
|
||||
echo <<<HTML
|
||||
<tr><td width="25%">{$spell["name"]}</td>
|
||||
<td width="25%">{$spell["mp"]}</td>
|
||||
<td width="25%">{$spell_types[$spell['type']]}</td>
|
||||
<td width="25%">{$spell["attribute"]}</td></tr>
|
||||
HTML;
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<ul>
|
||||
<li><b>Heal</b> spells always give you the maximum amount possible, until your current HP is full.</li>
|
||||
<li><b>Hurt</b> spells deal X damage (not always the maximum) to the monster, regardless of the monster's armor.</li>
|
||||
<li><b>Sleep</b> spells put the monster to sleep. The monster has an X in 15 chance of remaining asleep each turn.</li>
|
||||
<li><b>+Damage</b> spells increase your total attack damage by X percent until the end of the fight.</li>
|
||||
<li><b>+Defense</b> spells reduce the total damage you take from the monster by X percent until the end of each fight.</li>
|
||||
</ul>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
// @SPELLS END
|
||||
?>
|
||||
|
||||
<?php
|
||||
// @MONSTERS
|
||||
if ($page === 'monsters'):
|
||||
?>
|
||||
|
||||
<table width="75%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b>Monsters</b></center></td></tr>
|
||||
<tr><td><b>Name</b></td><td><b>Max HP</b></td><td><b>Max Damage</b></td><td><b>Armor</b></td><td><b>Level</b></td><td><b>Max Exp.</b></td><td><b>Max Gold</b></td><td><b>Immunity</b></td></tr>
|
||||
<?php
|
||||
$monsters = db()->query('SELECT * FROM monsters ORDER BY id;');
|
||||
$immunities = ['<span class="light">None</span>', 'Hurt', 'Hurt & Sleep'];
|
||||
|
||||
while ($m = $monsters->fetchArray(SQLITE3_ASSOC)) {
|
||||
$immune = $immunities[$m['immune']] ?? 'Unknown';
|
||||
echo "<tr><td width=\"30%\">".$m["name"]."</td><td width=\"10%\">".$m["maxhp"]."</td><td width=\"10%\">".$m["maxdam"]."</td><td width=\"10%\">".$m["armor"]."</td><td width=\"10%\">".$m["level"]."</td><td width=\"10%\">".$m["maxexp"]."</td><td width=\"10%\">".$m["maxgold"]."</td><td width=\"20%\">$immune</td></tr>\n";
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<?php
|
||||
endif;
|
||||
// @MONSTERS END
|
||||
?>
|
||||
|
||||
<?php
|
||||
// @LEVELS
|
||||
if ($page === 'levels'):
|
||||
|
||||
$rows = [];
|
||||
|
||||
$levels = db()->query('SELECT * FROM levels ORDER BY id;');
|
||||
while ($level = $levels->fetchArray(SQLITE3_ASSOC)) {
|
||||
$class_data = [1 => [], 2 => [], 3 => []];
|
||||
|
||||
foreach ($level as $column => $value) {
|
||||
if ($column === 'id') continue;
|
||||
|
||||
$parts = explode('_', $column);
|
||||
$class_number = (int) $parts[0];
|
||||
$attribute = $parts[1];
|
||||
|
||||
if (in_array($class_number, [1, 2, 3])) {
|
||||
$class_data[$class_number][$level['id']][$attribute] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$rows[$level['id']] = $class_data;
|
||||
}
|
||||
|
||||
$spells = [];
|
||||
$spells_query = db()->query('SELECT * FROM spells ORDER BY id;');
|
||||
while ($spell = $spells_query->fetchArray(SQLITE3_ASSOC)) {
|
||||
$spells[$spell['id']] = $spell;
|
||||
}
|
||||
?>
|
||||
|
||||
<table width="50%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b><? echo $controlrow["class1name"]; ?> Levels</b></center></td></tr>
|
||||
<tr><td><b>Level</b><td><b>Exp.</b></td><td><b>HP</b></td><td><b>MP</b></td><td><b>TP</b></td><td><b>Strength</b></td><td><b>Dexterity</b></td><td><b>Spell</b></td></tr>
|
||||
<?php
|
||||
foreach ($rows as $level => $class_data) {
|
||||
$level_data = $class_data[1][$level];
|
||||
|
||||
$spell_name = '';
|
||||
if (!empty($level_data['spells'])) $spell_name = $spells[$level_data['spells']]['name'];
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>' . $level . '</td>';
|
||||
echo '<td>' . ($level_data['exp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['hp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['mp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['tp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['strength'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['dexterity'] ?? '') . '</td>';
|
||||
echo '<td>' . (!empty($spell_name) ? $spell_name : '<span class="light">None</span>') . '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<br><br>
|
||||
|
||||
<table width="50%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b><? echo $controlrow["class2name"]; ?> Levels</b></center></td></tr>
|
||||
<tr><td><b>Level</b><td><b>Exp.</b></td><td><b>HP</b></td><td><b>MP</b></td><td><b>TP</b></td><td><b>Strength</b></td><td><b>Dexterity</b></td><td><b>Spell</b></td></tr>
|
||||
<?php
|
||||
foreach ($rows as $level => $class_data) {
|
||||
$level_data = $class_data[2][$level];
|
||||
|
||||
$spell_name = '';
|
||||
if (!empty($level_data['spells'])) $spell_name = $spells[$level_data['spells']]['name'];
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>' . $level . '</td>';
|
||||
echo '<td>' . ($level_data['exp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['hp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['mp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['tp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['strength'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['dexterity'] ?? '') . '</td>';
|
||||
echo '<td>' . (!empty($spell_name) ? $spell_name : '<span class="light">None</span>') . '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<br><br>
|
||||
|
||||
<table width="50%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b><? echo $controlrow["class3name"]; ?> Levels</b></center></td></tr>
|
||||
<tr><td><b>Level</b><td><b>Exp.</b></td><td><b>HP</b></td><td><b>MP</b></td><td><b>TP</b></td><td><b>Strength</b></td><td><b>Dexterity</b></td><td><b>Spell</b></td></tr>
|
||||
<?php
|
||||
foreach ($rows as $level => $class_data) {
|
||||
$level_data = $class_data[3][$level];
|
||||
|
||||
$spell_name = '';
|
||||
if (!empty($level_data['spells'])) $spell_name = $spells[$level_data['spells']]['name'];
|
||||
|
||||
echo '<tr>';
|
||||
echo '<td>' . $level . '</td>';
|
||||
echo '<td>' . ($level_data['exp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['hp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['mp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['tp'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['strength'] ?? '') . '</td>';
|
||||
echo '<td>' . ($level_data['dexterity'] ?? '') . '</td>';
|
||||
echo '<td>' . (!empty($spell_name) ? $spell_name : '<span class="light">None</span>') . '</td>';
|
||||
echo '</tr>';
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
Experience points listed are total values up until that point. All other values are just the new amount that you gain for each level.
|
||||
|
||||
<?php
|
||||
endif;
|
||||
// @LEVELS END
|
||||
?>
|
||||
|
||||
<br><br>
|
||||
|
||||
<table class="copyright" width="100%"><tr>
|
||||
<td width="50%" align="center">Powered by <a href="http://dragon.se7enet.com/dev.php" target="_new">Dragon Knight</a></td><td width="50%" align="center">© 2003-2006 by renderse7en</td>
|
||||
</tr></table>
|
||||
</body>
|
||||
</html>
|
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 6.1 KiB After Width: | Height: | Size: 6.1 KiB |
Before Width: | Height: | Size: 94 B After Width: | Height: | Size: 94 B |
Before Width: | Height: | Size: 94 B After Width: | Height: | Size: 94 B |
Before Width: | Height: | Size: 94 B After Width: | Height: | Size: 94 B |
Before Width: | Height: | Size: 527 B After Width: | Height: | Size: 527 B |
Before Width: | Height: | Size: 575 B After Width: | Height: | Size: 575 B |
Before Width: | Height: | Size: 561 B After Width: | Height: | Size: 561 B |
Before Width: | Height: | Size: 402 B After Width: | Height: | Size: 402 B |
Before Width: | Height: | Size: 551 B After Width: | Height: | Size: 551 B |
Before Width: | Height: | Size: 486 B After Width: | Height: | Size: 486 B |
Before Width: | Height: | Size: 474 B After Width: | Height: | Size: 474 B |
Before Width: | Height: | Size: 500 B After Width: | Height: | Size: 500 B |
Before Width: | Height: | Size: 523 B After Width: | Height: | Size: 523 B |
Before Width: | Height: | Size: 565 B After Width: | Height: | Size: 565 B |
Before Width: | Height: | Size: 469 B After Width: | Height: | Size: 469 B |
Before Width: | Height: | Size: 469 B After Width: | Height: | Size: 469 B |
Before Width: | Height: | Size: 461 B After Width: | Height: | Size: 461 B |
BIN
public/images/compass_01.gif
Normal file
After Width: | Height: | Size: 3.8 KiB |
BIN
public/images/compass_02.gif
Normal file
After Width: | Height: | Size: 2.4 KiB |
BIN
public/images/compass_03.gif
Normal file
After Width: | Height: | Size: 2.5 KiB |
BIN
public/images/compass_04.gif
Normal file
After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 147 B After Width: | Height: | Size: 147 B |
Before Width: | Height: | Size: 121 B After Width: | Height: | Size: 121 B |
Before Width: | Height: | Size: 112 B After Width: | Height: | Size: 112 B |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 4.8 KiB After Width: | Height: | Size: 4.8 KiB |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1005 B After Width: | Height: | Size: 1005 B |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.7 KiB After Width: | Height: | Size: 1.7 KiB |
Before Width: | Height: | Size: 386 KiB |
Before Width: | Height: | Size: 14 KiB |
318
public/index.php
|
@ -2,134 +2,264 @@
|
|||
|
||||
// index.php :: Primary program script, evil alien overlord, you decide.
|
||||
|
||||
require_once '../src/bootstrap.php';
|
||||
require_once '../src/lib.php';
|
||||
|
||||
// Do an early return with babblebox data if that's what's being requested
|
||||
if ($uri[0] === 'babblebox' && (isset($uri[1]) && $uri[1] === 'messages')) {
|
||||
echo babblebox_messages();
|
||||
if (!file_exists('../.installed')) redirect('install.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;
|
||||
}
|
||||
|
||||
$r = new Router;
|
||||
// Close game.
|
||||
if ((bool) $controlrow["gameopen"] === false) {
|
||||
display("The game is currently closed for maintanence. Please check back later.", "Game Closed");
|
||||
exit;
|
||||
}
|
||||
|
||||
$r->get('/', 'index');
|
||||
$r->post('/move', 'Explore\move');
|
||||
$r->get('/spell/:id', 'healspells');
|
||||
$r->get('/character', 'show_character_info');
|
||||
$r->get('/character/:id', 'show_character_info');
|
||||
$r->get('/showmap', 'show_map');
|
||||
$r->form('/babblebox', 'babblebox');
|
||||
$r->get('/babblebox/messages', 'babblebox_messages');
|
||||
// Force verify if the user isn't verified yet.
|
||||
if ((bool) $controlrow["verifyemail"] && (bool) $userrow["verify"] === false) {
|
||||
header("Location: users.php?do=verify");
|
||||
exit;
|
||||
}
|
||||
|
||||
Towns\register_routes($r);
|
||||
Fights\register_routes($r);
|
||||
Users\register_routes($r);
|
||||
Help\register_routes($r);
|
||||
Forum\register_routes($r);
|
||||
Install\register_routes($r);
|
||||
Admin\register_routes($r);
|
||||
// Block user if he/she has been banned.
|
||||
if ($userrow["authlevel"] === 2) {
|
||||
exit("Your account has been blocked.");
|
||||
}
|
||||
|
||||
/*
|
||||
NINJA! 🥷
|
||||
*/
|
||||
$r->get('/ninja', function() {
|
||||
exit('NINJA! 🥷');
|
||||
});
|
||||
require_once '../src/towns.php';
|
||||
require_once '../src/explore.php';
|
||||
require_once '../src/fight.php';
|
||||
require_once '../src/heal.php';
|
||||
|
||||
// [code, handler, params, middleware]
|
||||
$l = $r->lookup($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);
|
||||
$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()
|
||||
};
|
||||
|
||||
if (is_int($l)) exit("Error: $l");
|
||||
echo render_response($uri, $l['handler'](...$l['params'] ?? []));
|
||||
exit;
|
||||
|
||||
/**
|
||||
* Return a page for a couple generic actions.
|
||||
*/
|
||||
function index(): string
|
||||
function donothing()
|
||||
{
|
||||
if (user()->currentaction === "In Town") {
|
||||
$page = Towns\town();
|
||||
} elseif (user()->currentaction === "Exploring") {
|
||||
$page = Explore\explore();
|
||||
} elseif (user()->currentaction === "Fighting") {
|
||||
redirect('/fight');
|
||||
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');
|
||||
}
|
||||
|
||||
return $page;
|
||||
display($page, $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show a character's info. Defaults to the currently logged in user.
|
||||
* Spit out the main town page.
|
||||
*/
|
||||
function show_character_info(int $id = 0): string
|
||||
function dotown()
|
||||
{
|
||||
$user = $id !== 0 ? User::find($id) : user();
|
||||
if ($user === false) exit('Failed to show info for user ID '.$id);
|
||||
global $userrow, $controlrow;
|
||||
|
||||
$level = db()->query("SELECT `{$user->charclass}_exp` FROM levels WHERE id=? LIMIT 1;", [$user->level + 1])->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");
|
||||
|
||||
$spells = $user->spells();
|
||||
$magic_list = 'None';
|
||||
if (!empty($spells)) {
|
||||
$magic_list = '';
|
||||
foreach ($spells as $spell) $magic_list .= $spell['name'].'<br>';
|
||||
}
|
||||
$townrow["news"] = "";
|
||||
$townrow["whosonline"] = "";
|
||||
$townrow["babblebox"] = "";
|
||||
|
||||
$showchar = render('show_char', [
|
||||
'char' => $user,
|
||||
'level' => $level,
|
||||
'magic_list' => $magic_list
|
||||
]);
|
||||
return render('layouts/minimal', ['content' => $showchar, 'title' => $user->username.' Information']);
|
||||
// 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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the user their position on the current world map. Only works with a game size of 250 and the default towns 😅
|
||||
* 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 show_map()
|
||||
function doexplore()
|
||||
{
|
||||
$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 + user()->longitude * (500 / 500) - 3),
|
||||
round(258 - user()->latitude * (500 / 500) - 3)
|
||||
);
|
||||
|
||||
echo render('layouts/minimal', [
|
||||
'content' => '<img src="/img/map.gif" alt="Map">'.$pos,
|
||||
'title' => 'Map'
|
||||
]);
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a POST request to send a new babblebox message.
|
||||
*/
|
||||
function babblebox()
|
||||
{
|
||||
if (is_post()) {
|
||||
$content = trim($_POST["babble"]);
|
||||
if (!empty($content)) {
|
||||
db()->query('INSERT INTO babble (posttime, author, babble) VALUES (CURRENT_TIMESTAMP, ?, ?);',
|
||||
[user()->username, $content]);
|
||||
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]);
|
||||
}
|
||||
return babblebox_messages();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* The handler that is polled by HTMX for new babblebox messages.
|
||||
* NINJA! 🥷
|
||||
*/
|
||||
function babblebox_messages(): string
|
||||
function ninja(): void
|
||||
{
|
||||
if (user() === false) return '';
|
||||
|
||||
$query = db()->query('SELECT * FROM babble ORDER BY id ASC LIMIT 40;');
|
||||
$has_chats = false;
|
||||
$messages = '';
|
||||
while ($row = $query->fetchArray(SQLITE3_ASSOC)) {
|
||||
$has_chats = true;
|
||||
$messages .= '<div class="message">[<b>' . $row['author'] . '</b>] ' . make_safe($row['babble']) . '</div>';
|
||||
}
|
||||
if (!$has_chats) $messages = 'There are no messages. :(';
|
||||
return $messages;
|
||||
exit('NINJA! 🥷');
|
||||
}
|
||||
|
|
|
@ -1,27 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace Install;
|
||||
require_once '../src/lib.php';
|
||||
|
||||
use Router;
|
||||
if (file_exists('../.installed')) redirect('index.php');
|
||||
|
||||
function register_routes(Router $r): Router
|
||||
{
|
||||
if (!file_exists('../.installed')) {
|
||||
$r->get('/install', 'Install\first');
|
||||
$r->get('/install/second', 'Install\second');
|
||||
$r->get('/install/third', 'Install\third');
|
||||
$r->post('/install/fourth', 'Install\fourth');
|
||||
$r->get('/install/fifth', 'Install\fifth');
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
$page = $_GET['page'] ?? 1;
|
||||
match ((int) $page) {
|
||||
2 => second(),
|
||||
3 => third(),
|
||||
4 => fourth(),
|
||||
5 => fifth(),
|
||||
default => first(),
|
||||
};
|
||||
|
||||
/**
|
||||
* First page - show warnings and gather info
|
||||
*/
|
||||
function first()
|
||||
{
|
||||
return <<<HTML
|
||||
echo <<<HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Dragon Knight Installation</title>
|
||||
|
@ -30,7 +27,7 @@ function first()
|
|||
<body>
|
||||
<b>Dragon Knight Installation: Page One</b><br><br>
|
||||
Installation for Dragon Knight is a simple two-step process: set up the database tables, then create the admin user. After that, you're done.<br><br>
|
||||
<a href="/install/second"><button>Install</button></a>
|
||||
<a href="install.php?page=2"><button>Install</button></a>
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
@ -41,9 +38,7 @@ function first()
|
|||
*/
|
||||
function second()
|
||||
{
|
||||
if (file_exists('../database.db')) unlink('../database.db');
|
||||
|
||||
$page = "<html><head><title>Dragon Knight Installation</title></head><body><b>Dragon Knight Installation: Page Two</b><br><br>";
|
||||
echo "<html><head><title>Dragon Knight Installation</title></head><body><b>Dragon Knight Installation: Page Two</b><br><br>";
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE babble (
|
||||
|
@ -54,7 +49,31 @@ function second()
|
|||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Babble', 'create');
|
||||
echo $query === true ? 'Babble Box table created.<br>' : 'Error creating Babble Box table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE control (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
`gamename` TEXT NOT NULL DEFAULT 'Dragon Knight',
|
||||
`gamesize` INTEGER NOT NULL DEFAULT 250,
|
||||
`gameopen` INTEGER NOT NULL DEFAULT 1,
|
||||
`gameurl` TEXT NOT NULL DEFAULT '',
|
||||
`adminemail` TEXT NOT NULL DEFAULT '',
|
||||
`class1name` TEXT NOT NULL DEFAULT '',
|
||||
`class2name` TEXT NOT NULL DEFAULT '',
|
||||
`class3name` TEXT NOT NULL DEFAULT '',
|
||||
`verifyemail` INTEGER NOT NULL DEFAULT 0,
|
||||
`shownews` INTEGER NOT NULL DEFAULT 0,
|
||||
`showbabble` INTEGER NOT NULL DEFAULT 0,
|
||||
`showonline` INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
SQL);
|
||||
|
||||
echo $query === true ? 'Control table created.<br>' : 'Error creating Control table.';
|
||||
|
||||
$query = db()->exec("INSERT INTO control VALUES (1, 'Dragon Knight', 250, 1, '', '', 'Mage', 'Warrior', 'Paladin', 1, 1, 1, 1);");
|
||||
|
||||
echo $query === true ? 'Control table populated.<br>' : 'Error populating Control table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE drops (
|
||||
|
@ -67,7 +86,7 @@ function second()
|
|||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Drops', 'create');
|
||||
echo $query == true ? 'Drops table created.<br>' : 'Error creating Drops table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO drops VALUES
|
||||
|
@ -105,7 +124,7 @@ function second()
|
|||
(32, 'Fortune Drop', 5, 1, 'goldbonus,10', 'X');
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Drops', 'populate');
|
||||
echo $query === true ? 'Drops table populated.<br>' : 'Error populating Drops table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE forum (
|
||||
|
@ -120,7 +139,7 @@ function second()
|
|||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Forum', 'create');
|
||||
echo $query === true ? 'Forum table created.<br>' : 'Error creating Forum table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE items (
|
||||
|
@ -133,7 +152,7 @@ function second()
|
|||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Items', 'create');
|
||||
echo $query === true ? 'Items table created.<br>' : 'Error creating Items table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO items VALUES
|
||||
|
@ -172,36 +191,7 @@ function second()
|
|||
(33, 3, 'Destiny Aegis', 25000, 100, 'maxhp,50');
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Drops', 'populate');
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE classes (
|
||||
'id' INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
'name' TEXT NOT NULL,
|
||||
'lore' TEXT NOT NULL,
|
||||
'exp_rate' INTEGER NOT NULL DEFAULT 3,
|
||||
'base_hp' INTEGER NOT NULL DEFAULT 15,
|
||||
'base_mp' INTEGER NOT NULL DEFAULT 10,
|
||||
'base_str' INTEGER NOT NULL DEFAULT 1,
|
||||
'base_dex' INTEGER NOT NULL DEFAULT 1,
|
||||
'hp_rate' INTEGER NOT NULL DEFAULT 2,
|
||||
'mp_rate' INTEGER NOT NULL DEFAULT 2,
|
||||
'str_rate' INTEGER NOT NULL DEFAULT 2,
|
||||
'dex_rate' INTEGER NOT NULL DEFAULT 2,
|
||||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Classes', 'create');
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO classes VALUES
|
||||
(1, 'Adventurer', '', 3, 15, 10, 4, 4, 2, 2, 2, 2),
|
||||
(2, 'Mage', '', 1, 10, 15, 1, 7, 1, 3, 1, 2),
|
||||
(2, 'Warrior', '', 2, 20, 5, 7, 1, 3, 1, 3, 1),
|
||||
(3, 'Paladin', '', 5, 15, 15, 5, 5, 2, 2, 2, 2);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Classes', 'populate');
|
||||
echo $query === true ? 'Items table populated.<br>' : 'Error populating Items table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE levels (
|
||||
|
@ -230,7 +220,7 @@ function second()
|
|||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Levels', 'create');
|
||||
echo $query === true ? 'Levels table created.<br>' : 'Error creating Levels table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO levels VALUES
|
||||
|
@ -336,7 +326,7 @@ function second()
|
|||
(100, 16777215, 0, 0, 0, 0, 0, 0, 16777215, 0, 0, 0, 0, 0, 0, 16777215, 0, 0, 0, 0, 0, 0);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Levels', 'populate');
|
||||
echo $query === true ? 'Levels table populated.<br>' : 'Error populating Levels table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE monsters (
|
||||
|
@ -352,7 +342,7 @@ function second()
|
|||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Monsters', 'create');
|
||||
echo $query === true ? 'Monsters table created.<br>' : 'Error creating Monsters table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO monsters VALUES
|
||||
|
@ -509,7 +499,7 @@ function second()
|
|||
(151, 'Lucifuge', 600, 600, 400, 50, 10000, 10000, 2);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Monsters', 'populate');
|
||||
echo $query === true ? 'Monsters table populated.<br>' : 'Error populating Monsters table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE news (
|
||||
|
@ -520,11 +510,11 @@ function second()
|
|||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'News', 'create');
|
||||
echo $query === true ? 'News table created.<br>' : 'Error creating News table.';
|
||||
|
||||
$query = db()->exec("INSERT INTO news (content) VALUES ('This is the first news post. Please use the admin control panel to add another one and make this one go away.');");
|
||||
|
||||
$page .= table_status_msg($query === true, 'News', 'populate');
|
||||
echo $query === true ? 'News table populated.<br>' : 'Error populating News table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE spells (
|
||||
|
@ -536,7 +526,7 @@ function second()
|
|||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Spells', 'create');
|
||||
echo $query === true ? 'Spells table created.<br>' : 'Error creating Spells table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO spells VALUES
|
||||
|
@ -561,7 +551,7 @@ function second()
|
|||
(19, 'Barrier', 30, 50, 5);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Spells', 'populate');
|
||||
echo $query === true ? 'Spells table populated.<br>' : 'Error populating Spells table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE towns (
|
||||
|
@ -576,7 +566,7 @@ function second()
|
|||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Towns', 'create');
|
||||
echo $query === true ? 'Towns table created.<br>' : 'Error creating Towns table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
INSERT INTO towns VALUES
|
||||
|
@ -590,7 +580,7 @@ function second()
|
|||
(8, 'Endworld', -250, -250, 125, 9000, 160, '16,27,33');
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Towns', 'populate');
|
||||
echo $query === true ? 'Towns table populated.<br>' : 'Error populating Towns table.';
|
||||
|
||||
$query = db()->exec(<<<SQL
|
||||
CREATE TABLE users (
|
||||
|
@ -605,7 +595,6 @@ function second()
|
|||
`latitude` INTEGER NOT NULL default 0,
|
||||
`longitude` INTEGER NOT NULL default 0,
|
||||
`charclass` INTEGER NOT NULL default 0,
|
||||
'class_id' INTEGER NOT NULL DEFAULT 1,
|
||||
`currentaction` TEXT NOT NULL default 'In Town',
|
||||
`currentfight` INTEGER NOT NULL default 0,
|
||||
`currentmonster` INTEGER NOT NULL default 0,
|
||||
|
@ -643,15 +632,14 @@ function second()
|
|||
`slot3name` TEXT NOT NULL default 'None',
|
||||
`dropcode` INTEGER NOT NULL default 0,
|
||||
`spells` TEXT NOT NULL default '0',
|
||||
`towns` TEXT NOT NULL default '0',
|
||||
`game_skin` INTEGER NOT NULL DEFAULT 0
|
||||
`towns` TEXT NOT NULL default '0'
|
||||
);
|
||||
SQL);
|
||||
|
||||
$page .= table_status_msg($query === true, 'Users', 'create');
|
||||
echo $query === true ? 'Users table created.<br>' : 'Error creating Users table.';
|
||||
|
||||
$time = round((microtime(true) - START), 4);
|
||||
return $page . "<br>Database setup complete in $time seconds.<br><br><a href=\"/install/third\">Click here to continue with installation.</a></body></html>";
|
||||
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>";
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -659,7 +647,7 @@ function second()
|
|||
*/
|
||||
function third()
|
||||
{
|
||||
return <<<HTML
|
||||
echo <<<HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Dragon Knight Installation</title>
|
||||
|
@ -667,13 +655,13 @@ function third()
|
|||
<body>
|
||||
<b>Dragon Knight Installation: Page Three</b><br><br>
|
||||
Now you must create an administrator account so you can use the control panel. Fill out the form below to create your account. You will be able to customize the class names through the control panel once your admin account is created.<br><br>
|
||||
<form action="/install/fourth" method="post">
|
||||
<form action="install.php?page=4" method="post">
|
||||
<table width="50%">
|
||||
<tr><td width="20%" style="vertical-align:top;">Username:</td><td><input type="text" name="username" /><br><br><br></td></tr>
|
||||
<tr><td style="vertical-align:top;">Password:</td><td><input type="password" name="password" /></td></tr>
|
||||
<tr><td style="vertical-align:top;">Verify Password:</td><td><input type="password" name="confirm_password" /><br><br><br></td></tr>
|
||||
<tr><td style="vertical-align:top;">Email Address:</td><td><input type="text" name="email" /></td></tr>
|
||||
<tr><td style="vertical-align:top;">Verify Email:</td><td><input type="text" name="confirm_email" /><br><br><br></td></tr>
|
||||
<tr><td width="20%" style="vertical-align:top;">Username:</td><td><input type="text" name="username" size="30" maxlength="30" /><br><br><br></td></tr>
|
||||
<tr><td style="vertical-align:top;">Password:</td><td><input type="password" name="password1" size="30" maxlength="30" /></td></tr>
|
||||
<tr><td style="vertical-align:top;">Verify Password:</td><td><input type="password" name="password2" size="30" maxlength="30" /><br><br><br></td></tr>
|
||||
<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 colspan="2"><input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /></td></tr>
|
||||
</table>
|
||||
|
@ -688,27 +676,53 @@ function third()
|
|||
*/
|
||||
function fourth()
|
||||
{
|
||||
$form = validate($_POST, [
|
||||
'username' => ['length:3-18', 'alpha-spaces'],
|
||||
'email' => ['email'],
|
||||
'confirm_email' => ['confirm'],
|
||||
'password' => ['length:6-255'],
|
||||
'confirm_password' => ['confirm']
|
||||
]);
|
||||
$u = trim($_POST['username'] ??= '');
|
||||
$e = trim($_POST['email1'] ??= '');
|
||||
$ec = trim($_POST['email2'] ??= '');
|
||||
$p = $_POST['password1'] ??= '';
|
||||
$pc = $_POST['password2'] ??= '';
|
||||
|
||||
if (!$form['valid']) exit(ul_from_validate_errors($form['errors']));
|
||||
$errors = [];
|
||||
|
||||
if (empty($u) || strlen($u) < 3 || strlen($u) > 18 || !ctype_alnum(str_replace(' ', '', $u))) {
|
||||
$errors[] = 'Username is required and must be between 3 and 18 characters long and contain only
|
||||
alphanumeric characters and spaces.';
|
||||
}
|
||||
|
||||
if (empty($e) || strlen($e) > 255 || !filter_var($e, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'Email is required must be a valid email address.';
|
||||
}
|
||||
|
||||
if ($e !== $ec) {
|
||||
$errors[] = 'Verify Email must match.';
|
||||
}
|
||||
|
||||
if (empty($p) || strlen($p) < 6) {
|
||||
$errors[] = 'Password is required and must be at least 6 characters long.';
|
||||
}
|
||||
|
||||
if ($pc !== $p) {
|
||||
$errors[] = 'Verify Password must match.';
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
echo "<ul>";
|
||||
foreach ($errors as $error) echo "<li>$error</li>";
|
||||
echo "</ul>";
|
||||
exit;
|
||||
}
|
||||
|
||||
$form = $form['data'];
|
||||
if (db()->query(
|
||||
"INSERT INTO users (username, password, email, verify, charclass, authlevel) VALUES (?, ?, ?, 'g2g', ?, 1)",
|
||||
[$form['username'], password_hash($form['password'], PASSWORD_ARGON2ID), $form['email'], $form['charclass']]
|
||||
"INSERT INTO users (username, password, email, verify, charclass, authlevel) VALUES (?, ?, ?, 1, ?, 1)",
|
||||
[$u, password_hash($p, PASSWORD_ARGON2ID), $e, $_POST['charclass']]
|
||||
) === false) {
|
||||
exit("Failed to create user.");
|
||||
echo "Failed to create user.";
|
||||
exit;
|
||||
}
|
||||
|
||||
file_put_contents('../.installed', date('Y-m-d H:i:s'));
|
||||
|
||||
return <<<HTML
|
||||
echo <<<HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Dragon Knight Installation</title>
|
||||
|
@ -717,13 +731,13 @@ function fourth()
|
|||
<b>Dragon Knight Installation: Page Four</b><br><br>
|
||||
Your admin account was created successfully. Installation is complete.<br><br>
|
||||
Be sure to delete install.php from your Dragon Knight directory for security purposes.<br><br>
|
||||
You are now ready to <a href="/">play the game</a>. Note that you must log in through the public section before being allowed into the control panel. Once logged in, an "Admin" link will appear in the Functions box of the left sidebar panel.<br><br/>
|
||||
You are now ready to <a href="index.php">play the game</a>. Note that you must log in through the public section before being allowed into the control panel. Once logged in, an "Admin" link will appear in the Functions box of the left sidebar panel.<br><br/>
|
||||
Thank you for using Dragon Knight!<br><br>-----<br><br>
|
||||
<b>Optional:</b> Dragon Knight is a free product, and does not require registration of any sort. However, there is an
|
||||
optional "call home" function in the installer, which notifies the author of your game installation. The ONLY information
|
||||
transmitted with this function is the URL to your game. This is included mainly to satisfy the author's curiosity about
|
||||
how many copies of the game are being installed and used. If you choose to submit your URL to the author, please
|
||||
<a href="/install/fifth">click here</a>.
|
||||
<a href="install.php?page=5">click here</a>.
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
|
@ -735,10 +749,10 @@ function fourth()
|
|||
function fifth()
|
||||
{
|
||||
if (mail("sky@sharkk.net", "Dragon Knight Call Home", $_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]) !== true) {
|
||||
exit('Dragon Knight was unable to send your URL. Please go back and try again, or just continue on to <a href=\"/\">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>.');
|
||||
}
|
||||
|
||||
return <<<HTML
|
||||
echo <<<HTML
|
||||
<html>
|
||||
<head>
|
||||
<title>Dragon Knight Installation</title>
|
||||
|
@ -746,22 +760,8 @@ function fifth()
|
|||
<body>
|
||||
<b>Dragon Knight Installation: Page Five</b><br><br>
|
||||
Thank you for submitting your URL!<br><br>
|
||||
You are now ready to <a href="/">play the game</a>. Note that you must log in through the public section before being allowed into the control panel. Once logged in, an "Admin" link will appear in the Functions box of the left sidebar panel.
|
||||
You are now ready to <a href="index.php">play the game</a>. Note that you must log in through the public section before being allowed into the control panel. Once logged in, an "Admin" link will appear in the Functions box of the left sidebar panel.
|
||||
</body>
|
||||
</html>
|
||||
HTML;
|
||||
}
|
||||
|
||||
function table_status_msg(bool $condition, string $table_name, string $verb): string
|
||||
{
|
||||
$verb = match($verb) {
|
||||
'create' => ['created', 'creating'],
|
||||
'populate' => ['populated', 'populating']
|
||||
};
|
||||
|
||||
if ($condition === false) {
|
||||
return "Error {$verb[1]} $table_name table. (".db()->lastErrorMsg().")<br>";
|
||||
}
|
||||
|
||||
return "$table_name table {$verb[0]}.<br>";
|
||||
}
|
46
public/login.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
// login.php :: Handles logins and cookies.
|
||||
|
||||
require_once '../src/lib.php';
|
||||
|
||||
if (!file_exists('../.installed')) redirect('install.php');
|
||||
|
||||
match ($_GET['do'] ?? 'login') {
|
||||
'login' => login(),
|
||||
'logout' => logout()
|
||||
};
|
||||
|
||||
function login()
|
||||
{
|
||||
if (checkcookies() !== false) redirect('index.php');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$u = trim($_POST['username'] ?? '');
|
||||
|
||||
$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.");
|
||||
|
||||
$expiretime = isset($_POST["rememberme"]) ? time() + 31536000 : 0;
|
||||
$rememberme = isset($_POST["rememberme"]) ? 1 : 0;
|
||||
$cookie = implode(' ', [$row['id'], $row['username'], $row['password'], $rememberme]);
|
||||
|
||||
set_cookie("dkgame", $cookie, $expiretime);
|
||||
header("Location: index.php");
|
||||
exit;
|
||||
}
|
||||
|
||||
$page = gettemplate("login");
|
||||
$title = "Log In";
|
||||
display($page, $title, false, false, false, false);
|
||||
}
|
||||
|
||||
|
||||
function logout()
|
||||
{
|
||||
set_cookie("dkgame", "", -3600);
|
||||
header("Location: login.php?do=login");
|
||||
die();
|
||||
}
|
252
public/users.php
Normal file
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
|
||||
// users.php :: Handles user account functions.
|
||||
|
||||
require_once '../src/lib.php';
|
||||
|
||||
if (!file_exists('../.installed')) redirect('install.php');
|
||||
|
||||
$controlrow = get_control_row();
|
||||
|
||||
$do = $_GET['do'] ?? 'register';
|
||||
match ($do) {
|
||||
'verify' => verify(),
|
||||
'lostpassword' => lostpassword(),
|
||||
'changepassword' => changepassword(),
|
||||
default => register()
|
||||
};
|
||||
|
||||
/**
|
||||
* Register a new account.
|
||||
*/
|
||||
function register()
|
||||
{
|
||||
global $controlrow;
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$u = trim($_POST['username'] ?? '');
|
||||
$e = trim($_POST['email1'] ?? '');
|
||||
$e2 = trim($_POST['email2'] ?? '');
|
||||
$p = $_POST['password1'] ?? '';
|
||||
$p2 = $_POST['password2'] ?? '';
|
||||
|
||||
$errors = [];
|
||||
|
||||
// Process username.
|
||||
if (empty($u) || strlen($u) < 3 || strlen($u) > 18 || !ctype_alnum(str_replace(' ', '', $u))) {
|
||||
$errors[] = 'Username is required and must be between 3 and 18 characters long and contain only
|
||||
alphanumeric characters and spaces.';
|
||||
}
|
||||
|
||||
if (db()->exists('users', 'username', $u)) {
|
||||
$errors[] = 'Username already taken. Try another.';
|
||||
}
|
||||
|
||||
// Process email address.
|
||||
if (empty($e) || strlen($e) > 255 || !filter_var($e, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[] = 'Email is required must be a valid email address.';
|
||||
}
|
||||
|
||||
if ($e !== $e2) {
|
||||
$errors[] = 'Verify Email must match.';
|
||||
}
|
||||
|
||||
if (db()->exists('users', 'email', $e)) {
|
||||
$errors[] = 'Email already taken. Forgot your password?';
|
||||
}
|
||||
|
||||
// Process password.
|
||||
if (empty($p) || strlen($p) < 6) {
|
||||
$errors[] = 'Password is required and must be at least 6 characters long.';
|
||||
}
|
||||
|
||||
if ($p2 !== $p) {
|
||||
$errors[] = 'Verify Password must match.';
|
||||
}
|
||||
|
||||
$password = password_hash($p, PASSWORD_ARGON2ID);
|
||||
|
||||
if (count($errors) !== 0) {
|
||||
$err = "<ul>";
|
||||
foreach ($errors as $error) $err .= "<li>$error</li>";
|
||||
$err .= "</ul>";
|
||||
$page = "The following error(s) occurred when your account was being made:<br><span style=\"color:red;\">$err</span><br>Please go back and try again.";
|
||||
} else {
|
||||
$token = ($controlrow['verifyemail'] == true) ? token(8) : 'g2g';
|
||||
db()->query('INSERT INTO users (verify, username, password, email, charclass) VALUES (?, ?, ?, ?, ?)', [
|
||||
$token, $u, $password, $e, $_POST['charclass'] ?? 1
|
||||
]);
|
||||
|
||||
if ($controlrow['verifyemail'] == true) {
|
||||
if (sendregmail($e, $token)) {
|
||||
$page = "Your account was created successfully.<br><br>You should receive an Account Verification email shortly. You will need the verification code contained in that email before you are allowed to log in. Once you have received the email, please visit the <a href=\"users.php?do=verify\">Verification Page</a> to enter your code and start playing.";
|
||||
} else {
|
||||
$page = "Your account was created successfully.<br><br>However, there was a problem sending your verification email. Please check with the game administrator to help resolve this problem.";
|
||||
}
|
||||
} else {
|
||||
$page = "Your account was created succesfully.<br><br>You may now continue to the <a href=\"login.php?do=login\">Login Page</a> and continue playing ".$controlrow["gamename"]."!";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ($controlrow["verifyemail"] == true) {
|
||||
$controlrow["verifytext"] = "<br><span class=\"small\">A verification code will be sent to the address above, and you will not be able to log in without first entering the code. Please be sure to enter your correct email address.</span>";
|
||||
} else {
|
||||
$controlrow["verifytext"] = "";
|
||||
}
|
||||
|
||||
$page = parsetemplate(gettemplate("register"), $controlrow);
|
||||
}
|
||||
|
||||
$topnav = "<a href=\"login.php?do=login\"><img src=\"images/button_login.gif\" alt=\"Log In\" border=\"0\" /></a><a href=\"users.php?do=register\"><img src=\"images/button_register.gif\" alt=\"Register\" border=\"0\" /></a><a href=\"help.php\"><img src=\"images/button_help.gif\" alt=\"Help\" border=\"0\" /></a>";
|
||||
display($page, "Register", false, false, false);
|
||||
}
|
||||
|
||||
function verify()
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$u = trim($_POST['username'] ?? '');
|
||||
$e = trim($_POST['email'] ?? '');
|
||||
$t = trim($_POST['token'] ?? '');
|
||||
|
||||
$query = db()->query('SELECT id FROM users WHERE username=? AND email=? AND verify=? LIMIT 1;', [$u, $e, $t]);
|
||||
if ($query === false) exit('Verification failed. Go back, double-check your details, and try again.');
|
||||
|
||||
db()->query("UPDATE users SET verify='g2g' WHERE username=?;", [$u]);
|
||||
|
||||
display("Your account was verified successfully.<br><br>You may now continue to the <a href=\"login.php?do=login\">Login Page</a> and start playing the game.<br><br>Thanks for playing!","Verify Email",false,false,false);
|
||||
}
|
||||
|
||||
$topnav = "<a href=\"login.php?do=login\"><img src=\"images/button_login.gif\" alt=\"Log In\" border=\"0\" /></a><a href=\"users.php?do=register\"><img src=\"images/button_register.gif\" alt=\"Register\" border=\"0\" /></a><a href=\"help.php\"><img src=\"images/button_help.gif\" alt=\"Help\" border=\"0\" /></a>";
|
||||
display(gettemplate("verify"), "Verify Email", false, false, false);
|
||||
}
|
||||
|
||||
function lostpassword()
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$e = trim($_POST['email'] ?? '');
|
||||
|
||||
if (!db()->exists('users', 'email', $e)) exit("No account with that email address.");
|
||||
|
||||
$newpass = token(16);
|
||||
$hashed = password_hash($newpass, PASSWORD_ARGON2ID);
|
||||
|
||||
db()->query('UPDATE users SET password=? WHERE email=?;', [$hashed, $e]);
|
||||
|
||||
if (sendpassemail($e, $newpass)) {
|
||||
display("Your new password was emailed to the address you provided.<br><br>Once you receive it, you may <a href=\"login.php?do=login\">Log In</a> and continue playing.<br><br>Thank you.","Lost Password",false,false,false);
|
||||
} else {
|
||||
display("There was an error sending your new password.<br><br>Please check with the game administrator for more information.<br><br>We apologize for the inconvience.","Lost Password",false,false,false);
|
||||
}
|
||||
}
|
||||
|
||||
$topnav = "<a href=\"login.php?do=login\"><img src=\"images/button_login.gif\" alt=\"Log In\" border=\"0\" /></a><a href=\"users.php?do=register\"><img src=\"images/button_register.gif\" alt=\"Register\" border=\"0\" /></a><a href=\"help.php\"><img src=\"images/button_help.gif\" alt=\"Help\" border=\"0\" /></a>";
|
||||
display(gettemplate("lostpassword"), "Lost Password", false, false, false);
|
||||
|
||||
}
|
||||
|
||||
function changepassword()
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$u = trim($_POST['username'] ?? '');
|
||||
$p = $_POST['password'] ?? '';
|
||||
$np = $_POST['new_password'] ?? '';
|
||||
$np2 = $_POST['new_password2'] ?? '';
|
||||
|
||||
$user = db()->query("SELECT password FROM users WHERE username=? LIMIT 1;", [$u]);
|
||||
$user = $user->fetchArray(SQLITE3_ASSOC);
|
||||
if ($user === false) exit("No account with that username.");
|
||||
|
||||
if (!password_verify($p, $user['password'])) exit("The old password you provided was incorrect.");
|
||||
|
||||
if (empty($np) || strlen($np) < 6) {
|
||||
$errors[] = 'New password is required and must be at least 6 characters long.';
|
||||
}
|
||||
|
||||
if ($np2 !== $np) {
|
||||
$errors[] = 'Verify New Password must match.';
|
||||
}
|
||||
|
||||
$realnewpass = password_hash($np, PASSWORD_ARGON2ID);
|
||||
db()->query('UPDATE users SET password=? WHERE username=?;', [$realnewpass, $u]);
|
||||
|
||||
set_cookie('dkgame', '', -3600);
|
||||
|
||||
display("Your password was changed successfully.<br><br>You have been logged out of the game to avoid errors.<br><br>Please <a href=\"login.php?do=login\">log back in</a> to continue playing.","Change Password",false,false,false);
|
||||
}
|
||||
|
||||
$topnav = "<a href=\"login.php?do=login\"><img src=\"images/button_login.gif\" alt=\"Log In\" border=\"0\" /></a><a href=\"users.php?do=register\"><img src=\"images/button_register.gif\" alt=\"Register\" border=\"0\" /></a><a href=\"help.php\"><img src=\"images/button_help.gif\" alt=\"Help\" border=\"0\" /></a>";
|
||||
display(gettemplate("changepassword"), "Change Password", false, false, false);
|
||||
}
|
||||
|
||||
function sendpassemail($emailaddress, $password)
|
||||
{
|
||||
global $controlrow;
|
||||
extract($controlrow);
|
||||
|
||||
$email = <<<HTML
|
||||
You or someone using your email address submitted a Lost Password application on the $gamename server, located at $gameurl.
|
||||
|
||||
We have issued you a new password so you can log back into the game.
|
||||
|
||||
Your new password is: $password
|
||||
|
||||
Thanks for playing.
|
||||
HTML;
|
||||
|
||||
$status = mymail($emailaddress, "$gamename Lost Password", $email);
|
||||
return $status;
|
||||
}
|
||||
|
||||
function sendregmail($emailaddress, $vercode)
|
||||
{
|
||||
global $controlrow;
|
||||
extract($controlrow);
|
||||
$verurl = $gameurl . "?do=verify";
|
||||
|
||||
$email = <<<HTML
|
||||
You or someone using your email address recently signed up for an account on the $gamename server, located at $gameurl.
|
||||
|
||||
This email is sent to verify your registration email. In order to begin using your account, you must verify your email address.
|
||||
Please visit the Verification Page ($verurl) and enter the code below to activate your account.
|
||||
Verification code: $vercode
|
||||
|
||||
If you were not the person who signed up for the game, please disregard this message. You will not be emailed again.
|
||||
HTML;
|
||||
|
||||
$status = mymail($emailaddress, "$gamename Account Verification", $email);
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* thanks to arto dot PLEASE dot DO dot NOT dot SPAM at artoaaltonen dot fi.
|
||||
*/
|
||||
function mymail($to, $title, $body, $from = '')
|
||||
{
|
||||
global $controlrow;
|
||||
extract($controlrow);
|
||||
|
||||
$from = trim($from);
|
||||
|
||||
if (!$from) $from = '<'.$controlrow["adminemail"].'>';
|
||||
|
||||
$rp = $controlrow["adminemail"];
|
||||
$org = '$gameurl';
|
||||
$mailer = 'PHP';
|
||||
|
||||
$head = '';
|
||||
$head .= "Content-Type: text/plain \r\n";
|
||||
$head .= "Date: ". date('r'). " \r\n";
|
||||
$head .= "Return-Path: $rp \r\n";
|
||||
$head .= "From: $from \r\n";
|
||||
$head .= "Sender: $from \r\n";
|
||||
$head .= "Reply-To: $from \r\n";
|
||||
$head .= "Organization: $org \r\n";
|
||||
$head .= "X-Sender: $from \r\n";
|
||||
$head .= "X-Priority: 3 \r\n";
|
||||
$head .= "X-Mailer: $mailer \r\n";
|
||||
|
||||
$body = str_replace("\r\n", "\n", $body);
|
||||
$body = str_replace("\n", "\r\n", $body);
|
||||
|
||||
return mail($to, $title, $body, $head);
|
||||
}
|
|
@ -1,566 +0,0 @@
|
|||
<?php
|
||||
|
||||
// admin.php :: primary administration script.
|
||||
|
||||
namespace Admin;
|
||||
|
||||
use Router;
|
||||
use SQLite3Result;
|
||||
|
||||
function register_routes(Router $r): Router
|
||||
{
|
||||
if (user() !== false && user()->authlevel === 1) {
|
||||
$r->get('/admin', 'Admin\donothing');
|
||||
|
||||
$r->form('/admin/main', 'Admin\primary');
|
||||
|
||||
$r->get('/admin/items', 'Admin\items');
|
||||
$r->form('/admin/items/:id', 'Admin\edit_item');
|
||||
|
||||
$r->get('/admin/drops', 'Admin\drops');
|
||||
$r->form('/admin/drops/:id', 'Admin\edit_drop');
|
||||
|
||||
$r->get('/admin/towns', 'Admin\towns');
|
||||
$r->form('/admin/towns/:id', 'Admin\edit_town');
|
||||
|
||||
$r->get('/admin/monsters', 'Admin\monsters');
|
||||
$r->form('/admin/monsters/:id', 'Admin\edit_monster');
|
||||
|
||||
$r->get('/admin/levels', 'Admin\levels');
|
||||
$r->post('/admin/levels', 'Admin\edit_level');
|
||||
|
||||
$r->get('/admin/spells', 'Admin\spells');
|
||||
$r->form('/admin/spells/:id', 'Admin\edit_spell');
|
||||
|
||||
$r->get('/admin/users', 'Admin\users');
|
||||
$r->form('/admin/users/:id', 'Admin\edit_user');
|
||||
|
||||
$r->form('/admin/news', 'Admin\add_news');
|
||||
}
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Home page for the admin panel.
|
||||
*/
|
||||
function donothing(): string
|
||||
{
|
||||
page_title('Admin');
|
||||
|
||||
return <<<HTML
|
||||
Welcome to the administration section. Use the links on the left bar to control and edit various
|
||||
elements of the game.
|
||||
<br><br>
|
||||
Please note that the control panel has been created mostly as a shortcut for certain individual settings. It is
|
||||
meant for use primarily with editing one thing at a time. If you need to completely replace an entire table
|
||||
(say, to replace all stock monsters with your own new ones), it is suggested that you use a more in-depth
|
||||
database tool such as <a href="https://sqlitebrowser.org/" target="_new">SQLite Browser</a>.
|
||||
<br><br>
|
||||
Also, you should be aware that certain portions of the DK code are dependent on the formatting of certain
|
||||
database results (for example, the special attributes on item drops). While I have attempted to point these out
|
||||
throughout the admin script, you should definitely pay attention and be careful when editing some fields,
|
||||
because mistakes in the database content may result in script errors or your game breaking completely.
|
||||
HTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Main settings that get written to .env
|
||||
*/
|
||||
function primary(): string
|
||||
{
|
||||
if (is_post()) {
|
||||
$form = validate($_POST, [
|
||||
'gamename' => ['alphanum-spaces'],
|
||||
'gamesize' => ['int', 'min:5'],
|
||||
'class1name' => ['alpha-spaces'],
|
||||
'class2name' => ['alpha-spaces'],
|
||||
'class3name' => ['alpha-spaces'],
|
||||
'gameopen' => ['bool'],
|
||||
'verifyemail' => ['bool'],
|
||||
'shownews' => ['bool'],
|
||||
'showonline' => ['bool'],
|
||||
'showbabble' => ['bool']
|
||||
]);
|
||||
|
||||
if ($form['valid']) {
|
||||
$form = $form['data'];
|
||||
if (($form['gamesize'] % 5) != 0) exit('Map size must be divisible by five.');
|
||||
|
||||
// @todo
|
||||
// write changes to .env
|
||||
|
||||
$page = 'Main settings updated.';
|
||||
} else {
|
||||
$error_list = ul_from_validate_errors($form['errors']);
|
||||
$page = <<<HTML
|
||||
<b>Errors:</b><br>
|
||||
<div style="color: red;">{$error_list}</div><br>
|
||||
Please go back and try again.
|
||||
HTML;
|
||||
}
|
||||
} else {
|
||||
$page = render('admin/main_settings');
|
||||
}
|
||||
|
||||
page_title('Admin: Main Settings');
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the full list of items that can be edited.
|
||||
*/
|
||||
function items(): string
|
||||
{
|
||||
$items = db()->query('SELECT * FROM items ORDER BY id;');
|
||||
$page = "<h2>Edit Items</h2>Click an item's name or ID to edit it.<br><br>\n";
|
||||
$page .= build_bulk_table($items, 'name', '/admin/items');
|
||||
|
||||
page_title('Admin: Items');
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the form for editing an item via GET, processes edits via POST
|
||||
*/
|
||||
function edit_item(int $id): string
|
||||
{
|
||||
$item = get_item($id);
|
||||
|
||||
if (is_post()) {
|
||||
$page = handle_edit_form($id, 'items', validate($_POST, [
|
||||
'name' => [],
|
||||
'type' => ['int', 'in:1,2,3'],
|
||||
'buycost' => ['int', 'min:0'],
|
||||
'attribute' => ['int', 'min:0'],
|
||||
'special' => ['default:X']
|
||||
]));
|
||||
} else {
|
||||
$page = render('admin/edit_item', ['item' => $item]);
|
||||
}
|
||||
|
||||
page_title('Admin: Editing '.$item['name']);
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the full list of drops that can be edited
|
||||
*/
|
||||
function drops()
|
||||
{
|
||||
$drops = db()->query('SELECT * FROM drops ORDER BY id;');
|
||||
$page = "<h2>Edit Drops</h2>Click an item's name to edit it.<br><br>\n";
|
||||
$page .= build_bulk_table($drops, 'name', '/admin/drops');
|
||||
|
||||
page_title('Admin: Drops');
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form to edit drops via GET, process those edits via POST
|
||||
*/
|
||||
function edit_drop(int $id): string
|
||||
{
|
||||
$drop = get_drop($id);
|
||||
|
||||
if (is_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 = "<h2>Edit Towns</h2>Click an town's name or ID to edit it.<br><br>\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 = "<h2>Edit Monsters</h2>";
|
||||
|
||||
if ((env('game_size') / 5) !== $max_level) {
|
||||
$page .= "<span class=\"highlight\">Note:</span> 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.<br>";
|
||||
} else {
|
||||
$page .= "Monster level and map size match. No further actions are required for map compatibility.<br>";
|
||||
}
|
||||
|
||||
$page .= "Click an monster's name or ID to edit it.<br><br>\n";
|
||||
$page .= build_bulk_table($monsters, 'name', '/admin/monsters');
|
||||
|
||||
page_title('Admin: Monsters');
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the actual editing of the monster.
|
||||
*/
|
||||
function edit_monster(int $id): string
|
||||
{
|
||||
$monster = get_monster($id);
|
||||
|
||||
if (is_post()) {
|
||||
$page = handle_edit_form($id, 'monsters', validate($_POST, [
|
||||
'name' => [],
|
||||
'maxhp' => ['int', 'min:1'],
|
||||
'maxdam' => ['int', 'min:0'],
|
||||
'armor' => ['int', 'min:0'],
|
||||
'level' => ['int', 'min:1'],
|
||||
'maxexp' => ['int', 'min:0'],
|
||||
'maxgold' => ['int', 'min:0'],
|
||||
'immune' => ['in:0,1,2']
|
||||
]));
|
||||
} else {
|
||||
$page = render('admin/edit_monster', ['monster' => $monster]);
|
||||
}
|
||||
|
||||
page_title('Admin: Editing '.$monster['name']);
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* List all spells available to edit.
|
||||
*/
|
||||
function spells(): string
|
||||
{
|
||||
$page = "<h2>Edit Spells</h2>Click an spell's name to edit it.<br><br>\n";
|
||||
|
||||
$spells = db()->query('SELECT * FROM spells ORDER BY id;');
|
||||
$page .= build_bulk_table($spells, 'name', '/admin/spells');
|
||||
|
||||
page_title('Admin: Spells');
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the editing of an individual spell.
|
||||
*/
|
||||
function edit_spell(int $id): string
|
||||
{
|
||||
$spell = get_spell($id);
|
||||
|
||||
if (is_post()) {
|
||||
$page = handle_edit_form($id, 'spells', validate($_POST, [
|
||||
'name' => [],
|
||||
'mp' => ['int', 'min:0'],
|
||||
'attribute' => ['int', 'min:0'],
|
||||
'type' => ['in:1,2,3,4,5']
|
||||
]));
|
||||
} else {
|
||||
$page = render('admin/edit_spell', ['spell' => $spell]);
|
||||
}
|
||||
|
||||
page_title('Admin: Editing '.$spell['name']);
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* List all editable levels.
|
||||
*/
|
||||
function levels(): string
|
||||
{
|
||||
$max_level = db()->query('SELECT id FROM levels ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC)['id'];
|
||||
|
||||
$page = <<<HTML
|
||||
<h2>Edit Levels</h2>
|
||||
Select a level number from the dropdown box to edit it.<br><br>
|
||||
<form action="/admin/levels" method="post" hx-post="/admin/levels" hx-target="#main">
|
||||
<select name="level">
|
||||
HTML;
|
||||
for ($i = 2; $i < $max_level; $i++) $page .= "<option value=\"$i\">$i</option>\n";
|
||||
$page .= <<<HTML
|
||||
</select>
|
||||
<button type="submit">Edit</button>
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
page_title('Admin: Levels');
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the editing of a level.
|
||||
*/
|
||||
function edit_level()
|
||||
{
|
||||
if (!isset($_POST['level'])) return 'No level to edit.';
|
||||
$id = $_POST['level'];
|
||||
$level = db()->query('SELECT * FROM levels WHERE id=? LIMIT 1;', [$id])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if (is_post() && isset($_POST['save'])) {
|
||||
unset($_POST['save']);
|
||||
unset($_POST['level']);
|
||||
|
||||
$page = handle_edit_form($id, 'levels', validate($_POST, [
|
||||
'1_exp' => ['int', 'min:0'],
|
||||
'1_hp' => ['int', 'min:0'],
|
||||
'1_mp' => ['int', 'min:0'],
|
||||
'1_tp' => ['int', 'min:0'],
|
||||
'1_strength' => ['int', 'min:0'],
|
||||
'1_dexterity' => ['int', 'min:0'],
|
||||
'1_spells' => ['int', 'min:0'],
|
||||
'2_exp' => ['int', 'min:0'],
|
||||
'2_hp' => ['int', 'min:0'],
|
||||
'2_mp' => ['int', 'min:0'],
|
||||
'2_tp' => ['int', 'min:0'],
|
||||
'2_strength' => ['int', 'min:0'],
|
||||
'2_dexterity' => ['int', 'min:0'],
|
||||
'2_spells' => ['int', 'min:0'],
|
||||
'3_exp' => ['int', 'min:0'],
|
||||
'3_hp' => ['int', 'min:0'],
|
||||
'3_mp' => ['int', 'min:0'],
|
||||
'3_tp' => ['int', 'min:0'],
|
||||
'3_strength' => ['int', 'min:0'],
|
||||
'3_dexterity' => ['int', 'min:0'],
|
||||
'3_spells' => ['int', 'min:0']
|
||||
]), 'Level <b>'.$id.'</b> updated.');
|
||||
} else {
|
||||
$page = render('admin/edit_level', ['level' => $level]);
|
||||
}
|
||||
|
||||
page_title('Admin: Editing Level '.$id);
|
||||
return $page;
|
||||
}
|
||||
|
||||
function users()
|
||||
{
|
||||
$users = db()->query('SELECT * FROM users ORDER BY id;');
|
||||
$page = "<h2>Edit Users</h2>Click a username or ID to edit the account.<br><br><div class=\"table-wrapper\">";
|
||||
$page .= build_bulk_table($users, 'username', '/admin/users');
|
||||
|
||||
page_title('Admin: Users');
|
||||
return $page . '</div>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle editing a user.
|
||||
*/
|
||||
function edit_user(int $id): string
|
||||
{
|
||||
$user = db()->query('SELECT * FROM users WHERE id = ? LIMIT 1;', [$id])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if (is_post()) {
|
||||
$form = validate($_POST, [
|
||||
'username' => ['length:3-18', 'alpha-spaces', 'unique:users,username'],
|
||||
'verify' => [],
|
||||
'authlevel' => ['int'],
|
||||
'email' => ['email', 'unique:users,email'],
|
||||
'charclass' => ['in:1,2,3'],
|
||||
'latitude' => ['int', 'min:0', 'max:'.env('game_size')],
|
||||
'longitude' => ['int', 'min:0', 'max:'.env('game_size')],
|
||||
'currentaction' => [],
|
||||
'currentfight' => ['int'],
|
||||
'currentmonster' => ['int'],
|
||||
'currentmonsterhp' => ['int'],
|
||||
'currentmonstersleep' => ['int'],
|
||||
'currentmonsterimmune' => ['int'],
|
||||
'currentuberdamage' => ['int'],
|
||||
'currentuberdefense' => ['int'],
|
||||
'currenthp' => ['int', 'min:0'],
|
||||
'currentmp' => ['int', 'min:0'],
|
||||
'currenttp' => ['int', 'min:0'],
|
||||
'maxhp' => ['int', 'min:1'],
|
||||
'maxmp' => ['int', 'min:1'],
|
||||
'maxtp' => ['int', 'min:1'],
|
||||
'level' => ['int', 'min:1'],
|
||||
'gold' => ['int', 'min:0'],
|
||||
'experience' => ['int', 'min:0'],
|
||||
'goldbonus' => ['int'],
|
||||
'expbonus' => ['int'],
|
||||
'strength' => ['int'],
|
||||
'dexterity' => ['int'],
|
||||
'attackpower' => ['int'],
|
||||
'defensepower' => ['int'],
|
||||
'weaponid' => ['int'],
|
||||
'armorid' => ['int'],
|
||||
'shieldid' => ['int'],
|
||||
'slot1id' => ['int'],
|
||||
'slot2id' => ['int'],
|
||||
'slot3id' => ['int'],
|
||||
'weaponname' => ['default:None'],
|
||||
'armorname' => ['default:None'],
|
||||
'shieldname' => ['default:None'],
|
||||
'slot1name' => ['default:None'],
|
||||
'slot2name' => ['default:None'],
|
||||
'slot3name' => ['default:None'],
|
||||
'dropcode' => ['int', 'min:0', 'default:0'],
|
||||
'spells' => ['optional'],
|
||||
'towns' => ['optional']
|
||||
]);
|
||||
|
||||
if ($form['valid']) {
|
||||
save_data_row('users', $form['data'], $id);
|
||||
$page = 'User <b>'.$user['username'].'</b> updated.';
|
||||
} else {
|
||||
$error_list = ul_from_validate_errors($form['errors']);
|
||||
$page = <<<HTML
|
||||
<b>Errors:</b><br>
|
||||
<div style="color: red;">{$error_list}</div><br>
|
||||
Please go back and try again.
|
||||
HTML;
|
||||
}
|
||||
} else {
|
||||
$page = render('admin/edit_user', ['user' => $user]);
|
||||
}
|
||||
|
||||
page_title('Admin: Editing '.$user['username']);
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handling adding news posts.
|
||||
*/
|
||||
function add_news()
|
||||
{
|
||||
if (is_post()) {
|
||||
$c = trim($_POST['content'] ?? '');
|
||||
|
||||
$errors = [];
|
||||
if (empty($c)) $errors[] = "Content is required.";
|
||||
|
||||
if (count($errors) === 0) {
|
||||
db()->query('INSERT INTO news (author, content) VALUES (?, ?);', [user()->username, $c]);
|
||||
$page = 'News post added.';
|
||||
} else {
|
||||
$error_list = implode('<br>', $errors);
|
||||
$page = "<b>Errors:</b><br><div style=\"color:red;\">$error_list</div><br>Please go back and try again.";
|
||||
}
|
||||
} else {
|
||||
$page = <<<HTML
|
||||
<h2>Add a News Post</h2>
|
||||
<form action="/admin/news" method="post" hx-post="/admin/news" hx-target="#main">
|
||||
Type your post below and then click Submit to add it.<br>
|
||||
<textarea name="content" rows="5" cols="50"></textarea><br>
|
||||
<button type="submit">Submit</button>
|
||||
<button type="reset">Clear</button>
|
||||
</form>
|
||||
HTML;
|
||||
}
|
||||
|
||||
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
|
||||
* query.
|
||||
*/
|
||||
function build_bulk_table(SQLite3Result $query_data, string $edit_column, string $edit_link): string
|
||||
{
|
||||
$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 = [
|
||||
'<table><colgroup>',
|
||||
str_repeat('<col>', count($columns)),
|
||||
'</colgroup><thead><tr>'
|
||||
];
|
||||
|
||||
foreach ($columns as $column) {
|
||||
$html_parts[] = '<th>' .
|
||||
make_safe($column === 'id' ? 'ID' : ucfirst($column)) .
|
||||
'</th>';
|
||||
}
|
||||
$html_parts[] = '</tr></thead><tbody>';
|
||||
|
||||
$is_edit_column = array_flip(['id', $edit_column]);
|
||||
|
||||
foreach ($data as $row) {
|
||||
$html_parts[] = '<tr>';
|
||||
foreach ($columns as $column) {
|
||||
$name = make_safe($row[$column]);
|
||||
$html_parts[] = isset($is_edit_column[$column])
|
||||
? "<td><a href=\"{$edit_link}/{$row['id']}\" hx-get=\"{$edit_link}/{$row['id']}\" hx-target=\"#main\">{$name}</a></td>"
|
||||
: "<td>{$name}</td>";
|
||||
}
|
||||
$html_parts[] = '</tr>';
|
||||
}
|
||||
|
||||
$html_parts[] = '</tbody></table>';
|
||||
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 ?: '<b>'.$form['data']['name'].'</b> updated.';
|
||||
} else {
|
||||
$error_list = ul_from_validate_errors($form['errors']);
|
||||
$page = <<<HTML
|
||||
<b>Errors:</b><br>
|
||||
<div style="color: red;">{$error_list}</div><br>
|
||||
Please go back and try again.
|
||||
HTML;
|
||||
}
|
||||
|
||||
return $page;
|
||||
}
|
|
@ -1,69 +0,0 @@
|
|||
<?php
|
||||
|
||||
// explore.php :: Handles all map exploring, chances to fight, etc.
|
||||
|
||||
namespace Explore;
|
||||
|
||||
/**
|
||||
* 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 explore()
|
||||
{
|
||||
page_title('Exploring');
|
||||
return <<<HTML
|
||||
<div class="title"><img src="/img/title_exploring.gif" alt="Exploring"></div>
|
||||
You are exploring the map, and nothing has happened. Continue exploring using the direction buttons or the Travel To menus.
|
||||
HTML;
|
||||
}
|
||||
|
||||
function move() {
|
||||
// Early exit if fighting
|
||||
if (user()->currentaction == 'Fighting') redirect('/fight');
|
||||
|
||||
// Validate direction
|
||||
$form = validate($_POST, ['direction' => ['in:north,west,east,south']]);
|
||||
if (!$form['valid']) return ul_from_validate_errors($form['errors']);
|
||||
|
||||
// Current game state
|
||||
$game_size = env('game_size');
|
||||
$latitude = user()->latitude;
|
||||
$longitude = user()->longitude;
|
||||
$direction = $form['data']['direction'];
|
||||
|
||||
// Calculate new coordinates with boundary checks
|
||||
switch ($direction) {
|
||||
case 'north':
|
||||
$latitude = min($latitude + 1, $game_size);
|
||||
break;
|
||||
case 'south':
|
||||
$latitude = max($latitude - 1, -$game_size);
|
||||
break;
|
||||
case 'east':
|
||||
$longitude = min($longitude + 1, $game_size);
|
||||
break;
|
||||
case 'west':
|
||||
$longitude = max($longitude - 1, -$game_size);
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for town
|
||||
$town = get_town_by_xy($longitude, $latitude);
|
||||
if ($town !== false) {
|
||||
return \Towns\travelto($town['id'], false);
|
||||
}
|
||||
|
||||
// Determine action (1 in 5 chance of fighting)
|
||||
if (rand(1, 5) === 1) {
|
||||
user()->currentaction = 'Fighting';
|
||||
user()->currentfight = 1;
|
||||
} else {
|
||||
user()->currentaction = 'Exploring';
|
||||
}
|
||||
|
||||
user()->latitude = $latitude;
|
||||
user()->longitude = $longitude;
|
||||
user()->save();
|
||||
|
||||
return index();
|
||||
}
|
|
@ -1,451 +0,0 @@
|
|||
<?php
|
||||
|
||||
// fight.php :: Handles all fighting action.
|
||||
|
||||
namespace Fights;
|
||||
|
||||
use Router;
|
||||
|
||||
function register_routes(Router $r): Router
|
||||
{
|
||||
$r->form('/fight', 'Fights\fight');
|
||||
$r->get('/victory', 'Fights\victory');
|
||||
$r->form('/drop', 'Fights\drop');
|
||||
$r->get('/dead', 'Fights\dead');
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* One big long function that determines the outcome of the fight.
|
||||
*/
|
||||
function fight()
|
||||
{
|
||||
if (user()->currentaction !== 'Fighting') exit('Cheat attempt detected.<br><br>Get a life, loser.');
|
||||
|
||||
$page = ["magiclist" => "", "yourturn" => "", "monsterturn" => "", "monsterhp" => "", "command" => ""];
|
||||
$playerisdead = 0;
|
||||
|
||||
// Generate spell list
|
||||
$user_spells = user()->spells();
|
||||
if (!empty($user_spells)) {
|
||||
$page['magiclist'] = '<select name="userspell">';
|
||||
foreach ($user_spells as $spell) {
|
||||
$page['magiclist'] .= "<option value=\"{$spell['id']}\">{$spell['name']}</option>\n";
|
||||
}
|
||||
$page['magiclist'] .= '</select> <input type="submit" name="spell" value="Spell"><br><br>';
|
||||
}
|
||||
|
||||
// Determine initial combat parameters
|
||||
$chancetoswingfirst = rand(1, 10) + (int)ceil(sqrt(user()->dexterity));
|
||||
if (user()->currentfight === 1) {
|
||||
$maxlevel = (int)floor(max(abs(user()->latitude) + 5, abs(user()->longitude) + 5) / 5);
|
||||
$minlevel = max(1, $maxlevel - 2);
|
||||
|
||||
$monster = db()->query('SELECT * FROM monsters WHERE level >= ? AND level <= ? ORDER BY RANDOM() LIMIT 1;', [
|
||||
$minlevel, $maxlevel
|
||||
])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
user()->currentmonster = $monster["id"];
|
||||
user()->currentmonsterhp = rand((int)(($monster["maxhp"]/5)*4), $monster["maxhp"]);
|
||||
user()->currentmonstersleep = 0;
|
||||
user()->currentmonsterimmune = $monster["immune"];
|
||||
|
||||
$chancetoswingfirst = ($chancetoswingfirst > (rand(1,7) + (int)ceil(sqrt($monster["maxdam"])))) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Get monster statistics
|
||||
$monster = get_monster(user()->currentmonster);
|
||||
$page['monstername'] = $monster['name'];
|
||||
|
||||
// Run action
|
||||
if (isset($_POST["run"])) {
|
||||
$chancetorun = rand(4,10) + (int)ceil(sqrt(user()->dexterity));
|
||||
if ($chancetorun <= (rand(1,5) + (int)ceil(sqrt($monster["maxdam"])))) {
|
||||
$page["yourturn"] = "You tried to run away, but were blocked in front!<br><br>";
|
||||
$page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "<br><br>";
|
||||
|
||||
// Monster turn logic (similar to original function)
|
||||
$page["monsterturn"] = handleMonsterTurn($userrow, $monster);
|
||||
|
||||
user()->currentaction = 'Exploring';
|
||||
user()->save();
|
||||
redirect('/');
|
||||
}
|
||||
}
|
||||
|
||||
// Fight action
|
||||
if (isset($_POST["fight"])) {
|
||||
// Player's attack
|
||||
$min = (int)(user()->attackpower * 0.75);
|
||||
$max = (int)(user()->attackpower / 3);
|
||||
$tohit = (int)ceil(mt_rand(min($min, $max), max($min, $max)));
|
||||
|
||||
$toexcellent = rand(1,150);
|
||||
if ($toexcellent <= sqrt(user()->strength)) {
|
||||
$tohit *= 2;
|
||||
$page["yourturn"] .= "Excellent hit!<br>";
|
||||
}
|
||||
|
||||
$min = (int)($monster["armor"] * 0.75);
|
||||
$max = (int)$monster["armor"];
|
||||
$toblock = (int)ceil(rand(min($min, $max), max($min, $max)) / 3);
|
||||
|
||||
$tododge = rand(1, 100);
|
||||
|
||||
$monsterdamage = max(1, $tohit - $toblock);
|
||||
if ($tododge <= sqrt($monster["armor"])) {
|
||||
$monsterdamage = 0;
|
||||
$page["yourturn"] .= "The monster is dodging. No damage has been scored.<br>";
|
||||
}
|
||||
|
||||
if (user()->currentuberdamage != 0) {
|
||||
$monsterdamage += (int)ceil($monsterdamage * (user()->currentuberdamage / 100));
|
||||
}
|
||||
|
||||
user()->currentmonsterhp -= $monsterdamage;
|
||||
$page["yourturn"] .= "You attack the monster for $monsterdamage damage.<br><br>";
|
||||
$page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "<br><br>";
|
||||
|
||||
// Check for monster defeat
|
||||
if (user()->currentmonsterhp <= 0) {
|
||||
user()->currentmonsterhp = 0;
|
||||
user()->save();
|
||||
redirect('/victory');
|
||||
}
|
||||
|
||||
// Monster's turn
|
||||
$page["monsterturn"] = handleMonsterTurn($userrow, $monster);
|
||||
}
|
||||
|
||||
// Spell action
|
||||
if (isset($_POST["spell"])) {
|
||||
$pickedspell = $_POST["userspell"];
|
||||
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 'You have not yet learned this spell. Please go back and try again.';
|
||||
|
||||
if (user()->currentmp < $newspellrow["mp"]) {
|
||||
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)
|
||||
$page["yourturn"] = handleSpellCast($userrow, $newspellrow);
|
||||
$page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "<br><br>";
|
||||
|
||||
// Check for monster defeat
|
||||
if (user()->currentmonsterhp <= 0) {
|
||||
user()->currentmonsterhp = 0;
|
||||
user()->save();
|
||||
redirect('/victory');
|
||||
}
|
||||
|
||||
// Monster's turn
|
||||
$page["monsterturn"] = handleMonsterTurn($userrow, $monster);
|
||||
}
|
||||
|
||||
// Monster's turn if player lost first swing
|
||||
if (!isset($_POST["run"]) && !isset($_POST["fight"]) && !isset($_POST["spell"]) && $chancetoswingfirst == 0) {
|
||||
$page["yourturn"] = "The monster attacks before you are ready!<br><br>";
|
||||
$page["monsterhp"] = "Monster's HP: " . user()->currentmonsterhp . "<br><br>";
|
||||
$page["monsterturn"] = handleMonsterTurn($userrow, $monster);
|
||||
}
|
||||
|
||||
// Prepare command or death message
|
||||
if ($playerisdead != 1) {
|
||||
$page["command"] = <<<HTML
|
||||
Command?<br><br>
|
||||
<form action="/fight" method="post" hx-post="/fight" hx-target="#middle">
|
||||
<input type="submit" name="fight" value="Fight"><br><br>
|
||||
{$page['magiclist']}
|
||||
<input type="submit" name="run" value="Run"><br><br>
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
user()->currentfight += 1;
|
||||
} else {
|
||||
$page["command"] = <<<HTML
|
||||
<b>You have died.</b><br><br>
|
||||
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.<br><br>
|
||||
You may now continue back to <a href="/" hx-get="/" hx-target="#middle">town</a>, and we hope you fair better next time.
|
||||
HTML;
|
||||
}
|
||||
|
||||
user()->save();
|
||||
|
||||
// Finalize page and display it
|
||||
$page = render('fight', ['page' => $page]);
|
||||
return $page;
|
||||
}
|
||||
|
||||
function victory()
|
||||
{
|
||||
if (user()->currentmonsterhp != 0) redirect('/fight');
|
||||
if (user()->currentfight == 0) redirect('/');
|
||||
|
||||
$monsterrow = get_monster(user()->currentmonster);
|
||||
|
||||
$min = (int)(($monsterrow["maxexp"] / 6) * 5);
|
||||
$max = (int)$monsterrow["maxexp"];
|
||||
$exp = mt_rand(min($min, $max), max($min, $max));
|
||||
if ($exp < 1) { $exp = 1; }
|
||||
|
||||
if (user()->expbonus != 0) { $exp += ceil((user()->expbonus/100)*$exp); }
|
||||
|
||||
$min = (int)(($monsterrow["maxgold"] / 6) * 5);
|
||||
$max = (int)$monsterrow["maxgold"];
|
||||
|
||||
$gold = mt_rand(min($min, $max), max($min, $max));
|
||||
if ($gold < 1) { $gold = 1; }
|
||||
|
||||
if (user()->goldbonus != 0) { $gold += ceil((user()->goldbonus/100)*$exp); }
|
||||
if (user()->experience + $exp < 16777215) { $newexp = user()->experience += $exp; $warnexp = ""; } else { $newexp = user()->experience; $exp = 0; $warnexp = "You have maxed out your experience points."; }
|
||||
if (user()->gold + $gold < 16777215) { $newgold = user()->gold += $gold; $warngold = ""; } else { $newgold = user()->gold; $gold = 0; $warngold = "You have maxed out your gold."; }
|
||||
|
||||
$levelrow = db()->query('SELECT * FROM levels WHERE id=? LIMIT 1;', [user()->level + 1])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if (user()->level < 100) {
|
||||
if ($newexp >= $levelrow[user()->charclass."_exp"]) {
|
||||
user()->maxhp += $levelrow[user()->charclass."_hp"];
|
||||
user()->maxmp += $levelrow[user()->charclass."_mp"];
|
||||
user()->maxtp += $levelrow[user()->charclass."_tp"];
|
||||
user()->strength += $levelrow[user()->charclass."_strength"];
|
||||
user()->dexterity += $levelrow[user()->charclass."_dexterity"];
|
||||
user()->attackpower += $levelrow[user()->charclass."_strength"];
|
||||
user()->defensepower += $levelrow[user()->charclass."_dexterity"];
|
||||
user()->level += 1;
|
||||
$newlevel = $levelrow["id"];
|
||||
|
||||
if ($levelrow[user()->charclass."_spells"] != 0) {
|
||||
user()->spells .= ",".$levelrow[user()->charclass."_spells"];
|
||||
$spelltext = "You have learned a new spell.<br>";
|
||||
} else { $spelltext = ""; $newspell=""; }
|
||||
|
||||
$page = "Congratulations. You have defeated the ".$monsterrow["name"].".<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br><b>You have gained a level!</b><br><br>You gain ".$levelrow[user()->charclass."_hp"]." hit points.<br>You gain ".$levelrow[user()->charclass."_mp"]." magic points.<br>You gain ".$levelrow[user()->charclass."_tp"]." travel points.<br>You gain ".$levelrow[user()->charclass."_strength"]." strength.<br>You gain ".$levelrow[user()->charclass."_dexterity"]." dexterity.<br>$spelltext<br>You can now continue <a href=\"/\" hx-get=\"/\" hx-target=\"#middle\">exploring</a>.";
|
||||
$title = "Courage and Wit have served thee well!";
|
||||
$dropcode = "";
|
||||
} else {
|
||||
$page = "Congratulations. You have defeated the ".$monsterrow["name"].".<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br>";
|
||||
|
||||
if (rand(1, 30) === 1) {
|
||||
$droprow = db()->query('SELECT * FROM drops WHERE mlevel <= ? ORDER BY RANDOM() LIMIT 1;', [$monsterrow['level']])->fetchArray(SQLITE3_ASSOC);
|
||||
$dropcode = "dropcode='".$droprow["id"]."',";
|
||||
$page .= "This monster has dropped an item. <a href=\"/drop\" hx-get=\"/drop\" hx-target=\"#middle\">Click here</a> to reveal and equip the item, or you may also move on and continue <a href=\"/\" hx-get=\"/\" hx-target=\"#middle\">exploring</a>.";
|
||||
} else {
|
||||
$dropcode = "";
|
||||
$page .= 'You can now continue <a href="/" hx-get="/" hx-target="#middle">exploring</a>.';
|
||||
}
|
||||
|
||||
$title = "Victory!";
|
||||
}
|
||||
}
|
||||
|
||||
user()->currentaction = 'Exploring';
|
||||
user()->currentfight = 0;
|
||||
user()->currentuberdamage = 0;
|
||||
user()->currentuberdefense = 0;
|
||||
user()->currentmonstersleep = 0;
|
||||
user()->currentmonsterimmune = 0;
|
||||
user()->save();
|
||||
|
||||
page_title($title);
|
||||
return $page;
|
||||
}
|
||||
|
||||
function drop()
|
||||
{
|
||||
if (user()->dropcode == 0) redirect('/');
|
||||
|
||||
$droprow = get_drop(user()->dropcode);
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$slot = $_POST["slot"];
|
||||
|
||||
if ($slot === 0) return 'Please go back and select an inventory slot to continue.';
|
||||
|
||||
$slotstr = 'slot'.$slot.'id';
|
||||
if (user()->$slotstr != 0) {
|
||||
$slotrow = get_drop(user()->$slotstr);
|
||||
|
||||
$old1 = explode(",",$slotrow["attribute1"]);
|
||||
if ($slotrow["attribute2"] != "X") { $old2 = explode(",",$slotrow["attribute2"]); } else { $old2 = array(0=>"maxhp",1=>0); }
|
||||
$new1 = explode(",",$droprow["attribute1"]);
|
||||
if ($droprow["attribute2"] != "X") { $new2 = explode(",",$droprow["attribute2"]); } else { $new2 = array(0=>"maxhp",1=>0); }
|
||||
|
||||
user()->$old1[0] -= $old1[1];
|
||||
user()->$old2[0] -= $old2[1];
|
||||
if ($old1[0] == "strength") { user()->attackpower -= $old1[1]; }
|
||||
if ($old1[0] == "dexterity") { user()->defensepower -= $old1[1]; }
|
||||
if ($old2[0] == "strength") { user()->attackpower -= $old2[1]; }
|
||||
if ($old2[0] == "dexterity") { user()->defensepower -= $old2[1]; }
|
||||
|
||||
user()->$new1[0] += $new1[1];
|
||||
user()->$new2[0] += $new2[1];
|
||||
if ($new1[0] == "strength") { user()->attackpower += $new1[1]; }
|
||||
if ($new1[0] == "dexterity") { user()->defensepower += $new1[1]; }
|
||||
if ($new2[0] == "strength") { user()->attackpower += $new2[1]; }
|
||||
if ($new2[0] == "dexterity") { user()->defensepower += $new2[1]; }
|
||||
|
||||
if (user()->currenthp > user()->maxhp) { user()->currenthp = user()->maxhp; }
|
||||
if (user()->currentmp > user()->maxmp) { user()->currentmp = user()->maxmp; }
|
||||
if (user()->currenttp > user()->maxtp) { user()->currenttp = user()->maxtp; }
|
||||
|
||||
$slot_s = 'slot'.$_POST["slot"];
|
||||
$slot_name = "{$slot_s}name";
|
||||
$slot_id = "{$slot_s}id";
|
||||
|
||||
user()->$slot_name = $droprow['name'];
|
||||
user()->$slot_id = $droprow['id'];
|
||||
} else {
|
||||
$new1 = explode(",",$droprow["attribute1"]);
|
||||
if ($droprow["attribute2"] != "X") { $new2 = explode(",",$droprow["attribute2"]); } else { $new2 = array(0=>"maxhp",1=>0); }
|
||||
|
||||
user()->$new1[0] += $new1[1];
|
||||
user()->$new2[0] += $new2[1];
|
||||
if ($new1[0] == "strength") { user()->attackpower += $new1[1]; }
|
||||
if ($new1[0] == "dexterity") { user()->defensepower += $new1[1]; }
|
||||
if ($new2[0] == "strength") { user()->attackpower += $new2[1]; }
|
||||
if ($new2[0] == "dexterity") { user()->defensepower += $new2[1]; }
|
||||
|
||||
$slot_s = 'slot'.$_POST["slot"];
|
||||
$slot_name = "{$slot_s}name";
|
||||
$slot_id = "{$slot_s}id";
|
||||
|
||||
user()->$slot_name = $droprow['name'];
|
||||
user()->$slot_id = $droprow['id'];
|
||||
}
|
||||
|
||||
user()->save();
|
||||
return 'The item has been equipped. You can now continue <a href="/" hx-get="/" hx-target="#middle">exploring</a>.';
|
||||
}
|
||||
|
||||
$attributearray = array("maxhp"=>"Max HP",
|
||||
"maxmp"=>"Max MP",
|
||||
"maxtp"=>"Max TP",
|
||||
"defensepower"=>"Defense Power",
|
||||
"attackpower"=>"Attack Power",
|
||||
"strength"=>"Strength",
|
||||
"dexterity"=>"Dexterity",
|
||||
"expbonus"=>"Experience Bonus",
|
||||
"goldbonus"=>"Gold Bonus");
|
||||
|
||||
$page = "The monster dropped the following item: <b>".$droprow["name"]."</b><br><br>";
|
||||
$page .= "This item has the following attribute(s):<br>";
|
||||
|
||||
$attribute1 = explode(",",$droprow["attribute1"]);
|
||||
$page .= $attributearray[$attribute1[0]];
|
||||
if ($attribute1[1] > 0) { $page .= " +" . $attribute1[1] . "<br>"; } else { $page .= $attribute1[1] . "<br>"; }
|
||||
|
||||
if ($droprow["attribute2"] != "X") {
|
||||
$attribute2 = explode(",",$droprow["attribute2"]);
|
||||
$page .= $attributearray[$attribute2[0]];
|
||||
if ($attribute2[1] > 0) { $page .= " +" . $attribute2[1] . "<br>"; } else { $page .= $attribute2[1] . "<br>"; }
|
||||
}
|
||||
|
||||
$page .= "<br>Select an inventory slot from the list below to equip this item. If the inventory slot is already full, the old item will be discarded.";
|
||||
$page .= "<form action=\"/drop\" method=\"post\"><select name=\"slot\"><option value=\"0\">Choose One</option><option value=\"1\">Slot 1: ".user()->slot1name."</option><option value=\"2\">Slot 2: ".user()->slot2name."</option><option value=\"3\">Slot 3: ".user()->slot3name."</option></select> <input type=\"submit\" name=\"submit\" value=\"Submit\" /></form>";
|
||||
$page .= "You may also choose to just continue <a href=\"/\" hx-get=\"/\" hx-target=\"#middle\">exploring</a> and give up this item.";
|
||||
|
||||
return $page;
|
||||
}
|
||||
|
||||
|
||||
function dead()
|
||||
{
|
||||
return <<<HTML
|
||||
<b>You have died.</b><br><br>
|
||||
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.<br><br>
|
||||
You may now continue back to <a href="/" hx-get="/" hx-target="#middle">town</a>, and we hope you fair better next time.
|
||||
HTML;
|
||||
}
|
||||
|
||||
function handleMonsterTurn(&$userrow, $monsterrow)
|
||||
{
|
||||
$pagearray = "";
|
||||
if (user()->currentmonstersleep != 0) {
|
||||
$chancetowake = rand(1,15);
|
||||
if ($chancetowake > user()->currentmonstersleep) {
|
||||
user()->currentmonstersleep = 0;
|
||||
$pagearray .= "The monster has woken up.<br>";
|
||||
} else {
|
||||
$pagearray .= "The monster is still asleep.<br>";
|
||||
}
|
||||
}
|
||||
|
||||
if (user()->currentmonstersleep == 0) {
|
||||
$tohit = (int)ceil(mt_rand((int)($monsterrow["maxdam"] * 0.5), (int)$monsterrow["maxdam"]));
|
||||
$toblock = (int)ceil(mt_rand((int)(user()->defensepower * 0.75), (int)user()->defensepower) / 4);
|
||||
$tododge = rand(1, 150);
|
||||
|
||||
if ($tododge <= sqrt(user()->dexterity)) {
|
||||
$tohit = 0;
|
||||
$pagearray .= "You dodge the monster's attack. No damage has been scored.<br>";
|
||||
$persondamage = 0;
|
||||
} else {
|
||||
$persondamage = max(1, $tohit - $toblock);
|
||||
if (user()->currentuberdefense != 0) {
|
||||
$persondamage -= (int)ceil($persondamage * (user()->currentuberdefense/100));
|
||||
}
|
||||
$persondamage = max(1, $persondamage);
|
||||
}
|
||||
|
||||
$pagearray .= "The monster attacks you for $persondamage damage.<br><br>";
|
||||
user()->currenthp -= $persondamage;
|
||||
|
||||
if (user()->currenthp <= 0) {
|
||||
$newgold = (int)ceil(user()->gold/2);
|
||||
$newhp = (int)ceil(user()->maxhp/4);
|
||||
db()->query("UPDATE users SET currenthp=?, currentaction='In Town', currentmonster=0, currentmonsterhp=0, currentmonstersleep=0, currentmonsterimmune=0, currentfight=0, latitude=0, longitude=0, gold=? WHERE id=?;", [
|
||||
$newhp, $newgold, $userrow['id']
|
||||
]);
|
||||
dead();
|
||||
}
|
||||
}
|
||||
return $pagearray;
|
||||
}
|
||||
|
||||
function handleSpellCast(&$userrow, $newspellrow)
|
||||
{
|
||||
$pagearray = "";
|
||||
switch ($newspellrow["type"]) {
|
||||
case 1: // Heal spell
|
||||
$newhp = min(user()->currenthp + $newspellrow["attribute"], user()->maxhp);
|
||||
user()->currenthp = $newhp;
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, and gained {$newspellrow["attribute"]} Hit Points.<br><br>";
|
||||
break;
|
||||
case 2: // Hurt spell
|
||||
if (user()->currentmonsterimmune == 0) {
|
||||
$monsterdamage = mt_rand((int)(($newspellrow["attribute"]/6)*5), $newspellrow["attribute"]);
|
||||
user()->currentmonsterhp -= $monsterdamage;
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell for $monsterdamage damage.<br><br>";
|
||||
} else {
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.<br><br>";
|
||||
}
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
break;
|
||||
case 3: // Sleep spell
|
||||
if (user()->currentmonsterimmune != 2) {
|
||||
user()->currentmonstersleep = $newspellrow["attribute"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell. The monster is asleep.<br><br>";
|
||||
} else {
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.<br><br>";
|
||||
}
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
break;
|
||||
case 4: // +Damage spell
|
||||
user()->currentuberdamage = $newspellrow["attribute"];
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, and will gain {$newspellrow["attribute"]}% damage until the end of this fight.<br><br>";
|
||||
break;
|
||||
case 5: // +Defense spell
|
||||
user()->currentuberdefense = $newspellrow["attribute"];
|
||||
user()->currentmp -= $newspellrow["mp"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, and will gain {$newspellrow["attribute"]}% defense until the end of this fight.<br><br>";
|
||||
break;
|
||||
}
|
||||
return $pagearray;
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
<?php
|
||||
|
||||
// forum.php :: Internal forums script for the game.
|
||||
|
||||
namespace Forum;
|
||||
|
||||
use Router;
|
||||
|
||||
function register_routes(Router $r): Router
|
||||
{
|
||||
$r->get('/forum/thread/:x/:x', 'Forum\showthread');
|
||||
$r->form('/forum/new', 'Forum\newthread');
|
||||
$r->post('/forum/reply', 'Forum\reply');
|
||||
$r->get('/forum/list/:x', 'Forum\donothing');
|
||||
$r->get('/forum', 'Forum\donothing');
|
||||
return $r;
|
||||
}
|
||||
|
||||
function donothing($start = 0)
|
||||
{
|
||||
$query = db()->query('SELECT * FROM forum WHERE parent=0 ORDER BY newpostdate DESC LIMIT 20 OFFSET ?;', [20 * $start]);
|
||||
$page = <<<HTML
|
||||
<table width="100%">
|
||||
<tr>
|
||||
<td style="padding: 1px; background-color: black;">
|
||||
<table width="100%" style="margins: 0px;" cellspacing="1" cellpadding="3">
|
||||
<tr>
|
||||
<th colspan="3" style="background-color: #ddd;">
|
||||
<center><a href="/forum/new" hx-get="/forum/new" hx-target="#middle">New Thread</a></center>
|
||||
</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<th width="50%" style="background-color:#dddddd;">Thread</th>
|
||||
<th width="10%" style="background-color:#dddddd;">Replies</th>
|
||||
<th style="background-color:#dddddd;">Last Post</th>
|
||||
</tr>
|
||||
HTML;
|
||||
|
||||
$hasRows = false;
|
||||
|
||||
while ($row = $query->fetchArray(SQLITE3_ASSOC)) {
|
||||
$hasRows = true;
|
||||
$page .= <<<HTML
|
||||
<tr>
|
||||
<td style="background-color: white;"><a href="/forum/thread/{$row['id']}/0" hx-get="/forum/thread/{$row['id']}/0" hx-target="#middle">{$row['title']}</a></td>
|
||||
<td style="background-color: white;">{$row['replies']}</td>
|
||||
<td style="background-color: white;">{$row['newpostdate']}</td>
|
||||
</tr>
|
||||
HTML;
|
||||
}
|
||||
|
||||
if (!$hasRows) {
|
||||
$page .= '<tr><td style="background-color:#ffffff;" colspan="3"><b>No threads in forum.</b></td></tr>';
|
||||
}
|
||||
|
||||
$page .= '</table></td></tr></table>';
|
||||
|
||||
page_title('Forum');
|
||||
return $page;
|
||||
}
|
||||
|
||||
function showthread($id, $start)
|
||||
{
|
||||
$posts = db()->query('SELECT * FROM forum WHERE id=? OR parent=? ORDER BY id LIMIT 15 OFFSET ?;', [$id, $id, $start * 15]);
|
||||
$title = db()->query('SELECT title FROM forum WHERE id=? LIMIT 1;', [$id])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$page = "<table width=\"100%\"><tr><td style=\"padding:1px; background-color:black;\"><table width=\"100%\" style=\"margins:0px;\" cellspacing=\"1\" cellpadding=\"3\"><tr><td colspan=\"2\" style=\"background-color:#dddddd;\"><b><a href=\"/forum\" hx-get=\"/forum\" hx-target=\"#middle\">Forum</a> :: ".$title['title']."</b></td></tr>\n";
|
||||
while ($row = $posts->fetchArray(SQLITE3_ASSOC)) {
|
||||
$page .= "<tr><td width=\"25%\" style=\"background-color:#ffffff; vertical-align:top;\"><span class=\"small\"><b>".$row["author"]."</b><br><br>".pretty_date($row["postdate"])."</td><td style=\"background-color:#ffffff; vertical-align:top;\">".nl2br($row["content"])."</td></tr>\n";
|
||||
}
|
||||
$page .= "</table></td></tr></table><br>";
|
||||
$page .= "<table width=\"100%\"><tr><td><b>Reply To This Thread:</b><br><form action=\"/forum/reply\" method=\"post\" hx-post=\"/forum/reply\" hx-target=\"#middle\"><input type=\"hidden\" name=\"parent\" value=\"$id\" /><input type=\"hidden\" name=\"title\" value=\"Re: ".$title["title"]."\" /><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
|
||||
|
||||
page_title('Forum: '.$title['title']);
|
||||
return $page;
|
||||
}
|
||||
|
||||
function reply()
|
||||
{
|
||||
$form = validate($_POST, [
|
||||
'title' => [],
|
||||
'content' => []
|
||||
]);
|
||||
|
||||
if (!$form['valid']) exit(ul_from_validate_errors($form['errors']));
|
||||
|
||||
$form = $form['data'];
|
||||
|
||||
db()->query('INSERT INTO forum (author, title, content, parent) VALUES (?, ?, ?, ?);', [
|
||||
user()->username, $form['title'], $form['content'], $form['parent']
|
||||
]);
|
||||
db()->query('UPDATE forum SET newpostdate=CURRENT_TIMESTAMP, replies=replies + 1 WHERE id=?;', [$form['parent']]);
|
||||
return showthread($form['parent'], 0);
|
||||
}
|
||||
|
||||
function newthread()
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$form = validate($_POST, [
|
||||
'title' => ['length:2-30'],
|
||||
'content' => []
|
||||
]);
|
||||
|
||||
if (!$form['valid']) exit(ul_from_validate_errors($form['errors']));
|
||||
|
||||
$form = $form['data'];
|
||||
db()->query('INSERT INTO forum (author, title, content) VALUES (?, ?, ?);', [
|
||||
user()->username, $form['title'], $form['content']
|
||||
]);
|
||||
redirect('/forum/thread/'.db()->lastInsertRowID().'/0');
|
||||
}
|
||||
|
||||
page_title('Form: New Thread');
|
||||
return "<table width=\"100%\"><tr><td><b>Make A New Post:</b><br><br/ ><form action=\"/forum/new\" method=\"post\" hx-post=\"/forum/new\" hx-target=\"#middle\">Title:<br><input type=\"text\" name=\"title\" size=\"50\" maxlength=\"50\" /><br><br>Message:<br><textarea name=\"content\" rows=\"7\" cols=\"40\"></textarea><br><br><input type=\"submit\" name=\"submit\" value=\"Submit\" /> <input type=\"reset\" name=\"reset\" value=\"Reset\" /></form></td></tr></table>";
|
||||
}
|
|
@ -1,34 +0,0 @@
|
|||
<?php
|
||||
|
||||
// heal.php :: Handles stuff from the Quick Spells menu. (Healing spells only... other spells are handled in fight.php.)
|
||||
|
||||
function healspells(int $id): string
|
||||
{
|
||||
$user_spells = user()->spells();
|
||||
$spell = get_spell($id);
|
||||
$has_spell = false;
|
||||
foreach ($user_spells as $us) if ($us['id'] === $id) $has_spell = true;
|
||||
|
||||
if ($has_spell !== true) {
|
||||
$page = 'You have not yet learned this spell. Please go back and try again.';
|
||||
} elseif ($spell['type'] !== 1) {
|
||||
$page = 'This is not a healing spell. Please go back and try again.';
|
||||
} elseif (user()->currentmp < $spell['mp']) {
|
||||
$page = 'You do not have enough Magic Points to cast this spell. Please go back and try again.';
|
||||
} elseif (user()->currentaction === 'Fighting') {
|
||||
$page = 'You cannot use the Quick Spells list during a fight. Please go back and select the Healing Spell you wish to use from the Spells box on the main fighting screen to continue.';
|
||||
} elseif (user()->currenthp == user()->maxhp) {
|
||||
$page = 'Your HP is already full. You don\'t need to use a Healing spell now.';
|
||||
} else {
|
||||
$restored = user()->restore_hp($spell['attribute']);
|
||||
user()->currentmp -= $spell['mp'];
|
||||
user()->save();
|
||||
|
||||
$page = <<<HTML
|
||||
You have cast the {$spell['name']} spell, and gained {$restored} HP. You can now continue <a href="/" hx-get="/" hx-target="#middle">exploring</a>.
|
||||
HTML;
|
||||
}
|
||||
|
||||
page_title('Casting '.$spell['name']);
|
||||
return $page;
|
||||
}
|
|
@ -1,494 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Help;
|
||||
|
||||
use Router;
|
||||
|
||||
function register_routes(Router $r): Router
|
||||
{
|
||||
$r->get('/help', 'Help\main');
|
||||
$r->get('/help/items', 'Help\items');
|
||||
$r->get('/help/spells', 'Help\spells');
|
||||
$r->get('/help/monsters', 'Help\monsters');
|
||||
$r->get('/help/levels', 'Help\levels');
|
||||
return $r;
|
||||
}
|
||||
|
||||
function main()
|
||||
{
|
||||
$page = <<<HTML
|
||||
<h3>Table of Contents</h3>
|
||||
<ul>
|
||||
<li><a href="#intro">Introduction</a></li>
|
||||
<li><a href="#classes">Character Classes</a></li>
|
||||
<li><a href="#intown">Playing The Game: In Town</a></li>
|
||||
<li><a href="#exploring">Playing The Game: Exploring & Fighting</a></li>
|
||||
<li><a href="#status">Playing The Game: Status Panels</a></li>
|
||||
<li><a href="#items">Spoilers: Items & Drops</a></li>
|
||||
<li><a href="#monsters">Spoilers: Monsters</a></li>
|
||||
<li><a href="#spells">Spoilers: Spells</a></li>
|
||||
<li><a href="#levels">Spoilers: Levels</a></li>
|
||||
<li><a href="#credits">Credits</a></li>
|
||||
</ul>
|
||||
|
||||
<hr>
|
||||
|
||||
<h3><a name="intro"></a>Introduction</h3>
|
||||
Firstly, I'd like to say thank you for playing my game. The <i>Dragon Knight</i> game engine is the result of several months of
|
||||
planning, coding and testing. The original idea was to create a web-based tribute to the NES game, <i>Dragon
|
||||
Warrior</i>. In its current iteration, only the underlying fighting system really resembles that game, as almost
|
||||
everything else in DK has been made bigger and better. But you should still recognize bits and pieces as stemming
|
||||
from <i>Dragon Warrior</i> and other RPGs of old.<br><br>
|
||||
This is the first game I've ever written, and it has definitely been a positive experience. It got difficult at
|
||||
times, admittedly, but it was still a lot of fun to write, and even more fun to play. And I hope to use this
|
||||
experience so that if I ever want to create another game it will be even better than this one.<br><br>
|
||||
If you are a site administrator, and would like to install a copy of DK on your own server, you may visit the
|
||||
<a href="http://dragon.se7enet.com/dev.php" target="_new">development site</a> for <i>Dragon Knight</i>. This page
|
||||
includes the downloadable game souce code, as well as some other resources that developers and administrators may
|
||||
find valuable.<br><br>
|
||||
Once again, thanks for playing!<br><br>
|
||||
<i>Jamin Seven</i><br>
|
||||
<i>Dragon Knight creator</i><br>
|
||||
<a href="http://www.se7enet.com" target="_new">My Homepage</a><br>
|
||||
<a href="http://dragon.se7enet.com/dev.php" target="_new">Dragon Knight Homepage</a><br ><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="classes"></a>Character Classes</h3>
|
||||
There are three character classes in the game. The main differences between the classes are what spells you get
|
||||
access to, the speed with which you level up, and the amount of HP/MP/strength/dexterity you gain per level. Below
|
||||
is a basic outline of each of the character classes. For more detailed information about the characters, please
|
||||
view the Levels table at the bottom of this page. Also, note that the outline below refers to the stock class setup
|
||||
for the game. If your administrator has used his/her own class setup, this information may not be accurate.<br><br>
|
||||
<b>{env('class_1_name')}</b>
|
||||
<ul>
|
||||
<li>Fast level-ups</li>
|
||||
<li>High hit points</li>
|
||||
<li>High magic points</li>
|
||||
<li>Low strength</li>
|
||||
<li>Low dexterity</li>
|
||||
<li>5 heal spells</li>
|
||||
<li>5 hurt spells</li>
|
||||
<li>3 sleep spells</li>
|
||||
<li>3 +defense spells</li>
|
||||
<li>0 +attack spells</li>
|
||||
</ul>
|
||||
<b>{env('class_2_name')}</b>
|
||||
<ul>
|
||||
<li>Medium level-ups</li>
|
||||
<li>Medium hit points</li>
|
||||
<li>Low magic points</li>
|
||||
<li>High strength</li>
|
||||
<li>Low dexterity</li>
|
||||
<li>3 heal spells</li>
|
||||
<li>3 hurt spells</li>
|
||||
<li>2 sleep spells</li>
|
||||
<li>3 +defense spells</li>
|
||||
<li>3 +attack spells</li>
|
||||
</ul>
|
||||
<b>{env('class_3_name')}</b>
|
||||
<ul>
|
||||
<li>Slow level-ups</li>
|
||||
<li>Medium hit points</li>
|
||||
<li>Medium magic points</li>
|
||||
<li>Low strength</li>
|
||||
<li>High dexterity</li>
|
||||
<li>4 heal spells</li>
|
||||
<li>4 hurt spells</li>
|
||||
<li>3 sleep spells</li>
|
||||
<li>2 +defense spells</li>
|
||||
<li>2 +attack spells</li>
|
||||
</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>
|
||||
To heal yourself, click the "Rest at the Inn" link at the top of the town screen. Each town's Inn has a different price - some towns
|
||||
are cheap, others are expensive. No matter what town you're in, the Inns always serve the same function: they restore your current
|
||||
hit points, magic points, and travel points to their maximum amounts. Out in the field, you are free to use healing spells to restore
|
||||
your hit points, but when you run low on magic points, the only way to restore them is at an Inn.<br><br>
|
||||
Buying weapons and armor is accomplished through the appropriately-named "Buy Weapons/Armor" link. Not every item is available in
|
||||
every town, so in order to get the most powerful items, you'll need to explore some of the outer towns. Once you've clicked the link,
|
||||
you are presented with a list of items available in this town's store. To the left of each item is an icon that represents its type:
|
||||
weapon, armor or shield. The amount of attack/defense power, as well as the item's price, are displayed to the right of the item name.
|
||||
You'll notice that some items have a red asterisk (<span class="highlight">*</span>) next to their names. These are items that come
|
||||
with special attributes that modify other parts of your character profile. See the Items & Drops table at the bottom of this page for
|
||||
more information about special items.<br><br>
|
||||
Maps are the third function in towns. Buying a map to a town places the town in your Travel To box in the left status panel. Once
|
||||
you've purchased a town's map, you can click its name from your Travel To box and you will jump to that town. Travelling this way
|
||||
costs travel points, though, and you'll only be able to visit towns if you have enough travel points.<br><br>
|
||||
The final function in towns is displaying game information and statistics. This includes the latest news post made by the game
|
||||
administrator, a list of players who have been online recently, and the Babble Box.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="exploring"></a>Playing The Game: Exploring & Fighting</h3>
|
||||
Once you're done in town, you are free to start exploring the world. Use the compass buttons on the left status panel to move around.
|
||||
The game world is basically a big square, divided into four quadrants. Each quadrant is {{gamesize}} spaces
|
||||
square. The first town is usually located at (0N,0E). Click the North button from the first town, and now you'll be at (1N,0E).
|
||||
Likewise, if you now click the West button, you'll be at (1N,1W). Monster levels increase with every 5 spaces you move outward
|
||||
from (0N,0E).<br><br>
|
||||
While you're exploring, you will occasionally run into monsters. As in pretty much any other RPG game, you and the monster take turns
|
||||
hitting each other in an attempt to reduce each other's hit points to zero. Once you run into a monster, the Exploring screen changes
|
||||
to the Fighting screen.<br><br>
|
||||
When a fight begins, you'll see the monster's name and hit points, and the game will ask you for your first command. You then get to
|
||||
pick whether you want to fight, use a spell, or run away. Note, though, that sometimes the monster has the chance to hit you
|
||||
first.<br><br>
|
||||
The Fight button is pretty straightforward: you attack the monster, and the amount of damage dealt is based on your attack power and
|
||||
the monster's armor. On top of that, there are two other things that can happen: an Excellent Hit, which doubles your total attack
|
||||
damage; and a monster dodge, which results in you doing no damage to the monster.<br><br>
|
||||
The Spell button allows you to pick an available spell and cast it. See the Spells list at the bottom of this page for more information
|
||||
about spells.<br><br>
|
||||
Finally, there is the Run button, which lets you run away from a fight if the monster is too powerful. Be warned, though: it is
|
||||
possible for the monster to block you from running and attack you. So if your hit points are low, you may fare better by staying
|
||||
around monsters that you know can't do much damage to you.<br><br>
|
||||
Once you've had your turn, the monster also gets his turn. It is also possible for you to dodge the monster's attack and take no
|
||||
damage.<br><br>
|
||||
The end result of a fight is either you or the monster being knocked down to zero hit points. If you win, the monster dies and will
|
||||
give you a certain amount of experience and gold. There is also a chance that the monster will drop an item, which you can put into
|
||||
one of the three inventory slots to give you extra points in your character profile. If you lose and die, half of your gold is taken
|
||||
away - however, you are given back a few hit points to help you make it back to town (for example, if you don't have enough gold to
|
||||
pay for an Inn, and need to kill a couple low-level monsters to get the money).<br><br>
|
||||
When the fight is over, you can continue exploring until you find another monster to beat into submission.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="status"></a>Playing The Game: Status Panels</h3>
|
||||
There are two status panels on the game screen: left and right.<br><br>
|
||||
The left panel inclues your current location and play status (In Town, Exploring, Fighting), compass buttons for movement, and the
|
||||
Travel To list for jumping between towns. At the bottom of the left panel is also a list of game functions.<br><br>
|
||||
The right panel displays some character statistics, your inventory, and quick spells.<br><br>
|
||||
The Character section shows the most important character statistics. It also displays the status bars for your current hit points,
|
||||
magic points and travel points. These status bars are colored either green, yellow or red depending on your current amount of each
|
||||
stat. There is also a link to pop up your list of extended statistics, which shows more detailed character information.<br><br>
|
||||
The Fast Spells section lists any Heal spells you've learned. You may use these links any time you are in town or exploring to cast
|
||||
the heal spell. These may not be used during fights, however - you have to use the Spells box on the fight screen for that.
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="items"></a>Spoilers: Items & Drops</h3>
|
||||
<a href="/help/items">Click here</a> for the Items & Drops spoiler page.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="monsters"></a>Spoilers: Monsters</h3>
|
||||
<a href="/help/monsters">Click here</a> for the Monsters spoiler page.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="spells"></a>Spoilers: Spells</h3>
|
||||
<a href="/help/spells">Click here</a> for the Spells spoiler page.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="levels"></a>Spoilers: Levels</h3>
|
||||
<a href="/help/levels">Click here</a> for the Levels spoiler page.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<h3><a name="credits"></a>Credits</h3>
|
||||
<ul>
|
||||
<li><b>All program code and stock graphics for the game were created by Jamin Seven</b>.<br><br></li>
|
||||
<li>Major props go to a few people on the PHP manual site, for help with various chunks of code. The specific people are listed in the source code.<br><br></li>
|
||||
<li>Super monkey love goes to Enix and the developers of <i>Dragon Warrior</i>. If it weren't for you guys, my game never would have been made.<br><br></li>
|
||||
<li>Mega props go to Dalez from GameFAQs for his DW3 experience chart, which was where I got my experience levels from.<br><br></li>
|
||||
<li>
|
||||
Mad crazy ninja love goes to the following people for help and support throughout the development process:<br><br>
|
||||
<b>Ideas:</b> (whether they got used or not)
|
||||
<ul>
|
||||
<li>kushet</li>
|
||||
<li>lghtning</li>
|
||||
<li>Ebolamonkey3000</li>
|
||||
<li>Crimson Scythe</li>
|
||||
<li>SilDeath</li>
|
||||
</ul>
|
||||
<b>Beta Testing:</b> (forums name if applicable, character name otherwise)
|
||||
<ul>
|
||||
<li>Ebolamonkey3000</li>
|
||||
<li>lisi</li>
|
||||
<li>Junglist</li>
|
||||
<li>Crimson Scythe</li>
|
||||
<li>Sk8erpunk69</li>
|
||||
<li>lghtning</li>
|
||||
<li>kushet</li>
|
||||
<li>SilDeath</li>
|
||||
<li>lowrider4life</li>
|
||||
<li>dubiin</li>
|
||||
<li>Sam Wise The Great</li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
Apologies and lots of happy naked love to anyone I forgot. <br><br>
|
||||
And of course, thanks to <b>you</b> for playing my game! <br><br>
|
||||
<a href="/ninja">NINJA!</a> <br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
|
||||
<br><br><hr><br>
|
||||
|
||||
Please visit the following sites for more information:<br>
|
||||
<a href="http://www.se7enet.com" target="_new">Se7enet</a> (Jamin's homepage)<br>
|
||||
<a href="http://dragon.se7enet.com/dev.php" target="_new">Dragon Knight</a> (official DK homepage)<br>
|
||||
<a href="http://se7enet.com/forums" target="_new">Forums</a> (official DK forums)<br><br>
|
||||
All original coding and graphics for the <i>Dragon Knight</i> game engine are © 2003-2005 by Jamin Seven.<br><br>
|
||||
[ <a href="#top">Top</a> ]
|
||||
HTML;
|
||||
|
||||
return display_help($page);
|
||||
}
|
||||
|
||||
function items()
|
||||
{
|
||||
$page = <<<HTML
|
||||
<table width="60%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="5" bgcolor="#ffffff"><center><b>Items</b></center></td></tr>
|
||||
<tr><td><b>Type</b></td><td><b>Name</b></td><td><b>Cost</b></td><td><b>Attribute</b></td><td><b>Special</b></td></tr>
|
||||
HTML;
|
||||
|
||||
$items = db()->query('SELECT * FROM items ORDER BY id;');
|
||||
$item_types = [1 => ['weapon', 'Attack'], 2 => ['armor', 'Defense'], 3 => ['shield', 'Defense']];
|
||||
|
||||
while ($item = $items->fetchArray(SQLITE3_ASSOC)) {
|
||||
$image = $item_types[$item['type']][0];
|
||||
$power = $item_types[$item['type']][1];
|
||||
|
||||
if ($item['special'] !== 'X') {
|
||||
$special = explode(',', $item['special']);
|
||||
$attr = special_to_string($special[0]);
|
||||
$stat = (($special[1] > 0) ? '+' : '') . $special[1];
|
||||
$bigspecial = "$attr $stat";
|
||||
} else {
|
||||
$bigspecial = '<span class="light">None</span>';
|
||||
}
|
||||
|
||||
$page .= "<tr><td width=\"5%\"><img src=\"/img/icon_$image.gif\" alt=\"$image\"></td><td width=\"30%\">".$item["name"]."</td><td width=\"20%\">".$item["buycost"]." Gold</td><td width=\"20%\">".$item["attribute"]." $power Power</td><td width=\"25%\">$bigspecial</td></tr>\n";
|
||||
}
|
||||
|
||||
$page .= <<<HTML
|
||||
</table>
|
||||
|
||||
<br><br>
|
||||
|
||||
<table width="60%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="4" bgcolor="#ffffff"><center><b>Drops</b></center></td></tr>
|
||||
<tr><td><b>Name</b></td><td><b>Monster Level</b></td><td><b>Attribute 1</b></td><td><b>Attribute 2</b></td></tr>
|
||||
HTML;
|
||||
|
||||
$drops = db()->query('SELECT * FROM drops ORDER BY id;');
|
||||
|
||||
while ($drop = $drops->fetchArray(SQLITE3_ASSOC)) {
|
||||
if ($drop["attribute1"] !== "X") {
|
||||
$special = explode(',', $drop['attribute1']);
|
||||
$attr = special_to_string($special[0]);
|
||||
$stat = (($special[1] > 0) ? '+' : '') . $special[1];
|
||||
$bigspecial1 = "$attr $stat";
|
||||
} else {
|
||||
$bigspecial1 = '<span class="light">None</span>';
|
||||
}
|
||||
|
||||
if ($drop["attribute2"] !== "X") {
|
||||
$special = explode(',', $drop['attribute2']);
|
||||
$attr = special_to_string($special[0]);
|
||||
$stat = (($special[1] > 0) ? '+' : '') . $special[1];
|
||||
$bigspecial2 = "$attr $stat";
|
||||
} else {
|
||||
$bigspecial2 = '<span class="light">None</span>';
|
||||
}
|
||||
|
||||
$page .= "<tr><td width=\"25%\">".$drop["name"]."</td><td width=\"15%\">".$drop["mlevel"]."</td><td width=\"30%\">$bigspecial1</td><td width=\"30%\">$bigspecial2</td></tr>\n";
|
||||
}
|
||||
$page .= '</table>';
|
||||
|
||||
return display_help($page);
|
||||
}
|
||||
|
||||
|
||||
function spells()
|
||||
{
|
||||
$page = <<<HTML
|
||||
<table width="50%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b>Spells</b></center></td></tr>
|
||||
<tr><td><b>Name</b></td><td><b>Cost</b></td><td><b>Type</b></td><td><b>Attribute</b></td></tr>
|
||||
HTML;
|
||||
|
||||
$spells = db()->query('SELECT * FROM spells ORDER BY id;');
|
||||
$spell_types = ['None', 'Heal', 'Hurt', 'Sleep', '+Damage (%)', '+Defense (%)'];
|
||||
while ($spell = $spells->fetchArray(SQLITE3_ASSOC)) {
|
||||
$page .= <<<HTML
|
||||
<tr><td width="25%">{$spell["name"]}</td>
|
||||
<td width="25%">{$spell["mp"]}</td>
|
||||
<td width="25%">{$spell_types[$spell['type']]}</td>
|
||||
<td width="25%">{$spell["attribute"]}</td></tr>
|
||||
HTML;
|
||||
}
|
||||
|
||||
$page .= <<<HTML
|
||||
</table>
|
||||
<ul>
|
||||
<li><b>Heal</b> spells always give you the maximum amount possible, until your current HP is full.</li>
|
||||
<li><b>Hurt</b> spells deal X damage (not always the maximum) to the monster, regardless of the monster's armor.</li>
|
||||
<li><b>Sleep</b> spells put the monster to sleep. The monster has an X in 15 chance of remaining asleep each turn.</li>
|
||||
<li><b>+Damage</b> spells increase your total attack damage by X percent until the end of the fight.</li>
|
||||
<li><b>+Defense</b> spells reduce the total damage you take from the monster by X percent until the end of each fight.</li>
|
||||
</ul>
|
||||
HTML;
|
||||
|
||||
return display_help($page);
|
||||
}
|
||||
|
||||
function monsters()
|
||||
{
|
||||
$page = <<<HTML
|
||||
<table width="75%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b>Monsters</b></center></td></tr>
|
||||
<tr><td><b>Name</b></td><td><b>Max HP</b></td><td><b>Max Damage</b></td><td><b>Armor</b></td><td><b>Level</b></td><td><b>Max Exp.</b></td><td><b>Max Gold</b></td><td><b>Immunity</b></td></tr>
|
||||
HTML;
|
||||
|
||||
$monsters = db()->query('SELECT * FROM monsters ORDER BY id;');
|
||||
$immunities = ['<span class="light">None</span>', 'Hurt', 'Hurt & Sleep'];
|
||||
|
||||
while ($m = $monsters->fetchArray(SQLITE3_ASSOC)) {
|
||||
$immune = $immunities[$m['immune']] ?? 'Unknown';
|
||||
$page .= "<tr><td width=\"30%\">".$m["name"]."</td><td width=\"10%\">".$m["maxhp"]."</td><td width=\"10%\">".$m["maxdam"]."</td><td width=\"10%\">".$m["armor"]."</td><td width=\"10%\">".$m["level"]."</td><td width=\"10%\">".$m["maxexp"]."</td><td width=\"10%\">".$m["maxgold"]."</td><td width=\"20%\">$immune</td></tr>\n";
|
||||
}
|
||||
|
||||
return display_help($page.'</table>');
|
||||
}
|
||||
|
||||
function levels()
|
||||
{
|
||||
$rows = [];
|
||||
|
||||
$levels = db()->query('SELECT * FROM levels ORDER BY id;');
|
||||
while ($level = $levels->fetchArray(SQLITE3_ASSOC)) {
|
||||
$class_data = [1 => [], 2 => [], 3 => []];
|
||||
|
||||
foreach ($level as $column => $value) {
|
||||
if ($column === 'id') continue;
|
||||
|
||||
$parts = explode('_', $column);
|
||||
$class_number = (int) $parts[0];
|
||||
$attribute = $parts[1];
|
||||
|
||||
if (in_array($class_number, [1, 2, 3])) {
|
||||
$class_data[$class_number][$level['id']][$attribute] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$rows[$level['id']] = $class_data;
|
||||
}
|
||||
|
||||
$spells = [];
|
||||
$spells_query = db()->query('SELECT * FROM spells ORDER BY id;');
|
||||
while ($spell = $spells_query->fetchArray(SQLITE3_ASSOC)) {
|
||||
$spells[$spell['id']] = $spell;
|
||||
}
|
||||
|
||||
$page = <<<HTML
|
||||
<table width="50%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b>{{class1name}} Levels</b></center></td></tr>
|
||||
<tr><td><b>Level</b><td><b>Exp.</b></td><td><b>HP</b></td><td><b>MP</b></td><td><b>TP</b></td><td><b>Strength</b></td><td><b>Dexterity</b></td><td><b>Spell</b></td></tr>
|
||||
HTML;
|
||||
foreach ($rows as $level => $class_data) {
|
||||
$level_data = $class_data[1][$level];
|
||||
|
||||
$spell_name = '';
|
||||
if (!empty($level_data['spells'])) $spell_name = $spells[$level_data['spells']]['name'];
|
||||
|
||||
$page .= '<tr>';
|
||||
$page .= '<td>' . $level . '</td>';
|
||||
$page .= '<td>' . ($level_data['exp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['hp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['mp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['tp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['strength'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['dexterity'] ?? '') . '</td>';
|
||||
$page .= '<td>' . (!empty($spell_name) ? $spell_name : '<span class="light">None</span>') . '</td>';
|
||||
$page .= '</tr>';
|
||||
}
|
||||
|
||||
$page .= <<<HTML
|
||||
</table>
|
||||
|
||||
<br><br>
|
||||
|
||||
<table width="50%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b>{{class2name}} Levels</b></center></td></tr>
|
||||
<tr><td><b>Level</b><td><b>Exp.</b></td><td><b>HP</b></td><td><b>MP</b></td><td><b>TP</b></td><td><b>Strength</b></td><td><b>Dexterity</b></td><td><b>Spell</b></td></tr>
|
||||
HTML;
|
||||
|
||||
foreach ($rows as $level => $class_data) {
|
||||
$level_data = $class_data[2][$level];
|
||||
|
||||
$spell_name = '';
|
||||
if (!empty($level_data['spells'])) $spell_name = $spells[$level_data['spells']]['name'];
|
||||
|
||||
$page .= '<tr>';
|
||||
$page .= '<td>' . $level . '</td>';
|
||||
$page .= '<td>' . ($level_data['exp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['hp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['mp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['tp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['strength'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['dexterity'] ?? '') . '</td>';
|
||||
$page .= '<td>' . (!empty($spell_name) ? $spell_name : '<span class="light">None</span>') . '</td>';
|
||||
$page .= '</tr>';
|
||||
}
|
||||
|
||||
$page .= <<<HTML
|
||||
</table>
|
||||
|
||||
<br><br>
|
||||
|
||||
<table width="50%" style="border: solid 1px black" cellspacing="0" cellpadding="0">
|
||||
<tr><td colspan="8" bgcolor="#ffffff"><center><b>{{class3name}} Levels</b></center></td></tr>
|
||||
<tr><td><b>Level</b><td><b>Exp.</b></td><td><b>HP</b></td><td><b>MP</b></td><td><b>TP</b></td><td><b>Strength</b></td><td><b>Dexterity</b></td><td><b>Spell</b></td></tr>
|
||||
HTML;
|
||||
|
||||
foreach ($rows as $level => $class_data) {
|
||||
$level_data = $class_data[3][$level];
|
||||
|
||||
$spell_name = '';
|
||||
if (!empty($level_data['spells'])) $spell_name = $spells[$level_data['spells']]['name'];
|
||||
|
||||
$page .= '<tr>';
|
||||
$page .= '<td>' . $level . '</td>';
|
||||
$page .= '<td>' . ($level_data['exp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['hp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['mp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['tp'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['strength'] ?? '') . '</td>';
|
||||
$page .= '<td>' . ($level_data['dexterity'] ?? '') . '</td>';
|
||||
$page .= '<td>' . (!empty($spell_name) ? $spell_name : '<span class="light">None</span>') . '</td>';
|
||||
$page .= '</tr>';
|
||||
}
|
||||
|
||||
$page .= <<<HTML
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
Experience points listed are total values up until that point. All other values are just the new amount that you gain for each level.
|
||||
HTML;
|
||||
|
||||
return display_help($page);
|
||||
}
|
||||
|
||||
function display_help(string $content)
|
||||
{
|
||||
return render('layouts/help', [
|
||||
'content' => $content,
|
||||
'version' => VERSION,
|
||||
'build' => BUILD
|
||||
]);
|
||||
}
|
|
@ -1,401 +0,0 @@
|
|||
<?php
|
||||
|
||||
// towns.php :: Handles all actions you can do in town.
|
||||
|
||||
namespace Towns;
|
||||
|
||||
use Router;
|
||||
|
||||
function register_routes(Router $r): Router
|
||||
{
|
||||
$r->form('/inn', 'Towns\inn');
|
||||
$r->get('/shop', 'Towns\shop');
|
||||
$r->form('/buy/:id', 'Towns\buy');
|
||||
// $r->get('/sell', 'Towns\sell');
|
||||
$r->get('/maps', 'Towns\maps');
|
||||
$r->form('/maps/:id', 'Towns\buy_map');
|
||||
$r->get('/gotown/:id', 'Towns\travelto');
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Spit out the main town page.
|
||||
*/
|
||||
function town()
|
||||
{
|
||||
$town = get_town_by_xy(user()->longitude, user()->latitude);
|
||||
if ($town === false) exit('There is an error with your user account, or with the town data. Please try again.');
|
||||
|
||||
$page = ['news' => '', 'whos_online' => ''];
|
||||
|
||||
// News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe.
|
||||
if (env('show_news')) {
|
||||
$news = db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC);
|
||||
$news_date = pretty_date($news["postdate"]);
|
||||
$news_content = nl2br($news["content"]);
|
||||
$page['news'] = <<<HTML
|
||||
<div class="title">Latest News</div>
|
||||
<span class="light">$news_date</span><br>
|
||||
$news_content
|
||||
HTML;
|
||||
}
|
||||
|
||||
// Who's Online. Currently just members. Guests maybe later.
|
||||
if (env('show_online')) {
|
||||
$onlinequery = db()->query(<<<SQL
|
||||
SELECT id, username
|
||||
FROM users
|
||||
WHERE onlinetime >= datetime('now', '-600 seconds')
|
||||
ORDER BY username;
|
||||
SQL);
|
||||
|
||||
$online_count = 0;
|
||||
$online_rows = [];
|
||||
|
||||
while ($onlinerow = $onlinequery->fetchArray(SQLITE3_ASSOC)) {
|
||||
$online_count++;
|
||||
$online_rows[] = "<a href=\"javascript:opencharpopup({$onlinerow['id']})\">".$onlinerow["username"]."</a>";
|
||||
}
|
||||
|
||||
$online_rows = implode(', ', $online_rows);
|
||||
$page['whos_online'] = <<<HTML
|
||||
<div class="title">Who's Online</div>
|
||||
There are <b>$online_count</b> user(s) online within the last 10 minutes: $online_rows
|
||||
HTML;
|
||||
}
|
||||
|
||||
page_title($town['name']);
|
||||
return render('towns', ['town' => $town, 'news' => $page['news'], 'whos_online' => $page['whos_online']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Staying at the inn resets all expendable stats to their max values.
|
||||
* GET/POST /inn
|
||||
*/
|
||||
function inn()
|
||||
{
|
||||
$town = get_town_by_xy(user()->longitude, user()->latitude);
|
||||
if ($town === false) { exit('Cheat attempt detected.<br><br>Get a life, loser.'); }
|
||||
|
||||
if (user()->gold < $town['innprice']) {
|
||||
$page = <<<HTML
|
||||
You do not have enough gold to stay at this Inn tonight. <br><br>
|
||||
You may return to <a hx-get="/" hx-target="#middle">town</a>, or use the direction buttons on the left to start exploring.
|
||||
HTML;
|
||||
} elseif (is_post() && $_POST['rest']) {
|
||||
user()->gold -= $town['innprice'];
|
||||
user()->restore_points()->save();
|
||||
$page = <<<HTML
|
||||
You wake up feeling refreshed and ready for action. <br><br>
|
||||
You may return to <a hx-get="/" hx-target="#middle">town</a>, or use the direction buttons on the left to start exploring.
|
||||
HTML;
|
||||
} elseif (is_post() && !$_POST['rest']) {
|
||||
redirect('/');
|
||||
} else {
|
||||
$page = <<<HTML
|
||||
Resting at the inn will refill your current HP, MP, and TP to their maximum levels.<br><br>
|
||||
A night's sleep at this Inn will cost you <b>{$town['innprice']} gold</b>. Is that ok?<br><br>
|
||||
<form hx-post="/inn" hx-target="#middle">
|
||||
<button name="rest" value="1">Yes</button>
|
||||
<button name="rest" value="0">No</button>
|
||||
</form>
|
||||
HTML;
|
||||
}
|
||||
|
||||
page_title($town['name'] . ' Inn');
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a list of available items for purchase from the town the user is currently in. If the user is not in a town,
|
||||
* redirects to home.
|
||||
* GET /shop
|
||||
*/
|
||||
function shop()
|
||||
{
|
||||
$town = get_town_by_xy(user()->longitude, user()->latitude);
|
||||
if ($town === false) exit('Cheat attempt detected.<br><br>Get a life, loser.');
|
||||
|
||||
|
||||
$page = <<<HTML
|
||||
Buying weapons will increase your Attack Power. Buying armor and shields will increase your Defense Power.<br><br>
|
||||
Click an item name to purchase it.<br><br>
|
||||
The following items are available at this town:<br><br>
|
||||
<table>
|
||||
HTML;
|
||||
|
||||
$items = db()->query('SELECT * FROM items WHERE id IN (' . $town["itemslist"] . ');');
|
||||
while ($item = $items->fetchArray(SQLITE3_ASSOC)) {
|
||||
$attrib = ($item["type"] == 1) ? "Attack Power:" : "Defense Power:";
|
||||
$page .= '<tr><td width="4%">';
|
||||
$page .= match ($item["type"]) {
|
||||
1 => '<img src="/img/icon_weapon.gif" alt="weapon">',
|
||||
2 => '<img src="/img/icon_armor.gif" alt="armor">',
|
||||
3 => '<img src="/img/icon_shield.gif" alt="shield">'
|
||||
};
|
||||
$page .= '</td>';
|
||||
if (user()->weaponid === $item["id"] || user()->armorid === $item["id"] || user()->shieldid === $item["id"]) {
|
||||
$page .= <<<HTML
|
||||
<td width="32%"><span class="light">{$item["name"]}</span></td>
|
||||
<td width="32%"><span class="light">$attrib {$item['attribute']}</span></td>
|
||||
<td width="32%"><span class="light">Already purchased</span></td>
|
||||
HTML;
|
||||
} else {
|
||||
$specialdot = $item['special'] !== 'X' ? '<span class="highlight">*</span>' : '';
|
||||
$page .= <<<HTML
|
||||
<td width="32%"><b><a hx-get="/buy/{$item['id']}" hx-target="#middle">{$item['name']}</a>$specialdot</b></td>
|
||||
<td width="32%">$attrib <b>{$item['attribute']}</b></td>
|
||||
<td width="32%">Price: <b>{$item['buycost']} gold</b></td>
|
||||
HTML;
|
||||
}
|
||||
$page .= '</tr>';
|
||||
}
|
||||
$page .= <<<HTML
|
||||
</table><br>
|
||||
If you've changed your mind, you may also return back to <a hx-get="/" hx-target="#middle">town</a>.
|
||||
HTML;
|
||||
|
||||
page_title($town['name'] . ' Shop');
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm user's intent to purchase item.
|
||||
*/
|
||||
function buy(int $id)
|
||||
{
|
||||
$town = get_town_by_xy(user()->longitude, user()->latitude);
|
||||
if ($town === false) redirect('/');
|
||||
if (!in_array($id, explode(',', $town['itemslist']))) redirect('/shop');
|
||||
$item = get_item($id);
|
||||
$can_afford = user()->gold >= $item['buycost'];
|
||||
|
||||
if (!$can_afford) {
|
||||
$page = <<<HTML
|
||||
You do not have enough gold to buy <b>{$item['name']}</b>.<br><br>
|
||||
You may return to <a hx-get="/" hx-target="#middle">town</a>, <a hx-get="/shop" hx-target="#middle">shop</a>,
|
||||
or use the direction buttons on the left to start exploring.
|
||||
HTML;
|
||||
} elseif (is_post() && !$_POST['buy']) {
|
||||
redirect('/shop');
|
||||
} elseif (is_post() && $_POST['buy']) {
|
||||
$type_mapping = [
|
||||
1 => ['id' => 'weaponid', 'name' => 'weaponname', 'power' => 'attackpower'],
|
||||
2 => ['id' => 'armorid', 'name' => 'armorname', 'power' => 'defensepower'],
|
||||
3 => ['id' => 'shieldid', 'name' => 'shieldname', 'power' => 'defensepower']
|
||||
];
|
||||
|
||||
if (!isset($type_mapping[$item["type"]])) { // should never happen
|
||||
return 'Error! Invalid item type...<br>'.var_dump($item);
|
||||
}
|
||||
|
||||
// Retrieve current equipped item or create a default
|
||||
$current_equip_id = user()->{$type_mapping[$item["type"]]['id']};
|
||||
if ($current_equip_id != 0) {
|
||||
$item2 = get_item($current_equip_id);
|
||||
} else {
|
||||
$item2 = ["attribute" => 0, "buycost" => 0, "special" => "X"];
|
||||
}
|
||||
|
||||
// Process special item effects
|
||||
$specialFields = [];
|
||||
$specialValues = [];
|
||||
$powerAdjustments = 0;
|
||||
|
||||
foreach ([$item, $item2] as $index => $process_item) {
|
||||
if ($process_item["special"] != "X") {
|
||||
$special = explode(",", $process_item["special"]);
|
||||
$toChange = $special[0];
|
||||
$changeAmount = $index === 0 ? $special[1] : -$special[1];
|
||||
|
||||
user()->$toChange += $changeAmount;
|
||||
$specialFields[] = "$toChange = ?";
|
||||
$specialValues[] = user()->$toChange;
|
||||
|
||||
// Adjust attack or defense power
|
||||
if ($toChange == "strength" || $toChange == "dexterity") {
|
||||
$powerType = $toChange == "strength" ? "attackpower" : "defensepower";
|
||||
$powerAdjustments += $changeAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine power and type-specific updates
|
||||
$currentType = $type_mapping[$item['type']];
|
||||
$powerField = $currentType['power'];
|
||||
user()->$powerField += $item['attribute'] - $item2['attribute'];
|
||||
|
||||
// Calculate new gold with trade-in value
|
||||
user()->gold += ceil($item2['buycost'] / 2) - $item['buycost'];
|
||||
|
||||
// Ensure current HP/MP/TP don't exceed max values
|
||||
user()->currenthp = min(user()->currenthp, user()->maxhp);
|
||||
user()->currentmp = min(user()->currentmp, user()->maxmp);
|
||||
user()->currenttp = min(user()->currenttp, user()->maxtp);
|
||||
|
||||
// Update item info in user
|
||||
user()->{$type_mapping[$item['type']]['id']} = $item['id'];
|
||||
user()->{$type_mapping[$item['type']]['name']} = $item['name'];
|
||||
|
||||
user()->save();
|
||||
|
||||
$page = <<<HTML
|
||||
Thank you for purchasing <b>{$item['name']}</b>.<br><br>
|
||||
You may return to <a hx-get="/" hx-target="#middle">town</a>, <a hx-get="/shop" hx-target="#middle">shop</a>, or use the direction buttons on the
|
||||
left to start exploring.
|
||||
HTML;
|
||||
} else {
|
||||
$type_to_row_mapping = [1 => 'weaponid', 2 => 'armorid', 3 => 'shieldid'];
|
||||
$current_equipped_id = user()->{$type_to_row_mapping[$item['type']]} ?? 0;
|
||||
|
||||
if ($current_equipped_id != 0) {
|
||||
$item2 = get_item($current_equipped_id);
|
||||
$sell_price = ceil($item2['buycost'] / 2);
|
||||
$page = <<<HTML
|
||||
If you are buying the {$item['name']}, then I will buy your {$item2['name']} for $sell_price gold. Is that ok?<br><br>
|
||||
<form hx-post="/buy/$id" hx-target="#middle">
|
||||
<button name="buy" value="1">Yes</button>
|
||||
<button name="buy" value="0">No</button>
|
||||
</form>
|
||||
HTML;
|
||||
} else {
|
||||
$page = <<<HTML
|
||||
You are buying {$item['name']} for {$item['buycost']} gold, is that ok?<br><br>
|
||||
<form hx-post="/buy/$id" hx-target="#middle">
|
||||
<button name="buy" value="1">Yes</button>
|
||||
<button name="buy" value="0">No</button>
|
||||
</form>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
|
||||
page_title('Buying '.$item['name']);
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* List maps the user can buy.
|
||||
*/
|
||||
function maps()
|
||||
{
|
||||
$page = <<<HTML
|
||||
Buying maps will put the town in your Travel To box, and it won't cost you as many TP to get there.<br><br>
|
||||
Click a town name to purchase its map.<br><br>
|
||||
<table>
|
||||
HTML;
|
||||
|
||||
$mapped = explode(',', user()->towns);
|
||||
$towns = db()->query('SELECT * FROM towns ORDER BY id;');
|
||||
while ($town = $towns->fetchArray(SQLITE3_ASSOC)) {
|
||||
$latitude = ($town["latitude"] >= 0) ? $town["latitude"] . "N," : ($town["latitude"] * -1) . "S,";
|
||||
$longitude = ($town["longitude"] >= 0) ? $town["longitude"] . "E" : ($town["longitude"] * -1) . "W";
|
||||
|
||||
if (in_array($town['id'], $mapped)) {
|
||||
$page .= <<<HTML
|
||||
<tr>
|
||||
<td width="25%"><span class="light">{$town['name']}</span></td>
|
||||
<td width="25%"><span class="light">Already mapped.</span></td>
|
||||
<td width="35%"><span class="light">Location: $latitude $longitude</span></td>
|
||||
<td width="15%"><span class="light">TP: {$town['travelpoints']}</span></td>
|
||||
</tr>
|
||||
HTML;
|
||||
} else {
|
||||
$page .= <<<HTML
|
||||
<tr>
|
||||
<td width="25%"><a href="/maps/{$town['id']}">{$town['name']}</a></td>
|
||||
<td width="25%">Price: {$town['mapprice']} gold</td>
|
||||
<td width="50%" colspan="2">Buy map to reveal details.</td>
|
||||
</tr>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
|
||||
$page .= <<<HTML
|
||||
</table><br>
|
||||
If you've changed your mind, you may also return back to <a hx-get="/" hx-target="#middle">town</a>.
|
||||
HTML;
|
||||
|
||||
page_title('Maps');
|
||||
return $page;
|
||||
}
|
||||
|
||||
function buy_map(int $id): string
|
||||
{
|
||||
$town = get_town_by_id($id);
|
||||
if ($town === false) redirect('/maps');
|
||||
|
||||
if (user()->gold < $town['mapprice']) {
|
||||
$page = <<<HTML
|
||||
You do not have enough gold to buy this map.<br><br>
|
||||
You may return to <a hx-get="/" hx-target="#middle">town</a>, <a hx-get="/maps" hx-target="#middle">store</a>, or use the direction buttons on the left to start exploring.
|
||||
HTML;
|
||||
} elseif (is_post() && $_POST['buy']) {
|
||||
user()->towns .= ",$id";
|
||||
user()->gold -= $town['mapprice'];
|
||||
user()->save();
|
||||
|
||||
$page = <<<HTML
|
||||
Thank you for purchasing this map.<br><br>
|
||||
You may return to <a hx-get="/" hx-target="#middle">town</a>, <a hx-get="/maps" hx-target="#middle">map shop</a>, or use the direction buttons on the left to start exploring.
|
||||
HTML;
|
||||
} elseif (is_post() && !$_POST['buy']) {
|
||||
redirect('/maps');
|
||||
} else {
|
||||
$page = <<<HTML
|
||||
You are buying the <b>{$town['name']}</b> map for {$town['mapprice']} gold. Is that ok?<br><br>
|
||||
<form action="/maps/$id" method="post">
|
||||
<button name="buy" value="1">Yes</button>
|
||||
<button name="buy" value="0">No</button>
|
||||
</form>
|
||||
HTML;
|
||||
}
|
||||
|
||||
page_title('Buying '.$town['name'].' Map');
|
||||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a user to a town from the Travel To menu.
|
||||
*/
|
||||
function travelto(int $id, bool $use_points = true): string
|
||||
{
|
||||
if (user()->currentaction == "Fighting") redirect('/fight');
|
||||
|
||||
$town = get_town_by_id($id);
|
||||
$cost = $use_points ? $town['travelpoints'] : 0;
|
||||
$mapped = explode(',', user()->towns);
|
||||
$travelled = false;
|
||||
|
||||
if ($use_points && !in_array($id, $mapped)) {
|
||||
// trying to teleport to this town when it is not mapped
|
||||
redirect('/');
|
||||
} elseif (user()->currenttp < $cost) {
|
||||
$page = 'You do not have enough TP to travel here. Please <a href="/" hx-get="/" hx-target="#middle">go back</a> and try again when you get more TP.';
|
||||
} elseif ((user()->latitude == $town['latitude']) && (user()->longitude == $town['longitude'])) {
|
||||
if (!in_array($id, $mapped)) {
|
||||
// add town to user's mapped if they travelled here
|
||||
user()->towns .= ",$id";
|
||||
$travelled = true;
|
||||
$page = <<<HTML
|
||||
You have discovered <b>{$town['name']}</b>! It has been added to your mapped towns.<br><br>
|
||||
You may now <a href="/" hx-get="/" hx-target="#middle">enter this town</a>.
|
||||
HTML;
|
||||
} else {
|
||||
$page = 'You are already in this town. <a href="/" hx-get="/" hx-target="#middle">Click here</a> to return.';
|
||||
}
|
||||
} else {
|
||||
user()->latitude = $town['latitude'];
|
||||
user()->longitude = $town['longitude'];
|
||||
user()->currenttp -= $cost;
|
||||
$travelled = true;
|
||||
$page = 'You have travelled to <b>'.$town['name'].'</b>. You may now <a href="/" hx-get="/" hx-target="#middle">enter this town</a>.';
|
||||
}
|
||||
|
||||
if ($travelled) {
|
||||
user()->currentaction = 'In Town';
|
||||
user()->save();
|
||||
}
|
||||
|
||||
page_title('Travelling to '.$town['name']);
|
||||
return $page;
|
||||
}
|
|
@ -1,226 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Users;
|
||||
|
||||
use Router;
|
||||
|
||||
function register_routes(Router $r): Router
|
||||
{
|
||||
$r->form('/login', 'Users\login');
|
||||
$r->get('/logout', 'Users\logout');
|
||||
$r->form('/register', 'Users\register');
|
||||
$r->form('/lostpassword', 'Users\lostpassword');
|
||||
$r->post('/changepassword', 'Users\changepassword');
|
||||
$r->form('/verify', 'Users\verify');
|
||||
$r->form('/settings', 'Users\settings');
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the login page, and processes login requests.
|
||||
*/
|
||||
function login()
|
||||
{
|
||||
global $auth;
|
||||
|
||||
if (is_post()) {
|
||||
$form = validate($_POST, [
|
||||
'username' => ['length:3-18', 'alpha-spaces'],
|
||||
'password' => ['length:6-255']
|
||||
]);
|
||||
|
||||
if (!$form['valid']) exit(ul_from_validate_errors($form['errors']));
|
||||
|
||||
$good = $auth->login($form['data']['username'], $form['data']['password']);
|
||||
if (!$good) exit('Invalid username or password. Please go back and try again.');
|
||||
|
||||
redirect('/');
|
||||
}
|
||||
|
||||
page_title('Login');
|
||||
return render('login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the current cookie and redirect to home.
|
||||
*/
|
||||
function logout()
|
||||
{
|
||||
global $auth;
|
||||
$auth->logout();
|
||||
redirect('/login');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a new account.
|
||||
*/
|
||||
function register()
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$form = validate($_POST, [
|
||||
'username' => ['length:3-18', 'alpha-spaces', 'unique:users,username'],
|
||||
'email' => ['email', 'unique:users,email'],
|
||||
'confirm_email' => ['confirm'],
|
||||
'password' => ['length:6-255'],
|
||||
'confirm_password' => ['confirm'],
|
||||
'charclass' => ['in:1,2,3']
|
||||
]);
|
||||
|
||||
if (!$form['valid']) {
|
||||
$err = ul_from_validate_errors($form['errors']);
|
||||
$page = "The following error(s) occurred when your account was being made:<br><span style=\"color:red;\">$err</span><br>Please go back and try again.";
|
||||
} else {
|
||||
$form = $form['data'];
|
||||
$password = password_hash($form['password'], PASSWORD_ARGON2ID);
|
||||
$token = env('verify_email') ? token(8) : 'g2g';
|
||||
db()->query('INSERT INTO users (verify, username, password, email, charclass) VALUES (?, ?, ?, ?, ?)', [
|
||||
$token, $form['username'], $password, $form['email'], $form['charclass']
|
||||
]);
|
||||
|
||||
if (env('verify_email')) {
|
||||
if (sendregmail($form['email'], $token)) {
|
||||
$page = "Your account was created successfully.<br><br>You should receive an Account Verification email shortly. You will need the verification code contained in that email before you are allowed to log in. Once you have received the email, please visit the <a href=\"users.php?do=verify\">Verification Page</a> to enter your code and start playing.";
|
||||
} else {
|
||||
$page = "Your account was created successfully.<br><br>However, there was a problem sending your verification email. Please check with the game administrator to help resolve this problem.";
|
||||
}
|
||||
} else {
|
||||
$page = "Your account was created succesfully.<br><br>You may now continue to the <a href=\"/login\">Login Page</a> and continue playing ".env('game_name')."!";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (env('verify_email')) {
|
||||
$verify_text = "<br><span class=\"small\">A verification code will be sent to the address above, and you will not be able to log in without first entering the code. Please be sure to enter your correct email address.</span>";
|
||||
} else {
|
||||
$verify_text = "";
|
||||
}
|
||||
|
||||
$page = render('register', ['verify_text' => $verify_text]);
|
||||
}
|
||||
|
||||
page_title('Register');
|
||||
return $page;
|
||||
}
|
||||
|
||||
function verify()
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$u = trim($_POST['username'] ?? '');
|
||||
$e = trim($_POST['email'] ?? '');
|
||||
$t = trim($_POST['token'] ?? '');
|
||||
|
||||
$query = db()->query('SELECT id FROM users WHERE username=? AND email=? AND verify=? LIMIT 1;', [$u, $e, $t]);
|
||||
if ($query === false) exit('Verification failed. Go back, double-check your details, and try again.');
|
||||
|
||||
db()->query("UPDATE users SET verify='g2g' WHERE username=?;", [$u]);
|
||||
|
||||
return "Your account was verified successfully.<br><br>You may now continue to the <a href=\"/login\">Login Page</a> and start playing the game.<br><br>Thanks for playing!";
|
||||
}
|
||||
|
||||
return render('verify');
|
||||
}
|
||||
|
||||
function lostpassword()
|
||||
{
|
||||
if (isset($_POST["submit"])) {
|
||||
$e = trim($_POST['email'] ?? '');
|
||||
|
||||
if (!db()->exists('users', 'email', $e)) exit("No account with that email address.");
|
||||
|
||||
$newpass = token(16);
|
||||
$hashed = password_hash($newpass, PASSWORD_ARGON2ID);
|
||||
|
||||
db()->query('UPDATE users SET password=? WHERE email=?;', [$hashed, $e]);
|
||||
|
||||
if (sendpassemail($e, $newpass)) {
|
||||
return "Your new password was emailed to the address you provided.<br><br>Once you receive it, you may <a href=\"/login\">Log In</a> and continue playing.<br><br>Thank you.";
|
||||
} else {
|
||||
return "There was an error sending your new password.<br><br>Please check with the game administrator for more information.<br><br>We apologize for the inconvience.";
|
||||
}
|
||||
}
|
||||
|
||||
return render('lostpassword');
|
||||
}
|
||||
|
||||
function changepassword()
|
||||
{
|
||||
global $auth;
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$u = trim($_POST['username'] ?? '');
|
||||
$p = $_POST['password'] ?? '';
|
||||
$np = $_POST['new_password'] ?? '';
|
||||
$np2 = $_POST['new_password2'] ?? '';
|
||||
|
||||
$user = db()->query("SELECT password FROM users WHERE username=? LIMIT 1;", [$u]);
|
||||
$user = $user->fetchArray(SQLITE3_ASSOC);
|
||||
if ($user === false) exit("No account with that username.");
|
||||
|
||||
if (!password_verify($p, $user['password'])) exit("The old password you provided was incorrect.");
|
||||
|
||||
if (empty($np) || strlen($np) < 6) {
|
||||
$errors[] = 'New password is required and must be at least 6 characters long.';
|
||||
}
|
||||
|
||||
if ($np2 !== $np) {
|
||||
$errors[] = 'Verify New Password must match.';
|
||||
}
|
||||
|
||||
$realnewpass = password_hash($np, PASSWORD_ARGON2ID);
|
||||
db()->query('UPDATE users SET password=? WHERE username=?;', [$realnewpass, $u]);
|
||||
|
||||
$auth->logout();
|
||||
|
||||
return "Your password was changed successfully.<br><br>You have been logged out of the game to avoid errors.<br><br>Please <a href=\"/login\">log back in</a> to continue playing.";
|
||||
}
|
||||
}
|
||||
|
||||
function settings()
|
||||
{
|
||||
if (is_post()) {
|
||||
$form = validate($_POST, [
|
||||
'game_skin' => ['in:0,1']
|
||||
]);
|
||||
if (!$form['valid']) exit(ul_from_validate_errors($form['errors']));
|
||||
$form = $form['data'];
|
||||
|
||||
user()->game_skin = $form['game_skin'];
|
||||
user()->save();
|
||||
|
||||
$alert = '<div class="alert">Settings updated</div>';
|
||||
return $alert . render('settings');
|
||||
}
|
||||
|
||||
return render('settings');
|
||||
}
|
||||
|
||||
function sendpassemail($emailaddress, $password)
|
||||
{
|
||||
$email = <<<HTML
|
||||
You or someone using your email address submitted a Lost Password application on the {env('game_name')} server, located at {env('game_url')}.
|
||||
|
||||
We have issued you a new password so you can log back into the game.
|
||||
|
||||
Your new password is: $password
|
||||
|
||||
Thanks for playing.
|
||||
HTML;
|
||||
|
||||
return send_email($emailaddress, env('game_name')." Lost Password", $email);
|
||||
}
|
||||
|
||||
function sendregmail($emailaddress, $vercode)
|
||||
{
|
||||
$verurl = env('game_url') . "/verify";
|
||||
|
||||
$email = <<<HTML
|
||||
You or someone using your email address recently signed up for an account on the {env('game_name')} server, located at {env('game_url')}.
|
||||
|
||||
This email is sent to verify your registration email. In order to begin using your account, you must verify your email address.
|
||||
Please visit the Verification Page ($verurl) and enter the code below to activate your account.
|
||||
Verification code: $vercode
|
||||
|
||||
If you were not the person who signed up for the game, please disregard this message. You will not be emailed again.
|
||||
HTML;
|
||||
|
||||
return send_email($emailaddress, env('game_name')." Account Verification", $email);
|
||||
}
|
104
src/auth.php
|
@ -1,104 +0,0 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
This is an experimental new class for handling user auth. The idea is to rely as much as possible on PHP's native
|
||||
session handling. When authenticated, the class will store use data in GLOBALS state.
|
||||
*/
|
||||
|
||||
class Auth
|
||||
{
|
||||
/**
|
||||
* Set up the auth manager; adjust PHP session settings on the fly to improve security. Starts the session for
|
||||
* this request.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// enhance the native session's sessid cryptography
|
||||
ini_set('session.sid_length', 64);
|
||||
ini_set('session.sid_bits_per_character', 6);
|
||||
|
||||
session_set_cookie_params([
|
||||
'lifetime' => 2592000, // 30 days
|
||||
'path' => '/',
|
||||
'secure' => true,
|
||||
'httponly' => true,
|
||||
'samesite' => 'Strict'
|
||||
]);
|
||||
|
||||
session_start();
|
||||
|
||||
$this->validate();
|
||||
}
|
||||
|
||||
private function validate(): void
|
||||
{
|
||||
// Check for IP address change
|
||||
if (!isset($_SESSION['ip_address'])) {
|
||||
$_SESSION['ip_address'] = $_SERVER['REMOTE_ADDR'];
|
||||
} elseif ($_SESSION['ip_address'] !== $_SERVER['REMOTE_ADDR']) {
|
||||
$this->destroy(); // Possible hijacking
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check for User-Agent change
|
||||
if (!isset($_SESSION['user_agent'])) {
|
||||
$_SESSION['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
|
||||
} elseif ($_SESSION['user_agent'] !== $_SERVER['HTTP_USER_AGENT']) {
|
||||
$this->destroy(); // Possible hijacking
|
||||
exit;
|
||||
}
|
||||
|
||||
// Regenerate session ID periodically for security
|
||||
if (!isset($_SESSION['last_regeneration'])) {
|
||||
$_SESSION['last_regeneration'] = time();
|
||||
} elseif (time() - $_SESSION['last_regeneration'] > 300) { // Every 5 minutes
|
||||
$this->regenerate();
|
||||
}
|
||||
}
|
||||
|
||||
public function login(string $username, string $password): bool
|
||||
{
|
||||
$user = get_user($username);
|
||||
if ($user === false) return false;
|
||||
|
||||
if (password_verify($password, $user['password'])) {
|
||||
$_SESSION['authenticated'] = true;
|
||||
$_SESSION['user_id'] = $user['id'];
|
||||
$_SESSION['login_time'] = time();
|
||||
|
||||
$this->regenerate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function good(): bool
|
||||
{
|
||||
return isset($_SESSION['authenticated']) && $_SESSION['authenticated'] === true;
|
||||
}
|
||||
|
||||
public function logout(): void
|
||||
{
|
||||
$this->destroy();
|
||||
}
|
||||
|
||||
private function regenerate(): void
|
||||
{
|
||||
session_regenerate_id(true);
|
||||
$_SESSION['last_regeneration'] = time();
|
||||
}
|
||||
|
||||
public function destroy(): void
|
||||
{
|
||||
$_SESSION = [];
|
||||
|
||||
if (ini_get("session.use_cookies")) {
|
||||
$params = session_get_cookie_params();
|
||||
setcookie(session_name(), '', time() - 42000, $params['path'], $params['domain'], $params['secure'], $params['httponly']);
|
||||
}
|
||||
|
||||
session_destroy();
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
<?php
|
||||
|
||||
require_once 'lib.php';
|
||||
require_once 'router.php';
|
||||
require_once 'auth.php';
|
||||
require_once 'mail.php';
|
||||
require_once 'render.php';
|
||||
require_once 'actions/explore.php';
|
||||
require_once 'actions/heal.php';
|
||||
require_once 'actions/users.php';
|
||||
require_once 'actions/help.php';
|
||||
require_once 'actions/towns.php';
|
||||
require_once 'actions/fight.php';
|
||||
require_once 'actions/forum.php';
|
||||
require_once 'actions/install.php';
|
||||
require_once 'actions/admin.php';
|
||||
require_once 'models/model.php';
|
||||
require_once 'models/user.php';
|
||||
|
||||
env_load('../.env');
|
||||
|
||||
$uri = explode('/', trim($_SERVER['REQUEST_URI'], '/'));
|
||||
$GLOBALS['cache'] = [];
|
||||
$GLOBALS['state'] = [];
|
||||
|
||||
/**
|
||||
* These are table names whose data we want to be able to edit in the admin panel in bulk.
|
||||
*/
|
||||
define('ADMIN_BULK_DATA_STRUCTS', [
|
||||
'users', 'items', 'drops', 'towns', 'monsters', 'levels', 'spells'
|
||||
]);
|
||||
|
||||
if (!file_exists('../.installed') && $uri[0] !== 'install') { // need to install the game
|
||||
redirect('/install');
|
||||
} elseif (file_exists(('../.installed')) && $uri[0] === 'install') { // game is installed, go play!
|
||||
redirect('/');
|
||||
} elseif (file_exists(('../.installed')) && $uri[0] !== 'install') { // boostrap the game
|
||||
if (!env('game_open')) {
|
||||
echo Render\content('The game is currently closed for maintanence. Please check back later.');
|
||||
exit;
|
||||
}
|
||||
|
||||
$auth = new Auth;
|
||||
|
||||
// Login (or verify) if not logged in.
|
||||
if (user() === false) {
|
||||
if (!in_array($uri[0], ['login', 'register', 'verify', 'lostpassword', 'help'])) {
|
||||
redirect('/login');
|
||||
}
|
||||
} elseif ($auth->good()) {
|
||||
// Block user if he/she has been banned.
|
||||
if (user()->authlevel === 2) {
|
||||
exit("Your account has been banned.");
|
||||
}
|
||||
|
||||
// Force verify if the user isn't verified yet.
|
||||
if (env('verify_email') && user()->verify !== 'g2g' && !in_array($uri[0], ['verify', 'logout'])) {
|
||||
redirect('/verify');
|
||||
}
|
||||
|
||||
// Ensure the user can't use the admin panel.
|
||||
if (user()->authlevel !== 1 && $uri[0] === 'admin') {
|
||||
redirect('/');
|
||||
}
|
||||
|
||||
// Update default page layout based on root endpoint
|
||||
page_layout('layouts/primary');
|
||||
if ($uri[0] === 'admin') page_layout('layouts/admin');
|
||||
if ($uri[0] === 'help') page_layout('layouts/help');
|
||||
|
||||
user()->update_online_time();
|
||||
} else {
|
||||
$auth->logout();
|
||||
redirect('/login');
|
||||
}
|
||||
}
|
|
@ -9,9 +9,6 @@ class Database extends SQLite3
|
|||
public array $log = [];
|
||||
public float $query_time = 0;
|
||||
|
||||
/**
|
||||
* Make a big, chonky connection to our SQLite database.
|
||||
*/
|
||||
public function __construct(string $db_path)
|
||||
{
|
||||
parent::__construct($db_path);
|
||||
|
@ -21,32 +18,19 @@ class Database extends SQLite3
|
|||
parent::exec('PRAGMA temp_store = MEMORY');
|
||||
}
|
||||
|
||||
/**
|
||||
* Query the database. Uses prepared statements, and your choise of placeholder syntax. (:key or ?) Logs
|
||||
* the query in the class.
|
||||
*/
|
||||
public function query(string $query, array $params = []): SQLite3Result|false
|
||||
{
|
||||
$p = strpos($query, '?') !== false;
|
||||
try {
|
||||
$stmt = $this->prepare($query);
|
||||
foreach ($params ?? [] as $k => $v) $stmt->bindValue($p ? $k + 1 : $k, $v, $this->getSQLiteType($v));
|
||||
} catch (Exception $e) {
|
||||
exit("Failed to prepare query ($query): ".$this->lastErrorMsg());
|
||||
}
|
||||
$stmt = $this->prepare($query);
|
||||
foreach ($params ?? [] as $k => $v) $stmt->bindValue($p ? $k + 1 : $k, $v, $this->getSQLiteType($v));
|
||||
|
||||
$start = microtime(true);
|
||||
$error = '';
|
||||
$r = $stmt->execute();
|
||||
|
||||
$this->log($query, microtime(true) - $start, $error);
|
||||
$r = $stmt->execute();
|
||||
$this->log($query, microtime(true) - $start);
|
||||
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a result-less query on the database.
|
||||
*/
|
||||
public function exec(string $query): bool
|
||||
{
|
||||
$start = microtime(true);
|
||||
|
@ -55,10 +39,6 @@ class Database extends SQLite3
|
|||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a given value exists in a given column in a given table. Can optionally make it
|
||||
* case-sensitive!
|
||||
*/
|
||||
public function exists(string $table, string $column, mixed $value, bool $case_insensitive = true): bool
|
||||
{
|
||||
if ($case_insensitive) {
|
||||
|
@ -71,19 +51,13 @@ class Database extends SQLite3
|
|||
return $result->fetchArray(SQLITE3_NUM) !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Log the query, including the time it took. Increment the query counter.
|
||||
*/
|
||||
private function log(string $query, float $time_taken, string $error = ''): void
|
||||
private function log(string $query, float $time_taken): void
|
||||
{
|
||||
$this->count++;
|
||||
$this->query_time += $time_taken;
|
||||
$this->log[] = [$query, $time_taken, $error];
|
||||
$this->log[] = [$query, $time_taken];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the correct SQLite3 type for the given value.
|
||||
*/
|
||||
private function getSQLiteType(mixed $value): int
|
||||
{
|
||||
return match (true) {
|
||||
|
|
30
src/explore.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
|
||||
// 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(); }
|
||||
|
||||
$latitude = $userrow["latitude"];
|
||||
$longitude = $userrow["longitude"];
|
||||
if (isset($_POST["north"])) { $latitude++; if ($latitude > $controlrow["gamesize"]) { $latitude = $controlrow["gamesize"]; } }
|
||||
if (isset($_POST["south"])) { $latitude--; if ($latitude < ($controlrow["gamesize"]*-1)) { $latitude = ($controlrow["gamesize"]*-1); } }
|
||||
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); } }
|
||||
|
||||
$town = get_town_by_xy($longitude, $latitude);
|
||||
if ($town !== false) {
|
||||
require_once __DIR__ . '/towns.php';
|
||||
travelto($town['id'], false);
|
||||
return;
|
||||
}
|
||||
|
||||
$chancetofight = rand(1, 5);
|
||||
$action = $chancetofight === 1 ? "currentaction='Fighting', currentfight='1'," : "currentaction='Exploring',";
|
||||
|
||||
db()->query("UPDATE users SET $action latitude = ?, longitude = ?, dropcode = 0 WHERE id = ?;", [$latitude, $longitude, $userrow['id']]);
|
||||
header("Location: index.php");
|
||||
}
|
464
src/fight.php
Normal file
|
@ -0,0 +1,464 @@
|
|||
<?php
|
||||
|
||||
// fight.php :: Handles all fighting action.
|
||||
|
||||
/**
|
||||
* One big long function that determines the outcome of the fight.
|
||||
*/
|
||||
function fight()
|
||||
{
|
||||
global $userrow;
|
||||
if ($userrow["currentaction"] != "Fighting") display("Cheat attempt detected.<br><br>Get a life, loser.", "Error");
|
||||
|
||||
$pagearray = ["magiclist" => "", "yourturn" => "", "monsterturn" => "", "monsterhp" => "", "command" => ""];
|
||||
$playerisdead = 0;
|
||||
|
||||
// Populate magic list
|
||||
$userspells = explode(",", $userrow["spells"]);
|
||||
$spellquery = db()->query('SELECT id, name FROM spells ORDER BY id;');
|
||||
while ($spellrow = $spellquery->fetchArray(SQLITE3_ASSOC)) {
|
||||
if (in_array($spellrow["id"], $userspells)) {
|
||||
$pagearray["magiclist"] .= "<option value=\"{$spellrow["id"]}\">{$spellrow["name"]}</option>\n";
|
||||
}
|
||||
}
|
||||
$pagearray["magiclist"] = $pagearray["magiclist"] ?: "<option value=\"0\">None</option>\n";
|
||||
$magiclist = $pagearray["magiclist"];
|
||||
|
||||
// Determine initial combat parameters
|
||||
$chancetoswingfirst = rand(1, 10) + (int)ceil(sqrt($userrow["dexterity"]));
|
||||
if ($userrow["currentfight"] == 1) {
|
||||
$maxlevel = (int)floor(max(abs($userrow["latitude"]) + 5, abs($userrow["longitude"]) + 5) / 5);
|
||||
$minlevel = max(1, $maxlevel - 2);
|
||||
|
||||
$monsterrow = db()->query('SELECT * FROM monsters WHERE level >= ? AND level <= ? ORDER BY RANDOM() LIMIT 1;', [
|
||||
$minlevel, $maxlevel
|
||||
])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
$userrow["currentmonster"] = $monsterrow["id"];
|
||||
$userrow["currentmonsterhp"] = rand((int)(($monsterrow["maxhp"]/5)*4), $monsterrow["maxhp"]);
|
||||
$userrow["currentmonstersleep"] = 0;
|
||||
$userrow["currentmonsterimmune"] = $monsterrow["immune"];
|
||||
|
||||
$chancetoswingfirst = ($chancetoswingfirst > (rand(1,7) + (int)ceil(sqrt($monsterrow["maxdam"])))) ? 1 : 0;
|
||||
}
|
||||
|
||||
// Get monster statistics
|
||||
$monsterrow = get_monster($userrow['currentmonster']);
|
||||
$pagearray["monstername"] = $monsterrow["name"];
|
||||
|
||||
// Run action
|
||||
if (isset($_POST["run"])) {
|
||||
$chancetorun = rand(4,10) + (int)ceil(sqrt($userrow["dexterity"]));
|
||||
if ($chancetorun <= (rand(1,5) + (int)ceil(sqrt($monsterrow["maxdam"])))) {
|
||||
$pagearray["yourturn"] = "You tried to run away, but were blocked in front!<br><br>";
|
||||
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
|
||||
|
||||
// Monster turn logic (similar to original function)
|
||||
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
|
||||
|
||||
db()->query("UPDATE users SET currentaction='Exploring' WHERE id=?;", [$userrow['id']]);
|
||||
redirect('index.php');
|
||||
}
|
||||
}
|
||||
|
||||
// Fight action
|
||||
if (isset($_POST["fight"])) {
|
||||
// Player's attack
|
||||
$min = (int)($userrow["attackpower"] * 0.75);
|
||||
$max = (int)($userrow["attackpower"] / 3);
|
||||
$tohit = (int)ceil(mt_rand(min($min, $max), max($min, $max)));
|
||||
|
||||
$toexcellent = rand(1,150);
|
||||
if ($toexcellent <= sqrt($userrow["strength"])) {
|
||||
$tohit *= 2;
|
||||
$pagearray["yourturn"] .= "Excellent hit!<br>";
|
||||
}
|
||||
|
||||
$min = (int)($monsterrow["armor"] * 0.75);
|
||||
$max = (int)$monsterrow["armor"];
|
||||
$toblock = (int)ceil(rand(min($min, $max), max($min, $max)) / 3);
|
||||
|
||||
$tododge = rand(1,200);
|
||||
|
||||
$monsterdamage = max(1, $tohit - $toblock);
|
||||
if ($tododge <= sqrt($monsterrow["armor"])) {
|
||||
$monsterdamage = 0;
|
||||
$pagearray["yourturn"] .= "The monster is dodging. No damage has been scored.<br>";
|
||||
}
|
||||
|
||||
if ($userrow["currentuberdamage"] != 0) {
|
||||
$monsterdamage += (int)ceil($monsterdamage * ($userrow["currentuberdamage"]/100));
|
||||
}
|
||||
|
||||
$userrow["currentmonsterhp"] -= $monsterdamage;
|
||||
$pagearray["yourturn"] .= "You attack the monster for $monsterdamage damage.<br><br>";
|
||||
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
|
||||
|
||||
// Check for monster defeat
|
||||
if ($userrow["currentmonsterhp"] <= 0) {
|
||||
db()->query('UPDATE users SET currentmonsterhp=0 WHERE id=?;', [$userrow['id']]);
|
||||
redirect('index.php?do=victory');
|
||||
}
|
||||
|
||||
// Monster's turn
|
||||
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
|
||||
}
|
||||
|
||||
// Spell action
|
||||
if (isset($_POST["spell"])) {
|
||||
$pickedspell = $_POST["userspell"];
|
||||
if ($pickedspell == 0) {
|
||||
display("You must select a spell first. Please go back and try again.", "Error");
|
||||
die();
|
||||
}
|
||||
|
||||
$newspellrow = get_spell($pickedspell);
|
||||
$spell = in_array($pickedspell, $userspells);
|
||||
|
||||
if (!$spell) {
|
||||
display("You have not yet learned this spell. Please go back and try again.", "Error");
|
||||
die();
|
||||
}
|
||||
|
||||
if ($userrow["currentmp"] < $newspellrow["mp"]) {
|
||||
display("You do not have enough Magic Points to cast this spell. Please go back and try again.", "Error");
|
||||
die();
|
||||
}
|
||||
|
||||
// Spell type handling (similar to original function)
|
||||
$pagearray["yourturn"] = handleSpellCast($userrow, $newspellrow);
|
||||
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
|
||||
|
||||
// Check for monster defeat
|
||||
if ($userrow["currentmonsterhp"] <= 0) {
|
||||
db()->query('UPDATE users SET currentmonsterhp=0, currenthp=?, currentmp=? WHERE id=?;', [
|
||||
$userrow['currenthp'], $userrow['currentmp'], $userrow['id']
|
||||
]);
|
||||
redirect('index.php?do=victory');
|
||||
}
|
||||
|
||||
// Monster's turn
|
||||
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
|
||||
}
|
||||
|
||||
// Monster's turn if player lost first swing
|
||||
if (!isset($_POST["run"]) && !isset($_POST["fight"]) && !isset($_POST["spell"]) && $chancetoswingfirst == 0) {
|
||||
$pagearray["yourturn"] = "The monster attacks before you are ready!<br><br>";
|
||||
$pagearray["monsterhp"] = "Monster's HP: " . $userrow["currentmonsterhp"] . "<br><br>";
|
||||
$pagearray["monsterturn"] = handleMonsterTurn($userrow, $monsterrow);
|
||||
}
|
||||
|
||||
// Prepare command or death message
|
||||
if ($playerisdead != 1) {
|
||||
$pagearray["command"] = <<<HTML
|
||||
Command?<br><br>
|
||||
<form action="index.php?do=fight" method="post">
|
||||
<input type="submit" name="fight" value="Fight" /><br><br>
|
||||
<select name="userspell"><option value="0">Choose One</option>$magiclist</select> <input type="submit" name="spell" value="Spell" /><br><br>
|
||||
<input type="submit" name="run" value="Run" /><br><br>
|
||||
</form>
|
||||
HTML;
|
||||
|
||||
db()->query("UPDATE users SET
|
||||
currentaction='Fighting',
|
||||
currenthp=?,
|
||||
currentmp=?,
|
||||
currentfight=?,
|
||||
currentmonster=?,
|
||||
currentmonsterhp=?,
|
||||
currentmonstersleep=?,
|
||||
currentmonsterimmune=?,
|
||||
currentuberdamage=?,
|
||||
currentuberdefense=?
|
||||
WHERE id=?;", [
|
||||
$userrow['currenthp'],
|
||||
$userrow['currentmp'],
|
||||
$userrow['currentfight'] + 1,
|
||||
$userrow['currentmonster'],
|
||||
$userrow['currentmonsterhp'],
|
||||
$userrow['currentmonstersleep'],
|
||||
$userrow['currentmonsterimmune'],
|
||||
$userrow['currentuberdamage'],
|
||||
$userrow['currentuberdefense'],
|
||||
$userrow['id']
|
||||
]);
|
||||
} else {
|
||||
$pagearray["command"] = "<b>You have died.</b><br><br>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.<br><br>You may now continue back to <a href=\"index.php\">town</a>, and we hope you fair better next time.";
|
||||
}
|
||||
|
||||
// Finalize page and display it
|
||||
display(parsetemplate(gettemplate("fight"), $pagearray), "Fighting");
|
||||
}
|
||||
|
||||
function victory()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
if ($userrow["currentmonsterhp"] != 0) { header("Location: index.php?do=fight"); die(); }
|
||||
if ($userrow["currentfight"] == 0) { header("Location: index.php"); die(); }
|
||||
|
||||
$monsterrow = get_monster($userrow['currentmonster']);
|
||||
|
||||
$min = (int)(($monsterrow["maxexp"] / 6) * 5);
|
||||
$max = (int)$monsterrow["maxexp"];
|
||||
$exp = mt_rand(min($min, $max), max($min, $max));
|
||||
if ($exp < 1) { $exp = 1; }
|
||||
|
||||
if ($userrow["expbonus"] != 0) { $exp += ceil(($userrow["expbonus"]/100)*$exp); }
|
||||
|
||||
$min = (int)(($monsterrow["maxgold"] / 6) * 5);
|
||||
$max = (int)$monsterrow["maxgold"];
|
||||
|
||||
$gold = mt_rand(min($min, $max), max($min, $max));
|
||||
if ($gold < 1) { $gold = 1; }
|
||||
|
||||
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."; }
|
||||
|
||||
$levelrow = db()->query('SELECT * FROM levels WHERE id=? LIMIT 1;', [$userrow['level'] + 1])->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
if ($userrow["level"] < 100) {
|
||||
if ($newexp >= $levelrow[$userrow["charclass"]."_exp"]) {
|
||||
$newhp = $userrow["maxhp"] + $levelrow[$userrow["charclass"]."_hp"];
|
||||
$newmp = $userrow["maxmp"] + $levelrow[$userrow["charclass"]."_mp"];
|
||||
$newtp = $userrow["maxtp"] + $levelrow[$userrow["charclass"]."_tp"];
|
||||
$newstrength = $userrow["strength"] + $levelrow[$userrow["charclass"]."_strength"];
|
||||
$newdexterity = $userrow["dexterity"] + $levelrow[$userrow["charclass"]."_dexterity"];
|
||||
$newattack = $userrow["attackpower"] + $levelrow[$userrow["charclass"]."_strength"];
|
||||
$newdefense = $userrow["defensepower"] + $levelrow[$userrow["charclass"]."_dexterity"];
|
||||
$newlevel = $levelrow["id"];
|
||||
|
||||
if ($levelrow[$userrow["charclass"]."_spells"] != 0) {
|
||||
$userspells = $userrow["spells"] . ",".$levelrow[$userrow["charclass"]."_spells"];
|
||||
$newspell = "spells='$userspells',";
|
||||
$spelltext = "You have learned a new spell.<br>";
|
||||
} else { $spelltext = ""; $newspell=""; }
|
||||
|
||||
$page = "Congratulations. You have defeated the ".$monsterrow["name"].".<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br><b>You have gained a level!</b><br><br>You gain ".$levelrow[$userrow["charclass"]."_hp"]." hit points.<br>You gain ".$levelrow[$userrow["charclass"]."_mp"]." magic points.<br>You gain ".$levelrow[$userrow["charclass"]."_tp"]." travel points.<br>You gain ".$levelrow[$userrow["charclass"]."_strength"]." strength.<br>You gain ".$levelrow[$userrow["charclass"]."_dexterity"]." dexterity.<br>$spelltext<br>You can now continue <a href=\"index.php\">exploring</a>.";
|
||||
$title = "Courage and Wit have served thee well!";
|
||||
$dropcode = "";
|
||||
} else {
|
||||
$newhp = $userrow["maxhp"];
|
||||
$newmp = $userrow["maxmp"];
|
||||
$newtp = $userrow["maxtp"];
|
||||
$newstrength = $userrow["strength"];
|
||||
$newdexterity = $userrow["dexterity"];
|
||||
$newattack = $userrow["attackpower"];
|
||||
$newdefense = $userrow["defensepower"];
|
||||
$newlevel = $userrow["level"];
|
||||
$newspell = "";
|
||||
$page = "Congratulations. You have defeated the ".$monsterrow["name"].".<br>You gain $exp experience. $warnexp <br>You gain $gold gold. $warngold <br><br>";
|
||||
|
||||
if (rand(1, 30) === 1) {
|
||||
$droprow = db()->query('SELECT * FROM drops WHERE mlevel <= ? ORDER BY RANDOM() LIMIT 1;', [$monsterrow['level']])->fetchArray(SQLITE3_ASSOC);
|
||||
$dropcode = "dropcode='".$droprow["id"]."',";
|
||||
$page .= "This monster has dropped an item. <a href=\"index.php?do=drop\">Click here</a> to reveal and equip the item, or you may also move on and continue <a href=\"index.php\">exploring</a>.";
|
||||
} else {
|
||||
$dropcode = "";
|
||||
$page .= "You can now continue <a href=\"index.php\">exploring</a>.";
|
||||
}
|
||||
|
||||
$title = "Victory!";
|
||||
}
|
||||
}
|
||||
|
||||
db()->query("UPDATE users SET currentaction='Exploring', level=?, maxhp=?, maxmp=?, maxtp=?, strength=?, dexterity=?, attackpower=?, defensepower=?, $newspell currentfight=0, currentmonster=0, currentmonsterhp=0, currentmonstersleep=0, currentmonsterimmune=0, currentuberdamage=0, currentuberdefense=0,$dropcode experience=?, gold=? WHERE id=?;", [
|
||||
$newlevel, $newhp, $newmp, $newtp, $newstrength, $newdexterity, $newattack, $newdefense, $newexp, $newgold, $userrow['id']
|
||||
]);
|
||||
|
||||
display($page, $title);
|
||||
}
|
||||
|
||||
function drop()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
if ($userrow["dropcode"] == 0) redirect('index.php');
|
||||
|
||||
$droprow = get_drop($userrow['dropcode']);
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$slot = $_POST["slot"];
|
||||
|
||||
if ($slot == 0) { display("Please go back and select an inventory slot to continue.","Error"); }
|
||||
|
||||
if ($userrow["slot{$slot}id"] != 0) {
|
||||
$slotrow = get_drop($userrow["slot{$slot}id"]);
|
||||
|
||||
$old1 = explode(",",$slotrow["attribute1"]);
|
||||
if ($slotrow["attribute2"] != "X") { $old2 = explode(",",$slotrow["attribute2"]); } else { $old2 = array(0=>"maxhp",1=>0); }
|
||||
$new1 = explode(",",$droprow["attribute1"]);
|
||||
if ($droprow["attribute2"] != "X") { $new2 = explode(",",$droprow["attribute2"]); } else { $new2 = array(0=>"maxhp",1=>0); }
|
||||
|
||||
$userrow[$old1[0]] -= $old1[1];
|
||||
$userrow[$old2[0]] -= $old2[1];
|
||||
if ($old1[0] == "strength") { $userrow["attackpower"] -= $old1[1]; }
|
||||
if ($old1[0] == "dexterity") { $userrow["defensepower"] -= $old1[1]; }
|
||||
if ($old2[0] == "strength") { $userrow["attackpower"] -= $old2[1]; }
|
||||
if ($old2[0] == "dexterity") { $userrow["defensepower"] -= $old2[1]; }
|
||||
|
||||
$userrow[$new1[0]] += $new1[1];
|
||||
$userrow[$new2[0]] += $new2[1];
|
||||
if ($new1[0] == "strength") { $userrow["attackpower"] += $new1[1]; }
|
||||
if ($new1[0] == "dexterity") { $userrow["defensepower"] += $new1[1]; }
|
||||
if ($new2[0] == "strength") { $userrow["attackpower"] += $new2[1]; }
|
||||
if ($new2[0] == "dexterity") { $userrow["defensepower"] += $new2[1]; }
|
||||
|
||||
if ($userrow["currenthp"] > $userrow["maxhp"]) { $userrow["currenthp"] = $userrow["maxhp"]; }
|
||||
if ($userrow["currentmp"] > $userrow["maxmp"]) { $userrow["currentmp"] = $userrow["maxmp"]; }
|
||||
if ($userrow["currenttp"] > $userrow["maxtp"]) { $userrow["currenttp"] = $userrow["maxtp"]; }
|
||||
|
||||
$slot_s = 'slot'.$_POST["slot"];
|
||||
db()->query("UPDATE users SET {$slot_s}name=?, {$slot_s}id=?, {$old1[0]}=?, {$old2[0]}=?, {$new1[0]}=?, {$new2[0]}=?, attackpower=?, defensepower=?, currenthp=?, currentmp=?, currenttp=?, dropcode=0 WHERE id=?;", [
|
||||
$droprow["name"], $droprow["id"], $userrow[$old1[0]], $userrow[$old2[0]], $userrow[$new1[0]], $userrow[$new2[0]], $userrow["attackpower"], $userrow["defensepower"], $userrow["currenthp"], $userrow["currentmp"], $userrow["currenttp"], $userrow['id']
|
||||
]);
|
||||
} else {
|
||||
$new1 = explode(",",$droprow["attribute1"]);
|
||||
if ($droprow["attribute2"] != "X") { $new2 = explode(",",$droprow["attribute2"]); } else { $new2 = array(0=>"maxhp",1=>0); }
|
||||
|
||||
$userrow[$new1[0]] += $new1[1];
|
||||
$userrow[$new2[0]] += $new2[1];
|
||||
if ($new1[0] == "strength") { $userrow["attackpower"] += $new1[1]; }
|
||||
if ($new1[0] == "dexterity") { $userrow["defensepower"] += $new1[1]; }
|
||||
if ($new2[0] == "strength") { $userrow["attackpower"] += $new2[1]; }
|
||||
if ($new2[0] == "dexterity") { $userrow["defensepower"] += $new2[1]; }
|
||||
|
||||
$slot_s = 'slot'.$_POST["slot"];
|
||||
db()->query("UPDATE users SET {$slot_s}name=?, {$slot_s}id=?, {$new1[0]}=?, {$new2[0]}=?, attackpower=?, defensepower=?, currenthp=?, currentmp=?, currenttp=?, dropcode=0 WHERE id=?;", [
|
||||
$droprow["name"], $droprow["id"], $userrow[$new1[0]], $userrow[$new2[0]], $userrow["attackpower"], $userrow["defensepower"], $userrow["currenthp"], $userrow["currentmp"], $userrow["currenttp"], $userrow['id']
|
||||
]);
|
||||
}
|
||||
|
||||
display("The item has been equipped. You can now continue <a href=\"index.php\">exploring</a>.", "Item Drop");
|
||||
}
|
||||
|
||||
$attributearray = array("maxhp"=>"Max HP",
|
||||
"maxmp"=>"Max MP",
|
||||
"maxtp"=>"Max TP",
|
||||
"defensepower"=>"Defense Power",
|
||||
"attackpower"=>"Attack Power",
|
||||
"strength"=>"Strength",
|
||||
"dexterity"=>"Dexterity",
|
||||
"expbonus"=>"Experience Bonus",
|
||||
"goldbonus"=>"Gold Bonus");
|
||||
|
||||
$page = "The monster dropped the following item: <b>".$droprow["name"]."</b><br><br>";
|
||||
$page .= "This item has the following attribute(s):<br>";
|
||||
|
||||
$attribute1 = explode(",",$droprow["attribute1"]);
|
||||
$page .= $attributearray[$attribute1[0]];
|
||||
if ($attribute1[1] > 0) { $page .= " +" . $attribute1[1] . "<br>"; } else { $page .= $attribute1[1] . "<br>"; }
|
||||
|
||||
if ($droprow["attribute2"] != "X") {
|
||||
$attribute2 = explode(",",$droprow["attribute2"]);
|
||||
$page .= $attributearray[$attribute2[0]];
|
||||
if ($attribute2[1] > 0) { $page .= " +" . $attribute2[1] . "<br>"; } else { $page .= $attribute2[1] . "<br>"; }
|
||||
}
|
||||
|
||||
$page .= "<br>Select an inventory slot from the list below to equip this item. If the inventory slot is already full, the old item will be discarded.";
|
||||
$page .= "<form action=\"index.php?do=drop\" method=\"post\"><select name=\"slot\"><option value=\"0\">Choose One</option><option value=\"1\">Slot 1: ".$userrow["slot1name"]."</option><option value=\"2\">Slot 2: ".$userrow["slot2name"]."</option><option value=\"3\">Slot 3: ".$userrow["slot3name"]."</option></select> <input type=\"submit\" name=\"submit\" value=\"Submit\" /></form>";
|
||||
$page .= "You may also choose to just continue <a href=\"index.php\">exploring</a> and give up this item.";
|
||||
|
||||
display($page, "Item Drop");
|
||||
}
|
||||
|
||||
|
||||
function dead()
|
||||
{
|
||||
$page = <<<HTML
|
||||
<b>You have died.</b><br><br>
|
||||
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.<br><br>
|
||||
You may now continue back to <a href="index.php">town</a>, and we hope you fair better next time.
|
||||
HTML;
|
||||
display($page, 'You Died');
|
||||
}
|
||||
|
||||
function handleMonsterTurn(&$userrow, $monsterrow)
|
||||
{
|
||||
$pagearray = "";
|
||||
if ($userrow["currentmonstersleep"] != 0) {
|
||||
$chancetowake = rand(1,15);
|
||||
if ($chancetowake > $userrow["currentmonstersleep"]) {
|
||||
$userrow["currentmonstersleep"] = 0;
|
||||
$pagearray .= "The monster has woken up.<br>";
|
||||
} else {
|
||||
$pagearray .= "The monster is still asleep.<br>";
|
||||
}
|
||||
}
|
||||
|
||||
if ($userrow["currentmonstersleep"] == 0) {
|
||||
$tohit = (int)ceil(mt_rand((int)($monsterrow["maxdam"] * 0.5), (int)$monsterrow["maxdam"]));
|
||||
$toblock = (int)ceil(mt_rand((int)($userrow["defensepower"] * 0.75), (int)$userrow["defensepower"]) / 4);
|
||||
$tododge = rand(1, 150);
|
||||
|
||||
if ($tododge <= sqrt($userrow["dexterity"])) {
|
||||
$tohit = 0;
|
||||
$pagearray .= "You dodge the monster's attack. No damage has been scored.<br>";
|
||||
$persondamage = 0;
|
||||
} else {
|
||||
$persondamage = max(1, $tohit - $toblock);
|
||||
if ($userrow["currentuberdefense"] != 0) {
|
||||
$persondamage -= (int)ceil($persondamage * ($userrow["currentuberdefense"]/100));
|
||||
}
|
||||
$persondamage = max(1, $persondamage);
|
||||
}
|
||||
|
||||
$pagearray .= "The monster attacks you for $persondamage damage.<br><br>";
|
||||
$userrow["currenthp"] -= $persondamage;
|
||||
|
||||
if ($userrow["currenthp"] <= 0) {
|
||||
$newgold = (int)ceil($userrow["gold"]/2);
|
||||
$newhp = (int)ceil($userrow["maxhp"]/4);
|
||||
db()->query("UPDATE users SET currenthp=?, currentaction='In Town', currentmonster=0, currentmonsterhp=0, currentmonstersleep=0, currentmonsterimmune=0, currentfight=0, latitude=0, longitude=0, gold=? WHERE id=?;", [
|
||||
$newhp, $newgold, $userrow['id']
|
||||
]);
|
||||
dead();
|
||||
}
|
||||
}
|
||||
return $pagearray;
|
||||
}
|
||||
|
||||
function handleSpellCast(&$userrow, $newspellrow)
|
||||
{
|
||||
$pagearray = "";
|
||||
switch ($newspellrow["type"]) {
|
||||
case 1: // Heal spell
|
||||
$newhp = min($userrow["currenthp"] + $newspellrow["attribute"], $userrow["maxhp"]);
|
||||
$userrow["currenthp"] = $newhp;
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, and gained {$newspellrow["attribute"]} Hit Points.<br><br>";
|
||||
break;
|
||||
case 2: // Hurt spell
|
||||
if ($userrow["currentmonsterimmune"] == 0) {
|
||||
$monsterdamage = mt_rand((int)(($newspellrow["attribute"]/6)*5), $newspellrow["attribute"]);
|
||||
$userrow["currentmonsterhp"] -= $monsterdamage;
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell for $monsterdamage damage.<br><br>";
|
||||
} else {
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.<br><br>";
|
||||
}
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
break;
|
||||
case 3: // Sleep spell
|
||||
if ($userrow["currentmonsterimmune"] != 2) {
|
||||
$userrow["currentmonstersleep"] = $newspellrow["attribute"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell. The monster is asleep.<br><br>";
|
||||
} else {
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, but the monster is immune to it.<br><br>";
|
||||
}
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
break;
|
||||
case 4: // +Damage spell
|
||||
$userrow["currentuberdamage"] = $newspellrow["attribute"];
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, and will gain {$newspellrow["attribute"]}% damage until the end of this fight.<br><br>";
|
||||
break;
|
||||
case 5: // +Defense spell
|
||||
$userrow["currentuberdefense"] = $newspellrow["attribute"];
|
||||
$userrow["currentmp"] -= $newspellrow["mp"];
|
||||
$pagearray = "You have cast the {$newspellrow["name"]} spell, and will gain {$newspellrow["attribute"]}% defense until the end of this fight.<br><br>";
|
||||
break;
|
||||
}
|
||||
return $pagearray;
|
||||
}
|
28
src/heal.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
// heal.php :: Handles stuff from the Quick Spells menu. (Healing spells only... other spells are handled in fight.php.)
|
||||
|
||||
function healspells($id)
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
$userspells = explode(",", $userrow["spells"]);
|
||||
$spellrow = get_spell($id);
|
||||
|
||||
// All the various ways to error out.
|
||||
$spell = false;
|
||||
foreach ($userspells as $b) if ($b == $id) $spell = true;
|
||||
if ($spell !== true) display("You have not yet learned this spell. Please go back and try again.", "Error");
|
||||
if ($spellrow["type"] != 1) display("This is not a healing spell. Please go back and try again.", "Error");
|
||||
if ($userrow["currentmp"] < $spellrow["mp"]) display("You do not have enough Magic Points to cast this spell. Please go back and try again.", "Error");
|
||||
if ($userrow["currentaction"] == "Fighting") display("You cannot use the Quick Spells list during a fight. Please go back and select the Healing Spell you wish to use from the Spells box on the main fighting screen to continue.", "Error");
|
||||
if ($userrow["currenthp"] == $userrow["maxhp"]) display("Your Hit Points are already full. You don't need to use a Healing spell now.", "Error");
|
||||
|
||||
$newhp = $userrow["currenthp"] + $spellrow["attribute"];
|
||||
if ($userrow["maxhp"] < $newhp) { $spellrow["attribute"] = $userrow["maxhp"] - $userrow["currenthp"]; $newhp = $userrow["currenthp"] + $spellrow["attribute"]; }
|
||||
$newmp = $userrow["currentmp"] - $spellrow["mp"];
|
||||
|
||||
db()->query('UPDATE users SET currenthp=?, currentmp=? WHERE id=?;', [$newhp, $newmp, $userrow['id']]);
|
||||
|
||||
display("You have cast the ".$spellrow["name"]." spell, and gained ".$spellrow["attribute"]." Hit Points. You can now continue <a href=\"index.php\">exploring</a>.", "Healing Spell");
|
||||
}
|
651
src/lib.php
|
@ -2,8 +2,8 @@
|
|||
|
||||
require_once __DIR__ . '/database.php';
|
||||
|
||||
define('VERSION', '1.2.5');
|
||||
define('BUILD', 'Reawaken');
|
||||
define('VERSION', '1.1.11');
|
||||
define('BUILD', '');
|
||||
define('START', microtime(true));
|
||||
|
||||
/**
|
||||
|
@ -19,81 +19,242 @@ function db(): Database
|
|||
*/
|
||||
function redirect(string $location): void
|
||||
{
|
||||
if (is_htmx()) {
|
||||
$target = isset($_SERVER['HTTP_HX_TARGET']) ? '#'.$_SERVER['HTTP_HX_TARGET'] : '#middle';
|
||||
$json = json_encode(['path' => $location, 'target' => $target]);
|
||||
header("HX-Location: $json");
|
||||
} else {
|
||||
header("Location: $location");
|
||||
}
|
||||
|
||||
header("Location: $location");
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a view with the given data. Can be used redundantly within the template.
|
||||
*/
|
||||
function render(string $path_to_base_view, array $data = []): string|false
|
||||
{
|
||||
ob_start();
|
||||
extract($data);
|
||||
require "../templates/$path_to_base_view.php";
|
||||
return ob_get_clean();
|
||||
function gettemplate($templatename) { // SQL query for the template.
|
||||
|
||||
$filename = __DIR__ . "/../templates/" . $templatename . ".php";
|
||||
include("$filename");
|
||||
return $template;
|
||||
|
||||
}
|
||||
|
||||
function parsetemplate($template, $array) { // Replace template with proper content.
|
||||
|
||||
foreach($array as $a => $b) {
|
||||
$template = str_replace("{{{$a}}}", $b, $template);
|
||||
}
|
||||
return $template;
|
||||
|
||||
}
|
||||
|
||||
function getmicrotime() { // Used for timing script operations.
|
||||
|
||||
list($usec, $sec) = explode(" ",microtime());
|
||||
return ((float)$usec + (float)$sec);
|
||||
|
||||
}
|
||||
|
||||
function prettydate($uglydate) { // Change the MySQL date format (YYYY-MM-DD) into something friendlier.
|
||||
|
||||
return date("F j, Y", mktime(0,0,0,substr($uglydate, 5, 2),substr($uglydate, 8, 2),substr($uglydate, 0, 4)));
|
||||
|
||||
}
|
||||
|
||||
function prettyforumdate($uglydate) { // Change the MySQL date format (YYYY-MM-DD) into something friendlier.
|
||||
|
||||
return date("F j, Y", mktime(0,0,0,substr($uglydate, 5, 2),substr($uglydate, 8, 2),substr($uglydate, 0, 4)));
|
||||
|
||||
}
|
||||
|
||||
function is_email($email) { // Thanks to "mail(at)philipp-louis.de" from php.net!
|
||||
|
||||
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
|
||||
|
||||
}
|
||||
|
||||
function makesafe($d) {
|
||||
return htmlentities($d);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace tags with given content.
|
||||
* Finalize page and output to browser.
|
||||
*/
|
||||
function parse(string $template, array $array): string
|
||||
function admindisplay($content, $title)
|
||||
{
|
||||
return strtr($template, array_combine(
|
||||
array_map(fn($key) => "{{{$key}}}", array_keys($array)),
|
||||
array_values($array)
|
||||
));
|
||||
}
|
||||
global $userrow, $controlrow;
|
||||
if (!isset($controlrow)) {
|
||||
$query = db()->query('SELECT * FROM control WHERE id=1 LIMIT 1;');
|
||||
$controlrow = $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the SQLite3 datetime format (YYYY-MM-DD HH:MM:SS) into something friendlier.
|
||||
*/
|
||||
function pretty_date(string $uglydate): string
|
||||
{
|
||||
return date("l, F j, Y", mktime(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
substr($uglydate, 5, 2), // Month
|
||||
substr($uglydate, 8, 2), // Day
|
||||
substr($uglydate, 0, 4) // Year
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Use htmlentities with UTF-8 encoding to ensure we're only outputting healthy, safe and effective HTML.
|
||||
*/
|
||||
function make_safe(string $content): string
|
||||
{
|
||||
return htmlentities($content, ENT_QUOTES, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Finalize admin page and output to browser.
|
||||
*/
|
||||
function display_admin($content, $title)
|
||||
{
|
||||
echo render('layouts/admin', [
|
||||
$page = parsetemplate(gettemplate("admin"), [
|
||||
"title" => $title,
|
||||
"content" => $content
|
||||
"content" => $content,
|
||||
"totaltime" => round(getmicrotime() - START, 4),
|
||||
"numqueries" => db()->count,
|
||||
"version" => VERSION,
|
||||
"build" => BUILD
|
||||
]);
|
||||
|
||||
echo "<html>\n" . $page;
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine what game skin to use. If a user is logged in then it uses their setting, otherwise defaults to 0 (retro).
|
||||
*/
|
||||
function game_skin(): int
|
||||
function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true, $badstart=false) { // Finalize page and output to browser.
|
||||
|
||||
global $numqueries, $userrow, $controlrow, $version, $build;
|
||||
if (!isset($controlrow)) {
|
||||
$query = db()->query('SELECT * FROM control WHERE id=1 LIMIT 1;');
|
||||
$controlrow = $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
if ($badstart == false) { global $starttime; } else { $starttime = $badstart; }
|
||||
|
||||
if ($rightnav == true) { $rightnav = gettemplate("rightnav"); } else { $rightnav = ""; }
|
||||
if ($leftnav == true) { $leftnav = gettemplate("leftnav"); } else { $leftnav = ""; }
|
||||
if ($topnav == true) {
|
||||
$topnav = "<a href=\"login.php?do=logout\"><img src=\"images/button_logout.gif\" alt=\"Log Out\" title=\"Log Out\" border=\"0\" /></a> <a href=\"help.php\"><img src=\"images/button_help.gif\" alt=\"Help\" title=\"Help\" border=\"0\" /></a>";
|
||||
} else {
|
||||
$topnav = "<a href=\"login.php?do=login\"><img src=\"images/button_login.gif\" alt=\"Log In\" title=\"Log In\" border=\"0\" /></a> <a href=\"users.php?do=register\"><img src=\"images/button_register.gif\" alt=\"Register\" title=\"Register\" border=\"0\" /></a> <a href=\"help.php\"><img src=\"images/button_help.gif\" alt=\"Help\" title=\"Help\" border=\"0\" /></a>";
|
||||
}
|
||||
|
||||
if (isset($userrow)) {
|
||||
|
||||
// Get userrow again, in case something has been updated.
|
||||
$userquery = db()->query('SELECT * FROM users WHERE id = ? LIMIT 1;', [$userrow['id']]);
|
||||
unset($userrow);
|
||||
$userrow = $userquery->fetchArray(SQLITE3_ASSOC);
|
||||
|
||||
// Current town name.
|
||||
if ($userrow["currentaction"] == "In Town") {
|
||||
$townquery = db()->query('SELECT * FROM towns WHERE latitude = ? AND longitude = ? LIMIT 1;', [$userrow["latitude"], $userrow["longitude"]]);
|
||||
$townrow = $townquery->fetchArray(SQLITE3_ASSOC);
|
||||
$userrow["currenttown"] = "Welcome to <b>".$townrow["name"]."</b>.<br><br>";
|
||||
} else {
|
||||
$userrow["currenttown"] = "";
|
||||
}
|
||||
|
||||
$userrow["forumslink"] = "<a href=\"forum.php\">Forum</a><br>";
|
||||
|
||||
// Format various userrow stuffs...
|
||||
if ($userrow["latitude"] < 0) { $userrow["latitude"] = $userrow["latitude"] * -1 . "S"; } else { $userrow["latitude"] .= "N"; }
|
||||
if ($userrow["longitude"] < 0) { $userrow["longitude"] = $userrow["longitude"] * -1 . "W"; } else { $userrow["longitude"] .= "E"; }
|
||||
$userrow["experience"] = number_format($userrow["experience"]);
|
||||
$userrow["gold"] = number_format($userrow["gold"]);
|
||||
if ($userrow["authlevel"] == 1) { $userrow["adminlink"] = "<a href=\"admin.php\">Admin</a><br>"; } else { $userrow["adminlink"] = ""; }
|
||||
|
||||
// HP/MP/TP bars.
|
||||
$stathp = ceil($userrow["currenthp"] / $userrow["maxhp"] * 100);
|
||||
if ($userrow["maxmp"] != 0) { $statmp = ceil($userrow["currentmp"] / $userrow["maxmp"] * 100); } else { $statmp = 0; }
|
||||
$stattp = ceil($userrow["currenttp"] / $userrow["maxtp"] * 100);
|
||||
$stattable = "<table width=\"100\"><tr><td width=\"33%\">\n";
|
||||
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
|
||||
if ($stathp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
|
||||
if ($stathp < 66 && $stathp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
|
||||
if ($stathp < 33) { $stattable .= "<div style=\"padding:0px; height:".$stathp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
|
||||
$stattable .= "</td></tr></table></td><td width=\"33%\">\n";
|
||||
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
|
||||
if ($statmp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
|
||||
if ($statmp < 66 && $statmp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
|
||||
if ($statmp < 33) { $stattable .= "<div style=\"padding:0px; height:".$statmp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
|
||||
$stattable .= "</td></tr></table></td><td width=\"33%\">\n";
|
||||
$stattable .= "<table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"padding:0px; width:15px; height:100px; border:solid 1px black; vertical-align:bottom;\">\n";
|
||||
if ($stattp >= 66) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_green.gif);\"><img src=\"images/bars_green.gif\" alt=\"\" /></div>"; }
|
||||
if ($stattp < 66 && $stattp >= 33) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_yellow.gif);\"><img src=\"images/bars_yellow.gif\" alt=\"\" /></div>"; }
|
||||
if ($stattp < 33) { $stattable .= "<div style=\"padding:0px; height:".$stattp."px; border-top:solid 1px black; background-image:url(images/bars_red.gif);\"><img src=\"images/bars_red.gif\" alt=\"\" /></div>"; }
|
||||
$stattable .= "</td></tr></table></td>\n";
|
||||
$stattable .= "</tr><tr><td>HP</td><td>MP</td><td>TP</td></tr></table>\n";
|
||||
$userrow["statbars"] = $stattable;
|
||||
|
||||
// Now make numbers stand out if they're low.
|
||||
if ($userrow["currenthp"] <= ($userrow["maxhp"]/5)) { $userrow["currenthp"] = "<blink><span class=\"highlight\"><b>*".$userrow["currenthp"]."*</b></span></blink>"; }
|
||||
if ($userrow["currentmp"] <= ($userrow["maxmp"]/5)) { $userrow["currentmp"] = "<blink><span class=\"highlight\"><b>*".$userrow["currentmp"]."*</b></span></blink>"; }
|
||||
|
||||
$spellquery = db()->query('SELECT id, name, type FROM spells;');
|
||||
$userspells = explode(",",$userrow["spells"]);
|
||||
$userrow["magiclist"] = "";
|
||||
while ($spellrow = $spellquery->fetchArray(SQLITE3_ASSOC)) {
|
||||
$spell = false;
|
||||
foreach($userspells as $a => $b) {
|
||||
if ($b == $spellrow["id"] && $spellrow["type"] == 1) { $spell = true; }
|
||||
}
|
||||
if ($spell == true) {
|
||||
$userrow["magiclist"] .= "<a href=\"index.php?do=spell:".$spellrow["id"]."\">".$spellrow["name"]."</a><br>";
|
||||
}
|
||||
}
|
||||
if ($userrow["magiclist"] == "") { $userrow["magiclist"] = "None"; }
|
||||
|
||||
// Travel To list.
|
||||
$townslist = explode(",",$userrow["towns"]);
|
||||
$townquery2 = db()->query('SELECT * FROM towns ORDER BY id;');
|
||||
$userrow["townslist"] = "";
|
||||
while ($townrow2 = $townquery2->fetchArray(SQLITE3_ASSOC)) {
|
||||
$town = false;
|
||||
foreach($townslist as $a => $b) {
|
||||
if ($b == $townrow2["id"]) { $town = true; }
|
||||
}
|
||||
if ($town == true) {
|
||||
$userrow["townslist"] .= "<a href=\"index.php?do=gotown:".$townrow2["id"]."\">".$townrow2["name"]."</a><br>\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$userrow = [];
|
||||
}
|
||||
|
||||
$page = parsetemplate(gettemplate("primary"), [
|
||||
"dkgamename" => $controlrow["gamename"],
|
||||
"title" => $title,
|
||||
"content" => $content,
|
||||
"rightnav" => parsetemplate($rightnav, $userrow),
|
||||
"leftnav" => parsetemplate($leftnav, $userrow),
|
||||
"topnav" => $topnav,
|
||||
"totaltime" => round(getmicrotime() - START, 4),
|
||||
"numqueries" => db()->count,
|
||||
"version" => VERSION,
|
||||
"build" => BUILD
|
||||
]);
|
||||
|
||||
echo "<html>\n" . $page;
|
||||
exit;
|
||||
}
|
||||
|
||||
function checkcookies()
|
||||
{
|
||||
return user() !== false ? user()->game_skin : 0;
|
||||
$row = false;
|
||||
|
||||
if (isset($_COOKIE["dkgame"])) {
|
||||
// COOKIE FORMAT:
|
||||
// {ID} {USERNAME} {PASSWORDHASH} {REMEMBERME}
|
||||
$theuser = explode(" ",$_COOKIE["dkgame"]);
|
||||
$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 = ?;', [$theuser[0]]);
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a cookie with secure and HTTP-only flags.
|
||||
*/
|
||||
function set_cookie($name, $value, $expires)
|
||||
{
|
||||
setcookie($name, $value, [
|
||||
'expires' => $expires,
|
||||
'path' => '/',
|
||||
'domain' => '', // Defaults to the current domain
|
||||
'secure' => true, // Ensure the cookie is only sent over HTTPS
|
||||
'httponly' => true, // Prevent access to cookie via JavaScript
|
||||
'samesite' => 'Strict' // Enforce SameSite=Strict
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current control row from the database.
|
||||
*/
|
||||
function get_control_row(): array|false
|
||||
{
|
||||
$query = db()->query('SELECT * FROM control WHERE id = 1 LIMIT 1;');
|
||||
if ($query === false) return false;
|
||||
return $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -101,15 +262,9 @@ function game_skin(): int
|
|||
*/
|
||||
function get_town_by_xy(int $x, int $y): array|false
|
||||
{
|
||||
$cache_tag = "town-$x-$y";
|
||||
|
||||
if (!isset($GLOBALS['cache'][$cache_tag])) {
|
||||
$query = db()->query('SELECT * FROM towns WHERE longitude = ? AND latitude = ? LIMIT 1;', [$x, $y]);
|
||||
if ($query === false) return false;
|
||||
$GLOBALS['cache'][$cache_tag] = $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
return $GLOBALS['cache'][$cache_tag];
|
||||
$query = db()->query('SELECT * FROM towns WHERE longitude = ? AND latitude = ? LIMIT 1;', [$x, $y]);
|
||||
if ($query === false) return false;
|
||||
return $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -122,19 +277,6 @@ function get_town_by_id(int $id): array|false
|
|||
return $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a user's data by their ID, username or email.
|
||||
*/
|
||||
function get_user(int|string $id, string $data = '*'): array|false
|
||||
{
|
||||
$query = db()->query(
|
||||
"SELECT $data FROM users WHERE id=? OR username=? COLLATE NOCASE OR email=? COLLATE NOCASE LIMIT 1;",
|
||||
[$id, $id, $id]
|
||||
);
|
||||
if ($query === false) return false;
|
||||
return $query->fetchArray(SQLITE3_ASSOC);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item by it's ID.
|
||||
*/
|
||||
|
@ -201,346 +343,3 @@ function token($length = 32): string
|
|||
{
|
||||
return bin2hex(random_bytes($length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate any given array of data against rules. Returns [valid, data, error]. Data contains the trimmed
|
||||
* values from the input array. Note: all fields with rules are assumed to be required, unless the optional
|
||||
* rule is used.
|
||||
*
|
||||
* Example: ['required', 'no-trim', 'length:5-20', 'alphanum-spaces']
|
||||
*/
|
||||
function validate(array $input_data, array $rules): array
|
||||
{
|
||||
$data = [];
|
||||
$errors = [];
|
||||
|
||||
foreach ($rules as $field => $field_rules) {
|
||||
$value = $input_data[$field] ?? null;
|
||||
$field_name = ucfirst(str_replace('_', ' ', $field));
|
||||
$is_required = true;
|
||||
$default_value = null;
|
||||
|
||||
if (in_array('optional', $field_rules)) {
|
||||
$is_required = false;
|
||||
}
|
||||
|
||||
foreach ($field_rules as $rule) {
|
||||
if (strpos($rule, 'default:') === 0) {
|
||||
$default_value = substr($rule, 8);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (($value === null || $value === '') && $default_value !== null) {
|
||||
$value = $default_value;
|
||||
}
|
||||
|
||||
if (($value === null || $value === '') && !$is_required) continue;
|
||||
|
||||
if ($is_required && ($value === null || $value === '')) {
|
||||
$errors[$field][] = "{$field_name} is required.";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!in_array('no-trim', $field_rules)) {
|
||||
$value = trim($value);
|
||||
}
|
||||
|
||||
$data[$field] = $value;
|
||||
|
||||
foreach ($field_rules as $rule) {
|
||||
// Parse rule and arguments
|
||||
if (strpos($rule, ':') !== false) {
|
||||
list($rule_name, $rule_args) = explode(':', $rule, 2);
|
||||
} else {
|
||||
$rule_name = $rule;
|
||||
$rule_args = null;
|
||||
}
|
||||
|
||||
if ($rule_name === 'optional') continue;
|
||||
|
||||
switch ($rule_name) {
|
||||
case 'bool':
|
||||
if (!isset($input_data[$field]) || empty($value)) {
|
||||
$value = false;
|
||||
} else {
|
||||
$value = filter_var($value, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
|
||||
|
||||
if ($value === null) {
|
||||
$errors[$field][] = "{$field_name} must be a valid boolean value.";
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case 'length':
|
||||
list($min, $max) = explode('-', $rule_args);
|
||||
$len = strlen((string)$value);
|
||||
if ($len < $min || $len > $max) {
|
||||
$errors[$field][] = "{$field_name} must be between {$min} and {$max} characters.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'alphanum':
|
||||
if (!preg_match('/^[a-zA-Z0-9]+$/', $value)) {
|
||||
$errors[$field][] = "{$field_name} must contain only letters and numbers.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'alpha':
|
||||
if (!preg_match('/^[a-zA-Z]+$/', $value)) {
|
||||
$errors[$field][] = "{$field_name} must contain only letters and numbers.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'alphanum-spaces':
|
||||
if (!preg_match('/^[a-zA-Z0-9\s_]+$/', $value)) {
|
||||
$errors[$field][] = "{$field_name} must contain only letters, numbers, spaces, and underscores.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'alpha-spaces':
|
||||
if (!preg_match('/^[a-zA-Z\s_]+$/', $value)) {
|
||||
$errors[$field][] = "{$field_name} must contain only letters, numbers, spaces, and underscores.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'email':
|
||||
if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
|
||||
$errors[$field][] = "{$field_name} must be a valid email address.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'int':
|
||||
if (filter_var($value, FILTER_VALIDATE_INT) === false) {
|
||||
$errors[$field][] = "{$field_name} must be an integer.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'min':
|
||||
if ($value < $rule_args) {
|
||||
$errors[$field][] = "{$field_name} must be at least {$rule_args}.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'max':
|
||||
if ($value > $rule_args) {
|
||||
$errors[$field][] = "{$field_name} must be no more than {$rule_args}.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'regex':
|
||||
if (!preg_match($rule_args, $value)) {
|
||||
$errors[$field][] = "{$field_name} does not match the required pattern.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'in':
|
||||
$options = explode(',', $rule_args);
|
||||
if (!in_array($value, $options)) {
|
||||
$errors[$field][] = "{$field_name} must be one of: " . implode(', ', $options);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'confirm':
|
||||
$field_to_confirm = substr($field, 8);
|
||||
$confirm_value = $data[$field_to_confirm] ?? '';
|
||||
$confirm_field_name = ucfirst(str_replace('_', ' ', $field_to_confirm));
|
||||
if ($value !== $confirm_value) {
|
||||
$errors[$field][] = "{$field_name} must match {$confirm_field_name}.";
|
||||
}
|
||||
break;
|
||||
|
||||
case 'unique':
|
||||
list($table, $column) = explode(',', $rule_args, 2);
|
||||
if (db()->exists($table, $column, $value)) {
|
||||
$errors[$field][] = "{$field_name} must be unique.";
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($input_data as $field => $value) {
|
||||
if (!isset($data[$field])) $data[$field] = trim($value);
|
||||
}
|
||||
|
||||
return [
|
||||
'valid' => empty($errors),
|
||||
'data' => $data,
|
||||
'errors' => $errors
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a ul list from `validate()`'s errors.
|
||||
*/
|
||||
function ul_from_validate_errors(array $errors): string
|
||||
{
|
||||
$string = '<ul>';
|
||||
foreach ($errors as $field => $errors) {
|
||||
$string .= '<li>';
|
||||
foreach ($errors as $error) $string .= $error;
|
||||
$string .= '</li>';
|
||||
}
|
||||
return $string . '</ul>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the environment variables from the .env file.
|
||||
*/
|
||||
function env_load(string $filePath): void
|
||||
{
|
||||
if (!file_exists($filePath)) throw new Exception("The .env file does not exist. (el)");
|
||||
|
||||
$lines = file($filePath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
||||
foreach ($lines as $line) {
|
||||
$line = trim($line);
|
||||
|
||||
// Skip lines that are empty after trimming or are comments
|
||||
if ($line === '' || str_starts_with($line, '#')) continue;
|
||||
|
||||
// Skip lines without an '=' character
|
||||
if (strpos($line, '=') === false) continue;
|
||||
|
||||
[$name, $value] = explode('=', $line, 2);
|
||||
|
||||
$name = trim($name);
|
||||
$value = trim($value, " \t\n\r\0\x0B\"'"); // Trim whitespace and quotes
|
||||
|
||||
if (!array_key_exists($name, $_SERVER) && !array_key_exists($name, $_ENV)) {
|
||||
putenv("$name=$value");
|
||||
$_ENV[$name] = $value;
|
||||
$_SERVER[$name] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve an environment variable.
|
||||
*/
|
||||
function env(string $key, mixed $default = null): mixed
|
||||
{
|
||||
$v = $_ENV[$key] ?? $_SERVER[$key] ?? (getenv($key) ?: $default);
|
||||
return match(true) {
|
||||
$v === 'true' => true,
|
||||
$v === 'false' => false,
|
||||
is_numeric($v) => (int) $v,
|
||||
is_float($v) => (float) $v,
|
||||
default => $v
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data on spells from a given list of IDs.
|
||||
*/
|
||||
function get_spells_from_list(array|string $spell_ids): array|false
|
||||
{
|
||||
if (is_string($spell_ids)) $spell_ids = explode(',', $spell_ids);
|
||||
$placeholders = implode(',', array_fill(0, count($spell_ids), '?'));
|
||||
$query = db()->query("SELECT id, name, type FROM spells WHERE id IN($placeholders)", $spell_ids);
|
||||
if ($query === false) return false;
|
||||
$rows = [];
|
||||
while ($row = $query->fetchArray(SQLITE3_ASSOC)) $rows[] = $row;
|
||||
return !empty($rows) ? $rows : false;
|
||||
}
|
||||
|
||||
function generate_stat_bar(int $current, int $max): string
|
||||
{
|
||||
$percent = $max > 0 ? round(max(0, $current) / $max * 100, 4) : 0;
|
||||
if ($percent < 0) $percent = 0;
|
||||
if ($percent > 100) $percent = 100;
|
||||
$color = $percent >= 66 ? 'green' : ($percent >= 33 ? 'yellow' : 'red');
|
||||
|
||||
return <<<HTML
|
||||
<div class="stat-bar" style="width: 15px; height: 100px; border: solid 1px black;">
|
||||
<div style="height: $percent%; background-image: url(/img/bars_$color.gif);"></div>
|
||||
</div>
|
||||
HTML;
|
||||
}
|
||||
|
||||
function create_stat_table(): string
|
||||
{
|
||||
$stat_table = '<div class="stat-table">' .
|
||||
'<div class="stat-row">' .
|
||||
'<div class="stat-col">' . generate_stat_bar((int)user()->currenthp, (int)user()->maxhp) . '<div>HP</div></div>' .
|
||||
'<div class="stat-col">' . generate_stat_bar((int)user()->currentmp, (int)user()->maxmp) . '<div>MP</div></div>' .
|
||||
'<div class="stat-col">' . generate_stat_bar((int)user()->currenttp, (int)user()->maxtp) . '<div>TP</div></div>' .
|
||||
'</div>' .
|
||||
'</div>';
|
||||
|
||||
return $stat_table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user in the GLOBALS state, if there is one. If not, populates it if there is a SESSION user_id.
|
||||
*/
|
||||
function user(): User|false
|
||||
{
|
||||
$GLOBALS['state']['user'] ??= (isset($_SESSION['user_id']) ? User::find($_SESSION['user_id']) : false);
|
||||
return $GLOBALS['state']['user'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether a request is from HTMX. If HTMX is trying to restore history, we will say no in order to render
|
||||
* full pages.
|
||||
*/
|
||||
function is_htmx(): bool
|
||||
{
|
||||
if (isset($_SERVER['HTTP_HX_HISTORY_RESTORE_REQUEST']) && $_SERVER['HTTP_HX_HISTORY_RESTORE_REQUEST'] === 'true') return false;
|
||||
return isset($_SERVER['HTTP_HX_REQUEST']) && $_SERVER['HTTP_HX_REQUEST'] === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether the request is POST.
|
||||
*/
|
||||
function is_post(): bool
|
||||
{
|
||||
return $_SERVER['REQUEST_METHOD'] === 'POST';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current page title per updates. Optionally set a new title.
|
||||
*/
|
||||
function page_title(string $new_title = ''): string
|
||||
{
|
||||
if ($new_title) return $GLOBALS['state']['new-page-title'] = $new_title;
|
||||
return $GLOBALS['state']['new-page-title'] ?? env('game_name');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the response for the browser based on the request context. The main point is to seperate the handling
|
||||
* of HTMX responses from normal responses.
|
||||
*/
|
||||
function render_response(array $uri, string $content): string
|
||||
{
|
||||
if ($uri[0] === 'babblebox') return $content;
|
||||
|
||||
if (is_htmx()) {
|
||||
header('HX-Push-Url: '.$_SERVER['REQUEST_URI']);
|
||||
|
||||
$content .= '<title>'.page_title().'</title>';
|
||||
|
||||
$content .= Render\debug_db_info();
|
||||
|
||||
if (env('debug', false)) {
|
||||
$content .= Render\debug_query_log();
|
||||
}
|
||||
|
||||
if ($GLOBALS['state']['user-state-changed'] ?? false) {
|
||||
$content .= Render\right_nav();
|
||||
$content .= Render\left_nav();
|
||||
}
|
||||
}
|
||||
|
||||
return Render\content($content, page_layout());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get/set page layout through GLOBALS state.
|
||||
*/
|
||||
function page_layout(string $layout = ''): string
|
||||
{
|
||||
if ($layout === '') return $GLOBALS['state']['page-layout'] ?? 'layouts/primary';
|
||||
return $GLOBALS['state']['page-layout'] = $layout;
|
||||
}
|
||||
|
|
109
src/mail.php
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Send an email or log email details
|
||||
*
|
||||
* @param string $to Recipient email address
|
||||
* @param string $subject Email subject
|
||||
* @param string $message Email body
|
||||
* @param array $options Optional configuration options
|
||||
* @return bool Success status of email sending or logging
|
||||
*/
|
||||
function send_email(string $to, string $subject, string $message, array $options = []): bool
|
||||
{
|
||||
// Default configuration
|
||||
$config = array_merge([
|
||||
'from' => env('admin_email', 'noreply@'.$_SERVER['SERVER_NAME']),
|
||||
'log_path' => '../logs/email.log',
|
||||
'method' => 'smtp', // 'smtp' or 'log'
|
||||
'smtp_host' => env('smtp_host', 'localhost'),
|
||||
'smtp_port' => env('smtp_port', 25),
|
||||
'smtp_username' => env('smtp_username', null),
|
||||
'smtp_password' => env('smtp_password', null),
|
||||
'smtp_encryption' => env('smtp_encryption', null)
|
||||
], $options);
|
||||
|
||||
// Always send to log during debug
|
||||
if (env('debug', false)) $config['method'] = 'log';
|
||||
|
||||
// Validate input
|
||||
if (empty($to) || empty($subject) || empty($message)) {
|
||||
error_log('Email sending failed: Missing required parameters');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prepare email headers
|
||||
$headers = [
|
||||
'From: ' . $config['from'],
|
||||
'X-Mailer: PHP/' . phpversion()
|
||||
];
|
||||
|
||||
// Choose sending method
|
||||
switch ($config['method']) {
|
||||
case 'log':
|
||||
// Log email details to file
|
||||
$logMessage = sprintf(
|
||||
"[%s] To: %s, Subject: %s, Message:\n\n %s\n\n\n\n",
|
||||
date('Y-m-d H:i:s'),
|
||||
$to,
|
||||
$subject,
|
||||
$message
|
||||
);
|
||||
|
||||
// Attempt to log to file
|
||||
if (file_put_contents($config['log_path'], $logMessage, FILE_APPEND) === false) {
|
||||
error_log('Failed to write to log file: ' . $config['log_path']);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
case 'smtp':
|
||||
default:
|
||||
// Attempt to send via SMTP
|
||||
try {
|
||||
// Prepare SMTP connection
|
||||
$smtpConfig = [
|
||||
'host' => $config['smtp_host'],
|
||||
'port' => $config['smtp_port'],
|
||||
'username' => $config['smtp_username'],
|
||||
'password' => $config['smtp_password'],
|
||||
'encryption' => $config['smtp_encryption']
|
||||
];
|
||||
|
||||
// Send email using PHP's mail function (basic SMTP)
|
||||
$result = mail(
|
||||
$to,
|
||||
$subject,
|
||||
$message,
|
||||
implode("\r\n", $headers)
|
||||
);
|
||||
|
||||
if (!$result) {
|
||||
error_log('SMTP email sending failed');
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
error_log('Email sending error: ' . $e->getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Example usage:
|
||||
// Send via SMTP
|
||||
// send_email('recipient@example.com', 'Test Subject', 'Email body text');
|
||||
|
||||
// Send via log
|
||||
// send_email('recipient@example.com', 'Test Subject', 'Email body text', ['method' => 'log']);
|
||||
|
||||
// Customize SMTP settings
|
||||
// send_email('recipient@example.com', 'Test Subject', 'Email body text', [
|
||||
// 'method' => 'smtp',
|
||||
// 'smtp_host' => 'smtp.yourserver.com',
|
||||
// 'smtp_port' => 587,
|
||||
// 'smtp_username' => 'your_username',
|
||||
// 'smtp_password' => 'your_password',
|
||||
// 'smtp_encryption' => 'tls'
|
||||
// ]);
|
98
src/math.php
|
@ -1,98 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Math;
|
||||
|
||||
/*
|
||||
Internal math functions, such as to calculate EXP, HP, stats, etc.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Calculates the ***total*** EXP required at a particular level in order to level up.
|
||||
*/
|
||||
function calculate_exp(int $level, int $growth_rate): int
|
||||
{
|
||||
if ($level < 1) throw new \InvalidArgumentException("Level must be 1 or greater");
|
||||
|
||||
// Growth rates:
|
||||
// 0 = Erratic
|
||||
// 1 = Fast
|
||||
// 2 = Medium Fast
|
||||
// 3 = Medium Slow
|
||||
// 4 = Slow
|
||||
// 5 = Fluctuating
|
||||
|
||||
if ($growth_rate < 0 || $growth_rate > 5) throw new \InvalidArgumentException("Growth rate must be between 0 and 5");
|
||||
|
||||
return match($growth_rate) {
|
||||
0 => calculate_erratic_exp($level),
|
||||
1 => (4 * pow($level, 3)) / 5,
|
||||
2 => pow($level, 3),
|
||||
3 => ((6 * pow($level, 3)) / 5) - (15 * pow($level, 2)) + (100 * $level) - 140,
|
||||
4 => (5 * pow($level, 3)) / 4,
|
||||
5 => calculate_fluctuating_exp($level),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the ***total*** EXP for a given level in the Erratic formula.
|
||||
*/
|
||||
function calculate_erratic_exp(int $level): int
|
||||
{
|
||||
if ($level <= 50) {
|
||||
return (pow($level, 3) * (100 - $level)) / 50;
|
||||
} elseif ($level <= 68) {
|
||||
return (pow($level, 3) * (150 - $level)) / 100;
|
||||
} elseif ($level <= 98) {
|
||||
return (pow($level, 3) * ((1911 - (10 * $level)) / 3)) / 500;
|
||||
} else {
|
||||
return (pow($level, 3) * (160 - $level)) / 100;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the ***total*** EXP for a given level in the Fluctuating formula.
|
||||
*/
|
||||
function calculate_fluctuating_exp(int $level): int
|
||||
{
|
||||
if ($level <= 15) {
|
||||
return pow($level, 3) * ((((($level + 1) / 3) + 24) / 50));
|
||||
} elseif ($level <= 36) {
|
||||
return pow($level, 3) * (($level + 14) / 50);
|
||||
} else {
|
||||
return pow($level, 3) * ((($level / 2) + 32) / 50);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a points total from a base. Modes: 1 (weak), 2 (normal), 3 (strong)
|
||||
*/
|
||||
function calculate_points(int $base_points, int $level, int $mode = 2): int
|
||||
{
|
||||
if ($level < 1) throw new \InvalidArgumentException("Level must be 1 or greater");
|
||||
|
||||
$growth_multiplier = match($mode) {
|
||||
1 => 0.15,
|
||||
2 => 0.3,
|
||||
3 => 0.6,
|
||||
default => throw new \InvalidArgumentException("Invalid mode. Use 1 (weak), 2 (normal), or 3 (strong)")
|
||||
};
|
||||
|
||||
return floor((2 * $base_points * $level * $growth_multiplier) / 100) + $level + 10;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate a stat total from a base. Modes: 1 (weak), 2 (normal), 3 (strong)
|
||||
*/
|
||||
function calculate_stat(int $base_stat, int $level, int $mode = 2): int
|
||||
{
|
||||
if ($level < 1) throw new \InvalidArgumentException("Level must be 1 or greater");
|
||||
|
||||
$growth_multiplier = match($mode) {
|
||||
1 => 0.15,
|
||||
2 => 0.3,
|
||||
3 => 0.6,
|
||||
default => throw new \InvalidArgumentException("Invalid mode. Use 1 (weak), 2 (normal), or 3 (strong)")
|
||||
};
|
||||
|
||||
return floor((2 * $base_stat * $level * $growth_multiplier) / 100) + 5;
|
||||
}
|
|
@ -1,46 +0,0 @@
|
|||
<?php
|
||||
|
||||
class Model
|
||||
{
|
||||
protected string $table_name = '';
|
||||
protected array $original_data = [];
|
||||
protected array $changes = [];
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->original_data = $data;
|
||||
$this->changes = [];
|
||||
}
|
||||
|
||||
public function __get(string $key): mixed
|
||||
{
|
||||
return array_key_exists($key, $this->changes) ? $this->changes[$key] : $this->original_data[$key] ?? false;
|
||||
}
|
||||
|
||||
public function __set(string $key, mixed $value): void
|
||||
{
|
||||
if (array_key_exists($key, $this->original_data)) {
|
||||
if ($value !== $this->original_data[$key]) $this->changes[$key] = $value;
|
||||
} else {
|
||||
throw new InvalidArgumentException("Attempted to write to $key, which doesn't exist in the data for this model.");
|
||||
}
|
||||
}
|
||||
|
||||
public function save(): bool
|
||||
{
|
||||
if (empty($this->changes)) return true;
|
||||
|
||||
$placeholders = [];
|
||||
$values = [];
|
||||
foreach ($this->changes as $key => $value) {
|
||||
$placeholders[] = "$key=?";
|
||||
$values[] = $value;
|
||||
}
|
||||
|
||||
$values[] = $this->id;
|
||||
$query = 'UPDATE ' . $this->table_name . ' SET ' . implode(', ', $placeholders) . ' WHERE id = ?;';
|
||||
|
||||
$result = db()->query($query, $values);
|
||||
return $result === false ? false : true;
|
||||
}
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
<?php
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
protected string $table_name = 'users';
|
||||
|
||||
/**
|
||||
* Find a user by their ID, username or email. Returns false on any failure.
|
||||
*/
|
||||
public static function find(int|string $id): User|false
|
||||
{
|
||||
$query = db()->query(
|
||||
"SELECT * FROM users WHERE id=? OR username=? COLLATE NOCASE OR email=? COLLATE NOCASE LIMIT 1;",
|
||||
[$id, $id, $id]
|
||||
);
|
||||
if ($query === false) return false;
|
||||
$data = $query->fetchArray(SQLITE3_ASSOC);
|
||||
if ($data === false) return false;
|
||||
return new User($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of spells from this user's spell list.
|
||||
*/
|
||||
public function spells(): array|false
|
||||
{
|
||||
return get_spells_from_list($this->spells);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restore all HP, MP, and TP values to their max.
|
||||
*/
|
||||
public function restore_points(): User
|
||||
{
|
||||
$this->currenthp = $this->maxhp;
|
||||
$this->currentmp = $this->maxmp;
|
||||
$this->currenttp = $this->maxtp;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a manual update to online time for this user.
|
||||
*/
|
||||
public function update_online_time(): void
|
||||
{
|
||||
if ($this->onlinetime && strtotime($this->onlinetime) > strtotime('-9 minutes')) return;
|
||||
db()->query('UPDATE users SET onlinetime=CURRENT_TIMESTAMP WHERE id=?;', [$this->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Heal HP by a given amount. Caps to max HP. Returns number of points restored.
|
||||
*/
|
||||
function restore_hp(int $amount): int
|
||||
{
|
||||
$initial_hp = $this->currenthp;
|
||||
$this->currenthp += $amount;
|
||||
if ($this->currenthp > $this->maxhp) $this->currenthp = $this->maxhp;
|
||||
return $this->currenthp - $initial_hp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Save works just as it does on the Model class. In our case, though, user state changing may necessitate
|
||||
* OOB swaps for parts of the UI that have user data displayed. Left and right nav, for example. In these cases,
|
||||
* we set a flag in GLOBALS state to signify this.
|
||||
*/
|
||||
public function save(): bool
|
||||
{
|
||||
if (empty($this->changes)) return true;
|
||||
|
||||
$placeholders = [];
|
||||
$values = [];
|
||||
foreach ($this->changes as $key => $value) {
|
||||
$placeholders[] = "$key=?";
|
||||
$values[] = $value;
|
||||
}
|
||||
|
||||
$values[] = $this->id;
|
||||
$query = 'UPDATE ' . $this->table_name . ' SET ' . implode(', ', $placeholders) . ' WHERE id = ?;';
|
||||
|
||||
$result = db()->query($query, $values);
|
||||
if ($result === false) return false;
|
||||
$GLOBALS['state']['user-state-changed'] = true;
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace Render;
|
||||
|
||||
/*
|
||||
This file contains functions to render various UI elements. The goal is to begin shifting elements in the game
|
||||
to HTMX/AJAX for more fluid gameplay.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Prepare content for final render. If the request is HTMX-based, will return just the content passed to it. Otherwise
|
||||
* it will render() onto $layout with some additional bits.
|
||||
*/
|
||||
function content(string $content, string $layout = 'layouts/primary'): string
|
||||
{
|
||||
if (is_htmx()) return $content;
|
||||
return render($layout, ['content' => $content]);
|
||||
}
|
||||
|
||||
function debug_db_info(): string {
|
||||
$total_time = round(microtime(true) - START, 4);
|
||||
$htmx = is_htmx() ? ' (htmx)' : '';
|
||||
return '<div id="debug-db-info" hx-swap-oob="true">'. $total_time . ' Seconds, ' . db()->count . ' Queries'.$htmx.'</div>';
|
||||
}
|
||||
|
||||
function right_nav(): string
|
||||
{
|
||||
if (user() === false) return '';
|
||||
|
||||
// Flashy numbers if they're low
|
||||
$hp = (user()->currenthp <= (user()->maxhp / 5)) ? "<blink><span class=\"highlight\"><b>*" . user()->currenthp . "*</b></span></blink>" : user()->currenthp;
|
||||
$mp = (user()->currentmp <= (user()->maxmp / 5)) ? "<blink><span class=\"highlight\"><b>*" . user()->currentmp . "*</b></span></blink>" : user()->currentmp;
|
||||
|
||||
$template = render('right_nav', ['hp' => $hp, 'mp' => $mp]);
|
||||
if (is_htmx()) $template = '<section id="right" hx-swap-oob="true">'.$template."</section>";
|
||||
return $template;
|
||||
}
|
||||
|
||||
function left_nav(): string
|
||||
{
|
||||
if (user() === false) return '';
|
||||
|
||||
$template = render('left_nav');
|
||||
if (is_htmx()) $template = '<section id="left" hx-swap-oob="true">'.$template."</section>";
|
||||
return $template;
|
||||
}
|
||||
|
||||
function babblebox(): string
|
||||
{
|
||||
return render('babblebox', ['messages' => babblebox_messages()]);
|
||||
}
|
||||
|
||||
function debug_query_log(): string
|
||||
{
|
||||
$html = '<pre id="debug-query-log" hx-swap-oob="true">';
|
||||
foreach (db()->log as $record) {
|
||||
$query_string = str_replace(["\r\n", "\n", "\r"], ' ', $record[0]);
|
||||
$error_string = !empty($record[2]) ? '// '.$record[2] : '';
|
||||
$html .= '<div>['.round($record[1], 2)."s] {$query_string}{$error_string}</div>";
|
||||
}
|
||||
return $html . '</pre>';
|
||||
}
|
187
src/router.php
|
@ -1,187 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* A radix-trie based URI router. Seperates URIs into chunks, then turns those chunks into an efficiently parsed
|
||||
* trie. Supports URI variables!
|
||||
*/
|
||||
class Router
|
||||
{
|
||||
/**
|
||||
* List of valid HTTP verbs.
|
||||
*/
|
||||
private const VALID_METHODS = ['GET', 'POST', 'PUT', 'DELETE', 'PATCH', 'HEAD', 'OPTIONS'];
|
||||
|
||||
/**
|
||||
* The tree of currently registered routes.
|
||||
*/
|
||||
private array $routes = [];
|
||||
|
||||
/**
|
||||
* Store the last inserted node so we can register middleware and attributes to it.
|
||||
*/
|
||||
private array $last_inserted_node;
|
||||
|
||||
/**
|
||||
* Add a route to the route tree. The route must be a URI path, and contain dynamic segments
|
||||
* using a colon prefix. (:id, :slug, etc)
|
||||
*
|
||||
* Example:
|
||||
* `$r->add($routes, 'GET', '/posts/:id', function($id) { echo "Viewing post $id"; });`
|
||||
*/
|
||||
public function add(string $method, string $route, callable $handler): Router
|
||||
{
|
||||
$this->validateMethod($method);
|
||||
$this->validateRoute($route);
|
||||
|
||||
$segments = $route === '/' ? [''] : explode('/', trim($route, '/'));
|
||||
|
||||
$node = &$this->routes;
|
||||
foreach ($segments as $segment) {
|
||||
$segment = str_starts_with($segment, ':') ? ':x' : $segment;
|
||||
if ($segment === '') continue;
|
||||
$node = &$node[$segment];
|
||||
}
|
||||
|
||||
$node[$method] = [
|
||||
'handler' => $handler,
|
||||
'middleware' => []
|
||||
];
|
||||
|
||||
$this->last_inserted_node = &$node[$method];
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a lookup in the route tree for a given method and URI. Returns an array with a result code,
|
||||
* a handler if found, and any dynamic parameters. Codes are 200 for success, 404 for not found, and
|
||||
* 405 for method not allowed.
|
||||
*
|
||||
* @return array ['code', 'handler', 'params']
|
||||
*/
|
||||
public function lookup(string $method, string $uri): array|int
|
||||
{
|
||||
$node = $this->routes;
|
||||
$params = [];
|
||||
|
||||
if ($uri === '/') return $node[$method] ?? 405;
|
||||
|
||||
foreach (explode('/', trim($uri, '/')) as $segment) {
|
||||
if (isset($node[$segment])) {
|
||||
$node = $node[$segment];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isset($node[':x'])) {
|
||||
$params[] = $segment;
|
||||
$node = $node[':x'];
|
||||
continue;
|
||||
}
|
||||
|
||||
return 404;
|
||||
}
|
||||
|
||||
$node[$method]['params'] = $params;
|
||||
return $node[$method] ?? 405;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a middleware function to the last inserted node's stack.
|
||||
*/
|
||||
public function middleware(callable $middleware): Router
|
||||
{
|
||||
$this->last_inserted_node['middleware'][] = $middleware;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand to register a GET route.
|
||||
*/
|
||||
public function get(string $route, callable $handler): Router
|
||||
{
|
||||
return $this->add('GET', $route, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand to register a POST route.
|
||||
*/
|
||||
public function post(string $route, callable $handler): Router
|
||||
{
|
||||
return $this->add('POST', $route, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand to register a PUT route.
|
||||
*/
|
||||
public function put(string $route, callable $handler): Router
|
||||
{
|
||||
return $this->add('PUT', $route, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand to register a DELETE route.
|
||||
*/
|
||||
public function delete(string $route, callable $handler): Router
|
||||
{
|
||||
return $this->add('DELETE', $route, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shorthand to register a PATCH route.
|
||||
*/
|
||||
public function patch(string $route, callable $handler): Router
|
||||
{
|
||||
return $this->add('PATCH', $route, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register multiple verbs to the same route.
|
||||
*/
|
||||
public function many(array $methods, string $route, callable $handler): Router
|
||||
{
|
||||
foreach ($methods as $method) $this->add($method, $route, $handler);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Register all verbs to the same route.
|
||||
*/
|
||||
public function any(string $route, callable $handler): Router
|
||||
{
|
||||
foreach (SELF::VALID_METHODS as $method) $this->add($method, $route, $handler);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some pages function entirely as forms; thus we can shorthand a GET/POST route.
|
||||
*/
|
||||
public function form(string $route, callable $handler): Router
|
||||
{
|
||||
return $this->many(['GET', 'POST'], $route, $handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the given method against valid HTTP verbs.
|
||||
*/
|
||||
private function validateMethod(string $method): void
|
||||
{
|
||||
if (!in_array($method, self::VALID_METHODS)) {
|
||||
throw new InvalidArgumentException("Invalid HTTP method: $method");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a new route follows expected formatting.
|
||||
*/
|
||||
private function validateRoute(string $route): void
|
||||
{
|
||||
if ($route === '') {
|
||||
throw new InvalidArgumentException("Route cannot be empty");
|
||||
}
|
||||
|
||||
// Ensure route starts with a slash
|
||||
if (!str_starts_with($route, '/')) {
|
||||
throw new InvalidArgumentException("Route must start with a '/'");
|
||||
}
|
||||
}
|
||||
}
|
337
src/towns.php
Normal file
|
@ -0,0 +1,337 @@
|
|||
<?php
|
||||
|
||||
// towns.php :: Handles all actions you can do in town.
|
||||
|
||||
/**
|
||||
* Staying at the inn resets all expendable stats to their max values.
|
||||
*/
|
||||
function inn()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
$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");
|
||||
}
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$newgold = $userrow["gold"] - $townrow["innprice"];
|
||||
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"])) {
|
||||
redirect('index.php');
|
||||
} else {
|
||||
$title = "Inn";
|
||||
$page = <<<HTML
|
||||
Resting at the inn will refill your current HP, MP, and TP to their maximum levels.<br><br>
|
||||
A night's sleep at this Inn will cost you <b>{$townrow["innprice"]} gold</b>. Is that ok?<br><br>
|
||||
<form action="index.php?do=inn" method="post">
|
||||
<input type="submit" name="submit" value="Yes" /> <input type="submit" name="cancel" value="No" />
|
||||
</form>
|
||||
HTML;
|
||||
}
|
||||
|
||||
display($page, $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a list of available items for purchase.
|
||||
*/
|
||||
function buy()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
$townrow = get_town_by_xy($userrow['longitude'], $userrow['latitude']);
|
||||
if ($townrow === false) display("Cheat attempt detected.<br><br>Get a life, loser.", "Error");
|
||||
|
||||
$items = db()->query("SELECT * FROM items WHERE id IN ({$townrow["itemslist"]});");
|
||||
$page = "Buying weapons will increase your Attack Power. Buying armor and shields will increase your Defense Power.<br><br>Click an item name to purchase it.<br><br>The following items are available at this town:<br><br>\n";
|
||||
$page .= "<table width=\"80%\">\n";
|
||||
while ($itemsrow = $items->fetchArray(SQLITE3_ASSOC)) {
|
||||
$attrib = ($itemsrow["type"] == 1) ? "Attack Power:" : "Defense Power:";
|
||||
$page .= "<tr><td width=\"4%\">";
|
||||
$page .= match ($itemsrow["type"]) {
|
||||
1 => '<img src="images/icon_weapon.gif" alt="weapon" /></td>',
|
||||
2 => '<img src="images/icon_armor.gif" alt="armor" /></td>',
|
||||
3 => '<img src="images/icon_shield.gif" alt="shield" /></td>'
|
||||
};
|
||||
if ($userrow["weaponid"] == $itemsrow["id"] || $userrow["armorid"] == $itemsrow["id"] || $userrow["shieldid"] == $itemsrow["id"]) {
|
||||
$page .= "<td width=\"32%\"><span class=\"light\">".$itemsrow["name"]."</span></td><td width=\"32%\"><span class=\"light\">$attrib ".$itemsrow["attribute"]."</span></td><td width=\"32%\"><span class=\"light\">Already purchased</span></td></tr>\n";
|
||||
} else {
|
||||
if ($itemsrow["special"] != "X") { $specialdot = "<span class=\"highlight\">*</span>"; } else { $specialdot = ""; }
|
||||
$page .= "<td width=\"32%\"><b><a href=\"index.php?do=buy2:".$itemsrow["id"]."\">".$itemsrow["name"]."</a>$specialdot</b></td><td width=\"32%\">$attrib <b>".$itemsrow["attribute"]."</b></td><td width=\"32%\">Price: <b>".$itemsrow["buycost"]." gold</b></td></tr>\n";
|
||||
}
|
||||
}
|
||||
$page .= "</table><br>\n";
|
||||
$page .= "If you've changed your mind, you may also return back to <a href=\"index.php\">town</a>.\n";
|
||||
$title = "Buy Items";
|
||||
|
||||
display($page, $title);
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm user's intent to purchase item.
|
||||
*/
|
||||
function buy2($id)
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
$townrow = get_town_by_xy($userrow['longitude'], $userrow['latitude']);
|
||||
if ($townrow === false) display("Cheat attempt detected.<br><br>Get a life, loser.", "Error");
|
||||
$townitems = explode(",", $townrow["itemslist"]);
|
||||
if (!in_array($id, $townitems)) display("Cheat attempt detected.<br><br>Get a life, loser.", "Error");
|
||||
|
||||
$item = get_item($id);
|
||||
|
||||
if ($userrow["gold"] < $item["buycost"]) {
|
||||
display("You do not have enough gold to buy this item.<br><br>You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=buy\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Items");
|
||||
}
|
||||
|
||||
$type_to_row_mapping = [1 => 'weaponid', 2 => 'armorid', 3 => 'shieldid'];
|
||||
$current_equipped_id = $userrow[$type_to_row_mapping[$item['type']] ?? 0];
|
||||
|
||||
if ($current_equipped_id != 0) {
|
||||
$item2 = get_item($current_equipped_id);
|
||||
$page = "If you are buying the ".$item["name"].", then I will buy your ".$item2["name"]." for ".ceil($item2["buycost"] / 2)." gold. Is that ok?<br><br><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||
} else {
|
||||
$page = "You are buying the ".$item["name"].", is that ok?<br><br><form action=\"index.php?do=buy3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||
}
|
||||
|
||||
display($page, "Buy Items");
|
||||
}
|
||||
|
||||
/**
|
||||
* Update user profile with new item & stats.
|
||||
*/
|
||||
function buy3($id)
|
||||
{
|
||||
|
||||
if (isset($_POST["cancel"])) redirect('index.php');
|
||||
|
||||
global $userrow;
|
||||
|
||||
$townrow = get_town_by_xy($userrow['longitude'], $userrow['latitude']);
|
||||
if ($townrow === false) display("Cheat attempt detected.<br><br>Get a life, loser.", "Error");
|
||||
$townitems = explode(",", $townrow["itemslist"]);
|
||||
if (!in_array($id, $townitems)) display("Cheat attempt detected.<br><br>Get a life, loser.", "Error");
|
||||
|
||||
$item = get_item($id);
|
||||
|
||||
if ($userrow["gold"] < $item["buycost"]) {
|
||||
display("You do not have enough gold to buy this item.<br><br>You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=buy\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Items");
|
||||
}
|
||||
|
||||
$type_mapping = [
|
||||
1 => ['id' => 'weaponid', 'name' => 'weaponname', 'power' => 'attackpower'],
|
||||
2 => ['id' => 'armorid', 'name' => 'armorname', 'power' => 'defensepower'],
|
||||
3 => ['id' => 'shieldid', 'name' => 'shieldname', 'power' => 'defensepower']
|
||||
];
|
||||
|
||||
// Validate item type
|
||||
if (!isset($type_mapping[$item["type"]])) {
|
||||
display("Invalid item type.", "Error");
|
||||
}
|
||||
|
||||
// Retrieve current equipped item or create a default
|
||||
$current_equip_id = $userrow[$type_mapping[$item["type"]]['id']];
|
||||
if ($current_equip_id != 0) {
|
||||
$item2 = get_item($current_equip_id);
|
||||
} else {
|
||||
$item2 = ["attribute" => 0, "buycost" => 0, "special" => "X"];
|
||||
}
|
||||
|
||||
// Process special item effects
|
||||
$specialFields = [];
|
||||
$specialValues = [];
|
||||
$powerAdjustments = 0;
|
||||
|
||||
foreach ([$item, $item2] as $index => $process_item) {
|
||||
if ($process_item["special"] != "X") {
|
||||
$special = explode(",", $process_item["special"]);
|
||||
$toChange = $special[0];
|
||||
$changeAmount = $index === 0 ? $special[1] : -$special[1];
|
||||
|
||||
$userrow[$toChange] += $changeAmount;
|
||||
$specialFields[] = "$toChange = ?";
|
||||
$specialValues[] = $userrow[$toChange];
|
||||
|
||||
// Adjust attack or defense power
|
||||
if ($toChange == "strength" || $toChange == "dexterity") {
|
||||
$powerType = $toChange == "strength" ? "attackpower" : "defensepower";
|
||||
$powerAdjustments += $changeAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Determine power and type-specific updates
|
||||
$currentType = $type_mapping[$item["type"]];
|
||||
$powerField = $currentType['power'];
|
||||
$newPower = $userrow[$powerField] + $item["attribute"] - $item2["attribute"];
|
||||
|
||||
// Calculate new gold with trade-in value
|
||||
$newGold = $userrow["gold"] + ceil($item2["buycost"]/2) - $item["buycost"];
|
||||
|
||||
// Ensure current HP/MP/TP don't exceed max values
|
||||
$newhp = min($userrow["currenthp"], $userrow["maxhp"]);
|
||||
$newmp = min($userrow["currentmp"], $userrow["maxmp"]);
|
||||
$newtp = min($userrow["currenttp"], $userrow["maxtp"]);
|
||||
|
||||
$updateFields = array_merge(
|
||||
$specialFields,
|
||||
[
|
||||
"gold = ?",
|
||||
"{$powerField} = ?",
|
||||
"{$currentType['id']} = ?",
|
||||
"{$currentType['name']} = ?",
|
||||
"currenthp = ?",
|
||||
"currentmp = ?",
|
||||
"currenttp = ?"
|
||||
]
|
||||
);
|
||||
|
||||
$updateValues = array_merge(
|
||||
$specialValues,
|
||||
[
|
||||
$newGold,
|
||||
$newPower,
|
||||
$item["id"],
|
||||
$item["name"],
|
||||
$newhp,
|
||||
$newmp,
|
||||
$newtp,
|
||||
$userrow["id"]
|
||||
]
|
||||
);
|
||||
|
||||
$stmt = db()->query("UPDATE users SET " . implode(", ", $updateFields) . " WHERE id = ?;", $updateValues);
|
||||
if ($stmt === false) exit("Failed to purchase and equip $id. Go back and try again.");
|
||||
|
||||
display("Thank you for purchasing this item.<br><br>You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=buy\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Items");
|
||||
}
|
||||
|
||||
/**
|
||||
* List maps the user can buy.
|
||||
*/
|
||||
function maps()
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
$mappedtowns = explode(",", $userrow["towns"]);
|
||||
|
||||
$page = "Buying maps will put the town in your Travel To box, and it won't cost you as many TP to get there.<br><br>\n";
|
||||
$page .= "Click a town name to purchase its map.<br><br>\n";
|
||||
$page .= "<table width=\"90%\">\n";
|
||||
|
||||
$towns = db()->query('SELECT * FROM towns ORDER BY id;');
|
||||
while ($townrow = $towns->fetchArray(SQLITE3_ASSOC)) {
|
||||
$latitude = ($townrow["latitude"] >= 0) ? $townrow["latitude"] . "N," : ($townrow["latitude"] * -1) . "S,";
|
||||
$longitude = ($townrow["longitude"] >= 0) ? $townrow["longitude"] . "E" : ($townrow["longitude"] * -1) . "W";
|
||||
|
||||
$mapped = false;
|
||||
foreach($mappedtowns as $b) if ($b == $townrow["id"]) $mapped = true;
|
||||
|
||||
if ($mapped == false) {
|
||||
$page .= "<tr><td width=\"25%\"><a href=\"index.php?do=maps2:".$townrow["id"]."\">".$townrow["name"]."</a></td><td width=\"25%\">Price: ".$townrow["mapprice"]." gold</td><td width=\"50%\" colspan=\"2\">Buy map to reveal details.</td></tr>\n";
|
||||
} else {
|
||||
$page .= "<tr><td width=\"25%\"><span class=\"light\">".$townrow["name"]."</span></td><td width=\"25%\"><span class=\"light\">Already mapped.</span></td><td width=\"35%\"><span class=\"light\">Location: $latitude $longitude</span></td><td width=\"15%\"><span class=\"light\">TP: ".$townrow["travelpoints"]."</span></td></tr>\n";
|
||||
}
|
||||
}
|
||||
|
||||
$page .= "</table><br>\n";
|
||||
$page .= "If you've changed your mind, you may also return back to <a href=\"index.php\">town</a>.\n";
|
||||
|
||||
display($page, "Buy Maps");
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm user's intent to purchase map.
|
||||
*/
|
||||
function maps2($id)
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
$townrow = get_town_by_id($id);
|
||||
|
||||
if ($userrow["gold"] < $townrow["mapprice"]) {
|
||||
display("You do not have enough gold to buy this map.<br><br>You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=maps\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Maps");
|
||||
}
|
||||
|
||||
$page = "You are buying the ".$townrow["name"]." map. Is that ok?<br><br><form action=\"index.php?do=maps3:$id\" method=\"post\"><input type=\"submit\" name=\"submit\" value=\"Yes\" /> <input type=\"submit\" name=\"cancel\" value=\"No\" /></form>";
|
||||
|
||||
display($page, "Buy Maps");
|
||||
}
|
||||
|
||||
/**
|
||||
* Add new map to user's profile.
|
||||
*/
|
||||
function maps3($id)
|
||||
{
|
||||
if (isset($_POST["cancel"])) redirect('index.php');
|
||||
|
||||
global $userrow;
|
||||
|
||||
$townrow = get_town_by_id($id);
|
||||
|
||||
if ($userrow["gold"] < $townrow["mapprice"]) {
|
||||
display("You do not have enough gold to buy this map.<br><br>You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=maps\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Maps");
|
||||
}
|
||||
|
||||
$mappedtowns = $userrow["towns"].",$id";
|
||||
$newgold = $userrow["gold"] - $townrow["mapprice"];
|
||||
|
||||
db()->query('UPDATE users SET towns=?, gold=? WHERE id=?;', [$mappedtowns, $newgold, $userrow['id']]);
|
||||
|
||||
display("Thank you for purchasing this map.<br><br>You may return to <a href=\"index.php\">town</a>, <a href=\"index.php?do=maps\">store</a>, or use the direction buttons on the left to start exploring.", "Buy Maps");
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a user to a town from the Travel To menu.
|
||||
*/
|
||||
function travelto($id, bool $usepoints = true)
|
||||
{
|
||||
global $userrow;
|
||||
|
||||
if ($userrow["currentaction"] == "Fighting") redirect('index.php?do=fight');
|
||||
|
||||
$townrow = get_town_by_id($id);
|
||||
|
||||
if ($usepoints) {
|
||||
if ($userrow["currenttp"] < $townrow["travelpoints"]) {
|
||||
display("You do not have enough TP to travel here. Please go back and try again when you get more TP.", "Travel To");
|
||||
}
|
||||
$mapped = explode(",",$userrow["towns"]);
|
||||
if (!in_array($id, $mapped)) { display("Cheat attempt detected.<br><br>Get a life, loser.", "Error"); }
|
||||
}
|
||||
|
||||
if (($userrow["latitude"] == $townrow["latitude"]) && ($userrow["longitude"] == $townrow["longitude"])) {
|
||||
display("You are already in this town. <a href=\"index.php\">Click here</a> to return to the main town screen.", "Travel To");
|
||||
}
|
||||
|
||||
$newtp = ($usepoints) ? $userrow["currenttp"] - $townrow["travelpoints"] : $userrow["currenttp"];
|
||||
|
||||
$newlat = $townrow["latitude"];
|
||||
$newlon = $townrow["longitude"];
|
||||
$newid = $userrow["id"];
|
||||
|
||||
// If they got here by exploring, add this town to their map.
|
||||
$mapped = explode(",",$userrow["towns"]);
|
||||
$town = false;
|
||||
foreach($mapped as $b) if ($b == $id) $town = true;
|
||||
$mapped = implode(",", $mapped);
|
||||
if ($town == false) $mapped .= ",$id";
|
||||
|
||||
$mapped = "towns='".$mapped."',";
|
||||
|
||||
db()->query("UPDATE users SET currentaction='In Town',$mapped currenttp=?, latitude=?, longitude=? WHERE id=?;", [
|
||||
$newtp, $newlat, $newlon, $newid
|
||||
]);
|
||||
|
||||
$page = "You have travelled to ".$townrow["name"].". You may now <a href=\"index.php\">enter this town</a>.";
|
||||
display($page, "Travel To");
|
||||
}
|
78
templates/admin.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
<head>
|
||||
<title>{{title}}</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
color: black;
|
||||
font: 11px verdana;
|
||||
}
|
||||
table {
|
||||
border-style: none;
|
||||
padding: 0px;
|
||||
font: 11px verdana;
|
||||
}
|
||||
td {
|
||||
border-style: none;
|
||||
padding: 3px;
|
||||
vertical-align: top;
|
||||
}
|
||||
a {
|
||||
color: #663300;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
}
|
||||
a:hover {
|
||||
color: #330000;
|
||||
}
|
||||
.small {
|
||||
font: 10px verdana;
|
||||
}
|
||||
.highlight {
|
||||
color: red;
|
||||
}
|
||||
.light {
|
||||
color: #999999;
|
||||
}
|
||||
.title {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font-weight: bold;
|
||||
padding: 5px;
|
||||
margin: 3px;
|
||||
}
|
||||
.copyright {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font: 10px verdana;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body><center>
|
||||
<table width="90%"><tr>
|
||||
<td width="150" style="border-right: solid 1px black;">
|
||||
<b><u>DK Administration</u></b><br><br>
|
||||
<b>Links:</b><br>
|
||||
<a href="admin.php">Admin Home</a><br>
|
||||
<a href="index.php">Game Home</a><br><br>
|
||||
<b>Primary Data:</b><br>
|
||||
<a href="admin.php?do=main">Main Settings</a><br>
|
||||
<a href="admin.php?do=news">Add News Post</a><br>
|
||||
<a href="admin.php?do=users">Edit Users</a><br><br>
|
||||
<b>Game Data:</b><br>
|
||||
<a href="admin.php?do=items">Edit Items</a><br>
|
||||
<a href="admin.php?do=drops">Edit Drops</a><br>
|
||||
<a href="admin.php?do=towns">Edit Towns</a><br>
|
||||
<a href="admin.php?do=monsters">Edit Monsters</a><br>
|
||||
<a href="admin.php?do=levels">Edit Levels</a><br>
|
||||
<a href="admin.php?do=spells">Edit Spells</a><br>
|
||||
</td><td>
|
||||
{{content}}
|
||||
</td></tr></table>
|
||||
<br>
|
||||
<table class="copyright" width="90%"><tr>
|
||||
<td width="25%" align="center">Powered by <a href="http://dragon.se7enet.com/dev.php" target="_new">Dragon Knight</a></td><td width="25%" align="center">© 2003-2006 by renderse7en</td><td width="25%" align="center">{{totaltime}} Seconds, {{numqueries}} Queries</td><td width="25%" align="center">Version {{version}} {{build}}</td>
|
||||
</center></body>
|
||||
</html>
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
|
@ -1,49 +0,0 @@
|
|||
<h2>Editing <?= $drop['name'] ?></h2>
|
||||
<form action="/admin/drops/<?= $drop['id'] ?>" method="post" hx-post="/admin/drops/<?= $drop['id'] ?>" hx-target="#main">
|
||||
<table width="90%">
|
||||
<tr><td width="20%">ID:</td><td><?= $drop['id'] ?></td></tr>
|
||||
<tr><td width="20%">Name:</td><td><input type="text" name="name" value="<?= $drop['name'] ?>"></td></tr>
|
||||
<tr>
|
||||
<td width="20%">Monster Level:</td>
|
||||
<td>
|
||||
<input type="number" name="mlevel" value="<?= $drop['mlevel'] ?>"><br>
|
||||
<span class="small">Minimum monster level that will drop this item.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Attribute 1:</td>
|
||||
<td>
|
||||
<input type="text" name="attribute1" value="<?= $drop['attribute1'] ?>"><br>
|
||||
<span class="small">Must be a special code. First attribute cannot be disabled. Edit this field very
|
||||
carefully because mistakes to formatting or field names can create problems in the game.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Attribute 2:</td>
|
||||
<td>
|
||||
<input type="text" name="attribute2" value="<?= $drop['attribute2'] ?>"><br>
|
||||
<span class="small">Should be either a special code or <span class="highlight">X</span> to
|
||||
disable. Edit this field very carefully because mistakes to formatting or field names can create
|
||||
problems in the game.</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<button type="submit">Save</button>
|
||||
<button type="reset">Reset</button>
|
||||
</form>
|
||||
|
||||
<br>
|
||||
|
||||
<h3>Special Codes</h3>
|
||||
Special codes are used in the two attribute fields to give the item properties. The first attribute field must contain a special code, but the second one may be left empty ("X") if you wish. Special codes are in the format <span class="highlight">attribute,value</span>. <span class="highlight">Attribute</span> can be any database field from the Users table - however, it is suggested that you only use the ones from the list below, otherwise things can get freaky. <span class="highlight">Value</span> may be any positive or negative whole number. For example, if you want a weapon to give an additional 50 max hit points, the special code would be <span class="highlight">maxhp,50</span>.<br><br>
|
||||
Suggested user fields for special codes:<br>
|
||||
maxhp - max hit points<br>
|
||||
maxmp - max magic points<br>
|
||||
maxtp - max travel points<br>
|
||||
goldbonus - gold bonus, in percent<br>
|
||||
expbonus - experience bonus, in percent<br>
|
||||
strength - strength (which also adds to attackpower)<br>
|
||||
dexterity - dexterity (which also adds to defensepower)<br>
|
||||
attackpower - total attack power<br>
|
||||
defensepower - total defense power
|
|
@ -1,55 +0,0 @@
|
|||
<h2>Edit <?= $item['name'] ?></h2>
|
||||
<form action="/admin/items/<?= $item['id'] ?>" method="post" hx-post="/admin/items/<?= $item['id'] ?>" hx-target="#main">
|
||||
<table>
|
||||
<tr><td width="20%">ID:</td><td><?= $item['id'] ?></td></tr>
|
||||
<tr>
|
||||
<td width="20%">Name:</td>
|
||||
<td><input type="text" name="name" value="<?= $item['name'] ?>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Type:</td>
|
||||
<td><select name="type">
|
||||
<option value="1" <?= $item['type'] === 1 ? 'selected' : '' ?>>Weapon</option>
|
||||
<option value="2" <?= $item['type'] === 2 ? 'selected' : '' ?>>Armor</option>
|
||||
<option value="3" <?= $item['type'] === 3 ? 'selected' : '' ?>>Shield</option>
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Cost:</td>
|
||||
<td><input type="text" name="buycost" value="<?= $item['buycost'] ?>"> gold</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Attribute:</td>
|
||||
<td>
|
||||
<input type="number" name="attribute" value="<?= $item['attribute'] ?>"><br>
|
||||
<span class="small">How much the item adds to total attackpower (weapons) or defensepower (armor/shields).</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Special:</td>
|
||||
<td>
|
||||
<input type="text" name="special" value="<?= $item['special'] ?>"><br>
|
||||
<span class="small">Should be either a special code or <span class="highlight">X</span> to disable. Edit
|
||||
this field very carefully because mistakes to formatting or field names can create problems in the game.</span>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<button type="submit">Save</button>
|
||||
<button type="reset">Reset</button>
|
||||
</form>
|
||||
|
||||
<br>
|
||||
|
||||
<h3>Special Codes</h3>
|
||||
Special codes can be added in the item's Special field to give it extra user attributes. Special codes are in the format <span class="highlight">attribute,value</span>. <span class="highlight">Attribute</span> can be any database field from the Users table - however, it is suggested that you only use the ones from the list below, otherwise things can get freaky. <span class="highlight">Value</span> may be any positive or negative whole number. For example, if you want a weapon to give an additional 50 max hit points, the special code would be <span class="highlight">maxhp,50</span>.<br><br>
|
||||
Suggested user fields for special codes:<br>
|
||||
maxhp - max hit points<br>
|
||||
maxmp - max magic points<br>
|
||||
maxtp - max travel points<br>
|
||||
goldbonus - gold bonus, in percent<br>
|
||||
expbonus - experience bonus, in percent<br>
|
||||
strength - strength (which also adds to attackpower)<br>
|
||||
dexterity - dexterity (which also adds to defensepower)<br>
|
||||
attackpower - total attack power<br>
|
||||
defensepower - total defense power
|
|
@ -1,33 +0,0 @@
|
|||
<h2>Edit Level <?= $level['id'] ?></h2>
|
||||
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.<br><br>
|
||||
|
||||
<form action="/admin/levels" method="post" hx-post="/admin/levels" hx-target="#main">
|
||||
<input type="hidden" name="save" value="true">
|
||||
<input type="hidden" name="level" value="<?= $level['id'] ?>">
|
||||
<table>
|
||||
<colgroup><col><col></colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>ID:</td>
|
||||
<td><?= $level['id'] ?></td>
|
||||
</tr>
|
||||
|
||||
<tr><td colspan="2"></td></tr>
|
||||
|
||||
<?php foreach ([1, 2, 3] as $n): ?>
|
||||
<?php $class_name = env("class_{$n}_name"); ?>
|
||||
<tr><td><?= $class_name ?> EXP</td> <td><input type="number" name="<?= $n ?>_exp" value="<?= $level["{$n}_exp"] ?>"></td></tr>
|
||||
<tr><td><?= $class_name ?> HP</td> <td><input type="number" name="<?= $n ?>_hp" value="<?= $level["{$n}_hp"] ?>"></td></tr>
|
||||
<tr><td><?= $class_name ?> MP</td> <td><input type="number" name="<?= $n ?>_mp" value="<?= $level["{$n}_mp"] ?>"></td></tr>
|
||||
<tr><td><?= $class_name ?> TP</td> <td><input type="number" name="<?= $n ?>_tp" value="<?= $level["{$n}_tp"] ?>"></td></tr>
|
||||
<tr><td><?= $class_name ?> Strength</td> <td><input type="number" name="<?= $n ?>_strength" value="<?= $level["{$n}_strength"] ?>"></td></tr>
|
||||
<tr><td><?= $class_name ?> Dexterity</td><td><input type="number" name="<?= $n ?>_dexterity" value="<?= $level["{$n}_dexterity"] ?>"></td></tr>
|
||||
<tr><td><?= $class_name ?> Spells</td> <td><input type="number" name="<?= $n ?>_spells" value="<?= $level["{$n}_spells"] ?>"></td></tr>
|
||||
<?= $n !== 3 ? '<tr><td colspan="2"></td></tr>' : '' ?>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="submit">Save</button>
|
||||
<button type="reset">Reset</button>
|
||||
</form>
|
|
@ -1,74 +0,0 @@
|
|||
<h2>Edit <?= $monster['name'] ?></h2>
|
||||
|
||||
<form action="/admin/monsters/<?= $monster['id'] ?>"
|
||||
method="post"
|
||||
hx-post="/admin/monsters/<?= $monster['id'] ?>"
|
||||
hx-target="#main">
|
||||
<table>
|
||||
<colgroup><col><col></colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td><?= $monster['id'] ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td><input type="text" name="name" value="<?= $monster['name'] ?>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Max HP</td>
|
||||
<td><input type="number" name="maxhp" value="<?= $monster['maxhp'] ?>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Max Damage</td>
|
||||
<td>
|
||||
<input type="number" name="maxdam" value="<?= $monster['maxdam'] ?>"><br>
|
||||
<span class="small">Compares to player's attack power.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Armor</td>
|
||||
<td>
|
||||
<input type="number" name="armor" value="<?= $monster['armor'] ?>"><br>
|
||||
<span class="small">Compares to player's defense power.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Monster Level</td>
|
||||
<td>
|
||||
<input type="number" name="level" value="<?= $monster['level'] ?>"><br>
|
||||
<span class="small">Determines spawn location and item drops.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Max EXP</td>
|
||||
<td>
|
||||
<input type="number" name="maxexp" value="<?= $monster['maxexp'] ?>"><br>
|
||||
<span class="small">Max experience gained from defeating monster.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Max Gold</td>
|
||||
<td>
|
||||
<input type="number" name="maxgold" value="<?= $monster['maxgold'] ?>"><br>
|
||||
<span class="small">Max gold gained from defeating monster.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Immunity</td>
|
||||
<td>
|
||||
<select name="immune">
|
||||
<option value="0" <?= $monster['immune'] == 0 ? 'selected' : '' ?>>None</option>
|
||||
<option value="1" <?= $monster['immune'] == 1 ? 'selected' : '' ?>>Hurt Spells</option>
|
||||
<option value="2" <?= $monster['immune'] == 2 ? 'selected' : '' ?>>Hurt & Sleep Spells</option>
|
||||
</select>
|
||||
<br>
|
||||
<span class="small">Some monsters may not be hurt by certain spells.</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="submit">Save</button>
|
||||
<button type="reset">Reset</button>
|
||||
</form>
|
|
@ -1,56 +0,0 @@
|
|||
<h2>Edit <?= $spell['name'] ?></h2>
|
||||
|
||||
<form action="/admin/spells/<?= $spell['id'] ?>" method="post", hx-post="/admin/spells/<?= $spell['id'] ?>" hx-target="#main">
|
||||
<table>
|
||||
<colgroup><col><col></colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>ID</td>
|
||||
<td><?= $spell['id'] ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td><input type="text" name="name" value="<?= $spell['name'] ?>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>MP</td>
|
||||
<td>
|
||||
<input type="number" name="mp" value="<?= $spell['mp'] ?>">
|
||||
<br>
|
||||
<span class="small">MP required to cast spell.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Attribute</td>
|
||||
<td>
|
||||
<input type="number" name="attribute" value="<?= $spell['attribute'] ?>">
|
||||
<br>
|
||||
<span class="small">Numeric value of the spell's effect. Ties with type, below.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Type</td>
|
||||
<td>
|
||||
<select name="type">
|
||||
<option value="1" <?= $spell['type'] == 1 ? 'selected' : '' ?>>Heal</option>
|
||||
<option value="2" <?= $spell['type'] == 2 ? 'selected' : '' ?>>Hurt</option>
|
||||
<option value="3" <?= $spell['type'] == 3 ? 'selected' : '' ?>>Sleep</option>
|
||||
<option value="4" <?= $spell['type'] == 4 ? 'selected' : '' ?>>Uber Attack</option>
|
||||
<option value="5" <?= $spell['type'] == 5 ? 'selected' : '' ?>>Uber Defense</option>
|
||||
</select>
|
||||
<br>
|
||||
<span class="small">
|
||||
- Heal gives player back [attribute] hit points.<br>
|
||||
- Hurt deals [attribute] damage to monster.<br>
|
||||
- Sleep keeps monster from attacking ([attribute] is monster's chance out of 15 to stay asleep each turn).<br>
|
||||
- Uber Attack increases total attack damage by [attribute] percent.<br>
|
||||
- Uber Defense increases total defense from attack by [attribute] percent.
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="submit">Save</button>
|
||||
<button type="reset">Reset</button>
|
||||
</form>
|
|
@ -1,58 +0,0 @@
|
|||
<h2>Edit <?= $town['name'] ?></h2>
|
||||
<form action="/admin/towns/<?= $town['id'] ?>" method="post" hx-post="/admin/towns/<?= $town['id'] ?>" hx-target="#main">
|
||||
<table>
|
||||
<colgroup><col><col></colgroup>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>ID</td> <td><?= $town['id'] ?></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td><input type="text" name="name" value="<?= $town['name'] ?>"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Latitude</td>
|
||||
<td>
|
||||
<input type="number" name="latitude" value="<?= $town['latitude'] ?>"><br>
|
||||
<span class="small">Positive or negative integer.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Longitude</td>
|
||||
<td>
|
||||
<input type="number" name="longitude" value="<?= $town['longitude'] ?>" /><br>
|
||||
<span class="small">Positive or negative integer.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Inn Price</td>
|
||||
<td><input type="number" name="innprice" value="<?= $town['innprice'] ?>"> gold</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Map Price</td>
|
||||
<td>
|
||||
<input type="number" name="mapprice" value="<?= $town['mapprice'] ?>"> gold<br>
|
||||
<span class="small">How much it costs to buy the map to this town.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Travel Points</td>
|
||||
<td>
|
||||
<input type="number" name="travelpoints" value="<?= $town['travelpoints'] ?>"><br>
|
||||
<span class="small">How many TP are consumed when travelling to this town.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Items List</td>
|
||||
<td>
|
||||
<input type="text" name="itemslist" value="<?= $town['itemslist'] ?>"><br>
|
||||
<span class="small">Comma-separated list of item ID numbers available for purchase at this town.
|
||||
(Example: <span class="highlight">1,2,3,6,9,10,13,20</span>)</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="submit">Save</button>
|
||||
<button type="reset">Reset</button>
|
||||
</form>
|
|
@ -1,89 +0,0 @@
|
|||
<h2>Edit <?= $user['username'] ?></h2>
|
||||
<form action="/admin/users/<?= $user['id'] ?>" method="post" hx-post="/admin/users/<?= $user['id'] ?>" hx-target="#main">
|
||||
<table>
|
||||
<colgroup><col><col></colgroup>
|
||||
<tbody>
|
||||
<tr><td>ID</td><td><?= $user['id'] ?></td></tr>
|
||||
<tr><td>Username</td><td><input type="text" name="username" value="<?= $user['username'] ?>"></td></tr>
|
||||
<tr><td>Email</td><td><input type="text" name="email" value="<?= $user['email'] ?>"></td></tr>
|
||||
<tr><td>Register Date</td><td><?= pretty_date($user['regdate']) ?></td></tr>
|
||||
<tr><td>Last Online</td><td><?= pretty_date($user['onlinetime']) ?></td></tr>
|
||||
<tr><td>Auth Level</td><td>
|
||||
<select name="authlevel">
|
||||
<option value="0" <?= $user['authlevel'] == 0 ? 'selected' : '' ?>>User</option>
|
||||
<option value="1" <?= $user['authlevel'] == 1 ? 'selected' : '' ?>>Admin</option>
|
||||
<option value="2" <?= $user['authlevel'] == 2 ? 'selected' : '' ?>>Blocked</option>
|
||||
</select><br>
|
||||
<span class="small">Set to "Blocked" to temporarily (or permanently) ban a user.</span>
|
||||
</td></tr>
|
||||
|
||||
<tr><td colspan="2"></td></tr>
|
||||
|
||||
<tr><td>Latitude</td><td><input type="number" name="latitude" value="<?= $user['latitude'] ?>" /></td></tr>
|
||||
<tr><td>Longitude</td><td><input type="number" name="longitude" value="<?= $user['longitude'] ?>" /></td></tr>
|
||||
<tr><td>Character Class</td><td>
|
||||
<select name="charclass">
|
||||
<option value="1" <?= $user['charclass'] == 1 ? 'selected' : '' ?>><?= env('class_1_name') ?></option>
|
||||
<option value="2" <?= $user['charclass'] == 2 ? 'selected' : '' ?>><?= env('class_2_name') ?></option>
|
||||
<option value="3" <?= $user['charclass'] == 3 ? 'selected' : '' ?>><?= env('class_3_name') ?></option>
|
||||
</select>
|
||||
</td></tr>
|
||||
|
||||
<tr><td colspan="2"></td></tr>
|
||||
|
||||
<tr><td>Current Action</td><td><input type="text" name="currentaction" value="<?= $user['currentaction'] ?>" /></td></tr>
|
||||
<tr><td>Current Fight</td><td><input type="number" name="currentfight" value="<?= $user['currentfight'] ?>" /></td></tr>
|
||||
<tr><td>Current Monster</td><td><input type="number" name="currentmonster" value="<?= $user['currentmonster'] ?>" /></td></tr>
|
||||
<tr><td>Current Monster HP</td><td><input type="number" name="currentmonsterhp" value="<?= $user['currentmonsterhp'] ?>" /></td></tr>
|
||||
<tr><td>Current Monster Sleep</td><td><input type="number" name="currentmonsterimmune" value="<?= $user['currentmonsterimmune'] ?>" /></td></tr>
|
||||
<tr><td>Current Monster Immune</td><td><input type="number" name="currentmonstersleep" value="<?= $user['currentmonstersleep'] ?>" /></td></tr>
|
||||
<tr><td>Current Uber Damage</td><td><input type="number" name="currentuberdamage" value="<?= $user['currentuberdamage'] ?>" /></td></tr>
|
||||
<tr><td>Current Uber Defense</td><td><input type="number" name="currentuberdefense" value="<?= $user['currentuberdefense'] ?>" /></td></tr>
|
||||
|
||||
<tr><td colspan="2"></td></tr>
|
||||
|
||||
<tr><td>Current HP</td><td><input type="number" name="currenthp" value="<?= $user['currenthp'] ?>" /></td></tr>
|
||||
<tr><td>Current MP</td><td><input type="number" name="currentmp" value="<?= $user['currentmp'] ?>" /></td></tr>
|
||||
<tr><td>Current TP</td><td><input type="number" name="currenttp" value="<?= $user['currenttp'] ?>" /></td></tr>
|
||||
<tr><td>Max HP</td><td><input type="number" name="maxhp" value="<?= $user['maxhp'] ?>" /></td></tr>
|
||||
<tr><td>Max MP</td><td><input type="number" name="maxmp" value="<?= $user['maxmp'] ?>" /></td></tr>
|
||||
<tr><td>Max TP</td><td><input type="number" name="maxtp" value="<?= $user['maxtp'] ?>" /></td></tr>
|
||||
|
||||
<tr><td colspan="2"></td></tr>
|
||||
|
||||
<tr><td>Level</td><td><input type="number" name="level" value="<?= $user['level'] ?>" /></td></tr>
|
||||
<tr><td>Gold</td><td><input type="number" name="gold" value="<?= $user['gold'] ?>" /></td></tr>
|
||||
<tr><td>Experience</td><td><input type="number" name="experience" value="<?= $user['experience'] ?>" /></td></tr>
|
||||
<tr><td>Gold Bonus</td><td><input type="number" name="goldbonus" value="<?= $user['goldbonus'] ?>" /></td></tr>
|
||||
<tr><td>EXP Bonus</td><td><input type="number" name="expbonus" value="<?= $user['expbonus'] ?>" /></td></tr>
|
||||
<tr><td>Strength</td><td><input type="number" name="strength" value="<?= $user['strength'] ?>" /></td></tr>
|
||||
<tr><td>Dexterity</td><td><input type="number" name="dexterity" value="<?= $user['dexterity'] ?>" /></td></tr>
|
||||
<tr><td>Attack Power</td><td><input type="number" name="attackpower" value="<?= $user['attackpower'] ?>" /></td></tr>
|
||||
<tr><td>Defense Power</td><td><input type="number" name="defensepower" value="<?= $user['defensepower'] ?>" /></td></tr>
|
||||
|
||||
<tr><td colspan="2"></td></tr>
|
||||
|
||||
<tr><td>Weapon ID</td><td><input type="number" name="weaponid" value="<?= $user['weaponid'] ?>"></td></tr>
|
||||
<tr><td>Armor ID</td><td><input type="number" name="armorid" value="<?= $user['armorid'] ?>"></td></tr>
|
||||
<tr><td>Shield ID</td><td><input type="number" name="shieldid" value="<?= $user['shieldid'] ?>"></td></tr>
|
||||
<tr><td>Slot 1 ID</td><td><input type="number" name="slot1id" value="<?= $user['slot1id'] ?>"></td></tr>
|
||||
<tr><td>Slot 2 ID</td><td><input type="number" name="slot2id" value="<?= $user['slot2id'] ?>"></td></tr>
|
||||
<tr><td>Slot 3 ID</td><td><input type="number" name="slot3id" value="<?= $user['slot3id'] ?>"></td></tr>
|
||||
<tr><td>Weapon Name</td><td><input type="text" name="weaponname" value="<?= $user['weaponname'] ?>"></td></tr>
|
||||
<tr><td>Armor Name</td><td><input type="text" name="armorname" value="<?= $user['armorname'] ?>"></td></tr>
|
||||
<tr><td>Shield Name</td><td><input type="text" name="shieldname" value="<?= $user['shieldname'] ?>"></td></tr>
|
||||
<tr><td>Slot 1 Name</td><td><input type="text" name="slot1name" value="<?= $user['slot1name'] ?>"></td></tr>
|
||||
<tr><td>Slot 2 Name</td><td><input type="text" name="slot2name" value="<?= $user['slot2name'] ?>"></td></tr>
|
||||
<tr><td>Slot 3 Name</td><td><input type="text" name="slot3name" value="<?= $user['slot3name'] ?>"></td></tr>
|
||||
|
||||
<tr><td colspan="2"></td></tr>
|
||||
|
||||
<tr><td>Drop Code</td><td><input type="number" name="dropcode" value="<?= $user['dropcode'] ?>"></td></tr>
|
||||
<tr><td>Spells</td><td><input type="text" name="spells" value="<?= $user['spells'] ?>"></td></tr>
|
||||
<tr><td>Towns</td><td><input type="text" name="towns" value="<?= $user['towns'] ?>"></td></tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<button type="submit">Save</button>
|
||||
<button type="reset">Reset</button>
|
||||
</form>
|
|
@ -1,110 +0,0 @@
|
|||
<h2>Main Settings</h2>
|
||||
<p>These options control several major settings for the game engine.</p>
|
||||
<p>Note that these particular settings are written to the .env file in the root directory, and not the database.</p>
|
||||
<br>
|
||||
<form action="/admin/main" method="post" hx-post="/admin/main" hx-target="#main">
|
||||
<table>
|
||||
<tr>
|
||||
<td width="20%"><span class="highlight">Game Open:</span></td>
|
||||
<td>
|
||||
<select name="gameopen">
|
||||
<option value="1" <?= env('game_open') ? 'selected' : '' ?>>Open</option>
|
||||
<option value="0" <?= !env('game_open') ? 'selected' : '' ?>>Closed</option>
|
||||
</select><br>
|
||||
<span class="small">Close the game if you are upgrading or working on settings and don't want to
|
||||
cause odd errors for end-users. Closing the game will completely halt all activity.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Game Name:</td>
|
||||
<td>
|
||||
<input type="text" name="gamename" value="<?= env('game_name') ?>"><br>
|
||||
<span class="small">Change this if you want to change to call your game something different.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Game URL:</td>
|
||||
<td>
|
||||
<input type="text" name="gameurl" value="<?= env('game_url') ?>"><br>
|
||||
<span class="small">Please specify the full URL to your game installation
|
||||
("https://www.dragonknight.com/"). This gets used in the registration email sent to users. If
|
||||
you leave this field blank or incorrect, users may not be able to register correctly.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Admin Email:</td>
|
||||
<td>
|
||||
<input type="text" name="adminemail" value="<?= env('admin_email') ?>"><br>
|
||||
<span class="small">Please specify your email address. This gets used when the game has to send an
|
||||
email to users.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Map Size:</td>
|
||||
<td>
|
||||
<input type="number" name="gamesize" value="<?= env('game_size') ?>"><br>
|
||||
<span class="small">
|
||||
Default is 250. This is the size of each map quadrant. Note that monster
|
||||
levels increase every 5 spaces, so you should ensure that you have at least (map size / 5)
|
||||
monster levels total, otherwise there will be parts of the map without any monsters, or some
|
||||
monsters won't ever get used. Ex: with a map size of 250, you should have 50 monster levels total.
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Email Verification:</td>
|
||||
<td>
|
||||
<select name="verifyemail">
|
||||
<option value="0" <?= !env('verify_email') ? 'selected' : '' ?>>Disabled</option>
|
||||
<option value="1" <?= env('verify_email') ? 'selected' : '' ?>>Enabled</option>
|
||||
</select><br>
|
||||
<span class="small">Make users verify their email address for added security.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Show News:</td>
|
||||
<td>
|
||||
<select name="shownews">
|
||||
<option value="0" <?= !env('show_news') ? 'selected' : '' ?>>No</option>
|
||||
<option value="1" <?= env('show_news') ? 'selected' : '' ?>>Yes</option>
|
||||
</select><br>
|
||||
<span class="small">Toggle display of the Latest News box in towns.
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Show Who's Online:</td>
|
||||
<td>
|
||||
<select name="showonline">
|
||||
<option value="0" <?= !env('show_online') ? 'selected' : '' ?>>No</option>
|
||||
<option value="1" <?= env('show_online') ? 'selected' : '' ?>>Yes</option>
|
||||
</select><br>
|
||||
<span class="small">Toggle display of the Who's Online box in towns.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Show Babblebox:</td>
|
||||
<td>
|
||||
<select name="showbabble">
|
||||
<option value="0" <?= !env('show_babble') ? 'selected' : '' ?>>No</option>
|
||||
<option value="1" <?= env('show_babble') ? 'selected' : '' ?>>Yes</option>
|
||||
</select><br>
|
||||
<span class="small">Toggle display of the Babble Box in towns.</span>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Class 1 Name:</td>
|
||||
<td><input type="text" name="class1name" value="<?= env('class_1_name') ?>"><br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Class 2 Name:</td>
|
||||
<td><input type="text" name="class2name" value="<?= env('class_2_name') ?>"><br></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td width="20%">Class 3 Name:</td>
|
||||
<td><input type="text" name="class3name" value="<?= env('class_3_name') ?>"><br></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<button type="submit">Save</button>
|
||||
<button type="reset">Reset</button>
|
||||
</form>
|
|
@ -1,29 +1,34 @@
|
|||
<div id="babblebox">
|
||||
<div class="messages" hx-get="/babblebox/messages" hx-trigger="every 5s">
|
||||
<?= $messages ?>
|
||||
</div>
|
||||
|
||||
<form hx-post="/babblebox" hx-target="#babblebox > .messages" style="margin-top: 1rem;">
|
||||
<input type="text" name="babble" maxlength="255"><br>
|
||||
<input type="submit" name="submit" value="Babble">
|
||||
<input type="reset" name="reset" value="Clear">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
let chatBox = document.querySelector('#babblebox > .messages')
|
||||
let isUserAtBottom = true
|
||||
if (chatBox !== null) {
|
||||
chatBox.scrollTop = chatBox.scrollHeight;
|
||||
const isAtBottom = () => chatBox.scrollHeight - chatBox.scrollTop === chatBox.clientHeight
|
||||
|
||||
const scrollChatToBottom = () => {
|
||||
if (isUserAtBottom) chatBox.scrollTop = chatBox.scrollHeight;
|
||||
}
|
||||
|
||||
const observer = new MutationObserver(scrollChatToBottom)
|
||||
observer.observe(chatBox, { childList: true, subtree: true })
|
||||
|
||||
chatBox.addEventListener('scroll', () => isUserAtBottom = isAtBottom())
|
||||
}
|
||||
</script>
|
||||
</div>
|
||||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
<head>
|
||||
<title>shoutbox</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
background-image: url(images/background.jpg);
|
||||
color: black;
|
||||
font: 11px verdana;
|
||||
margins: 0px;
|
||||
padding: 0px;
|
||||
}
|
||||
div {
|
||||
padding: 2px;
|
||||
border: solid 1px black;
|
||||
margin: 2px;
|
||||
text-align: left;
|
||||
}
|
||||
a {
|
||||
color: #663300;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
}
|
||||
a:hover {
|
||||
color: #330000;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="window.scrollTo(0,99999)">
|
||||
{{content}}
|
||||
</body>
|
||||
</html>
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
14
templates/changepassword.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
<form action="users.php?do=changepassword" method="post">
|
||||
<table width="100%">
|
||||
<tr><td colspan="2">Use the form below to change your password. All fields are required. New passwords must be 10 alphanumeric characters or less.</td></tr>
|
||||
<tr><td width="20%">Username:</td><td><input type="text" name="username" size="30" maxlength="30" /></td></tr>
|
||||
<tr><td>Old Password:</td><td><input type="password" name="password" /></td></tr>
|
||||
<tr><td>New Password:</td><td><input type="password" name="new_password" /></td></tr>
|
||||
<tr><td>Verify New Password:</td><td><input type="password" name="new_password2" /><br><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>
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
|
@ -1,10 +1,14 @@
|
|||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
<table width="100%">
|
||||
<tr><td class="title"><img src="/img/title_fighting.gif" alt="Fighting" /></td></tr>
|
||||
<tr><td>
|
||||
You are fighting a <b><?= $page['monstername'] ?></b><br><br>
|
||||
<?= $page['monsterhp'] ?>
|
||||
<?= $page['yourturn'] ?>
|
||||
<?= $page['monsterturn'] ?>
|
||||
<?= $page['command'] ?>
|
||||
</td></tr>
|
||||
<tr><td class="title"><img src="images/title_fighting.gif" alt="Fighting" /></td></tr>
|
||||
<tr><td>
|
||||
You are fighting a <b>{{monstername}}</b><br><br>
|
||||
{{monsterhp}}
|
||||
{{yourturn}}
|
||||
{{monsterturn}}
|
||||
{{command}}
|
||||
</td></tr>
|
||||
</table>
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= page_title() ?></title>
|
||||
<link rel="stylesheet" href="/css/admin.css">
|
||||
<script src="/js/htmx.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="admin-container">
|
||||
<header>
|
||||
<h1><?= env('game_name') ?></h1>
|
||||
<h3>Admin</h3>
|
||||
</header>
|
||||
<main>
|
||||
<nav>
|
||||
<a href="/admin" hx-get="/admin" hx-target="#main">Admin Home</a><br>
|
||||
<a href="/">Game Home</a><br><br>
|
||||
|
||||
<br>
|
||||
<a href="/admin/main" hx-get="/admin/main" hx-target="#main">Main Settings</a><br>
|
||||
<a href="/admin/news" hx-get="/admin/news" hx-target="#main">Add News Post</a><br>
|
||||
<a href="/admin/users" hx-get="/admin/users" hx-target="#main">Edit Users</a><br><br>
|
||||
|
||||
<br>
|
||||
<a href="/admin/items" hx-get="/admin/items" hx-target="#main">Edit Items</a><br>
|
||||
<a href="/admin/drops" hx-get="/admin/drops" hx-target="#main">Edit Drops</a><br>
|
||||
<a href="/admin/towns" hx-get="/admin/towns" hx-target="#main">Edit Towns</a><br>
|
||||
<a href="/admin/monsters" hx-get="/admin/monsters" hx-target="#main">Edit Monsters</a><br>
|
||||
<a href="/admin/levels" hx-get="/admin/levels" hx-target="#main">Edit Levels</a><br>
|
||||
<a href="/admin/spells" hx-get="/admin/spells" hx-target="#main">Edit Spells</a><br>
|
||||
</nav>
|
||||
|
||||
<section id="main">
|
||||
<?= $content ?>
|
||||
</section>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div>Powered by <a href="/" target="_new">Dragon Knight</a></div>
|
||||
<div>© 2024 Sharkk</div>
|
||||
<?= Render\debug_db_info(); ?>
|
||||
<div>Version <?= VERSION ?> <?= BUILD ?></div>
|
||||
</footer>
|
||||
|
||||
<?php if (env('debug', false)) echo Render\debug_query_log(); ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,27 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= env('game_name', 'Dragon Knight') ?> Help</title>
|
||||
<link rel="stylesheet" href="/css/help.css">
|
||||
</head>
|
||||
<body>
|
||||
<a name="top"></a>
|
||||
<h1><?= env('game_name', 'Dragon Knight') ?> Help</h1>
|
||||
[ <a href="/help">Back to Help</a> ]<br>
|
||||
[ <a href="/">Return to Game</a> ]
|
||||
|
||||
<br><br><hr>
|
||||
|
||||
<?= $content ?>
|
||||
|
||||
<br><br>
|
||||
|
||||
<footer>
|
||||
<div>Powered by <a href="/" target="_new">Dragon Knight</a></div>
|
||||
<div>© 2024 Sharkk</div>
|
||||
<div>Version <?= $version ?> <?= $build ?></div>
|
||||
</footer>
|
||||
</body>
|
||||
</html>
|
|
@ -1,11 +0,0 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= $title ?></title>
|
||||
<link rel="stylesheet" href="/css/dk.css">
|
||||
</head>
|
||||
<body>
|
||||
<?= $content ?>
|
||||
</body>
|
||||
</html>
|
|
@ -1,54 +0,0 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= page_title() ?></title>
|
||||
<link rel="stylesheet" href="/css/dk.css">
|
||||
<script src="/js/htmx.js"></script>
|
||||
|
||||
<script>
|
||||
function opencharpopup(id = 0)
|
||||
{
|
||||
const url = id == 0 ? '/character' : '/character/' + id
|
||||
window.open(url, "", "width=210,height=500,scrollbars")
|
||||
}
|
||||
|
||||
function openmappopup()
|
||||
{
|
||||
window.open("/showmap", "", "width=520,height=520,scrollbars")
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body class="skin-<?= game_skin() ?>">
|
||||
<div id="game-container">
|
||||
<header>
|
||||
<a href="/"><img id="logo" src="/img/logo.gif" alt="<?= env('game_name', 'Dragon Knight') ?>" title="<?= env('game_name', 'Dragon Knight') ?>"></a>
|
||||
<nav>
|
||||
<?php if (user() !== false): ?>
|
||||
<a href='/logout'><img src='/img/button_logout.gif' alt='Log Out' title='Log Out'></a>
|
||||
<?php else: ?>
|
||||
<a href='/login'><img src='/img/button_login.gif' alt='Log In' title='Log In'></a>
|
||||
<a href='/register'><img src='/img/button_register.gif' alt='Register' title='Register'></a>
|
||||
<?php endif; ?>
|
||||
<a href="/help" hx-boost='/help'><img src='/img/button_help.gif' alt='Help' title='Help'></a>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<main>
|
||||
<section id="left"><?= Render\left_nav() ?></section>
|
||||
<section id="middle"><?= $content ?></section>
|
||||
<section id="right"><?= Render\right_nav() ?></section>
|
||||
</main>
|
||||
|
||||
<footer>
|
||||
<div>Powered by <a href="/" target="_new">Dragon Knight</a></div>
|
||||
<div>© 2024 Sharkk</div>
|
||||
<?= Render\debug_db_info(); ?>
|
||||
<div>Version <?= VERSION ?> <?= BUILD ?></div>
|
||||
</footer>
|
||||
|
||||
<?php if (env('debug', false)) echo Render\debug_query_log(); ?>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,58 +0,0 @@
|
|||
<section>
|
||||
<div class="title"><img src="/img/button_location.gif" alt="Location" title="Location"></div>
|
||||
Currently: <?= user()->currentaction ?><br>
|
||||
<?php
|
||||
$lat = user()->latitude;
|
||||
$lon = user()->longitude;
|
||||
if ($lat < 0) { $lat = ($lat * -1) . "S"; } else { $lat .= "N"; }
|
||||
if ($lon < 0) { $lon = ($lon * -1) . "W"; } else { $lon .= "E"; }
|
||||
?>
|
||||
Latitude: <?= $lat ?><br>
|
||||
Longitude: <?= $lon ?><br>
|
||||
<a href="javascript:openmappopup()">View Map</a><br>
|
||||
<form action="/move" method="post" hx-post="/move" hx-target="#middle" class="move-compass">
|
||||
<button name="direction" value="north" class="north">North</button>
|
||||
<div class="mid">
|
||||
<button name="direction" value="west" class="west">West</button>
|
||||
<button name="direction" value="east" class="east">East</button>
|
||||
</div>
|
||||
<button name="direction" value="south" class="south">South</button>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<div class="title"><img src="/img/button_towns.gif" alt="Towns" title="Towns"></div>
|
||||
<?php
|
||||
if (user()->currentaction == 'In Town') {
|
||||
$town = get_town_by_xy((int) user()->latitude, (int) user()->longitude);
|
||||
echo "Welcome to <b>{$town['name']}</b>.<br><br>";
|
||||
}
|
||||
?>
|
||||
Travel To:<br>
|
||||
<?php
|
||||
$town_list = explode(",", user()->towns);
|
||||
$towns = db()->query('SELECT * FROM towns ORDER BY id;');
|
||||
$mapped = false;
|
||||
while ($row = $towns->fetchArray(SQLITE3_ASSOC)) {
|
||||
$mapped = true;
|
||||
if (in_array($row['id'], $town_list)) {
|
||||
echo <<<HTML
|
||||
<a href="/gotown/{$row['id']}" hx-get="/gotown/{$row['id']}" hx-target="#middle">{$row['name']}</a><br>
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
if (!$mapped) echo 'You have no towns mapped.';
|
||||
?>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<div class="title"><img src="/img/button_functions.gif" alt="Functions" title="Functions"></div>
|
||||
<a href="/" hx-get="/" hx-target="#middle">Home</a><br>
|
||||
<a href="/forum" hx-get="/forum" hx-target="#middle">Forum</a><br>
|
||||
<a href="/settings">Settings</a><br>
|
||||
<?php if (user()->authlevel === 1): ?>
|
||||
<a href="/admin">Admin</a><br>
|
||||
<?php endif; ?>
|
||||
<a href="/help">Help</a><br>
|
||||
<a href="/logout">Log Out</a>
|
||||
</section>
|
44
templates/leftnav.php
Normal file
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
$template = <<<HTML
|
||||
<table width="100%">
|
||||
<tr><td class="title"><img src="images/button_location.gif" alt="Location" title="Location" /></td></tr>
|
||||
<tr><td>
|
||||
Currently: {{currentaction}}<br>
|
||||
Latitude: {{latitude}}<br>
|
||||
Longitude: {{longitude}}<br>
|
||||
<a href="javascript:openmappopup()">View Map</a><br><br>
|
||||
<form action="index.php?do=move" method="post">
|
||||
<center>
|
||||
<input name="north" type="submit" value="North" /><br>
|
||||
<input name="west" type="submit" value="West" /><input name="east" type="submit" value="East" /><br>
|
||||
<input name="south" type="submit" value="South" />
|
||||
</center>
|
||||
</form>
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<table width="100%">
|
||||
<tr><td class="title"><img src="images/button_towns.gif" alt="Towns" title="Towns" /></td></tr>
|
||||
<tr><td>
|
||||
{{currenttown}}
|
||||
Travel To:<br>
|
||||
{{townslist}}
|
||||
</td></tr>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
|
||||
<table width="100%">
|
||||
<tr><td class="title"><img src="images/button_functions.gif" alt="Functions" title="Functions" /></td></tr>
|
||||
<tr><td>
|
||||
<a href="/index.php">Home</a><br>
|
||||
{{forumslink}}
|
||||
{{adminlink}}
|
||||
<a href="users.php?do=changepassword">Change Password</a><br>
|
||||
<a href="login.php?do=logout">Log Out</a><br>
|
||||
<a href="help.php">Help</a>
|
||||
</td></tr>
|
||||
</table>
|
||||
HTML;
|
|
@ -1,24 +1,13 @@
|
|||
<form action="/login" method="post">
|
||||
<table width="75%">
|
||||
<tr>
|
||||
<td width="30%">Username:</td>
|
||||
<td><input type="text" name="username"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Password:</td>
|
||||
<td><input type="password" name="password"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2"><input type="submit" name="submit" value="Log In"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2">
|
||||
Checking the "Remember Me" option will store your login information in a cookie so you don't have
|
||||
to enter it next time you get online.<br><br>Want to play? You gotta
|
||||
<a href="/register">register your own character.</a><br><br>You may also
|
||||
<a href="/changepassword">change your password</a>, or
|
||||
<a href="/lostpassword">request a new one</a> if you've lost yours.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
<form action="login.php?do=login" method="post">
|
||||
<table width="75%">
|
||||
<tr><td width="30%">Username:</td><td><input type="text" size="30" name="username" /></td></tr>
|
||||
<tr><td>Password:</td><td><input type="password" size="30" name="password" /></td></tr>
|
||||
<tr><td>Remember me?</td><td><input type="checkbox" name="rememberme" value="yes" /> Yes</td></tr>
|
||||
<tr><td colspan="2"><input type="submit" name="submit" value="Log In" /></td></tr>
|
||||
<tr><td colspan="2">Checking the "Remember Me" option will store your login information in a cookie so you don't have to enter it next time you get online.<br><br>Want to play? You gotta <a href="users.php?do=register">register your own character.</a><br><br>You may also <a href="users.php?do=changepassword">change your password</a>, or <a href="users.php?do=lostpassword">request a new one</a> if you've lost yours.</td></tr>
|
||||
</table>
|
||||
</form>
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
<form action="/lostpassword" method="post">
|
||||
<table width="80%">
|
||||
<tr><td colspan="2">If you've lost your password, enter your email address below and you will be sent a new one.</td></tr>
|
||||
<tr><td width="20%">Email Address:</td><td><input type="text" name="email"></td></tr>
|
||||
<tr><td colspan="2"><input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset"></td></tr>
|
||||
</table>
|
||||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
<form action="users.php?do=lostpassword" method="post">
|
||||
<table width="80%">
|
||||
<tr><td colspan="2">If you've lost your password, enter your email address below and you will be sent a new one.</td></tr>
|
||||
<tr><td width="20%">Email Address:</td><td><input type="text" name="email" size="30" maxlength="100" /></td></tr>
|
||||
<tr><td colspan="2"><input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /></td></tr>
|
||||
</table>
|
||||
</form>
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
68
templates/minimal.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
$template = <<<THEVERYENDOFYOU
|
||||
<head>
|
||||
<title>{{title}}</title>
|
||||
<style type="text/css">
|
||||
body {
|
||||
background-image: url(images/background.jpg);
|
||||
color: black;
|
||||
font: 11px verdana;
|
||||
}
|
||||
table {
|
||||
border-style: none;
|
||||
padding: 0px;
|
||||
font: 11px verdana;
|
||||
}
|
||||
td {
|
||||
border-style: none;
|
||||
padding: 3px;
|
||||
vertical-align: top;
|
||||
}
|
||||
td.top {
|
||||
border-bottom: solid 2px black;
|
||||
}
|
||||
td.left {
|
||||
width: 150px;
|
||||
border-right: solid 2px black;
|
||||
}
|
||||
td.right {
|
||||
width: 150px;
|
||||
border-left: solid 2px black;
|
||||
}
|
||||
a {
|
||||
color: #663300;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
}
|
||||
a:hover {
|
||||
color: #330000;
|
||||
}
|
||||
.small {
|
||||
font: 10px verdana;
|
||||
}
|
||||
.highlight {
|
||||
color: red;
|
||||
}
|
||||
.light {
|
||||
color: #999999;
|
||||
}
|
||||
.title {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font-weight: bold;
|
||||
padding: 5px;
|
||||
margin: 3px;
|
||||
}
|
||||
.copyright {
|
||||
border: solid 1px black;
|
||||
background-color: #eeeeee;
|
||||
font: 10px verdana;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body><center>
|
||||
{{content}}
|
||||
</center></body>
|
||||
</html>
|
||||
THEVERYENDOFYOU;
|
||||
?>
|
39
templates/onlinechar.php
Normal file
|
@ -0,0 +1,39 @@
|
|||
<?php
|
||||
$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>
|
||||
|
||||
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>
|
||||
|
||||
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>
|
||||
HTML;
|