Bugfixing. Adding sanity checks

This commit is contained in:
color.diff=auto 2021-03-27 02:53:26 -06:00
parent b85fbf02b3
commit 9bc941faea
8 changed files with 187 additions and 68 deletions

View File

@ -1,13 +0,0 @@
<?php
session_start();
include "./_pdo.php";
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';

View File

@ -1,17 +1,17 @@
<?php
session_start();
/*
D2UniqueMaker
D2IM
GPLv2 (C) <2021> <HashCasper>
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');
}
?>

View File

@ -1,26 +1,49 @@
<?php
include "includes.php";
// Second step after D2Config. If we made it here, d2im.db should
// have been created. Config writes active mod to session.
session_start();
include "./_pdo.php";
// check to see if config db exists or if for some reason it doesn't exist
if (file_exists("d2im.db")) {
if(file_exists(DB_FILE)) unlink(DB_FILE);
if (file_exists($_SESSION['modname'] . ".db")) {
unlink($_SESSION['modname'] . ".db"); // delete old mod db file
}
// Set CONSTANTS (if d2im.db exists, D2Config set the session mod correctly)
define('FILTER_PROPERTIES_FILE', 'filterProperties.txt');
define('DB_FILE', $_SESSION['modname'] . ".db");
define('TXT_PATH', $_SESSION['path']);
// require D2IM src
require_once "./src/D2Functions.php";
require_once "./src/D2Database.php";
require_once './src/D2Files.php';
require_once './src/D2TxtParser.php';
// Create D2IM objects
$files = new D2Files();
$parser = new D2TxtParser();
$db = new D2Database();
// Parse all files
foreach ($files->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.
?>
<!doctype html>
<html lang="en">

View File

@ -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");
});
});

View File

@ -49,6 +49,7 @@ if (!empty($_POST)) {
echo '<center><h1 style="font-family:Lato; color:#880000;"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
ERROR: INVALID PATH</h1></center>';
} 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</h1></center>';
echo '<center><h1 style="font-family:Lato; color:#880000;"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
ERROR: INVALID PATH</h1></center>';
} 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

View File

@ -78,9 +78,6 @@ class D2Database {
}
$sql = rtrim($sql, ", ");
var_dump($file);
var_dump($sql);
PDO_Execute($sql);
}
}

View File

@ -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;
}
}

View File

@ -1,16 +1,25 @@
<?php
include "includes.php";
PDO_Connect("sqlite:" . "d2im.db");
$sql = "SELECT * FROM d2im";
$mods = PDO_FetchAll($sql);
session_start();
include "./_pdo.php";
if (!empty($_POST)) {
$sql = "SELECT * FROM d2im WHERE `modname`='{$_POST['modname']}'";
$mod = PDO_FetchRow($sql);
$_SESSION['modname'] = $mod[modname];
$_SESSION['path'] = $mod['path'];
header("Location: /");
// if config db exists, connect to it and grab list of mods
if (file_exists("d2im.db")) {
PDO_Connect("sqlite:d2im.db");
$sql = "SELECT * FROM d2im";
$mods = PDO_FetchAll($sql);
if (!empty($_POST)) {
$sql = "SELECT * FROM d2im WHERE `modname`='{$_POST['modname']}'";
$mod = PDO_FetchRow($sql);
$_SESSION['modname'] = $mod['modname'];
$_SESSION['path'] = $mod['path'];
header("Location: /");
}
} else {
// if config db does not exist, go to config page
header("Location: /src/D2Config.php");
}
?>
<!doctype html>