diff --git a/public/index.php b/public/index.php
index 7d0f50e..6e1cdd0 100644
--- a/public/index.php
+++ b/public/index.php
@@ -76,8 +76,6 @@ function index(): string
*/
function show_character_info(int $id = 0): string
{
- global $controlrow;
-
$user = $id !== 0 ? User::find($id) : user();
if ($user === false) exit('Failed to show info for user ID '.$id);
@@ -90,11 +88,10 @@ function show_character_info(int $id = 0): string
foreach ($spells as $spell) $magic_list .= $spell['name'].' ';
}
- $showchar = render('showchar', [
+ $showchar = render('show_char', [
'char' => $user,
'level' => $level,
- 'magic_list' => $magic_list,
- 'controlrow' => $controlrow
+ 'magic_list' => $magic_list
]);
return render('layouts/minimal', ['content' => $showchar, 'title' => $user->username.' Information']);
}
diff --git a/src/actions/explore.php b/src/actions/explore.php
index e41dcbf..30e2142 100644
--- a/src/actions/explore.php
+++ b/src/actions/explore.php
@@ -18,8 +18,6 @@ function explore()
}
function move() {
- global $controlrow;
-
// Early exit if fighting
if (user()->currentaction == 'Fighting') redirect('/fight');
@@ -31,7 +29,7 @@ function move() {
}
// Current game state
- $game_size = $controlrow['gamesize'];
+ $game_size = env('game_size');
$latitude = user()->latitude;
$longitude = user()->longitude;
$direction = $form['data']['direction'];
diff --git a/src/actions/help.php b/src/actions/help.php
index 31d4cda..feed9bf 100644
--- a/src/actions/help.php
+++ b/src/actions/help.php
@@ -16,8 +16,6 @@ function register_routes(Router $r): Router
function main()
{
- global $controlrow;
-
$page = <<Table of Contents
@@ -63,7 +61,7 @@ function main()
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.
- {{class1name}}
+ {env('class_1_name')}
Fast level-ups
High hit points
@@ -76,7 +74,7 @@ function main()
3 +defense spells
0 +attack spells
- {{class2name}}
+ {env('class_2_name')}
Medium level-ups
Medium hit points
@@ -89,7 +87,7 @@ function main()
3 +defense spells
3 +attack spells
- {{class3name}}
+ {env('class_3_name')}
Slow level-ups
Medium hit points
@@ -246,13 +244,11 @@ function main()
[ Top ]
HTML;
- return display_help(parse($page, $controlrow));
+ return display_help($page);
}
function items()
{
- global $controlrow;
-
$page = <<
Items
@@ -319,8 +315,6 @@ function items()
function spells()
{
- global $controlrow;
-
$page = <<
Spells
@@ -373,8 +367,6 @@ function monsters()
function levels()
{
- global $controlrow;
-
$rows = [];
$levels = db()->query('SELECT * FROM levels ORDER BY id;');
@@ -489,14 +481,12 @@ function levels()
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(parse($page, $controlrow));
+ return display_help($page);
}
function display_help(string $content)
{
- global $controlrow;
return render('layouts/help', [
- 'control' => $controlrow,
'content' => $content,
'version' => VERSION,
'build' => BUILD
diff --git a/src/actions/install.php b/src/actions/install.php
index d9bbe92..fc64d21 100644
--- a/src/actions/install.php
+++ b/src/actions/install.php
@@ -56,33 +56,6 @@ function second()
echo table_status_msg($query === true, 'Babble', 'create');
- $query = db()->exec(<<query("INSERT INTO control VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", [
- 1, 'Dragon Knight', 250, 1, $_SERVER['SERVER_NAME'], 'noreply@'.$_SERVER['SERVER_NAME'],
- 'Mage', 'Warrior', 'Paladin', 1, 1, 1, 1
- ]);
-
- echo table_status_msg($query !== false, 'Control', 'populate');
-
$query = db()->exec(<<longitude, 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.');
$page = ['news' => '', 'whos_online' => ''];
// News box. Grab latest news entry and display it. Something a little more graceful coming soon maybe.
- if ($controlrow['shownews'] === 1) {
+ 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"]);
@@ -43,7 +41,7 @@ function town()
}
// Who's Online. Currently just members. Guests maybe later.
- if ($controlrow['showonline'] === 1) {
+ if (env('show_online')) {
$onlinequery = db()->query(<< ['length:3-18', 'alpha-spaces', 'unique:users,username'],
@@ -75,29 +73,29 @@ function register()
} else {
$form = $form['data'];
$password = password_hash($form['password'], PASSWORD_ARGON2ID);
- $token = ($controlrow['verifyemail'] == true) ? token(8) : 'g2g';
+ $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 ($controlrow['verifyemail'] == true) {
+ if (env('verify_email')) {
if (sendregmail($form['email'], $token)) {
$page = "Your account was created successfully.
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 Verification Page to enter your code and start playing.";
} else {
$page = "Your account was created successfully.
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.
You may now continue to the Login Page and continue playing ".$controlrow["gamename"]."!";
+ $page = "Your account was created succesfully.
You may now continue to the Login Page and continue playing ".env('game_name')."!";
}
}
} else {
- if ($controlrow["verifyemail"] == true) {
- $controlrow["verifytext"] = " 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.";
+ if (env('verify_email')) {
+ $verify_text = " 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.";
} else {
- $controlrow["verifytext"] = "";
+ $verify_text = "";
}
- $page = render('register', ['controlrow' => $controlrow]);
+ $page = render('register', ['verify_text' => $verify_text]);
}
page_title('Register');
@@ -198,11 +196,8 @@ function settings()
function sendpassemail($emailaddress, $password)
{
- global $controlrow;
- extract($controlrow);
-
$email = <<verify !== 'g2g' && !in_array($uri[0], ['verify', 'logout'])) {
+ if (env('verify_email') && user()->verify !== 'g2g' && !in_array($uri[0], ['verify', 'logout'])) {
redirect('/verify');
}
diff --git a/src/lib.php b/src/lib.php
index 5eb9fa9..baf8800 100644
--- a/src/lib.php
+++ b/src/lib.php
@@ -37,7 +37,7 @@ function render(string $path_to_base_view, array $data = []): string|false
{
ob_start();
extract($data);
- require "../templates/$name.php";
+ require "../templates/$path_to_base_view.php";
return ob_get_clean();
}
@@ -100,16 +100,6 @@ function game_skin(): int
return user() !== false ? user()->game_skin : 0;
}
-/**
- * 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);
-}
-
/**
* Get a town's data by it's coordinates.
*/
@@ -518,7 +508,6 @@ function is_post(): bool
*/
function page_title(string $new_title = ''): string
{
- global $controlrow;
if ($new_title) return $GLOBALS['state']['new-page-title'] = $new_title;
- return $GLOBALS['state']['new-page-title'] ?? $controlrow['gamename'];
+ return $GLOBALS['state']['new-page-title'] ?? env('game_name');
}
diff --git a/src/mail.php b/src/mail.php
index 10814ba..b955aa0 100644
--- a/src/mail.php
+++ b/src/mail.php
@@ -11,13 +11,9 @@
*/
function send_email(string $to, string $subject, string $message, array $options = []): bool
{
- global $controlrow;
-
- $from_addr = empty($controlrow['adminemail']) ? 'noreply@'.$_SERVER['SERVER_NAME'] : $controlrow['adminemail'];
-
- // Default configuration
+ // Default configuration
$config = array_merge([
- 'from' => $from_addr,
+ 'from' => env('admin_email', 'noreply@'.$_SERVER['SERVER_NAME']),
'log_path' => '../logs/email.log',
'method' => 'smtp', // 'smtp' or 'log'
'smtp_host' => env('smtp_host', 'localhost'),
diff --git a/src/render.php b/src/render.php
index d301af6..3814394 100644
--- a/src/render.php
+++ b/src/render.php
@@ -14,13 +14,7 @@ namespace Render;
function content(string $content): string
{
if (is_htmx()) return $content;
-
- global $controlrow;
-
- return render('layouts/primary', [
- "dkgamename" => $controlrow["gamename"],
- "content" => $content
- ]);
+ return render('layouts/primary', ['content' => $content]);
}
function debug_db_info(): string {
diff --git a/templates/layouts/help.php b/templates/layouts/help.php
index 285c75e..b140eca 100644
--- a/templates/layouts/help.php
+++ b/templates/layouts/help.php
@@ -3,12 +3,12 @@
- = $control['gamename'] ?> Help
+ = env('game_name', 'Dragon Knight') ?> Help
-
= $control['gamename'] ?> Help
+
= env('game_name', 'Dragon Knight') ?> Help
[ Back to Help ]
[ Return to Game ]
diff --git a/templates/layouts/primary.php b/templates/layouts/primary.php
index a6e2649..5e26e90 100644
--- a/templates/layouts/primary.php
+++ b/templates/layouts/primary.php
@@ -23,7 +23,7 @@