diff --git a/functions/add-modv.php b/functions/add-modv.php index e58935e..283e75c 100644 --- a/functions/add-modv.php +++ b/functions/add-modv.php @@ -2,32 +2,35 @@ session_start(); if (empty($_POST['pretty_name'])) { - die("Name not specified."); + die('{"status":"error","message":"Pretty name not specified."}'); } if (empty($_POST['name'])) { - die("Slug not specified."); + die('{"status":"error","message":"Slug not specified."}'); } if (empty($_POST['version'])) { - die("Version not specified."); + die('{"status":"error","message":"Version not specified."}'); } if (empty($_POST['url'])) { - die("URL not specified."); + die('{"status":"error","message":"File URL not specified."}'); } if (empty($_POST['md5'])) { - die("Md5 not specified."); + die('{"status":"error","message":"MD5 not specified."}'); +} +if (empty($_POST['filesize'])) { + die('{"status":"error","message":"Filesize not specified."}'); } if (empty($_POST['mcversion'])) { - die("Minecraft version not specified."); + die('{"status":"error","message":"Minecraft version not specified."}'); } if (empty($_POST['loadertype'])) { - die("Loader type not specified."); + die('{"status":"error","message":"Loader type not specified."}'); } if (!$_SESSION['user']||$_SESSION['user']=="") { - die("Unauthorized request or login session has expired!"); + die('{"status":"error","message":"Unauthorized request or login session has expired!"}'); } if (substr($_SESSION['perms'], 3, 1)!=="1") { - die("Insufficient permission!"); + die('{"status":"error","message":"Insufficient permission!"}'); } $config = require("./config.php"); @@ -38,26 +41,39 @@ $db->connect(); } +$name = $db->sanitize($_POST['name']); +$md5 = $db->sanitize($_POST['md5']); +$filesize = $db->sanitize($_POST['filesize']); $link = isset($_POST['link']) ? $db->sanitize($_POST['link']) : ''; $auth = isset($_POST['author']) ? $db->sanitize($_POST['author']) : ''; $desc = isset($_POST['description']) ? $db->sanitize($_POST['description']) : ''; $donlink = isset($_POST['donlink']) ? $db->sanitize($_POST['donlink']) : ''; -$db->execute("INSERT INTO `mods` - (`name`, `pretty_name`, `md5`, `url`, `link`, `author`, `donlink`, `description`, `version`, `mcversion`, `type`, `loadertype`) VALUES ( - '".$db->sanitize($_POST['name'])."', - '".$db->sanitize($_POST['pretty_name'])."', - '".$db->sanitize($_POST['md5'])."', - '".$db->sanitize($_POST['url'])."', - '".$link."', - '".$auth."', - '".$donlink."', - '".$desc."', - '".$db->sanitize($_POST['version'])."', - '".$db->sanitize($_POST['mcversion'])."', +// we use name (slug) and md5 to determine if its already installed. +// since we have md5. otherwise we should check version,mcversion,name/slug,type,loadertype +$existsq = $db->query("SELECT 1 FROM mods WHERE name='{$name}' AND md5='{$md5}'"); +if ($existsq && sizeof($existsq)>=1) { + die('{"status":"succ","message":"Mod is already added."}'); +} + +$addq = $db->execute("INSERT INTO `mods` + (`name`, `pretty_name`, `md5`, `filesize`, `url`, `link`, `author`, `donlink`, `description`, `version`, `mcversion`, `type`, `loadertype`) VALUES ( + '{$name}', + '{$db->sanitize($_POST['pretty_name'])}', + '{$md5}', + '{$filesize}', + '{$db->sanitize($_POST['url'])}', + '{$link}', + '{$auth}', + '{$donlink}', + '{$desc}', + '{$db->sanitize($_POST['version'])}', + '{$db->sanitize($_POST['mcversion'])}', 'mod', - '".$db->sanitize($_POST['loadertype'])."', + '{$db->sanitize($_POST['loadertype'])}' )"); +if ($addq) { + die('{"status":"succ","message":"Mod successfully added."}'); +} -header("Location: ".$config['dir']."lib-mods"); -exit(); +die('{"status":"error","message":"Could not add mod."}'); diff --git a/index.php b/index.php index 9dcbb5b..4eea14d 100644 --- a/index.php +++ b/index.php @@ -123,6 +123,7 @@ function uri($uri) { + @@ -1328,17 +1329,18 @@ function uri($uri) { } ?> - id="mod-"> + id="mod-"> : Mod does not exist! Please remove from this build.'; - } elseif (!$userModVersionOK) { - echo ': For Minecraft '.$mod['mcversion'].', you have '.$user['minecraft'].'. May not be compatible!'; } elseif(empty($mod['version'])) { echo ': Missing version! You must set it in mod details.'; + } elseif(empty($mod['mcversion'])) { + echo ': Missing mcversion! You must set it in mod details.'; + } elseif (!$userModVersionOK) { + echo ': For Minecraft '.$mod['mcversion'].', you have '.$user['minecraft'].'. May not be compatible!'; } - ?> query("SELECT * FROM mods WHERE type = 'mod' AND loadertype = '".$loadertype."'"); // todo: use a group-by? @@ -1478,8 +1478,8 @@ function uri($uri) { foreach ($version_details as $vals) { [$id,$version,$mcversion] = $vals; if (in_range($mcversion, $user['minecraft'])|| (!empty($_SESSION['showall']) && $_SESSION['showall'])) { - if (empty($version)) { - echo ""; + if (empty($version) || empty($mcversion)) { + echo ""; $num_missing_version+=1; } else { echo ""; @@ -1495,7 +1495,11 @@ function uri($uri) { - + + Issue(s) + + Add to Build + + +
+

Get mods - Modrinth

+
+
+ +
+
+ +
+
+ +
+
+ + + + + + + + + + + + +
NameCategoryDesc.Author
+ +
+ + + + +

Upload mods

@@ -1585,10 +1671,11 @@ function uri($uri) { - +
+
-

Add remote mods

+

Add remote mods

@@ -1605,7 +1692,7 @@ function uri($uri) { - + query("SELECT * FROM `mods` WHERE `type` = 'mod' ORDER BY `id` DESC"); if ($mods){ @@ -1641,8 +1728,8 @@ function uri($uri) { foreach ($modsi as $mod) { ?> - - Unknown"; } ?> + >Unknown" : $mod['pretty_name'] ?> + >Unknown"; } ?> @@ -1684,7 +1771,7 @@ function uri($uri) {
- + + @@ -1758,10 +1846,10 @@ function uri($uri) {
- + - - + +