♻️ Start using boot functions

This commit is contained in:
Kazhnuz 2025-02-28 22:53:43 +01:00
parent d8aaccce5b
commit 37599b90b9
14 changed files with 169 additions and 57 deletions

View file

@ -1,5 +1,10 @@
<?php // admin.php :: primary administration script. <?php // admin.php :: primary administration script.
// TODO: remove when porting to real boot files
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', __DIR__.DS);
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
include('kernel/lib.php'); include('kernel/lib.php');
include('kernel/cookies.php'); include('kernel/cookies.php');
$link = opendb(); $link = opendb();

View file

@ -1,5 +1,10 @@
<?php // forum.php :: Internal forums script for the game. <?php // forum.php :: Internal forums script for the game.
// TODO: remove when porting to real boot files
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', __DIR__.DS);
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
include('kernel/lib.php'); include('kernel/lib.php');
include('kernel/cookies.php'); include('kernel/cookies.php');
$link = opendb(); $link = opendb();

View file

@ -1,4 +1,9 @@
<?php <?php
// TODO: remove when porting to real boot files
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', __DIR__.DS);
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
include('kernel/lib.php'); include('kernel/lib.php');
$link = opendb(); $link = opendb();
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");

View file

@ -1,4 +1,9 @@
<?php <?php
// TODO: remove when porting to real boot files
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', __DIR__.DS);
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
include('kernel/lib.php'); include('kernel/lib.php');
$link = opendb(); $link = opendb();
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");

View file

@ -1,4 +1,9 @@
<?php <?php
// TODO: remove when porting to real boot files
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', __DIR__.DS);
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
include('kernel/lib.php'); include('kernel/lib.php');
$link = opendb(); $link = opendb();
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");

View file

@ -1,4 +1,9 @@
<?php <?php
// TODO: remove when porting to real boot files
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', __DIR__.DS);
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
include('kernel/lib.php'); include('kernel/lib.php');
$link = opendb(); $link = opendb();
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");

View file

@ -1,4 +1,9 @@
<?php <?php
// TODO: remove when porting to real boot files
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', __DIR__.DS);
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
include('kernel/lib.php'); include('kernel/lib.php');
$link = opendb(); $link = opendb();
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); $controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");

View file

@ -1,60 +1,31 @@
<?php // index.php :: Primary program script, evil alien overlord, you decide. <?php
if (file_exists('install.php')) { die("Please delete <b>install.php</b> from your Dragon Knight directory before continuing."); } /*
include('kernel/lib.php'); * Dragon Forks
include('kernel/cookies.php'); * https://git.kobold.cafe/game-projects/dragon-forks
$link = opendb(); * Original author Jamin Blount, forked by Kazhnuz
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control"); * Some code and structure are forked from Bludit by Diego Najar
$controlrow = mysqli_fetch_array($controlquery); * Dragon Forks is opensource software licensed under the MIT license.
*/
// Login (or verify) if not logged in. // TODO: use a better way to handle security
$userrow = checkcookies(); //if (file_exists('install.php')) { die("Please delete <b>install.php</b> from your Dragon Knight directory before continuing."); }
if ($userrow == false) {
if (isset($_GET["do"])) {
if ($_GET["do"] == "verify") { header("Location: users.php?do=verify"); die(); }
}
header("Location: login.php?do=login"); die();
}
// Close game.
if ($controlrow["gameopen"] == 0) { display("The game is currently closed for maintanence. Please check back later.","Game Closed"); die(); }
// Force verify if the user isn't verified yet.
if ($controlrow["verifyemail"] == 1 && $userrow["verify"] != 1) { header("Location: users.php?do=verify"); die(); }
// Block user if he/she has been banned.
if ($userrow["authlevel"] == 2) { die("Your account has been blocked. Please try back later."); }
if (isset($_GET["do"])) { // Load time init
$do = explode(":",$_GET["do"]); $loadTime = microtime(true);
// Town functions. // Security constant
if ($do[0] == "inn") { include('game/towns.php'); inn(); } define('DRAGONFORK', true);
elseif ($do[0] == "buy") { include('game/towns.php'); buy(); }
elseif ($do[0] == "buy2") { include('game/towns.php'); buy2($do[1]); }
elseif ($do[0] == "buy3") { include('game/towns.php'); buy3($do[1]); }
elseif ($do[0] == "sell") { include('game/towns.php'); sell(); }
elseif ($do[0] == "maps") { include('game/towns.php'); maps(); }
elseif ($do[0] == "maps2") { include('game/towns.php'); maps2($do[1]); }
elseif ($do[0] == "maps3") { include('game/towns.php'); maps3($do[1]); }
elseif ($do[0] == "gotown") { include('game/towns.php'); travelto($do[1]); }
// Exploring functions. // Directory separator
elseif ($do[0] == "move") { include('game/explore.php'); move(); } define('DS', DIRECTORY_SEPARATOR);
// Fighting functions. // PHP paths for init
elseif ($do[0] == "fight") { include('game/fight.php'); fight(); } define('PATH_ROOT', __DIR__.DS);
elseif ($do[0] == "victory") { include('game/fight.php'); victory(); } define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
elseif ($do[0] == "drop") { include('game/fight.php'); drop(); }
elseif ($do[0] == "dead") { include('game/fight.php'); dead(); }
// Misc functions. // Init
elseif ($do[0] == "verify") { header("Location: users.php?do=verify"); die(); } require(PATH_BOOT.'init.php');
elseif ($do[0] == "spell") { include('game/heal.php'); healspells($do[1]); } require(PATH_BOOT.'site.php');
elseif ($do[0] == "showchar") { include('game/misc.php'); showchar(); }
elseif ($do[0] == "onlinechar") { include('game/misc.php'); onlinechar($do[1]); }
elseif ($do[0] == "showmap") { include('game/misc.php'); showmap(); }
elseif ($do[0] == "babblebox") { include('game/misc.php'); babblebox(); }
elseif ($do[0] == "ninja") { include('game/misc.php'); ninja(); }
elseif ($do[0] == "die") { header('Location: index.php?do=buy'); die(); }
} else { include('game/misc.php'); donothing(); }
?> ?>

