2024-07-11 21:17:06 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
The second URI segment determines the step/page we are on.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class InstallModule
|
|
|
|
{
|
|
|
|
public static function handle()
|
|
|
|
{
|
|
|
|
$s = App::$req->uri(1) ?? ''; // second segment
|
|
|
|
$m = App::$req->method; // request method
|
|
|
|
|
|
|
|
if ($s == '' || $s == 'intro') return self::intro();
|
|
|
|
if ($s == 'database' && $m == 'POST') return self::database();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function intro()
|
|
|
|
{
|
|
|
|
echo render('install/layout', ['title' => 'Intro', 'step' => 'first']);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static function database()
|
|
|
|
{
|
|
|
|
$istart = microtime(true); // time the database setup
|
|
|
|
if (!isset($_POST['mode'])) redirect('/install'); // redirect if no mode
|
|
|
|
$complete = $_POST['mode'] == 'complete'; // complete or partial setup
|
2024-07-12 22:29:34 -05:00
|
|
|
$resFmt = '%s <span class="extra-data">(%ss)</span><br />';
|
2024-07-12 23:24:59 -05:00
|
|
|
$defaults = SERVER.'/database/packs/Default/';
|
2024-07-11 21:17:06 -05:00
|
|
|
|
|
|
|
$results = '';
|
|
|
|
|
2024-07-11 21:53:36 -05:00
|
|
|
// @Settings
|
2024-07-12 23:24:59 -05:00
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'settings' (
|
2024-07-11 21:17:06 -05:00
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
game_name TEXT DEFAULT 'Dragon Knight',
|
|
|
|
game_version TEXT DEFAULT '1.0',
|
|
|
|
game_dev TEXT DEFAULT 'Sharkk',
|
|
|
|
game_url TEXT DEFAULT 'https://dragonknight.dev',
|
|
|
|
game_size INT DEFAULT 250,
|
|
|
|
game_open INT DEFAULT 1,
|
|
|
|
admin_email TEXT DEFAULT 'admin@dragonknight.dev',
|
|
|
|
forum_type INT DEFAULT 1,
|
|
|
|
forum_url TEXT DEFAULT '',
|
|
|
|
verify_email INT DEFAULT 1,
|
|
|
|
show_news INT DEFAULT 1,
|
|
|
|
show_online INT DEFAULT 1,
|
|
|
|
show_babble INT DEFAULT 1
|
|
|
|
);");
|
|
|
|
|
2024-07-11 21:53:36 -05:00
|
|
|
$results .= sprintf($resFmt, 'Settings table created', stopwatch($istart));
|
2024-07-11 21:17:06 -05:00
|
|
|
|
|
|
|
// insert default settings
|
|
|
|
App::$db->q("INSERT INTO settings DEFAULT VALUES;");
|
|
|
|
|
2024-07-11 21:53:36 -05:00
|
|
|
$results .= sprintf($resFmt, 'Default settings inserted', stopwatch($istart));
|
2024-07-11 21:17:06 -05:00
|
|
|
|
2024-07-11 21:53:36 -05:00
|
|
|
// @Classes
|
2024-07-12 23:24:59 -05:00
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'classes' (
|
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'name' TEXT DEFAULT '',
|
|
|
|
'start_hp' INT DEFAULT 0,
|
|
|
|
'start_mp' INT DEFAULT 0,
|
|
|
|
'start_str' INT DEFAULT 0,
|
|
|
|
'start_atk' INT DEFAULT 0,
|
|
|
|
'start_dex' INT DEFAULT 0,
|
|
|
|
'start_def' INT DEFAULT 0,
|
|
|
|
'growth_hp' INT DEFAULT 0,
|
|
|
|
'growth_mp' INT DEFAULT 0,
|
|
|
|
'growth_str' INT DEFAULT 0,
|
|
|
|
'growth_atk' INT DEFAULT 0,
|
|
|
|
'growth_dex' INT DEFAULT 0,
|
|
|
|
'growth_def' INT DEFAULT 0,
|
|
|
|
'spells' TEXT DEFAULT ''
|
2024-07-11 21:17:06 -05:00
|
|
|
);");
|
|
|
|
|
2024-07-11 21:53:36 -05:00
|
|
|
$results .= sprintf($resFmt, 'Classes table created', stopwatch($istart));
|
2024-07-11 21:17:06 -05:00
|
|
|
|
|
|
|
if ($complete) {
|
|
|
|
// add default classes if complete install
|
2024-07-12 23:24:59 -05:00
|
|
|
App::$db->insertFromCSV('classes', "$defaults/classes.csv");
|
2024-07-11 21:17:06 -05:00
|
|
|
} else {
|
|
|
|
// there must be at least one class, for user creation to work
|
|
|
|
App::$db->q("INSERT INTO classes (name) VALUES ('Adventurer');");
|
|
|
|
}
|
|
|
|
|
2024-07-11 21:53:36 -05:00
|
|
|
$results .= sprintf($resFmt, 'Default classes inserted', stopwatch($istart));
|
2024-07-11 21:17:06 -05:00
|
|
|
|
2024-07-11 21:53:36 -05:00
|
|
|
// @Babble
|
2024-07-12 23:24:59 -05:00
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'babble' (
|
2024-07-11 21:53:36 -05:00
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
author INTEGER NOT NULL,
|
|
|
|
babble TEXT NOT NULL,
|
|
|
|
posted DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
|
|
);");
|
|
|
|
|
|
|
|
$results .= sprintf($resFmt, 'Babble table created', stopwatch($istart));
|
2024-07-12 22:29:34 -05:00
|
|
|
|
|
|
|
// @Drops
|
2024-07-12 23:24:59 -05:00
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'drops' (
|
2024-07-12 22:29:34 -05:00
|
|
|
id INTEGER PRIMARY KEY,
|
|
|
|
name TEXT NOT NULL,
|
|
|
|
level INTEGER DEFAULT 1,
|
|
|
|
type INTEGER DEFAULT 1,
|
|
|
|
attr TEXT DEFAULT ''
|
|
|
|
);");
|
2024-07-12 23:24:59 -05:00
|
|
|
|
|
|
|
|
|
|
|
$results .= sprintf($resFmt, 'Drops table created', stopwatch($istart));
|
|
|
|
|
|
|
|
if ($complete) {
|
|
|
|
// add default drops if complete install
|
|
|
|
App::$db->insertFromCSV('drops', "$defaults/drops.csv");
|
|
|
|
|
|
|
|
$results .= sprintf($resFmt, 'Default drops inserted', stopwatch($istart));
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $results;
|
2024-07-11 21:17:06 -05:00
|
|
|
}
|
|
|
|
}
|