Skip to content

Commit

Permalink
modrinth integration (plus md support), dynamic ui changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cowpod committed Nov 13, 2024
1 parent 901ee3a commit 10de524
Show file tree
Hide file tree
Showing 6 changed files with 563 additions and 60 deletions.
64 changes: 40 additions & 24 deletions functions/add-modv.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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."}');
Loading

0 comments on commit 10de524

Please sign in to comment.