0
kernel/boot/admin.php Normal file
View file

42
kernel/boot/init.php Normal file
View file

@ -0,0 +1,42 @@
<?php // The initialisation of the kernel of dragon-fork
// Dragon Fork version
define('DRAGONFORK_VERSION', '0.0.1');
define('DRAGONFORK_CODENAME', '');
define('DRAGONFORK_RELEASE_DATE', '2024-08-23');
define('DRAGONFORK_BUILD', '20240806');
// Change to TRUE for debugging
define('DEBUG_MODE', TRUE);
define('DEBUG_TYPE', 'INFO'); // INFO, TRACE
// This determines whether errors should be printed to the screen as part of the output or if they should be hidden from the user.
ini_set("display_errors", 0);
// Even when display_errors is on, errors that occur during PHP's startup sequence are not displayed.
// It's strongly recommended to keep display_startup_errors off, except for debugging.
ini_set('display_startup_errors', 0);
// If disabled, error message will be solely plain text instead HTML code.
ini_set("html_errors", 0);
// Tells whether script error messages should be logged to the server's error log or error_log.
ini_set('log_errors', 1);
if (DEBUG_MODE) {
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
} else {
error_reporting(E_ERROR);
}
define('PATH_TEMPLATES', PATH_ROOT . 'templates' . DS);
//define('PATH_LANGUAGES', PATH_ROOT . 'languages' . DS);
//define('PATH_CONFIG', PATH_ROOT . 'config' . DS);
//define('PATH_PLUGINS', PATH_ROOT . 'plugins' . DS);
define('PATH_KERNEL', PATH_ROOT . 'kernel' . DS);
define('PATH_GAME', PATH_ROOT . 'game' . DS);
//define('PATH_ADMIN', PATH_ROOT . 'admin' . DS);
include(PATH_KERNEL . 'lib.php');
include(PATH_KERNEL . 'cookies.php');
$link = opendb();

54
kernel/boot/site.php Normal file
View file

