From 7ebd47ba6b8b7a720928347cd599ff5e95efc676 Mon Sep 17 00:00:00 2001 From: Docker VM Date: Mon, 1 Jul 2024 02:59:14 -0400 Subject: [PATCH] Finished implementing merge of mysql and sqlite branches, added sql file for mysql users. Updated readme. --- db/_ddd_db.sqlite | Bin 12288 -> 0 bytes db/ddd_db.sql | 14 ++++++ db/ddd_db.sqlite | Bin 12288 -> 12288 bytes ddd_scores.php | 96 ++++++++++++++++++++++++++++-------------- example.config.cfg | 17 +++++--- initialize_sqlite.php | 45 ++++++++++++++++++++ readme.md | 65 ++++++++++++++++++++++++++++ setup.sh | 46 ++++++++++++++++---- update_db.php | 4 +- 9 files changed, 239 insertions(+), 48 deletions(-) delete mode 100644 db/_ddd_db.sqlite create mode 100644 db/ddd_db.sql create mode 100755 initialize_sqlite.php create mode 100755 readme.md mode change 100644 => 100755 update_db.php diff --git a/db/_ddd_db.sqlite b/db/_ddd_db.sqlite deleted file mode 100644 index 6369f7c14e47debeca8fc383950d330747908fc1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI&O-jQ+6bJB`Mp`J?>Z;V$bJx;P1TWB}8A?o=)O=vO(pV!D+J>6CaH|(_;SoHN zM-bOeViDR>x)u39lKBX4-VDFpK>SO4vW)3Id6-2@I%h|WbJihZj47*Ec6o5w9<0V$ zm(BNu!rE6Chcc^Bd1I9?*&rYQ0SG_<0uX=z1Rwwb2tWV=I|K%WVy)HUqh)kEjnlj^Co6ll6FXd|~Vk7ltdS2mwZyi}{#`OD;|<~VtX(==}j>lN~E z)F{(NmBtg&;RNc|Dn}lG0x=B8apfD@_I8e+ZTVY# zcV0ia+gnRd(lk!jcU(JEGryZx-&yrTHV6nn00Izz00bZa0SG_<0uX=z1pbUbyHI2` z<=8ZyrqR4}Gcksir&<2MbX3Ylmg)3V@~zPJT-{aagy;FEd4Boq)fnn_C=5^Qs+8UT ndG(XY2LS;HKmY;|fB*y_009U<00Izzz&{cwbEVE#e>;2w6MlUw diff --git a/db/ddd_db.sql b/db/ddd_db.sql new file mode 100644 index 0000000..b5aef4c --- /dev/null +++ b/db/ddd_db.sql @@ -0,0 +1,14 @@ +-- Create the database +CREATE DATABASE IF NOT EXISTS ddd_db; + +-- Switch to the database +USE ddd_db; + +-- Create the scores table +CREATE TABLE IF NOT EXISTS scores ( + id INT AUTO_INCREMENT PRIMARY KEY, + Name VARCHAR(255) NOT NULL, + Score BIGINT NOT NULL, + Mode VARCHAR(50) NOT NULL, + Bosses TEXT +); diff --git a/db/ddd_db.sqlite b/db/ddd_db.sqlite index c8aa2ca30696edf0ffb30255ff564e7f23df9eac..4092ab3f5a169bb60d031988ed4d2e9817913a60 100644 GIT binary patch delta 82 zcmZojXh@hK&B#7c#+i|QW5PmyP6i+lU|`^Xw^>l(5&y&hR!Jd{5CZT5nT-5j82G|9hG|?>TJ?AN&14lA{Hs^+x zb8o)S+vj=CDFmWDq4DVy8p}>iB&X3HsaP_Zq3`TWf1g{nN?e zbSgKQHhy6p%%vu0QkjwUw*~FGUyJ!sO!J2PXq~n?lblGYhGoqei^;OJyxjEcIQSgN zPNi}=@@`)1fjmRicC_va`cNeho{P47pY{(hvzV_m_B;Uesh#8l2IVkCfK z{zME#x{Oym6yh~e9P%IM8|%W^(R=#xW^=hzZf(RhN!2*ztn_feqHXp&_Ura@ z_Az^_-DUgUcFlIqcF5+jS*>4KFIo><_gen4d}(>xlC!i~O!E8k^KzSfOs2U+|4LUPn%__d{c?jJC)5GPf7C^PWck0r%muMI-Wk7 znlk^fVmvH9Ey+@up$ufxqlLdNONQ|6H7y+N4n|ZIi|cw{FcMIak)ai5S^PAOS+e|wxthtbgn^PcKKbEWHtHKX?UZR7>emqRJE(tN!OwAVB*C zo;;I8%hGCotBuvtShVi?BgASiQ;qh6i=8pbm#jQlE{u2AT`-^xgyd*ICBqfcxbQLy z4G%Rm#WTT0hz_0iC9pR-XmkZptJ1`(jwz(hH3Q|V2zv($&+|!6TerD_jg7UySsCNC%_qSx z|o)6Rgp5nWuexrfNuR{sKZ3t!gQ-= zV91vMo^Zg?ek)1N^PY+~p+3l&5>$pbZS@x8z@Y^23MNe%M3`OXY*5tMIsgB4{05tIX*w(jl?*dz3~%1_7RoVNbMR?tFZOcJ!7$GFUU z6ZwvV0@I_thgcQ;#Hy0%5ISK2HZaph#}ix@jiWDs20UXDP^YI4vKZ|TX%RH6MPgdu z<0i-$6tpjN2P(aMgz{T#=V_fvoYSgL4Z=)OCJ;-BaoU|(=0-U0(_8L2T zsDo2D=I#T^kO%(TyvhBGWPFKB5D)|e0YN|z5CjAPK|l}?1Ox#=KoAfF{yzkYOaconnect_error) { + die("Connection failed: " . $mysqli->connect_error); + } else { + $db = $mysqli; + } } elseif ($database === 'sqlite') { - $db_path = 'db/ddd_db.sqlite'; - $db = new SQLite3($db_path); + $db_path = 'db/ddd_db.sqlite'; + if (file_exists($db_path)) { + try { + $db = new SQLite3($db_path); + } catch (Exception $e) { + die("Failed to open the SQLite database: " . $e->getMessage()); + } + } else { + die("Database file does not exist: " . $db_path); + } } else { - echo "Unsupported database type specified in config.cfg\n"; + die("Unsupported database type specified in config.cfg"); } } else { - echo "Database configuration not found in config.cfg\n"; + die("Database configuration not found in config.cfg"); } +// Get mode from request +$mode = $_REQUEST['mode'] ?? 'DX'; - -$mode = $_REQUEST['mode']; - +// Construct query based on mode if ($mode == "DX") { - echo "Top 100 DX Mode"; - $query = "SELECT * FROM ddd_db.scores WHERE ddd_db.scores.Mode = 'DX' ORDER BY ddd_db.scores.Score DESC LIMIT 100"; + echo "Top 100 DX Mode"; + $query = "SELECT * FROM scores WHERE Mode = 'DX' ORDER BY Score DESC LIMIT 100"; } elseif ($mode == "EX") { - echo "Top 100 EX Mode"; - $query = "SELECT * FROM ddd_db.scores WHERE ddd_db.scores.Mode = 'EX' ORDER BY ddd_db.scores.Score DESC LIMIT 100"; + echo "Top 100 EX Mode"; + $query = "SELECT * FROM scores WHERE Mode = 'EX' ORDER BY Score DESC LIMIT 100"; +} else { + die("Invalid mode specified"); } -$result = $db->query($query); +// Execute query and fetch results +$result = null; + +if ($db instanceof SQLite3) { + $result = $db->query($query); +} elseif ($db instanceof mysqli) { + $result = $db->query($query); +} if ($result) { - // output data of each row $counter = 1; + echo "
    "; - echo "
    "; - - while ($row = $result->fetchArray(SQLITE3_ASSOC)) { + while ($row = ($db instanceof SQLite3) ? $result->fetchArray(SQLITE3_ASSOC) : $result->fetch_assoc()) { $output = "" . $counter . " " . $row["Name"] . "" . "   " . "" . number_format($row["Score"]) . ""; @@ -54,18 +83,16 @@ if ($result) { if (!empty($bosses)) { echo "
    "; - // Display an image for each boss name - foreach ($bosses as $boss) { - $bossImage = trim(strtolower($boss)) . ".png"; - if($bossImage != ".png"){ - echo "
    "; - echo "" . $boss . ""; - echo "
    " . $boss . "
    "; - echo "
    "; - } - - } - + // Display an image for each boss name + foreach ($bosses as $boss) { + $bossImage = trim(strtolower($boss)) . ".png"; + if ($bossImage != ".png") { + echo "
    "; + echo "" . $boss . ""; + echo "
    " . $boss . "
    "; + echo "
    "; + } + } echo "
    "; } @@ -75,13 +102,18 @@ if ($result) { $counter++; } - echo "
"; + echo "
"; } else { echo "
0 results"; } -$db->close(); +// Close database connection +if ($db instanceof SQLite3) { + $db->close(); +} elseif ($db instanceof mysqli) { + $db->close(); +} ?>
Back diff --git a/example.config.cfg b/example.config.cfg index b1b42cf..5abf2b7 100755 --- a/example.config.cfg +++ b/example.config.cfg @@ -1,23 +1,30 @@ [options] database="sqlite" #sqlite or mysql +# Connect to your existing mysql database, we will create a single "scores" table with /db/ddd_db.sql [mysql] mysqlconnect_path="/var/config/mysqlconnect.php" host="localhost" -username="dbUser" -database="dbName" -password="dbPassword" +username="ddd_db_admin" +database="ddd_db" +password="dbd_db_password" [sqlite] -password="CHANGE_ME!" #This is used to manage the sqlite database from a ui at /update_db.php +sqlite_password="CHANGE_ME!" #This is used to manage the sqlite database from a ui at /update_db.php # To use this file, run setup.sh with bash # or you can use # # cp example.config.cfg config.cfg +# +# If using sqlite (default) +# you can use the existing empty ddd_db.sqlite file +# and manually enter the sqlite_password into the config.cfg file +# for managing the database from /update_db.php +# +# If using mysql # cp example.mysqlconnect.php /var/config/mysqlconnect.php # chmod 755 /var/config/mysqlconnect.php # -# and manually enter the values into the config.cfg file # the mysqlconnect.php is moved to /var/config to be outside the scope of the end user, # you can place it elsewhere if you desire, be sure to update the mysqlconnect_path variable \ No newline at end of file diff --git a/initialize_sqlite.php b/initialize_sqlite.php new file mode 100755 index 0000000..dd33a97 --- /dev/null +++ b/initialize_sqlite.php @@ -0,0 +1,45 @@ +exec($createTableQuery)) { + echo "Database and table created successfully.
"; + } else { + echo "Error creating table: " . $db->lastErrorMsg() . "
"; + } + + // Close the database connection + $db->close(); + } catch (Exception $e) { + echo 'Caught exception: ', $e->getMessage(), "
"; + } catch (Error $e) { + echo 'Caught error: ', $e->getMessage(), "
"; + } +} else { + echo "Database already exists.
"; +} +?> diff --git a/readme.md b/readme.md new file mode 100755 index 0000000..cc8921c --- /dev/null +++ b/readme.md @@ -0,0 +1,65 @@ +# DASH-DA-DASH DX Fan Patch + +This is a fan patch of DASH-DA-DASH DX that has been updated version of the source code available from [mulengine.itch.io/ddddx](https://mulengine.itch.io/ddddx). The original high score board is no longer online, so now it is hosted at [ddd.dylanbanta.com](https://ddd.dylanbanta.com/) with a functional scoreboard available [here](https://ddd.dylanbanta.com/ddd_index.php). The project can also be downloaded so that users can self-host their own copy of the site as a private scoreboard. + +The EXE file can be found here: [ddddxhs_files/DASH-DA-DASH DX (2023 Fan Patch).exe](https://git.dylanbanta.com/Dylan/Dash-Da-Dash-DX-2023-Fan-Patch-High-Scores/raw/branch/master/ddddxhs_files/DASH-DA-DASH%20DX%20%282023%20Fan%20Patch%29.exe) (SHA256 Checksum: 67ea139fa4721a05a26094d7bba9f3386c8473d7d7450ef762da7bf19ef921e5) + +The updated .mfa source file can be found here: [ddddxhs_files/DASH-DA-DASH DX (2023 Fan Patch).mfa](https://git.dylanbanta.com/Dylan/Dash-Da-Dash-DX-2023-Fan-Patch-High-Scores/raw/branch/master/ddddxhs_files/DASH-DA-DASH%20DX%20%282023%20Fan%20Patch%29.mfa) + + + +## Project Overview + +This project was made for fun, but it has been repurposed to showcase my usage of git, including creating branches from the original master branch to new sqlite and mysql branches, and then finally merging them back into the master branch. Plus it was a fun challenge to migrate the system to sqlite. + +The php and html is not great, but when I created the project I was focused on recreating the website from way back machine with authenticity. I didn't take it too seriously since it was a project I was doing for myself. Perhaps I'll come back and clean it up one day. + +## Setup Instructions + +To set up the project, you can run the `setup.sh` file or follow the manual instructions in the `example.config.cfg` file. + +## Example Configuration File + +```ini +[options] +database="sqlite" #sqlite or mysql + +# Connect to your existing mysql database, we will create a single "scores" table with /db/ddd_db.sql +[mysql] +mysqlconnect_path="/var/config/mysqlconnect.php" +host="localhost" +username="ddd_db_admin" +database="ddd_db" +password="dbd_db_password" + +[sqlite] +sqlite_password="CHANGE_ME!" #This is used to manage the sqlite database from a ui at /update_db.php + +# To use this file, run setup.sh with bash +# or you can use +# +# cp example.config.cfg config.cfg +# +# If using sqlite (default) +# you can use the existing empty ddd_db.sqlite file +# and manually enter the sqlite_password into the config.cfg file +# for managing the database from /update_db.php +# +# If using mysql +# cp example.mysqlconnect.php /var/config/mysqlconnect.php +# chmod 755 /var/config/mysqlconnect.php +# +# the mysqlconnect.php is moved to /var/config to be outside the scope of the end user, +# you can place it elsewhere if you desire, be sure to update the mysqlconnect_path variable +``` + +## Credits + +- [Wiki](https://lapfoxtrax.fandom.com/wiki/DASH-DA-DASH_DX) +- [itch.io (Has version 1.14 without 2023 Fan Patch)](https://mulengine.itch.io/ddddx) +- [DDDDX Archive](https://web.archive.org/web/20130821151756/http://renard.teknolust.org/ddd/) +- [Scores Archive](https://web.archive.org/web/20130710170054/http://renard.teknolust.org/ddd/score/index.php) +- [Current Website](https://halleylabs.com/) +- [Current Website Main](https://heckscaper.com/main.html) +- [Version 1.12 from WayBackMachine Archive](https://web.archive.org/web/20120615011611if_/http://renard.teknolust.org/ddd/dddxv12install.exe) +- [2023 Fan Patch .mfa Source File for Clickteam Fusion 2.5](https://ddd.dylanbanta.com/ddddxhs_files/DASH-DA-DASH%20DX%20(2023%20Fan%20Patch).mfa) diff --git a/setup.sh b/setup.sh index e3bd67b..e4e4b6f 100755 --- a/setup.sh +++ b/setup.sh @@ -8,13 +8,13 @@ database="$1" [mysql] mysqlconnect_path="/var/config/mysqlconnect.php" -host="localhost" -username="dbUser" -database="dbName" -password="dbPassword" +host="$2" +username="$3" +database="$4" +password="$5" [sqlite] -password="CHANGE_ME!" +sqlite_password="$6" EOF } @@ -25,14 +25,42 @@ read -t 5 -p "Enter your choice: " db_choice # Set default value if no input is given db_choice=${db_choice:-sqlite} -# Create config.cfg based on user input -create_config_file $db_choice - -# Create directory for mysql configuration if [ "$db_choice" = "mysql" ]; then + # Prompt user for MySQL options + read -p "Enter MySQL host (default: localhost): " mysql_host + mysql_host=${mysql_host:-localhost} + read -p "Enter MySQL username (default: dbUser): " mysql_user + mysql_user=${mysql_user:-dbUser} + read -p "Enter MySQL database name (default: dbName): " mysql_db + mysql_db=${mysql_db:-dbName} + read -s -p "Enter MySQL password (default: dbPassword): " mysql_pass + mysql_pass=${mysql_pass:-dbPassword} + echo # Move to a new line after reading the password + + # Create config.cfg for MySQL + create_config_file $db_choice $mysql_host $mysql_user $mysql_db $mysql_pass "" + + # Create directory for mysql configuration mkdir -p /var/config cp example.mysqlconnect.php /var/config/mysqlconnect.php chmod 755 /var/config/mysqlconnect.php + +elif [ "$db_choice" = "sqlite" ]; then + # Prompt user for SQLite password + read -s -p "Enter SQLite password (default: CHANGE_ME!): " sqlite_pass + sqlite_pass=${sqlite_pass:-CHANGE_ME!} + echo # Move to a new line after reading the password + + # Create config.cfg for SQLite + create_config_file $db_choice "" "" "" "" $sqlite_pass + + # Create empty sqlite database + php initialize_sqlite.php + + # Ensure the database directory and file have the correct permissions + chmod 777 db + chmod 777 config.cfg + chmod 666 db/ddd_db.sqlite fi echo "Setup complete. Configuration saved in config.cfg." diff --git a/update_db.php b/update_db.php old mode 100644 new mode 100755 index 6615221..d5736e0 --- a/update_db.php +++ b/update_db.php @@ -7,8 +7,8 @@ $config_path = 'config.cfg'; $password = ''; if (file_exists($config_path)) { $config = parse_ini_file($config_path); - if (isset($config['password'])) { - $password = $config['password']; + if (isset($config['sqlite_password'])) { + $password = $config['sqlite_password']; } }