mirror of
https://gitlab.com/hashborgir/d2tools.git
synced 2024-11-30 12:36:03 +00:00
Bugfixing. Adding sanity checks
This commit is contained in:
parent
b85fbf02b3
commit
9bc941faea
13
includes.php
13
includes.php
@ -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';
|
|
49
index.php
49
index.php
@ -1,17 +1,17 @@
|
|||||||
<?php
|
<?php
|
||||||
|
session_start();
|
||||||
/*
|
/*
|
||||||
D2UniqueMaker
|
D2IM
|
||||||
GPLv2 (C) <2021> <HashCasper>
|
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
|
D2UM is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 2 of the License, or
|
the Free Software Foundation, either version 2 of the License, or
|
||||||
(at your option) any later version.
|
(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
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
@ -24,30 +24,37 @@ ini_set('display_errors', 1);
|
|||||||
error_reporting(1);
|
error_reporting(1);
|
||||||
ini_set('log_errors', 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();
|
$db = new D2Database();
|
||||||
$parser = new D2TxtParser();
|
$parser = new D2TxtParser();
|
||||||
|
|
||||||
$armor = PDO_FetchAll('SELECT * FROM armor WHERE `spawnable`=1');
|
$armor = PDO_FetchAll('SELECT * FROM armor WHERE `spawnable`=1');
|
||||||
$weapon = PDO_FetchAll('SELECT * FROM weapons WHERE `spawnable`=1');
|
$weapon = PDO_FetchAll('SELECT * FROM weapons WHERE `spawnable`=1');
|
||||||
|
|
||||||
|
|
||||||
$prop = $parser->filterProps('Properties.txt');
|
$prop = $parser->filterProps('Properties.txt');
|
||||||
|
|
||||||
// If there's data, process it and save
|
// If there's data, process it and save
|
||||||
if (!empty($_POST)) {
|
if (!empty($_POST)) {
|
||||||
|
|
||||||
// save db name from post into conf file
|
// save db name from post into conf file
|
||||||
|
|
||||||
require_once './src/D2SaveFile.php';
|
require_once './src/D2SaveFile.php';
|
||||||
$saver = new D2SaveFile();
|
$saver = new D2SaveFile();
|
||||||
|
|
||||||
@ -66,8 +73,8 @@ if (file_exists("d2im.db") && (file_exists($_SESSION['modname'].".db"))){
|
|||||||
|
|
||||||
|
|
||||||
if ($_POST['formtype'] == "uniqueitems") {
|
if ($_POST['formtype'] == "uniqueitems") {
|
||||||
|
|
||||||
|
|
||||||
// if ladder or carry1 is 0, set empty field.
|
// if ladder or carry1 is 0, set empty field.
|
||||||
if (!$post['ladder']) {
|
if (!$post['ladder']) {
|
||||||
$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';
|
require_once './src/index.php';
|
||||||
} else {
|
|
||||||
header('Location: ./src/D2Config.php');
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
@ -1,26 +1,49 @@
|
|||||||
<?php
|
<?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("d2im.db")) {
|
||||||
|
if (file_exists($_SESSION['modname'] . ".db")) {
|
||||||
if(file_exists(DB_FILE)) unlink(DB_FILE);
|
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();
|
$files = new D2Files();
|
||||||
$parser = new D2TxtParser();
|
$parser = new D2TxtParser();
|
||||||
$db = new D2Database();
|
$db = new D2Database();
|
||||||
|
|
||||||
|
// Parse all files
|
||||||
foreach ($files->files as $k => $v) {
|
foreach ($files->files as $k => $v) {
|
||||||
$data[$v] = $parser->parseFile($v);
|
$data[$v] = $parser->parseFile($v);
|
||||||
}
|
}
|
||||||
|
// Write all parse data to mod db
|
||||||
foreach ($data as $k => $v) {
|
foreach ($data as $k => $v) {
|
||||||
$db->createTables($k, $v);
|
$db->createTables($k, $v);
|
||||||
$db->fillsTables($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>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
18
res/app.js
18
res/app.js
@ -12,7 +12,10 @@ $(document).ready(function () {
|
|||||||
$('option[disabled="disabled"]').show();
|
$('option[disabled="disabled"]').show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(function () {
|
||||||
|
$('[data-toggle="tooltip"]').tooltip()
|
||||||
|
})
|
||||||
|
|
||||||
$('.w-select').change(function () {
|
$('.w-select').change(function () {
|
||||||
$('.a-select').each(function (i, v) {
|
$('.a-select').each(function (i, v) {
|
||||||
@ -44,15 +47,20 @@ $(document).ready(function () {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$('.help').hover(function () {
|
$('.help').click(function () {
|
||||||
$(".fa-help").remove();
|
$(".fa-help").remove();
|
||||||
$(this).next().fadeToggle("slow").css({
|
$(this).next().fadeToggle("slow").focus().css({
|
||||||
"position": "absolute",
|
"position": "absolute",
|
||||||
"z-index": "1000",
|
"z-index": "1000",
|
||||||
"background": "#eee",
|
"background": "#eee",
|
||||||
"color": "black !important",
|
"color": "black !important",
|
||||||
"border": "1px solid #aaa",
|
"border": "1px solid #aaa",
|
||||||
"width": "300px",
|
"width": "300px",
|
||||||
});
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('.form-text').click(function () {
|
||||||
|
$(this).fadeOut("slow");
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
@ -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>
|
echo '<center><h1 style="font-family:Lato; color:#880000;"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
|
||||||
ERROR: INVALID PATH</h1></center>';
|
ERROR: INVALID PATH</h1></center>';
|
||||||
} else {
|
} else {
|
||||||
|
// set this mod to active mod in session
|
||||||
$_SESSION['path'] = $path;
|
$_SESSION['path'] = $path;
|
||||||
// Don't yell at me, security is the least of my considerations atm
|
// Don't yell at me, security is the least of my considerations atm
|
||||||
// check modname in db
|
// 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>
|
echo '<center><h1 style="font-family:Lato; color:#880000;"><i class="fa fa-exclamation-triangle" aria-hidden="true"></i>
|
||||||
ERROR: INVALID PATH</h1></center>';
|
ERROR: INVALID PATH</h1></center>';
|
||||||
} else {
|
} else {
|
||||||
|
// set this mod to active mod in session
|
||||||
$_SESSION['path'] = $path;
|
$_SESSION['path'] = $path;
|
||||||
// Don't yell at me, security is the least of my considerations atm
|
// Don't yell at me, security is the least of my considerations atm
|
||||||
// check modname in db
|
// check modname in db
|
||||||
|
@ -78,9 +78,6 @@ class D2Database {
|
|||||||
}
|
}
|
||||||
$sql = rtrim($sql, ", ");
|
$sql = rtrim($sql, ", ");
|
||||||
|
|
||||||
var_dump($file);
|
|
||||||
var_dump($sql);
|
|
||||||
|
|
||||||
PDO_Execute($sql);
|
PDO_Execute($sql);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
100
src/D2Files.php
100
src/D2Files.php
@ -21,14 +21,102 @@
|
|||||||
|
|
||||||
class D2Files {
|
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() {
|
public function __construct() {
|
||||||
$files = glob(TXT_PATH.DIRECTORY_SEPARATOR.'*.txt');
|
|
||||||
|
|
||||||
foreach ($files as $file){
|
|
||||||
$this->files[] = basename($file);
|
|
||||||
}
|
|
||||||
return $this->files;
|
return $this->files;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
include "includes.php";
|
session_start();
|
||||||
PDO_Connect("sqlite:" . "d2im.db");
|
include "./_pdo.php";
|
||||||
$sql = "SELECT * FROM d2im";
|
|
||||||
$mods = PDO_FetchAll($sql);
|
|
||||||
|
|
||||||
if (!empty($_POST)) {
|
// if config db exists, connect to it and grab list of mods
|
||||||
$sql = "SELECT * FROM d2im WHERE `modname`='{$_POST['modname']}'";
|
if (file_exists("d2im.db")) {
|
||||||
$mod = PDO_FetchRow($sql);
|
PDO_Connect("sqlite:d2im.db");
|
||||||
|
|
||||||
$_SESSION['modname'] = $mod[modname];
|
$sql = "SELECT * FROM d2im";
|
||||||
$_SESSION['path'] = $mod['path'];
|
$mods = PDO_FetchAll($sql);
|
||||||
header("Location: /");
|
|
||||||
|
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>
|
<!doctype html>
|
||||||
|
Loading…
Reference in New Issue
Block a user