Finish install 2
This commit is contained in:
parent
624e2a7bc8
commit
4eb4d29a5b
|
@ -34,9 +34,6 @@ if ($step == 'second') {
|
|||
"admin_email TEXT DEFAULT ''",
|
||||
'forum_type INTEGER DEFAULT 1',
|
||||
"forum_addr TEXT DEFAULT ''",
|
||||
"class_1_name TEXT DEFAULT 'Mage'",
|
||||
"class_2_name TEXT DEFAULT 'Warrior'",
|
||||
"class_3_name TEXT DEFAULT 'Paladin'",
|
||||
'verify_email INTEGER DEFAULT 1',
|
||||
'show_news INTEGER DEFAULT 1',
|
||||
'show_online INTEGER DEFAULT 1',
|
||||
|
@ -46,6 +43,37 @@ if ($step == 'second') {
|
|||
// Insert default control row
|
||||
$db->insertDefaultValues();
|
||||
|
||||
// Create classes table
|
||||
$db->table('classes')->create([
|
||||
'id INTEGER PRIMARY KEY',
|
||||
'name TEXT NOT NULL',
|
||||
'start_hp INTEGER DEFAULT 0',
|
||||
'start_mp INTEGER DEFAULT 0',
|
||||
'start_str INTEGER DEFAULT 0',
|
||||
'start_atk INTEGER DEFAULT 0',
|
||||
'start_def INTEGER DEFAULT 0',
|
||||
'start_dex INTEGER DEFAULT 0',
|
||||
'growth_hp INTEGER DEFAULT 0',
|
||||
'growth_mp INTEGER DEFAULT 0',
|
||||
'growth_str INTEGER DEFAULT 0',
|
||||
'growth_atk INTEGER DEFAULT 0',
|
||||
'growth_def INTEGER DEFAULT 0',
|
||||
'growth_dex INTEGER DEFAULT 0',
|
||||
"spells TEXT DEFAULT ''"
|
||||
]);
|
||||
|
||||
// Add default classes if complete install
|
||||
if ($complete) {
|
||||
$db->insert([
|
||||
['name' => 'Mage', 'start_hp' => 10, 'start_mp' => 10, 'start_str' => 5, 'start_atk' => 5, 'start_def' => 5, 'start_dex' => 5, 'growth_hp' => 3, 'growth_mp' => 5, 'growth_str' => 1, 'growth_atk' => 3, 'growth_def' => 1, 'growth_dex' => 3, 'spells' => '1:6,18'],
|
||||
['name' => 'Warrior', 'start_hp' => 20, 'start_mp' => 0, 'start_str' => 10, 'start_atk' => 5, 'start_def' => 10, 'start_dex' => 5, 'growth_hp' => 6, 'growth_mp' => 2, 'growth_str' => 3, 'growth_atk' => 1, 'growth_def' => 3, 'growth_dex' => 1, 'spells' => ''],
|
||||
['name' => 'Paladin', 'start_hp' => 15, 'start_mp' => 5, 'start_str' => 5, 'start_atk' => 5, 'start_def' => 10, 'start_dex' => 10, 'growth_hp' => 4, 'growth_mp' => 4, 'growth_str' => 2, 'growth_atk' => 2, 'growth_def' => 2, 'growth_dex' => 2, 'spells' => '1:1,15,18']
|
||||
]);
|
||||
} else {
|
||||
// There must be at least one class, for user creation to work
|
||||
$db->insert(['name' => 'Adventurer']);
|
||||
}
|
||||
|
||||
// Create Babble table
|
||||
$db->table('babble')->create([
|
||||
'id INTEGER PRIMARY KEY',
|
||||
|
@ -374,34 +402,34 @@ if ($step == 'second') {
|
|||
if ($complete) {
|
||||
$db->table('spells')->insert([
|
||||
// Type 1 = healing
|
||||
['name' => 'Heal', 'type' => 1, 'mp' => 5, 'effect' => 'heal:self,10', 'icon' => 'heal.png' ],
|
||||
['name' => 'Cure', 'type' => 1, 'mp' => 10, 'effect' => 'heal:self,25', 'icon' => 'cure.png' ],
|
||||
['name' => 'Breath', 'type' => 1, 'mp' => 25, 'effect' => 'heal:self,50', 'icon' => 'breath.png'],
|
||||
['name' => 'Revive', 'type' => 1, 'mp' => 50, 'effect' => 'heal:self,100', 'icon' => 'revive.png'],
|
||||
['name' => 'Gaia', 'type' => 1, 'mp' => 75, 'effect' => 'heal:self,150', 'icon' => 'gaia.png' ],
|
||||
['name' => 'Heal', 'type' => 1, 'mp' => 5, 'effect' => 'heal:self,10', 'icon' => 'heal.png' ], // 1
|
||||
['name' => 'Cure', 'type' => 1, 'mp' => 10, 'effect' => 'heal:self,25', 'icon' => 'cure.png' ], // 2
|
||||
['name' => 'Breath', 'type' => 1, 'mp' => 25, 'effect' => 'heal:self,50', 'icon' => 'breath.png'], // 3
|
||||
['name' => 'Revive', 'type' => 1, 'mp' => 50, 'effect' => 'heal:self,100', 'icon' => 'revive.png'], // 4
|
||||
['name' => 'Gaia', 'type' => 1, 'mp' => 75, 'effect' => 'heal:self,150', 'icon' => 'gaia.png' ], // 5
|
||||
|
||||
// Type 2 = damage
|
||||
['name' => 'Slash', 'type' => 2, 'mp' => 5, 'effect' => 'damage:opp,10', 'icon' => 'slash.png' ],
|
||||
['name' => 'Magic Missile', 'type' => 2, 'mp' => 12, 'effect' => 'damage:opp,35', 'icon' => 'missile.png' ],
|
||||
['name' => 'Fireball', 'type' => 2, 'mp' => 25, 'effect' => 'damage:opp,70', 'icon' => 'fireball.png' ],
|
||||
['name' => 'Pain', 'type' => 2, 'mp' => 40, 'effect' => 'damage:opp,100', 'icon' => 'pain.png' ],
|
||||
['name' => 'Lightning', 'type' => 2, 'mp' => 50, 'effect' => 'damage:opp,130', 'icon' => 'lightning.png'],
|
||||
['name' => 'Chaos', 'type' => 2, 'mp' => 75, 'effect' => 'damage:opp,200', 'icon' => 'chaos.png' ],
|
||||
['name' => 'Slash', 'type' => 2, 'mp' => 5, 'effect' => 'damage:opp,10', 'icon' => 'slash.png' ], // 6
|
||||
['name' => 'Magic Missile', 'type' => 2, 'mp' => 12, 'effect' => 'damage:opp,35', 'icon' => 'missile.png' ], // 7
|
||||
['name' => 'Fireball', 'type' => 2, 'mp' => 25, 'effect' => 'damage:opp,70', 'icon' => 'fireball.png' ], // 8
|
||||
['name' => 'Pain', 'type' => 2, 'mp' => 40, 'effect' => 'damage:opp,100', 'icon' => 'pain.png' ], // 9
|
||||
['name' => 'Lightning', 'type' => 2, 'mp' => 50, 'effect' => 'damage:opp,130', 'icon' => 'lightning.png'], // 10
|
||||
['name' => 'Chaos', 'type' => 2, 'mp' => 75, 'effect' => 'damage:opp,200', 'icon' => 'chaos.png' ], // 11
|
||||
|
||||
// Type 3 = sleep
|
||||
['name' => 'Sleep', 'type' => 3, 'mp' => 10, 'effect' => 'sleep:opp,3', 'icon' => 'sleep.png' ],
|
||||
['name' => 'Dream', 'type' => 3, 'mp' => 30, 'effect' => 'sleep:opp,6', 'icon' => 'dream.png' ],
|
||||
['name' => 'Nightmare', 'type' => 3, 'mp' => 60, 'effect' => 'sleep:opp,13', 'icon' => 'nightmare.png'],
|
||||
['name' => 'Sleep', 'type' => 3, 'mp' => 10, 'effect' => 'sleep:opp,3', 'icon' => 'sleep.png' ], // 12
|
||||
['name' => 'Dream', 'type' => 3, 'mp' => 30, 'effect' => 'sleep:opp,6', 'icon' => 'dream.png' ], // 13
|
||||
['name' => 'Nightmare', 'type' => 3, 'mp' => 60, 'effect' => 'sleep:opp,13', 'icon' => 'nightmare.png'], // 14
|
||||
|
||||
// Type 4 = rage
|
||||
['name' => 'Craze', 'type' => 4, 'mp' => 10, 'effect' => 'rage:self,3', 'icon' => 'craze.png'],
|
||||
['name' => 'Rage', 'type' => 4, 'mp' => 30, 'effect' => 'rage:self,6', 'icon' => 'rage.png' ],
|
||||
['name' => 'Fury', 'type' => 4, 'mp' => 60, 'effect' => 'rage:self,13', 'icon' => 'fury.png' ],
|
||||
['name' => 'Craze', 'type' => 4, 'mp' => 10, 'effect' => 'rage:self,3', 'icon' => 'craze.png'], // 15
|
||||
['name' => 'Rage', 'type' => 4, 'mp' => 30, 'effect' => 'rage:self,6', 'icon' => 'rage.png' ], // 16
|
||||
['name' => 'Fury', 'type' => 4, 'mp' => 60, 'effect' => 'rage:self,13', 'icon' => 'fury.png' ], // 17
|
||||
|
||||
// Type 5 = protect
|
||||
['name' => 'Ward', 'type' => 5, 'mp' => 10, 'effect' => 'protect:self,3', 'icon' => 'ward.png' ],
|
||||
['name' => 'Guard', 'type' => 5, 'mp' => 30, 'effect' => 'protect:self,6', 'icon' => 'guard.png' ],
|
||||
['name' => 'Barrier', 'type' => 5, 'mp' => 60, 'effect' => 'protect:self,13', 'icon' => 'barrier.png'],
|
||||
['name' => 'Ward', 'type' => 5, 'mp' => 10, 'effect' => 'protect:self,3', 'icon' => 'ward.png' ], // 18
|
||||
['name' => 'Guard', 'type' => 5, 'mp' => 30, 'effect' => 'protect:self,6', 'icon' => 'guard.png' ], // 19
|
||||
['name' => 'Barrier', 'type' => 5, 'mp' => 60, 'effect' => 'protect:self,13', 'icon' => 'barrier.png'] // 20
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -443,10 +471,11 @@ if ($step == 'second') {
|
|||
'last_online DATETIME DEFAULT CURRENT_TIMESTAMP',
|
||||
'currently INTEGER DEFAULT 0',
|
||||
'role INTEGER DEFAULT 1',
|
||||
'class INTEGER DEFAULT 1',
|
||||
'class_id INTEGER DEFAULT 1',
|
||||
'level INTEGER DEFAULT 1',
|
||||
'exp INTEGER DEFAULT 0',
|
||||
'gold INTEGER DEFAULT 0',
|
||||
'stat_points INTEGER DEFAULT 0',
|
||||
'hp INTEGER DEFAULT 0',
|
||||
'max_hp INTEGER DEFAULT 0',
|
||||
'mp INTEGER DEFAULT 0',
|
||||
|
@ -493,6 +522,7 @@ if ($step == 'second') {
|
|||
if ($step == 'third') {
|
||||
$errors = [];
|
||||
|
||||
// Make sure our info is at least mostly valid
|
||||
if (!required(['username', 'password', 'email'])) {
|
||||
$errors[] = 'All fields are required.';
|
||||
} else {
|
||||
|
@ -505,21 +535,22 @@ if ($step == 'third') {
|
|||
}
|
||||
}
|
||||
|
||||
$class = isset($_POST['class']) && in_array($_POST['class'], [1, 2, 3]) ? $_POST['class'] : 0;
|
||||
// Make sure the class selection is valid
|
||||
$class = isset($_POST['class']) && in_array($_POST['class'], [1, 2, 3]) ? $_POST['class'] : 1;
|
||||
|
||||
// If we have any errors, bail to the form and let the user know
|
||||
if (!empty($errors)) {
|
||||
echo render('install/layout', ['title' => 'Admin Account', 'step' => 'third', 'errors' => $errors, 'complete' => $_POST['complete'] ?? false]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$db->table('players')->insert([
|
||||
'username' => trim($_POST['username']),
|
||||
'password' => password_hash($_POST['password'], PASSWORD_ARGON2ID),
|
||||
'email' => trim($_POST['email']),
|
||||
'class' => $class,
|
||||
'role' => 5
|
||||
]);
|
||||
// Create the .installed file in the server folder
|
||||
file_put_contents(SERVER.'/.installed', 'Installed on '.date('Y-m-d H:i:s'));
|
||||
|
||||
// Create the admin account
|
||||
createUser($_POST['username'], $_POST['password'], $_POST['email'], $class, ['role' => 5, 'verified' => 1]);
|
||||
|
||||
// Render the finished page!
|
||||
echo render('install/layout', ['title' => 'Finished!', 'step' => 'done', 'name' => $_POST['username'], 'complete' => $_POST['complete'] ?? false]);
|
||||
exit;
|
||||
}
|
||||
|
|
|
@ -11,5 +11,5 @@ const VERSION = '1.1.11';
|
|||
const BUILD = '';
|
||||
const DB = SERVER.'/database/dragon.db';
|
||||
|
||||
require_once SERVER.'/lib.php';
|
||||
require_once SERVER.'/library.php';
|
||||
require_once SERVER.'/database.php';
|
Binary file not shown.
Binary file not shown.
|
@ -1,33 +1,43 @@
|
|||
<?php // lib.php :: Common functions used throughout the program.
|
||||
<?php // library.php :: Common functions used throughout the program.
|
||||
|
||||
// A stopwatch function to return the elapsed time in seconds.
|
||||
/**
|
||||
* A stopwatch function to return the elapsed time in seconds.
|
||||
*/
|
||||
function stopwatch(float $start, int $roundTo = 3): float
|
||||
{
|
||||
return round(microtime(true) - $start, $roundTo);
|
||||
}
|
||||
|
||||
// Redirect to another page.
|
||||
/**
|
||||
* Redirects to a URL.
|
||||
*/
|
||||
function redirect(string $url): void
|
||||
{
|
||||
header("Location: $url");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Check if the server is installed.
|
||||
/**
|
||||
* Checks if the server is installed.
|
||||
*/
|
||||
function installed(): bool
|
||||
{
|
||||
return file_exists(SERVER.'/.installed');
|
||||
}
|
||||
|
||||
// Get a template path.
|
||||
/**
|
||||
* Returns the path to a template.
|
||||
*/
|
||||
function template(string $name): string
|
||||
{
|
||||
return SERVER."/templates/$name.php";
|
||||
}
|
||||
|
||||
// Render a template. Pass data to it - uses an output buffer to have PHP process the template instead of using
|
||||
// a template engine. If you're including partials in the page, call render('partial', $data), as $data will still
|
||||
// be available.
|
||||
/**
|
||||
* Renders a template. Pass data to it - uses an output buffer to have PHP process the template instead of using
|
||||
* a template engine. If you're including partials in the page, call `render('partial', $data)`, as $data will still
|
||||
* be available.
|
||||
*/
|
||||
function render(string $baseView, array $data = []): string
|
||||
{
|
||||
ob_start();
|
||||
|
@ -36,7 +46,9 @@ function render(string $baseView, array $data = []): string
|
|||
return ob_get_clean();
|
||||
}
|
||||
|
||||
// Checks if all required POST variables are set.
|
||||
/**
|
||||
* Checks if all required fields are set.
|
||||
*/
|
||||
function required(array $keys): bool
|
||||
{
|
||||
foreach ($keys as $key) {
|
||||
|
@ -45,6 +57,9 @@ function required(array $keys): bool
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump and die. Useful for debugging.
|
||||
*/
|
||||
function dd(mixed $var, bool $r = false)
|
||||
{
|
||||
echo '<pre>';
|
||||
|
@ -53,22 +68,23 @@ function dd(mixed $var, bool $r = false)
|
|||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new user. Optionally pass an array of additional fields to add. Returns the user ID, or 0 if failed.
|
||||
*/
|
||||
function createUser(string $username, string $password, string $email, int $class = 1, array $addtl = []): int
|
||||
{
|
||||
// @BAD Yes, this is bad, but it works.
|
||||
global $db;
|
||||
|
||||
function gettemplate($templatename) { // SQL query for the template.
|
||||
$data = [
|
||||
'username' => trim($username),
|
||||
'password' => password_hash($password, PASSWORD_ARGON2ID),
|
||||
'email' => trim($email),
|
||||
'class_id' => $class
|
||||
];
|
||||
|
||||
$filename = "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;
|
||||
|
||||
$db->table('players')->insert(array_merge($data, $addtl));
|
||||
return $db->lastInsertId();
|
||||
}
|
||||
|
||||
function getmicrotime() { // Used for timing script operations.
|
|
@ -1,7 +1,8 @@
|
|||
<p class="mb-1">
|
||||
Congratulations, <?= $name ?>! Your installation is complete. Dragon Knight is ready to go.
|
||||
All that's left is to log in and start playing. <?php if (!$complete): ?>Once you've set the
|
||||
classes in the admin panel, you can assign yourself one.<?php endif; ?>
|
||||
All that's left is to log in and start playing. <?php if (!$complete): ?>Once you've logged in,
|
||||
you can create some classes and assign your character one. By default you are a useless Adventurer.
|
||||
😜<?php endif; ?>
|
||||
</p>
|
||||
|
||||
<p class="mb-1">
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
<li>
|
||||
<b>Partial Setup</b> only creates the table structure,
|
||||
it does not populate the tables - use this if you are
|
||||
going to be creating and importing your own customized
|
||||
going to be creating or importing your own customized
|
||||
game data later.
|
||||
</li>
|
||||
</ul>
|
||||
|
|
Loading…
Reference in New Issue
Block a user