From 9bc941faea2573dc41fa2714a5da9c342e65e61c Mon Sep 17 00:00:00 2001 From: "color.diff=auto" Date: Sat, 27 Mar 2021 02:53:26 -0600 Subject: [PATCH] Bugfixing. Adding sanity checks --- includes.php | 13 ------ index.php | 49 ++++++++++++---------- processFiles.php | 39 ++++++++++++++---- res/app.js | 18 +++++--- src/D2Config.php | 2 + src/D2Database.php | 3 -- src/D2Files.php | 100 ++++++++++++++++++++++++++++++++++++++++++--- switchMods.php | 31 +++++++++----- 8 files changed, 187 insertions(+), 68 deletions(-) delete mode 100644 includes.php diff --git a/includes.php b/includes.php deleted file mode 100644 index a9728ec..0000000 --- a/includes.php +++ /dev/null @@ -1,13 +0,0 @@ - - This file is part of D2UM. + This file is part of D2IM. D2UM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version. - D2UM is distributed in the hope that it will be useful, + D2IM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. @@ -24,30 +24,37 @@ ini_set('display_errors', 1); error_reporting(1); ini_set('log_errors', 1); -include "includes.php"; +include "./_pdo.php"; -if (file_exists("d2im.db") && (file_exists($_SESSION['modname'].".db"))){ +if (!isset($_SESSION['modname']) + || (!file_exists("d2im.db")) + || (!file_exists($_SESSION['modname'] . ".db"))) +{ + // first load, no active mod, go to switchmods to select mod + header("Location: /switchMods.php"); +} else { + define('FILTER_PROPERTIES_FILE', 'filterProperties.txt'); + define('DB_FILE', $_SESSION['modname'] . ".db"); + define('TXT_PATH', $_SESSION['path']); + + require_once "./src/D2Functions.php"; + require_once "./src/D2Database.php"; + require_once './src/D2Files.php'; + require_once './src/D2TxtParser.php'; - if (is_dir($_SESSION['path'])) { - define('TXT_PATH', $_SESSION['path']); - } else { - header('Location: /src/D2Config.php'); - } - $db = new D2Database(); $parser = new D2TxtParser(); - + $armor = PDO_FetchAll('SELECT * FROM armor WHERE `spawnable`=1'); $weapon = PDO_FetchAll('SELECT * FROM weapons WHERE `spawnable`=1'); - $prop = $parser->filterProps('Properties.txt'); - + // If there's data, process it and save if (!empty($_POST)) { - + // save db name from post into conf file - + require_once './src/D2SaveFile.php'; $saver = new D2SaveFile(); @@ -66,8 +73,8 @@ if (file_exists("d2im.db") && (file_exists($_SESSION['modname'].".db"))){ if ($_POST['formtype'] == "uniqueitems") { - - + + // if ladder or carry1 is 0, set empty field. if (!$post['ladder']) { $post['ladder'] = ''; @@ -85,9 +92,7 @@ if (file_exists("d2im.db") && (file_exists($_SESSION['modname'].".db"))){ } -// load app + // load app require_once './src/index.php'; -} else { - header('Location: ./src/D2Config.php'); } ?> \ No newline at end of file diff --git a/processFiles.php b/processFiles.php index 968e5b9..46509cb 100644 --- a/processFiles.php +++ b/processFiles.php @@ -1,26 +1,49 @@ files as $k => $v) { $data[$v] = $parser->parseFile($v); } + // Write all parse data to mod db foreach ($data as $k => $v) { $db->createTables($k, $v); $db->fillsTables($k, $v); } + + // put in html redirect as backup, because + // for some odd reason windows gives + // an error on header() but linux does not. +} else { + // if config db does not exist, go to configure page + header("Location: /src/D2Config.php"); } -die(); -// put in html redirect as backup, because -// for some odd reason windows gives -// an error on header() but linux does not. ?> diff --git a/res/app.js b/res/app.js index 540503b..261e186 100644 --- a/res/app.js +++ b/res/app.js @@ -12,7 +12,10 @@ $(document).ready(function () { $('option[disabled="disabled"]').show(); } }); - + + $(function () { + $('[data-toggle="tooltip"]').tooltip() + }) $('.w-select').change(function () { $('.a-select').each(function (i, v) { @@ -44,15 +47,20 @@ $(document).ready(function () { }); - $('.help').hover(function () { + $('.help').click(function () { $(".fa-help").remove(); - $(this).next().fadeToggle("slow").css({ + $(this).next().fadeToggle("slow").focus().css({ "position": "absolute", "z-index": "1000", "background": "#eee", "color": "black !important", "border": "1px solid #aaa", "width": "300px", - }); - }); + }) + }); + + $('.form-text').click(function () { + $(this).fadeOut("slow"); + }); + }); \ No newline at end of file diff --git a/src/D2Config.php b/src/D2Config.php index de9fae5..4596636 100644 --- a/src/D2Config.php +++ b/src/D2Config.php @@ -49,6 +49,7 @@ if (!empty($_POST)) { echo '

ERROR: INVALID PATH

'; } else { + // set this mod to active mod in session $_SESSION['path'] = $path; // Don't yell at me, security is the least of my considerations atm // check modname in db @@ -78,6 +79,7 @@ ERROR: INVALID PATH'; echo '

ERROR: INVALID PATH

'; } else { + // set this mod to active mod in session $_SESSION['path'] = $path; // Don't yell at me, security is the least of my considerations atm // check modname in db diff --git a/src/D2Database.php b/src/D2Database.php index 3e3d845..04566a3 100644 --- a/src/D2Database.php +++ b/src/D2Database.php @@ -78,9 +78,6 @@ class D2Database { } $sql = rtrim($sql, ", "); - var_dump($file); - var_dump($sql); - PDO_Execute($sql); } } diff --git a/src/D2Files.php b/src/D2Files.php index d62f39e..b159ef3 100644 --- a/src/D2Files.php +++ b/src/D2Files.php @@ -21,14 +21,102 @@ class D2Files { - public $files = []; + public $files = [ + "Arena.txt" => "Arena.txt", + "Armor.txt" => "Armor.txt", + "ArmType.txt" => "ArmType.txt", + "automagic.txt" => "automagic.txt", + "AutoMap.txt" => "AutoMap.txt", + "belts.txt" => "belts.txt", + "bodylocs.txt" => "bodylocs.txt", + "Books.txt" => "Books.txt", + "CharStats.txt" => "CharStats.txt", + "CharTemplate.txt" => "CharTemplate.txt", + "colors.txt" => "colors.txt", + "CompCode.txt" => "CompCode.txt", + "Composit.txt" => "Composit.txt", + "CubeMain.txt" => "CubeMain.txt", + "CubeMod.txt" => "CubeMod.txt", + "cubetype.txt" => "cubetype.txt", + "DifficultyLevels.txt" => "DifficultyLevels.txt", + "ElemTypes.txt" => "ElemTypes.txt", + "Events.txt" => "Events.txt", + "Experience.txt" => "Experience.txt", + "gamble.txt" => "gamble.txt", + "Gems.txt" => "Gems.txt", + "hiredesc.txt" => "hiredesc.txt", + "Hireling.txt" => "Hireling.txt", + "HitClass.txt" => "HitClass.txt", + "Inventory.txt" => "Inventory.txt", + "ItemRatio.txt" => "ItemRatio.txt", + "ItemStatCost.txt" => "ItemStatCost.txt", + "ItemTypes.txt" => "ItemTypes.txt", + "Levels.txt" => "Levels.txt", + "lowqualityitems.txt" => "lowqualityitems.txt", + "LvlMaze.txt" => "LvlMaze.txt", + "LvlPrest.txt" => "LvlPrest.txt", + "LvlSub.txt" => "LvlSub.txt", + "LvlTypes.txt" => "LvlTypes.txt", + "LvlWarp.txt" => "LvlWarp.txt", + "MagicPrefix.txt" => "MagicPrefix.txt", + "MagicSuffix.txt" => "MagicSuffix.txt", + "Misc.txt" => "Misc.txt", + "MissCalc.txt" => "MissCalc.txt", + "Missiles.txt" => "Missiles.txt", + "MonAi.txt" => "MonAi.txt", + "MonEquip.txt" => "MonEquip.txt", + "MonItemPercent.txt" => "MonItemPercent.txt", + "MonLvl.txt" => "MonLvl.txt", + "MonMode.txt" => "MonMode.txt", + "MonName.txt" => "MonName.txt", + "MonPlace.txt" => "MonPlace.txt", + "MonPreset.txt" => "MonPreset.txt", + "MonProp.txt" => "MonProp.txt", + "MonSeq.txt" => "MonSeq.txt", + "MonSounds.txt" => "MonSounds.txt", + "MonStats2.txt" => "MonStats2.txt", + "MonStats.txt" => "MonStats.txt", + "MonType.txt" => "MonType.txt", + "MonUMod.txt" => "MonUMod.txt", + "Npc.txt" => "Npc.txt", + "Objects.txt" => "Objects.txt", + "objgroup.txt" => "objgroup.txt", + "ObjMode.txt" => "ObjMode.txt", + "ObjType.txt" => "ObjType.txt", + "Overlay.txt" => "Overlay.txt", + "PetType.txt" => "PetType.txt", + "PlayerClass.txt" => "PlayerClass.txt", + "PlrMode.txt" => "PlrMode.txt", + "PlrType.txt" => "PlrType.txt", + "Properties.txt" => "Properties.txt", + "qualityitems.txt" => "qualityitems.txt", + "RarePrefix.txt" => "RarePrefix.txt", + "RareSuffix.txt" => "RareSuffix.txt", + "Runes.txt" => "Runes.txt", + "SetItems.txt" => "SetItems.txt", + "Sets.txt" => "Sets.txt", + "Shrines.txt" => "Shrines.txt", + "SkillCalc.txt" => "SkillCalc.txt", + "SkillDesc.txt" => "SkillDesc.txt", + "Skills.txt" => "Skills.txt", + "SoundEnviron.txt" => "SoundEnviron.txt", + "Sounds.txt" => "Sounds.txt", + "States.txt" => "States.txt", + "StorePage.txt" => "StorePage.txt", + "SuperUniques.txt" => "SuperUniques.txt", + "TreasureClassEx.txt" => "TreasureClassEx.txt", + "TreasureClass.txt" => "TreasureClass.txt", + "UniqueAppellation.txt" => "UniqueAppellation.txt", + "UniqueItems.txt" => "UniqueItems.txt", + "UniquePrefix.txt" => "UniquePrefix.txt", + "UniqueSuffix.txt" => "UniqueSuffix.txt", + "UniqueTitle.txt" => "UniqueTitle.txt", + "WeaponClass.txt" => "WeaponClass.txt", + "Weapons.txt" => "Weapons.txt", + ]; public function __construct() { - $files = glob(TXT_PATH.DIRECTORY_SEPARATOR.'*.txt'); - - foreach ($files as $file){ - $this->files[] = basename($file); - } return $this->files; } + } diff --git a/switchMods.php b/switchMods.php index a5ddf0c..2f660f4 100644 --- a/switchMods.php +++ b/switchMods.php @@ -1,16 +1,25 @@