Compare commits
2 Commits
2801550bdd
...
bf0b05064a
Author | SHA1 | Date | |
---|---|---|---|
bf0b05064a | |||
c2e15d580a |
|
@ -37,8 +37,8 @@ Admin\register_routes($r);
|
||||||
$r->post('/move', 'move');
|
$r->post('/move', 'move');
|
||||||
|
|
||||||
$r->get('/spell/:id', 'healspells');
|
$r->get('/spell/:id', 'healspells');
|
||||||
$r->get('/showchar', 'showchar');
|
$r->get('/character', 'show_character_info');
|
||||||
$r->get('/onlinechar/:id', 'onlinechar');
|
$r->get('/character/:id', 'show_character_info');
|
||||||
$r->get('/showmap', 'showmap');
|
$r->get('/showmap', 'showmap');
|
||||||
$r->form('/babblebox', 'babblebox');
|
$r->form('/babblebox', 'babblebox');
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ function dotown()
|
||||||
|
|
||||||
while ($onlinerow = $onlinequery->fetchArray(SQLITE3_ASSOC)) {
|
while ($onlinerow = $onlinequery->fetchArray(SQLITE3_ASSOC)) {
|
||||||
$online_count++;
|
$online_count++;
|
||||||
$online_rows[] = "<a href=\"/onlinechar/{$onlinerow["id"]}\">".$onlinerow["username"]."</a>";
|
$online_rows[] = "<a href=\"javascript:opencharpopup({$onlinerow['id']})\">".$onlinerow["username"]."</a>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$townrow["whosonline"] = '<div class="title">Who\'s Online</div>';
|
$townrow["whosonline"] = '<div class="title">Who\'s Online</div>';
|
||||||
|
@ -133,73 +133,40 @@ function doexplore()
|
||||||
HTML;
|
HTML;
|
||||||
}
|
}
|
||||||
|
|
||||||
function showchar()
|
/**
|
||||||
{
|
* Show a character's info. Defaults to the currently logged in user.
|
||||||
global $userrow, $controlrow;
|
*/
|
||||||
|
function show_character_info(int $id = 0): void
|
||||||
$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 render('minimal', $array);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onlinechar($id)
|
|
||||||
{
|
{
|
||||||
global $controlrow;
|
global $controlrow;
|
||||||
|
|
||||||
$query = db()->query('SELECT * FROM users WHERE id=? LIMIT 1;', [$id]);
|
if ($id === 0) {
|
||||||
if ($query !== false) { $userrow = $query->fetchArray(SQLITE3_ASSOC); } else { display("No such user.", "Error"); }
|
global $userrow;
|
||||||
unset($userrow['password']);
|
} else {
|
||||||
|
$userrow = get_user_by_id($id);
|
||||||
|
}
|
||||||
|
|
||||||
$userrow["experience"] = number_format($userrow["experience"]);
|
if ($userrow === false) exit('Failed to show info for user ID '.$id);
|
||||||
$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);
|
$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']) {
|
$spells = db()->query('SELECT id, name FROM spells;');
|
||||||
1 => $controlrow["class1name"],
|
$userspells = explode(',', $userrow['spells']);
|
||||||
2 => $controlrow["class2name"],
|
$magic_list = '';
|
||||||
3 => $controlrow["class3name"]
|
while ($spellrow = $spells->fetchArray(SQLITE3_ASSOC)) {
|
||||||
};
|
$spell = false;
|
||||||
|
foreach($userspells as $b) if ($b == $spellrow["id"]) $spell = true;
|
||||||
|
if ($spell == true) $magic_list .= $spellrow["name"]."<br>";
|
||||||
|
}
|
||||||
|
if ($magic_list == "") $magic_list = "None";
|
||||||
|
|
||||||
display(parsetemplate(gettemplate("onlinechar"), $userrow), "Character Information");
|
$showchar = render('showchar', [
|
||||||
|
'char' => $userrow,
|
||||||
|
'level' => $levelrow,
|
||||||
|
'magic_list' => $magic_list,
|
||||||
|
'controlrow' => $controlrow
|
||||||
|
]);
|
||||||
|
echo render('minimal', ['content' => $showchar, 'title' => $userrow['username'].' Information']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function showmap()
|
function showmap()
|
||||||
|
|
|
@ -108,7 +108,7 @@ function register()
|
||||||
$controlrow["verifytext"] = "";
|
$controlrow["verifytext"] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$page = parsetemplate(gettemplate("register"), $controlrow);
|
$page = render('register', ['controlrow' => $controlrow]);
|
||||||
}
|
}
|
||||||
|
|
||||||
display($page, "Register", false, false, false);
|
display($page, "Register", false, false, false);
|
||||||
|
|
12
src/lib.php
12
src/lib.php
|
@ -138,7 +138,7 @@ function display($content, $title, $topnav=true, $leftnav=true, $rightnav=true,
|
||||||
} else {
|
} else {
|
||||||
$topnav = <<<HTML
|
$topnav = <<<HTML
|
||||||
<a href='/login'><img src='/img/button_login.gif' alt='Log In' title='Log In'></a>
|
<a href='/login'><img src='/img/button_login.gif' alt='Log In' title='Log In'></a>
|
||||||
<a href='users.php?do=register'><img src='/img/button_register.gif' alt='Register' title='Register'></a>
|
<a href='/register'><img src='/img/button_register.gif' alt='Register' title='Register'></a>
|
||||||
<a href='/help'><img src='/img/button_help.gif' alt='Help' title='Help'></a>
|
<a href='/help'><img src='/img/button_help.gif' alt='Help' title='Help'></a>
|
||||||
HTML;
|
HTML;
|
||||||
}
|
}
|
||||||
|
@ -310,6 +310,16 @@ function get_town_by_id(int $id): array|false
|
||||||
return $query->fetchArray(SQLITE3_ASSOC);
|
return $query->fetchArray(SQLITE3_ASSOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a user's data by their ID.
|
||||||
|
*/
|
||||||
|
function get_user_by_id(int $id): array|false
|
||||||
|
{
|
||||||
|
$query = db()->query('SELECT * FROM users WHERE id = ? LIMIT 1;', [$id]);
|
||||||
|
if ($query === false) return false;
|
||||||
|
return $query->fetchArray(SQLITE3_ASSOC);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an item by it's ID.
|
* Get an item by it's ID.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
<title><?= $title ?></title>
|
<title><?= $title ?></title>
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body {
|
body {
|
||||||
background-image: url(/img/background.jpg);
|
background-image: url('/img/background.jpg');
|
||||||
color: black;
|
color: black;
|
||||||
font: 11px verdana;
|
font: 11px verdana;
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,6 @@
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<center>
|
|
||||||
<?= $content ?>
|
<?= $content ?>
|
||||||
</center>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -9,13 +9,15 @@ $template = <<<HTML
|
||||||
<link rel="stylesheet" href="/css/dk.css">
|
<link rel="stylesheet" href="/css/dk.css">
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
function opencharpopup(){
|
function opencharpopup(id = 0)
|
||||||
var popurl="/showchar"
|
{
|
||||||
winpops=window.open(popurl,"","width=210,height=500,scrollbars")
|
const url = id == 0 ? '/character' : '/character/' + id
|
||||||
|
window.open(url, "", "width=210,height=500,scrollbars")
|
||||||
}
|
}
|
||||||
function openmappopup(){
|
|
||||||
var popurl="/showmap"
|
function openmappopup()
|
||||||
winpops=window.open(popurl,"","width=520,height=520,scrollbars")
|
{
|
||||||
|
window.open("/showmap", "", "width=520,height=520,scrollbars")
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
|
|
|
@ -1,16 +1,21 @@
|
||||||
<?php
|
<form action="/register" method="post">
|
||||||
$template = <<<THEVERYENDOFYOU
|
|
||||||
<form action="users.php?do=register" method="post">
|
|
||||||
<table width="80%">
|
<table width="80%">
|
||||||
<tr><td width="20%">Username:</td><td><input type="text" name="username" size="30" maxlength="30" /><br>Usernames must be 30 alphanumeric characters or less.<br><br><br></td></tr>
|
<tr><td width="20%">Username:</td><td><input type="text" name="username"><br>Usernames must be 30 alphanumeric characters or less.<br><br><br></td></tr>
|
||||||
<tr><td>Password:</td><td><input type="password" name="password1" size="30" maxlength="10" /></td></tr>
|
<tr><td>Password:</td><td><input type="password" name="password"></td></tr>
|
||||||
<tr><td>Verify Password:</td><td><input type="password" name="password2" size="30" maxlength="10" /><br>Passwords must be 10 alphanumeric characters or less.<br><br><br></td></tr>
|
<tr><td>Verify Password:</td><td><input type="password" name="confirm_password"><br>Passwords must be 10 alphanumeric characters or less.<br><br><br></td></tr>
|
||||||
<tr><td>Email Address:</td><td><input type="text" name="email1" size="30" maxlength="100" /></td></tr>
|
<tr><td>Email Address:</td><td><input type="email" name="email"></td></tr>
|
||||||
<tr><td>Verify Email:</td><td><input type="text" name="email2" size="30" maxlength="100" />{{verifytext}}<br><br><br></td></tr>
|
<tr><td>Verify Email:</td><td><input type="email" name="confirm_email"><?= $controlrow['verifytext'] ?><br><br><br></td></tr>
|
||||||
<tr><td>Character Class:</td><td><select name="charclass"><option value="1">{{class1name}}</option><option value="2">{{class2name}}</option><option value="3">{{class3name}}</option></select></td></tr>
|
<tr>
|
||||||
|
<td>Character Class:</td>
|
||||||
|
<td>
|
||||||
|
<select name="charclass">
|
||||||
|
<option value="1"><?= $controlrow['class1name'] ?></option>
|
||||||
|
<option value="2"><?= $controlrow['class2name'] ?></option>
|
||||||
|
<option value="3"><?= $controlrow['class3name'] ?></option>
|
||||||
|
</select>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
<tr><td colspan="2">See <a href="/help">Help</a> for more information about character classes.<br><br></td></tr>
|
<tr><td colspan="2">See <a href="/help">Help</a> for more information about character classes.<br><br></td></tr>
|
||||||
<tr><td colspan="2"><input type="submit" name="submit" value="Submit" /> <input type="reset" name="reset" value="Reset" /></td></tr>
|
<tr><td colspan="2"><input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset"></td></tr>
|
||||||
</table>
|
</table>
|
||||||
</form>
|
</form>
|
||||||
THEVERYENDOFYOU;
|
|
||||||
?>
|
|
||||||
|
|
|
@ -1,46 +1,36 @@
|
||||||
<?php
|
<div class="title"><img src="/img/button_character.gif" alt="Character" title="Character"></div>
|
||||||
$template = <<<THEVERYENDOFYOU
|
<b><?= $char['username'] ?></b><br><br>
|
||||||
<table width="100%">
|
|
||||||
<tr><td class="title"><img src="/img/button_character.gif" alt="Character" title="Character" /></td></tr>
|
|
||||||
<tr><td>
|
|
||||||
<b>{{username}}</b><br><br>
|
|
||||||
|
|
||||||
Class: {{charclass}}<br><br>
|
Class: <?= match ($char['charclass']) {
|
||||||
|
1 => $controlrow["class1name"],
|
||||||
|
2 => $controlrow["class2name"],
|
||||||
|
3 => $controlrow["class3name"]
|
||||||
|
}; ?><br><br>
|
||||||
|
|
||||||
Level: {{level}}<br>
|
Level: <?= $char['level'] ?><br>
|
||||||
Experience: {{experience}} {{plusexp}}<br>
|
Experience: <?= number_format($char['experience']) ?>
|
||||||
Next Level: {{nextlevel}}<br>
|
<?php if ($char['expbonus'] !== 0): ?> <span class="light">(<?= $char['expbonus'] > 0 ? '+' : '' ?>) <?= $char['expbonus'] ?>%)</span> <?php endif; ?><br>
|
||||||
Gold: {{gold}} {{plusgold}}<br>
|
Next Level: <?php if ($char['level'] < 99) { echo number_format($level[$char['charclass']."_exp"]); } else { ?> <span class="light">None</span> <?php } ?><br>
|
||||||
Hit Points: {{currenthp}} / {{maxhp}}<br>
|
Gold: <?= number_format($char['gold']) ?>
|
||||||
Magic Points: {{currentmp}} / {{maxmp}}<br>
|
<?php if ($char['goldbonus'] !== 0): ?> <span class="light">(<?= $char['goldbonus'] > 0 ? '+' : '' ?>) <?= $char['goldbonus'] ?>%)</span> <?php endif; ?><br>
|
||||||
Travel Points: {{currenttp}} / {{maxtp}}<br><br>
|
Hit Points: <?= number_format($char['currenthp']) ?> / <?= number_format($char['maxhp']) ?><br>
|
||||||
|
Magic Points: <?= number_format($char['currentmp']) ?> / <?= number_format($char['maxmp']) ?><br>
|
||||||
|
Travel Points: <?= number_format($char['currenttp']) ?> / <?= number_format($char['maxtp']) ?><br><br>
|
||||||
|
|
||||||
Strength: {{strength}}<br>
|
Strength: <?= number_format($char['strength']) ?><br>
|
||||||
Dexterity: {{dexterity}}<br>
|
Dexterity: <?= number_format($char['dexterity']) ?><br>
|
||||||
Attack Power: {{attackpower}}<br>
|
Attack Power: <?= number_format($char['attackpower']) ?><br>
|
||||||
Defense Power: {{defensepower}}<br>
|
Defense Power: <?= number_format($char['defensepower']) ?><br>
|
||||||
</td></tr>
|
<br>
|
||||||
</table><br>
|
|
||||||
|
|
||||||
<table width="100%">
|
<div class="title"><img src="/img/button_inventory.gif" alt="Inventory" title="Inventory"></div>
|
||||||
<tr><td class="title"><img src="/img/button_inventory.gif" alt="Inventory" title="Inventory" /></td></tr>
|
<img src="/img/icon_weapon.gif" alt="Weapon" title="Weapon"> Weapon: <?= $char['weaponname'] ?><br>
|
||||||
<tr><td>
|
<img src="/img/icon_armor.gif" alt="Armor" title="Armor"> Armor: <?= $char['armorname'] ?><br>
|
||||||
<table width="100%">
|
<img src="/img/icon_shield.gif" alt="Shield" title="Shield"> Shield: <?= $char['shieldname'] ?><br>
|
||||||
<tr><td><img src="/img/icon_weapon.gif" alt="Weapon" title="Weapon" /></td><td width="100%">Weapon: {{weaponname}}</td></tr>
|
Slot 1: <?= $char['slot1name'] ?><br>
|
||||||
<tr><td><img src="/img/icon_armor.gif" alt="Armor" title="Armor" /></td><td width="100%">Armor: {{armorname}}</td></tr>
|
Slot 2: <?= $char['slot2name'] ?><br>
|
||||||
<tr><td><img src="/img/icon_shield.gif" alt="Shield" title="Shield" /></td><td width="100%">Shield: {{shieldname}}</td></tr>
|
Slot 3: <?= $char['slot3name'] ?>
|
||||||
</table>
|
<br>
|
||||||
Slot 1: {{slot1name}}<br>
|
|
||||||
Slot 2: {{slot2name}}<br>
|
|
||||||
Slot 3: {{slot3name}}
|
|
||||||
</td></tr>
|
|
||||||
</table><br>
|
|
||||||
|
|
||||||
<table width="100%">
|
<div class="title"><img src="/img/button_spells.gif" alt="Spells" title="Spells"></div>
|
||||||
<tr><td class="title"><img src="/img/button_spells.gif" alt="Spells" title="Spells" /></td></tr>
|
<?= $magic_list ?>
|
||||||
<tr><td>
|
|
||||||
{{magiclist}}
|
|
||||||
</td></tr>
|
|
||||||
</table><br>
|
|
||||||
THEVERYENDOFYOU;
|
|
||||||
?>
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user