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
$results = '';
// create Settings table
App::$db->q("CREATE TABLE IF NOT EXISTS settings (
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
);");
$results .= 'Settings table created. ('. stopwatch($istart) .'s)
';
// insert default settings
App::$db->q("INSERT INTO settings DEFAULT VALUES;");
$results .= 'Default settings inserted. ('. stopwatch($istart) .'s)
';
// create Classes table
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 '',
);");
$results .= 'Classes table created. ('. stopwatch($istart) .'s)
';
if ($complete) {
// add default classes if complete install
App::$db->q("INSERT INTO classes VALUES
(1, 'Mage', 10, 10, 5, 5, 5, 5, 3, 5, 1, 3, 1, 3, '1:6,18'),
(2, 'Warrior', 20, 0, 10, 5, 10, 5, 6, 2, 3, 1, 3, 1, ''),
(3, 'Paladin', 15, 5, 5, 5, 10, 10, 4, 4, 2, 2, 2, 2, '1:1,15,18');");
} else {
// there must be at least one class, for user creation to work
App::$db->q("INSERT INTO classes (name) VALUES ('Adventurer');");
}
$results .= 'Default classes inserted. ('. stopwatch($istart) .'s)
';
echo $results;
}
}