diff --git a/public/install/index.php b/public/install/index.php index 5cfe0d6..1fe0053 100644 --- a/public/install/index.php +++ b/public/install/index.php @@ -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; } diff --git a/server/bootstrap.php b/server/bootstrap.php index 8b54b52..4a94dcc 100644 --- a/server/bootstrap.php +++ b/server/bootstrap.php @@ -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'; \ No newline at end of file diff --git a/server/database/dragon.db-shm b/server/database/dragon.db-shm index b38007b..a9352cb 100644 Binary files a/server/database/dragon.db-shm and b/server/database/dragon.db-shm differ diff --git a/server/database/dragon.db-wal b/server/database/dragon.db-wal index 4e119a0..5680f1a 100644 Binary files a/server/database/dragon.db-wal and b/server/database/dragon.db-wal differ diff --git a/server/lib.php b/server/library.php similarity index 91% rename from server/lib.php rename to server/library.php index dd66d9c..0d5c9a7 100644 --- a/server/lib.php +++ b/server/library.php @@ -1,33 +1,43 @@ -'; @@ -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. diff --git a/server/templates/install/done.php b/server/templates/install/done.php index e0e5929..00184ab 100644 --- a/server/templates/install/done.php +++ b/server/templates/install/done.php @@ -1,7 +1,8 @@
Congratulations, = $name ?>! Your installation is complete. Dragon Knight is ready to go. - All that's left is to log in and start playing. Once you've set the - classes in the admin panel, you can assign yourself one. + All that's left is to log in and start playing. Once you've logged in, + you can create some classes and assign your character one. By default you are a useless Adventurer. + 😜
diff --git a/server/templates/install/first.php b/server/templates/install/first.php index f2c654c..3fc8f3a 100644 --- a/server/templates/install/first.php +++ b/server/templates/install/first.php @@ -17,7 +17,7 @@