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 23:24:59 -05:00
|
|
|
$defaults = SERVER.'/database/packs/Default/';
|
2024-07-11 21:17:06 -05:00
|
|
|
|
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-13 22:37:40 -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:17:06 -05:00
|
|
|
);");
|
|
|
|
|
|
|
|
// insert default settings
|
|
|
|
App::$db->q("INSERT INTO settings DEFAULT VALUES;");
|
|
|
|
|
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
|
|
|
);");
|
|
|
|
|
|
|
|
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 {
|
2024-07-13 22:37:40 -05:00
|
|
|
// there must be at least one class for user creation to work
|
2024-07-11 21:17:06 -05:00
|
|
|
App::$db->q("INSERT INTO classes (name) VALUES ('Adventurer');");
|
|
|
|
}
|
|
|
|
|
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-13 22:37:40 -05:00
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'author' INTEGER NOT NULL,
|
|
|
|
'babble' TEXT NOT NULL,
|
|
|
|
'posted' DATETIME DEFAULT CURRENT_TIMESTAMP
|
2024-07-11 21:53:36 -05:00
|
|
|
);");
|
|
|
|
|
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-13 22:37:40 -05:00
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'name' TEXT NOT NULL,
|
|
|
|
'level' INTEGER DEFAULT 1,
|
|
|
|
'type' INTEGER DEFAULT 1,
|
|
|
|
'attr' TEXT DEFAULT ''
|
2024-07-12 22:29:34 -05:00
|
|
|
);");
|
2024-07-12 23:24:59 -05:00
|
|
|
|
2024-07-13 22:37:40 -05:00
|
|
|
// add default drops if complete install
|
|
|
|
if ($complete) App::$db->insertFromCSV('drops', "$defaults/drops.csv");
|
2024-07-12 23:24:59 -05:00
|
|
|
|
2024-07-13 22:37:40 -05:00
|
|
|
// @Forum
|
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'forum' (
|
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'posted' DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
'new_post' DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
'author' INTEGER NOT NULL,
|
|
|
|
'subject' TEXT DEFAULT '',
|
|
|
|
'message' TEXT DEFAULT '',
|
|
|
|
'locked' INTEGER DEFAULT 0,
|
|
|
|
'sticky' INTEGER DEFAULT 0,
|
|
|
|
'parent' INTEGER DEFAULT 0,
|
|
|
|
'posts' INTEGER DEFAULT 0,
|
|
|
|
'views' INTEGER DEFAULT 0,
|
|
|
|
'hidden' INTEGER DEFAULT 0
|
|
|
|
);");
|
2024-07-12 23:24:59 -05:00
|
|
|
|
2024-07-13 22:37:40 -05:00
|
|
|
// @Items
|
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'items' (
|
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'type' INTEGER DEFAULT 1,
|
|
|
|
'name' TEXT NOT NULL,
|
|
|
|
'cost' INTEGER DEFAULT 0,
|
|
|
|
'attr' TEXT DEFAULT '',
|
|
|
|
'icon' TEXT DEFAULT ''
|
|
|
|
);");
|
2024-07-12 23:24:59 -05:00
|
|
|
|
2024-07-13 22:37:40 -05:00
|
|
|
// add default items if complete install
|
|
|
|
if ($complete) App::$db->insertFromCSV('items', "$defaults/items.csv");
|
|
|
|
|
|
|
|
// @Monsters
|
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'monsters' (
|
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'name' TEXT NOT NULL,
|
|
|
|
'level' INTEGER DEFAULT 1,
|
|
|
|
'hp' INTEGER DEFAULT 1,
|
|
|
|
'atk' INTEGER DEFAULT 1,
|
|
|
|
'def' INTEGER DEFAULT 1,
|
|
|
|
'exp' INTEGER DEFAULT 1,
|
|
|
|
'gold' INTEGER DEFAULT 1,
|
|
|
|
'immune' INTEGER DEFAULT 0,
|
|
|
|
'image' TEXT DEFAULT ''
|
|
|
|
);");
|
|
|
|
|
|
|
|
// add default monsters if complete install
|
|
|
|
if ($complete) App::$db->insertFromCSV('monsters', "$defaults/monsters.csv");
|
|
|
|
|
|
|
|
// @News
|
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'news' (
|
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'author' INTEGER DEFAULT 1,
|
|
|
|
'title' TEXT DEFAULT '',
|
|
|
|
'content' TEXT DEFAULT '',
|
|
|
|
'posted' DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
|
|
);");
|
|
|
|
|
|
|
|
// @Spells
|
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'spells' (
|
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'name' TEXT NOT NULL,
|
|
|
|
'type' INTEGER DEFAULT 1,
|
|
|
|
'mp' INTEGER DEFAULT 0,
|
|
|
|
'effect' TEXT DEFAULT '',
|
|
|
|
'icon' TEXT DEFAULT ''
|
|
|
|
);");
|
|
|
|
|
|
|
|
// add default spells if complete install
|
|
|
|
if ($complete) App::$db->insertFromCSV('spells', "$defaults/spells.csv");
|
|
|
|
|
|
|
|
// @Towns
|
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'towns' (
|
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'name' TEXT NOT NULL,
|
|
|
|
'x' INTEGER DEFAULT 0,
|
|
|
|
'y' INTEGER DEFAULT 0,
|
|
|
|
'inn_cost' INTEGER DEFAULT 0,
|
|
|
|
'map_cost' INTEGER DEFAULT 5,
|
|
|
|
'tp_cost' INTEGER DEFAULT 0,
|
|
|
|
'shop_list' TEXT DEFAULT '',
|
|
|
|
'image' TEXT DEFAULT ''
|
|
|
|
);");
|
|
|
|
|
|
|
|
// add default towns if complete install
|
|
|
|
if ($complete) App::$db->insertFromCSV('towns', "$defaults/towns.csv");
|
|
|
|
|
|
|
|
// @Players
|
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'players' (
|
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'username' TEXT NOT NULL,
|
|
|
|
'password' TEXT NOT NULL,
|
|
|
|
'email' TEXT DEFAULT '',
|
|
|
|
'verified' INTEGER DEFAULT 1,
|
|
|
|
'registered' DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
'last_online' DATETIME DEFAULT CURRENT_TIMESTAMP,
|
|
|
|
'currently' INTEGER DEFAULT 0,
|
|
|
|
'role' 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,
|
|
|
|
'max_mp' INTEGER DEFAULT 0,
|
|
|
|
'tp' INTEGER DEFAULT 0,
|
|
|
|
'max_tp' INTEGER DEFAULT 0,
|
|
|
|
'str' INTEGER DEFAULT 0,
|
|
|
|
'atk' INTEGER DEFAULT 0,
|
|
|
|
'dex' INTEGER DEFAULT 0,
|
|
|
|
'def' INTEGER DEFAULT 0,
|
|
|
|
'weapon_id' INTEGER DEFAULT 0,
|
|
|
|
'armor_id' INTEGER DEFAULT 0,
|
|
|
|
'shield_id' INTEGER DEFAULT 0,
|
|
|
|
'slot_1_id' INTEGER DEFAULT 0,
|
|
|
|
'slot_2_id' INTEGER DEFAULT 0,
|
|
|
|
'slot_3_id' INTEGER DEFAULT 0,
|
|
|
|
'spells' TEXT DEFAULT '',
|
|
|
|
'maps' TEXT DEFAULT ''
|
|
|
|
);");
|
|
|
|
|
|
|
|
// @Fights
|
|
|
|
App::$db->q("CREATE TABLE IF NOT EXISTS 'fights' (
|
|
|
|
'id' INTEGER PRIMARY KEY,
|
|
|
|
'p_id' INTEGER DEFAULT 1,
|
|
|
|
'm_id' INTEGER DEFAULT 1,
|
|
|
|
'turn' INTEGER DEFAULT 1,
|
|
|
|
'p_hp' INTEGER DEFAULT 0,
|
|
|
|
'p_maxhp' INTEGER DEFAULT 0,
|
|
|
|
'p_mp' INTEGER DEFAULT 0,
|
|
|
|
'p_maxmp' INTEGER DEFAULT 0,
|
|
|
|
'm_hp' INTEGER DEFAULT 0,
|
|
|
|
'm_maxhp' INTEGER DEFAULT 0,
|
|
|
|
'condi' TEXT DEFAULT ''
|
|
|
|
);");
|
2024-07-12 23:24:59 -05:00
|
|
|
|
2024-07-13 22:37:40 -05:00
|
|
|
echo render('install/layout', ['title' => 'Database Setup', 'step' => 'second', 'complete' => $complete, 'start' => $istart]);
|
2024-07-11 21:17:06 -05:00
|
|
|
}
|
|
|
|
}
|