From 56cd874963e5c6006ea1e500c46a1e2aba3dd990 Mon Sep 17 00:00:00 2001 From: Henry Gross-Hellsen <6283258+cowpod@users.noreply.github.com> Date: Thu, 31 Oct 2024 16:46:43 -0700 Subject: [PATCH] instant-modpack.php: switch to ids instead of name for builds, set loadertype, use insert_id for sql, fix mods not being added properly to build --- functions/instant-modpack.php | 36 ++++++++++++++++++++++------------ index.php | 3 ++- resources/js/page_dashboard.js | 11 ++++++++--- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/functions/instant-modpack.php b/functions/instant-modpack.php index 3e46931..fe2f37a 100644 --- a/functions/instant-modpack.php +++ b/functions/instant-modpack.php @@ -27,6 +27,7 @@ $bjava = $db->sanitize($_POST['java']); $bmemory = $db->sanitize($_POST['memory']); $bforge = $db->sanitize($_POST['versions']); + $db->execute("INSERT INTO modpacks(`name`, `display_name`, `icon`, `icon_md5`, `logo`, `logo_md5`, `background`, `background_md5`, `public`, `recommended`, `latest`) VALUES ('".$mpname."', '".$mpdname."', @@ -37,24 +38,33 @@ 'http://".$config['host'].$config['dir']."resources/default/background.png', '88F838780B89D7C7CD10FE6C3DBCDD39', 1, - '1.0', - '1.0')"); + '', + '')"); +// latest,public will be set later in this script -$mpq = $db->query("SELECT `id` FROM `modpacks` ORDER BY `id` DESC LIMIT 1"); -if ($mpq) { - assert(sizeof($mpq)==1); - $mp = $mpq[0]; -} -$mpi = intval($mp['id']); +// $mpq = $db->query("SELECT `id` FROM `modpacks` ORDER BY `id` DESC LIMIT 1"); +// if ($mpq) { +// assert(sizeof($mpq)==1); +// $mp = $mpq[0]; +// } +// $mpi = intval($mp['id']); +$mpi = $db->insert_id(); -$fq = $db->query("SELECT `mcversion` FROM `mods` WHERE `id` = ". $bforge); +$fq = $db->query("SELECT `loadertype`,`mcversion` FROM `mods` WHERE `id` = ". $bforge); if ($fq) { assert(sizeof($fq)==1); $f = $fq[0]; } -$minecraft = $f['mcversion']; -$db->execute("INSERT INTO builds(`name`,`modpack`,`public`,`mods`,`java`,`memory`,`minecraft`) - VALUES ('1.0','".$mpi."',1,'".$bforge.",".$bmods."','".$bjava."','".$bmemory."','".$minecraft."')"); - +$minecraft = $f['mcversion']; +$loadertype= $f['loadertype']; +$forgeandmods = !empty($bmods) ? $bforge.','.$bmods : $bforge; +error_log("FORGEANDMODS ".$forgeandmods); +$db->execute("INSERT INTO builds(`name`,`modpack`,`public`,`mods`,`java`,`memory`,`minecraft`,`loadertype`) + VALUES ('1.0', '".$mpi."', 1, '".$forgeandmods."', '".$bjava."', '".$bmemory."', '".$minecraft."', '".$loadertype."')"); + +$new_build_id = $db->insert_id(); + +$db->execute("UPDATE modpacks SET latest=".$new_build_id.", recommended=".$new_build_id." WHERE id=".$mpi); + header("Location: ".$config['dir']."modpack?id=".$mpi); exit(); diff --git a/index.php b/index.php index 704cb96..87dab7d 100644 --- a/index.php +++ b/index.php @@ -679,7 +679,8 @@ function uri($uri) { } ?>
- + +
diff --git a/resources/js/page_dashboard.js b/resources/js/page_dashboard.js index 125000d..cdb1f68 100644 --- a/resources/js/page_dashboard.js +++ b/resources/js/page_dashboard.js @@ -7,6 +7,7 @@ $('#modsform').submit(function() { } }); var addedmodslist = []; +var addedmodsliststr = []; mn = 1; function againMods() { $("#btn-done").attr("disabled",true); @@ -14,6 +15,7 @@ function againMods() { $("#upload-card").show(); $("#u-mods").hide(); addedmodslist = []; + addedmodsliststr= []; mn = 1; } function sendFile(file, i) { @@ -34,15 +36,18 @@ function sendFile(file, i) { console.log(request.response); response = JSON.parse(request.response); if (response.modid) { - if (! $('#modlist').val().split(",").includes(response.modid.toString())) { - addedmodslist.push(response.name); + if (!addedmodslist.includes(response.modid)) { + addedmodslist.push(response.modid); + addedmodsliststr.push(response.name); } } if ( mn == modcount ) { if (addedmodslist.length > 0) { - if ($('#modlist').val().length > 0) { + if ($('#modliststr').val().length > 0) { + $('#modliststr').val($('#modliststr').val() + "," + addedmodsliststr); $('#modlist').val($('#modlist').val() + "," + addedmodslist); } else { + $('#modliststr').val($('#modliststr').val() + addedmodsliststr); $('#modlist').val($('#modlist').val() + addedmodslist); } }