Full conversion from control row to env
This commit is contained in:
parent
d47e1c5744
commit
b90a9c179c
|
@ -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'].'<br>';
|
||||
}
|
||||
|
||||
$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']);
|
||||
}
|
||||
|
|
|
@ -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'];
|
||||
|
|
|
@ -16,8 +16,6 @@ function register_routes(Router $r): Router
|
|||
|
||||
function main()
|
||||
{
|
||||
global $controlrow;
|
||||
|
||||
$page = <<<HTML
|
||||
<h3>Table of Contents</h3>
|
||||
<ul>
|
||||
|
@ -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.<br><br>
|
||||
<b>{{class1name}}</b>
|
||||
<b>{env('class_1_name')}</b>
|
||||
<ul>
|
||||
<li>Fast level-ups</li>
|
||||
<li>High hit points</li>
|
||||
|
@ -76,7 +74,7 @@ function main()
|
|||
<li>3 +defense spells</li>
|
||||
<li>0 +attack spells</li>
|
||||
</ul>
|
||||
<b>{{class2name}}</b>
|
||||
<b>{env('class_2_name')}</b>
|
||||
<ul>
|
||||
<li>Medium level-ups</li>
|
||||
<li>Medium hit points</li>
|
||||
|
@ -89,7 +87,7 @@ function main()
|
|||
<li>3 +defense spells</li>
|
||||
<li>3 +attack spells</li>
|
||||
</ul>
|
||||
<b>{{class3name}}</b>
|
||||
<b>{env('class_3_name')}</b>
|
||||
<ul>
|
||||
<li>Slow level-ups</li>
|
||||
<li>Medium hit points</li>
|
||||
|
@ -246,13 +244,11 @@ function main()
|
|||
[ <a href="#top">Top</a> ]
|
||||
HTML;
|
||||
|
||||
return display_help(parse($page, $controlrow));
|
||||
return display_help($page);
|
||||
}
|
||||
|
||||
function items()
|
||||
{
|
||||
global $controlrow;
|
||||
|
||||
$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>
|
||||
|
@ -319,8 +315,6 @@ function items()
|
|||
|
||||
function spells()
|
||||
{
|
||||
global $controlrow;
|
||||
|
||||
$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>
|
||||
|
@ -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
|
||||
|
|
|
@ -56,33 +56,6 @@ function second()
|
|||
|
||||
echo table_status_msg($query === true, 'Babble', 'create');
|
||||
|
||||
$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 table_status_msg($query === true, 'Control', 'create');
|
||||
|
||||
$query = db()->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(<<<SQL
|
||||
CREATE TABLE drops (
|
||||
`id` INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
|
|
|
@ -23,15 +23,13 @@ function register_routes(Router $r): Router
|
|||
*/
|
||||
function town()
|
||||
{
|
||||
global $controlrow;
|
||||
|
||||
$town = get_town_by_xy(user()->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(<<<SQL
|
||||
SELECT id, username
|
||||
FROM users
|
||||
|
|
|
@ -57,8 +57,6 @@ function logout()
|
|||
*/
|
||||
function register()
|
||||
{
|
||||
global $controlrow;
|
||||
|
||||
if (isset($_POST["submit"])) {
|
||||
$form = validate($_POST, [
|
||||
'username' => ['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.<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 ".$controlrow["gamename"]."!";
|
||||
$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 ($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>";
|
||||
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 {
|
||||
$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 = <<<HTML
|
||||
You or someone using your email address submitted a Lost Password application on the $gamename server, located at $gameurl.
|
||||
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.
|
||||
|
||||
|
@ -211,17 +206,15 @@ function sendpassemail($emailaddress, $password)
|
|||
Thanks for playing.
|
||||
HTML;
|
||||
|
||||
return send_email($emailaddress, "$gamename Lost Password", $email);
|
||||
return send_email($emailaddress, env('game_name')." Lost Password", $email);
|
||||
}
|
||||
|
||||
function sendregmail($emailaddress, $vercode)
|
||||
{
|
||||
global $controlrow;
|
||||
extract($controlrow);
|
||||
$verurl = $gameurl . "/verify";
|
||||
$verurl = env('game_url') . "/verify";
|
||||
|
||||
$email = <<<HTML
|
||||
You or someone using your email address recently signed up for an account on the $gamename server, located at $gameurl.
|
||||
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.
|
||||
|
@ -230,5 +223,5 @@ function sendregmail($emailaddress, $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, "$gamename Account Verification", $email);
|
||||
return send_email($emailaddress, env('game_name')." Account Verification", $email);
|
||||
}
|
||||
|
|
|
@ -28,9 +28,7 @@ if (!file_exists('../.installed') && $uri[0] !== 'install') {
|
|||
} elseif (file_exists(('../.installed')) && $uri[0] === 'install') {
|
||||
redirect('/');
|
||||
} elseif (file_exists(('../.installed')) && $uri[0] !== 'install') {
|
||||
$controlrow = get_control_row();
|
||||
|
||||
if (!$controlrow["gameopen"]) {
|
||||
if (!env('game_open')) {
|
||||
echo Render\content('The game is currently closed for maintanence. Please check back later.');
|
||||
exit;
|
||||
}
|
||||
|
@ -49,7 +47,7 @@ if (!file_exists('../.installed') && $uri[0] !== 'install') {
|
|||
}
|
||||
|
||||
// Force verify if the user isn't verified yet.
|
||||
if ($controlrow['verifyemail'] && user()->verify !== 'g2g' && !in_array($uri[0], ['verify', 'logout'])) {
|
||||
if (env('verify_email') && user()->verify !== 'g2g' && !in_array($uri[0], ['verify', 'logout'])) {
|
||||
redirect('/verify');
|
||||
}
|
||||
|
||||
|
|
15
src/lib.php
15
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');
|
||||
}
|
||||
|
|
|
@ -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'),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= $control['gamename'] ?> Help</title>
|
||||
<title><?= env('game_name', 'Dragon Knight') ?> Help</title>
|
||||
<link rel="stylesheet" href="/css/help.css">
|
||||
</head>
|
||||
<body>
|
||||
<a name="top"></a>
|
||||
<h1><?= $control['gamename'] ?> Help</h1>
|
||||
<h1><?= env('game_name', 'Dragon Knight') ?> Help</h1>
|
||||
[ <a href="/help">Back to Help</a> ]<br>
|
||||
[ <a href="/">Return to Game</a> ]
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<body class="skin-<?= game_skin() ?>">
|
||||
<div id="game-container">
|
||||
<header>
|
||||
<a href="/"><img id="logo" src="/img/logo.gif" alt="<?= $dkgamename ?>" title="<?= $dkgamename ?>"></a>
|
||||
<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>
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
<tr><td>Password:</td><td><input type="password" name="password"></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="email" name="email"></td></tr>
|
||||
<tr><td>Verify Email:</td><td><input type="email" name="confirm_email"><?= $controlrow['verifytext'] ?><br><br><br></td></tr>
|
||||
<tr><td>Verify Email:</td><td><input type="email" name="confirm_email"><?= $verify_text ?><br><br><br></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>
|
||||
<option value="1"><?= env('class_1_name') ?></option>
|
||||
<option value="2"><?= env('class_2_name') ?></option>
|
||||
<option value="3"><?= env('class_3_name') ?></option>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
<b><?= $char->username ?></b><br><br>
|
||||
|
||||
Class: <?= match ($char->charclass) {
|
||||
1 => $controlrow["class1name"],
|
||||
2 => $controlrow["class2name"],
|
||||
3 => $controlrow["class3name"]
|
||||
1 => env('class_1_name'),
|
||||
2 => env('class_2_name'),
|
||||
3 => env('class_3_name')
|
||||
}; ?><br><br>
|
||||
|
||||
Level: <?= $char->level ?><br>
|
Loading…
Reference in New Issue
Block a user