@ -0,0 +1,54 @@
<?php // Functions relative to the site
$controlquery = doquery("SELECT * FROM {{table}} WHERE id='1' LIMIT 1", "control");
$controlrow = mysqli_fetch_array($controlquery);
// Login (or verify) if not logged in.
$userrow = checkcookies();
if ($userrow == false) {
if (isset($_GET["do"])) {
if ($_GET["do"] == "verify") { header("Location: users.php?do=verify"); die(); }
}
header("Location: login.php?do=login"); die();
}
// Close game.
if ($controlrow["gameopen"] == 0) { display("The game is currently closed for maintanence. Please check back later.","Game Closed"); die(); }
// Force verify if the user isn't verified yet.
if ($controlrow["verifyemail"] == 1 && $userrow["verify"] != 1) { header("Location: users.php?do=verify"); die(); }
// Block user if he/she has been banned.
if ($userrow["authlevel"] == 2) { die("Your account has been blocked. Please try back later."); }
if (isset($_GET["do"])) {
$do = explode(":",$_GET["do"]);
// Town functions.
if ($do[0] == "inn") { include(PATH_GAME . 'towns.php'); inn(); }
elseif ($do[0] == "buy") { include(PATH_GAME . 'towns.php'); buy(); }
elseif ($do[0] == "buy2") { include(PATH_GAME . 'towns.php'); buy2($do[1]); }
elseif ($do[0] == "buy3") { include(PATH_GAME . 'towns.php'); buy3($do[1]); }
elseif ($do[0] == "sell") { include(PATH_GAME . 'towns.php'); sell(); }
elseif ($do[0] == "maps") { include(PATH_GAME . 'towns.php'); maps(); }
elseif ($do[0] == "maps2") { include(PATH_GAME . 'towns.php'); maps2($do[1]); }
elseif ($do[0] == "maps3") { include(PATH_GAME . 'towns.php'); maps3($do[1]); }
elseif ($do[0] == "gotown") { include(PATH_GAME . 'towns.php'); travelto($do[1]); }
// Exploring functions.
elseif ($do[0] == "move") { include(PATH_GAME . 'explore.php'); move(); }
// Fighting functions.
elseif ($do[0] == "fight") { include(PATH_GAME . 'fight.php'); fight(); }
elseif ($do[0] == "victory") { include(PATH_GAME . 'fight.php'); victory(); }
elseif ($do[0] == "drop") { include(PATH_GAME . 'fight.php'); drop(); }
elseif ($do[0] == "dead") { include(PATH_GAME . 'fight.php'); dead(); }
// Misc functions.
elseif ($do[0] == "verify") { header("Location: users.php?do=verify"); die(); }
elseif ($do[0] == "spell") { include(PATH_GAME . 'heal.php'); healspells($do[1]); }
elseif ($do[0] == "showchar") { include(PATH_GAME . 'misc.php'); showchar(); }
elseif ($do[0] == "onlinechar") { include(PATH_GAME . 'misc.php'); onlinechar($do[1]); }
elseif ($do[0] == "showmap") { include(PATH_GAME . 'misc.php');showmap(); }
elseif ($do[0] == "babblebox") { include(PATH_GAME . 'misc.php');babblebox(); }
elseif ($do[0] == "ninja") { include(PATH_GAME . 'misc.php');ninja(); }
elseif ($do[0] == "die") { header('Location: index.php?do=buy'); die(); }
} else { include(PATH_GAME . 'misc.php');donothing(); }

View file

@ -40,7 +40,7 @@ function html_deep($value) {
} }
function opendb() { // Open database connection. function opendb() { // Open database connection.
include('../config.php'); include(PATH_ROOT.'config.php');
extract($dbsettings); extract($dbsettings);
// Créer une connexion à la base de données // Créer une connexion à la base de données
@ -55,7 +55,7 @@ function opendb() { // Open database connection.
} }
function doquery($query, $table) { // Something of a tiny little database abstraction layer. function doquery($query, $table) { // Something of a tiny little database abstraction layer.
include('../config.php'); include(PATH_ROOT.'/config.php');
global $numqueries; global $numqueries;
// Remplacer {{table}} par le préfixe de la table // Remplacer {{table}} par le préfixe de la table

View file

@ -1,5 +1,10 @@
<?php // login.php :: Handles logins and cookies. <?php // login.php :: Handles logins and cookies.
// TODO: remove when porting to real boot files
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', __DIR__.DS);
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
include('kernel/lib.php'); include('kernel/lib.php');
if (isset($_GET["do"])) { if (isset($_GET["do"])) {
if ($_GET["do"] == "login") { login(); } if ($_GET["do"] == "login") { login(); }

View file

@ -1,5 +1,10 @@
<?php // users.php :: Handles user account functions. <?php // users.php :: Handles user account functions.
// TODO: remove when porting to real boot files
define('DS', DIRECTORY_SEPARATOR);
define('PATH_ROOT', __DIR__.DS);
define('PATH_BOOT', PATH_ROOT.'kernel'.DS.'boot'.DS);
include('kernel/lib.php'); include('kernel/lib.php');
$link = opendb(); $link = opendb();