\n";
$page .= self::build_bulk_table($drops, 'name', '/admin/drops');
- Lib::page_title('Admin: Drops');
+ page_title('Admin: Drops');
return $page;
}
@@ -177,20 +191,20 @@ class Admin
*/
public static function edit_drop(int $id): string
{
- $drop = Lib::get_drop($id);
+ $drop = get_drop($id);
- if (Lib::is_post()) {
- $page = self::handle_edit_form($id, 'drops', Lib::validate($_POST, [
+ if (is_post()) {
+ $page = self::handle_edit_form($id, 'drops', validate($_POST, [
'name' => [],
'mlevel' => ['int', 'min:1'],
'attribute1' => [],
'attribute2' => ['default:X'],
]));
} else {
- $page = Lib::render('admin/edit_drop', ['drop' => $drop]);
+ $page = render('admin/edit_drop', ['drop' => $drop]);
}
- Lib::page_title('Admin: Editing '.$drop['name']);
+ page_title('Admin: Editing '.$drop['name']);
return $page;
}
@@ -200,11 +214,11 @@ class Admin
*/
public static function towns(): string
{
- $towns = Lib::db()->query('SELECT * FROM towns ORDER BY id;');
+ $towns = db()->query('SELECT * FROM towns ORDER BY id;');
$page = "
Edit Towns
Click an town's name or ID to edit it.
\n";
$page .= self::build_bulk_table($towns, 'name', '/admin/towns');
- Lib::page_title('Admin: Towns');
+ page_title('Admin: Towns');
return $page;
}
@@ -214,23 +228,23 @@ class Admin
*/
public static function edit_town(int $id): string
{
- $town = Lib::get_town_by_id($id);
+ $town = get_town_by_id($id);
- if (Lib::is_post()) {
- $page = self::handle_edit_form($id, 'towns', Lib::validate($_POST, [
+ if (is_post()) {
+ $page = self::handle_edit_form($id, 'towns', validate($_POST, [
'name' => [],
- 'latitude' => ['int', 'min:0', 'max:'.Lib::env('game_size')],
- 'longitude' => ['int', 'min:0', 'max:'.Lib::env('game_size')],
+ '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 = Lib::render('admin/edit_town', ['town' => $town]);
+ $page = render('admin/edit_town', ['town' => $town]);
}
- Lib::page_title('Admin: Editing '.$town['name']);
+ page_title('Admin: Editing '.$town['name']);
return $page;
}
@@ -240,19 +254,19 @@ class Admin
*/
public static function monsters()
{
- $max_level = Lib::db()->query('SELECT level FROM monsters ORDER BY level DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC)['level'];
- $monsters = Lib::db()->query('SELECT * FROM monsters ORDER BY id;');
+ $max_level = db()->query('SELECT level FROM monsters ORDER BY level DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC)['level'];
+ $monsters = db()->query('SELECT * FROM monsters ORDER BY id;');
$page = '
Edit Monsters
';
- $page .= ((Lib::env('game_size') / 5) !== $max_level)
- ? 'Note: Your highest monster level does not match with your entered map size. Highest monster level should be '.(Lib::env('game_size') / 5).", yours is $max_level. Please fix this before opening the game to the public. "
+ $page .= ((env('game_size') / 5) !== $max_level)
+ ? 'Note: Your highest monster level does not match with your entered map size. Highest monster level should be '.(env('game_size') / 5).", yours is $max_level. Please fix this before opening the game to the public. "
: 'Monster level and map size match. No further actions are required for map compatibility. ';
$page .= "Click an monster's name or ID to edit it.
diff --git a/src/DragonKnight/Actions/Explore.php b/src/DragonKnight/Actions/Explore.php
index 531fff2..211e1d1 100644
--- a/src/DragonKnight/Actions/Explore.php
+++ b/src/DragonKnight/Actions/Explore.php
@@ -13,7 +13,14 @@ declare(strict_types=1);
namespace DragonKnight\Actions;
-use DragonKnight\Lib;
+use function DragonKnight\env;
+use function DragonKnight\get_town_by_xy;
+use function DragonKnight\index;
+use function DragonKnight\page_title;
+use function DragonKnight\redirect;
+use function DragonKnight\ul_from_validate_errors;
+use function DragonKnight\user;
+use function DragonKnight\validate;
class Explore
{
@@ -23,7 +30,7 @@ class Explore
*/
public static function explore()
{
- Lib::page_title('Exploring');
+ page_title('Exploring');
return <<
@@ -34,20 +41,20 @@ class Explore
public static function move()
{
// Early exit if fighting
- if (Lib::user()->currentaction == 'Fighting') {
- Lib::redirect('/fight');
+ if (user()->currentaction == 'Fighting') {
+ redirect('/fight');
}
// Validate direction
- $form = Lib::validate($_POST, ['direction' => ['in:north,west,east,south']]);
+ $form = validate($_POST, ['direction' => ['in:north,west,east,south']]);
if (! $form['valid']) {
- return Lib::ul_from_validate_errors($form['errors']);
+ return ul_from_validate_errors($form['errors']);
}
// Current game state
- $game_size = Lib::env('game_size');
- $latitude = Lib::user()->latitude;
- $longitude = Lib::user()->longitude;
+ $game_size = env('game_size');
+ $latitude = user()->latitude;
+ $longitude = user()->longitude;
$direction = $form['data']['direction'];
// Calculate new coordinates with boundary checks
@@ -67,23 +74,23 @@ class Explore
}
// Check for town
- $town = Lib::get_town_by_xy($longitude, $latitude);
+ $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) {
- Lib::user()->currentaction = 'Fighting';
- Lib::user()->currentfight = 1;
+ user()->currentaction = 'Fighting';
+ user()->currentfight = 1;
} else {
- Lib::user()->currentaction = 'Exploring';
+ user()->currentaction = 'Exploring';
}
- Lib::user()->latitude = $latitude;
- Lib::user()->longitude = $longitude;
- Lib::user()->save();
+ user()->latitude = $latitude;
+ user()->longitude = $longitude;
+ user()->save();
- return Lib::index();
+ return index();
}
}
diff --git a/src/DragonKnight/Actions/Fight.php b/src/DragonKnight/Actions/Fight.php
index 90d1fe6..a3a7786 100644
--- a/src/DragonKnight/Actions/Fight.php
+++ b/src/DragonKnight/Actions/Fight.php
@@ -13,7 +13,6 @@ declare(strict_types=1);
namespace DragonKnight\Actions;
-use DragonKnight\Lib;
use DragonKnight\Router;
class Fight
@@ -33,7 +32,7 @@ class Fight
*/
public static function fight()
{
- if (Lib::user()->currentaction !== 'Fighting') {
+ if (user()->currentaction !== 'Fighting') {
exit('Cheat attempt detected.
Get a life, loser.');
}
@@ -41,7 +40,7 @@ class Fight
$playerisdead = 0;
// Generate spell list
- $user_spells = Lib::user()->spells();
+ $user_spells = user()->spells();
if (! empty($user_spells)) {
$page['magiclist'] = '
HTML;
- $monsters = Lib::db()->query('SELECT * FROM monsters ORDER BY id;');
+ $monsters = db()->query('SELECT * FROM monsters ORDER BY id;');
$immunities = ['None', 'Hurt', 'Hurt & Sleep'];
while ($m = $monsters->fetchArray(SQLITE3_ASSOC)) {
@@ -383,7 +382,7 @@ class Help
{
$rows = [];
- $levels = Lib::db()->query('SELECT * FROM levels ORDER BY id;');
+ $levels = db()->query('SELECT * FROM levels ORDER BY id;');
while ($level = $levels->fetchArray(SQLITE3_ASSOC)) {
$class_data = [1 => [], 2 => [], 3 => []];
@@ -405,7 +404,7 @@ class Help
}
$spells = [];
- $spells_query = Lib::db()->query('SELECT * FROM spells ORDER BY id;');
+ $spells_query = db()->query('SELECT * FROM spells ORDER BY id;');
while ($spell = $spells_query->fetchArray(SQLITE3_ASSOC)) {
$spells[$spell['id']] = $spell;
}
@@ -508,7 +507,7 @@ class Help
public static function display_help(string $content)
{
- return Lib::render('layouts/help', [
+ return render('layouts/help', [
'content' => $content,
'version' => VERSION,
'build' => BUILD,
diff --git a/src/DragonKnight/Actions/Install.php b/src/DragonKnight/Actions/Install.php
index c62d9ed..b2e8c09 100644
--- a/src/DragonKnight/Actions/Install.php
+++ b/src/DragonKnight/Actions/Install.php
@@ -13,9 +13,13 @@ declare(strict_types=1);
namespace DragonKnight\Actions;
-use DragonKnight\Lib;
use DragonKnight\Router;
+use function DragonKnight\db;
+use function DragonKnight\ul_from_validate_errors;
+use function DragonKnight\user;
+use function DragonKnight\validate;
+
class Install
{
public static function register_routes(Router $r): Router
@@ -56,20 +60,20 @@ class Install
*/
public static function second()
{
- if (! is_dir($path = getcwd().'/db')) {
+ if (! is_dir($path = getcwd().'/db')) {
if (mkdir($path, 0777, true) === false) {
- throw new \Exception('Failed to create database directory at '.$path.'. Please check permissions.');
- }
+ throw new \Exception('Failed to create database directory at '.$path.'. Please check permissions.');
+ }
}
if (file_exists($path = getcwd().'/db/database.db')) {
if (unlink($path) === false) {
- throw new \Exception('Failed to delete existing database file at '.$path.'. Please check permissions.');
- }
+ throw new \Exception('Failed to delete existing database file at '.$path.'. Please check permissions.');
+ }
}
$page = 'Dragon Knight InstallationDragon Knight Installation: Page Two
';
- $query = Lib::db()->exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<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.');");
+ $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 .= self::table_status_msg($query === true, 'News', 'populate');
- $query = Lib::db()->exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<<exec(<< ['length:3-18', 'alpha-spaces'],
'email' => ['email'],
'confirm_email' => ['confirm'],
@@ -723,11 +727,11 @@ class Install
]);
if (! $form['valid']) {
- exit(Lib::ul_from_validate_errors($form['errors']));
+ exit(ul_from_validate_errors($form['errors']));
}
$form = $form['data'];
- if (Lib::db()->query(
+ 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'] ?? null]
) === false) {
@@ -788,7 +792,7 @@ class Install
};
if ($condition === false) {
- return "Error {$verb[1]} $table_name table. (".Lib::db()->lastErrorMsg().') ';
+ return "Error {$verb[1]} $table_name table. (".db()->lastErrorMsg().') ';
}
return "$table_name table {$verb[0]}. ";
diff --git a/src/DragonKnight/Actions/Towns.php b/src/DragonKnight/Actions/Towns.php
index ffea7af..a9d4c4e 100644
--- a/src/DragonKnight/Actions/Towns.php
+++ b/src/DragonKnight/Actions/Towns.php
@@ -13,9 +13,19 @@ declare(strict_types=1);
namespace DragonKnight\Actions;
-use DragonKnight\Lib;
use DragonKnight\Router;
+use function DragonKnight\db;
+use function DragonKnight\env;
+use function DragonKnight\get_town_by_xy;
+use function DragonKnight\get_item;
+use function DragonKnight\get_town_by_id;
+use function DragonKnight\is_post;
+use function DragonKnight\page_title;
+use function DragonKnight\redirect;
+use function DragonKnight\render;
+use function DragonKnight\user;
+
class Towns
{
public static function register_routes(Router $r): Router
@@ -36,7 +46,7 @@ class Towns
*/
public static function town()
{
- $town = Lib::get_town_by_xy(Lib::user()->longitude, Lib::user()->latitude);
+ $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.');
}
@@ -44,9 +54,9 @@ class Towns
$page = ['news' => '', 'whos_online' => ''];
// News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe.
- if (Lib::env('show_news')) {
- $news = Lib::db()->query('SELECT * FROM news ORDER BY id DESC LIMIT 1;')->fetchArray(SQLITE3_ASSOC);
- $news_date = Lib::pretty_date($news['postdate']);
+ 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'] = <<Latest News
@@ -56,8 +66,8 @@ class Towns
}
// Who's Online. Currently just members. Guests maybe later.
- if (Lib::env('show_online')) {
- $onlinequery = Lib::db()->query(<<query(<<= datetime('now', '-600 seconds')
@@ -75,13 +85,13 @@ class Towns
$online_rows = implode(', ', $online_rows);
$page['whos_online'] = <<Who's Online
- There are $online_count Lib::user(s) online within the last 10 minutes: $online_rows
+ There are $online_count user(s) online within the last 10 minutes: $online_rows
HTML;
}
- Lib::page_title($town['name']);
+ page_title($town['name']);
- return Lib::render('towns', ['town' => $town, 'news' => $page['news'], 'whos_online' => $page['whos_online']]);
+ return render('towns', ['town' => $town, 'news' => $page['news'], 'whos_online' => $page['whos_online']]);
}
/**
@@ -90,25 +100,25 @@ class Towns
*/
public static function inn()
{
- $town = Lib::get_town_by_xy(Lib::user()->longitude, Lib::user()->latitude);
+ $town = get_town_by_xy(user()->longitude, user()->latitude);
if ($town === false) {
exit('Cheat attempt detected.
Get a life, loser.');
}
- if (Lib::user()->gold < $town['innprice']) {
+ if (user()->gold < $town['innprice']) {
$page = <<
You may return to town, or use the direction buttons on the left to start exploring.
HTML;
- } elseif (Lib::is_post() && $_POST['rest']) {
- Lib::user()->gold -= $town['innprice'];
- Lib::user()->restore_points()->save();
+ } elseif (is_post() && $_POST['rest']) {
+ user()->gold -= $town['innprice'];
+ user()->restore_points()->save();
$page = <<
You may return to town, or use the direction buttons on the left to start exploring.
HTML;
- } elseif (Lib::is_post() && ! $_POST['rest']) {
- Lib::redirect('/');
+ } elseif (is_post() && ! $_POST['rest']) {
+ redirect('/');
} else {
$page = <<
@@ -120,7 +130,7 @@ class Towns
HTML;
}
- Lib::page_title($town['name'].' Inn');
+ page_title($town['name'].' Inn');
return $page;
}
@@ -132,7 +142,7 @@ class Towns
*/
public static function shop()
{
- $town = Lib::get_town_by_xy(Lib::user()->longitude, Lib::user()->latitude);
+ $town = get_town_by_xy(user()->longitude, user()->latitude);
if ($town === false) {
exit('Cheat attempt detected.
Get a life, loser.');
}
@@ -144,7 +154,7 @@ class Towns
HTML;
- $items = Lib::db()->query('SELECT * FROM items WHERE id IN ('.$town['itemslist'].');');
+ $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 .= '
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.
@@ -18,14 +18,14 @@
Game Name:
-
+ Change this if you want to change to call your game something different.
Game URL:
-
+ 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.
@@ -34,7 +34,7 @@
Admin Email:
-
+ Please specify your email address. This gets used when the game has to send an
email to users.
@@ -42,7 +42,7 @@
Map Size:
-
+
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)
@@ -55,8 +55,8 @@
Email Verification:
Make users verify their email address for added security.