second(),
3 => third(),
4 => fourth(),
5 => fifth(),
default => first(),
};
/**
* First page - show warnings and gather info
*/
function first()
{
echo <<
Dragon Knight Installation
Dragon Knight Installation: Page One
NOTE: Please ensure you have filled in the correct values in config.php before continuing. Installation will fail if these values are not correct. Also, the MySQL database needs to already exist. This installer script will take care of setting up its structure and content, but the database itself must already exist on your MySQL server before the installer will work.
Installation for Dragon Knight is a simple two-step process: set up the database tables, then create the admin user. After that, you're done.
You have two options for database setup: complete or partial.
- Complete Setup includes table structure and all default data (items, drops, monsters, levels, spells, towns) - after complete setup, the game is totally ready to run.
- Partial Setup 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 game data later.
Click the appropriate button below for your preferred installation method.
HTML;
}
/**
* Set up database tables.
*/
function second()
{
echo "Dragon Knight InstallationDragon Knight Installation: Page Two
";
$full = isset($_POST["complete"]);
$query = db()->exec(<<' : 'Error creating Babble Box table.';
$query = db()->exec(<<' : 'Error creating Control table.';
$query = db()->exec("INSERT INTO control VALUES (1, 'Dragon Knight', 250, 1, '', '', 1, '', 'Mage', 'Warrior', 'Paladin', 'Easy', 1, 'Medium', 1.2, 'Hard', 1.5, 1, 1, 1, 1);");
echo $query === true ? 'Control table populated.
' : 'Error populating Control table.';
$query = db()->exec(<<' : 'Error creating Drops table.';
if ($full) {
$query = db()->exec(<<' : 'Error populating Drops table.';
}
$query = db()->exec(<<' : 'Error creating Forum table.';
$query = db()->exec(<<' : 'Error creating Items table.';
if ($full) {
$query = db()->exec(<<' : 'Error populating Items table.';
}
$query = db()->exec(<<' : 'Error creating Levels table.';
if ($full) {
$query = db()->exec(<<' : 'Error populating Levels table.';
}
$query = db()->exec(<<' : 'Error creating Monsters table.';
if ($full) {
$query = db()->exec(<<' : 'Error populating Monsters table.';
}
$query = db()->exec(<<' : 'Error creating News table.';
$query = db()->exec("INSERT INTO news VALUES (1, '2004-01-01 12:00:00', 'This is the first news post. Please use the admin control panel to add another one and make this one go away.');");
echo $query === true ? 'News table populated.
' : 'Error populating News table.';
$query = db()->exec(<<' : 'Error creating Spells table.';
if ($full) {
$query = db()->exec(<<' : 'Error populating Spells table.';
}
$query = db()->exec(<<' : 'Error creating Towns table.';
if ($full) {
$query = db()->exec(<<' : 'Error populating Towns table.';
}
$query = db()->exec(<<' : 'Error creating Users table.';
$time = round((microtime(true) - START), 4);
echo "
Database setup complete in $time seconds.
Click here to continue with installation.";
}
/**
* Gather user info for admin account.
*/
function third()
{
echo <<
Dragon Knight Installation
Dragon Knight Installation: Page Three
Now you must create an administrator account so you can use the control panel. Fill out the form below to create your account. You will be able to customize the class names through the control panel once your admin account is created.
HTML;
}
/**
* Final page: insert new user row, congratulate the person on a job well done.
*/
function fourth()
{
$u = trim($_POST['username'] ??= '');
$e = trim($_POST['email1'] ??= '');
$ec = trim($_POST['email2'] ??= '');
$p = $_POST['password1'] ??= '';
$pc = $_POST['password2'] ??= '';
$errors = [];
if (empty($u) || strlen($u) < 3 || strlen($u) > 18 || !ctype_alnum(str_replace(' ', '', $u))) {
$errors[] = 'Username is required and must be between 3 and 18 characters long and contain only
alphanumeric characters and spaces.';
}
if (empty($e) || strlen($e) > 255 || !filter_var($e, FILTER_VALIDATE_EMAIL)) {
$errors[] = 'Email is required must be a valid email address.';
}
if ($e !== $ec) {
$errors[] = 'Verify Email must match.';
}
if (empty($p) || strlen($p) < 6) {
$errors[] = 'Password is required and must be at least 6 characters long.';
}
if ($pc !== $p) {
$errors[] = 'Verify Password must match.';
}
if (!empty($errors)) {
echo "";
foreach ($errors as $error) echo "- $error
";
echo "
";
exit;
}
if (db()->query(
"INSERT INTO users (username, password, email, verify, charclass, authlevel) VALUES (?, ?, ?, 1, ?, 1)",
[$u, password_hash($p, PASSWORD_ARGON2ID), $e, $_POST['charclass']]
) === false) {
echo "Failed to create user.";
exit;
}
file_put_contents('../.installed', date('Y-m-d H:i:s'));
echo <<
Dragon Knight Installation
Dragon Knight Installation: Page Four
Your admin account was created successfully. Installation is complete.
Be sure to delete install.php from your Dragon Knight directory for security purposes.
You are now ready to play the game. Note that you must log in through the public section before being allowed into the control panel. Once logged in, an "Admin" link will appear in the Functions box of the left sidebar panel.
Thank you for using Dragon Knight!
-----
Optional: Dragon Knight is a free product, and does not require registration of any sort. However, there is an
optional "call home" function in the installer, which notifies the author of your game installation. The ONLY information
transmitted with this function is the URL to your game. This is included mainly to satisfy the author's curiosity about
how many copies of the game are being installed and used. If you choose to submit your URL to the author, please
click here.
HTML;
}
/**
* Call Home function.
*/
function fifth()
{
if (mail("sky@sharkk.net", "Dragon Knight Call Home", $_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"]) !== true) {
exit('Dragon Knight was unable to send your URL. Please go back and try again, or just continue on to the game.');
}
echo <<
Dragon Knight Installation
Dragon Knight Installation: Page Five
Thank you for submitting your URL!
You are now ready to play the game. Note that you must log in through the public section before being allowed into the control panel. Once logged in, an "Admin" link will appear in the Functions box of the left sidebar panel.
HTML;
}