Skip to content

Commit

Permalink
instant-modpack.php: switch to ids instead of name for builds, set lo…
Browse files Browse the repository at this point in the history
…adertype, use insert_id for sql, fix mods not being added properly to build
  • Loading branch information
cowpod committed Oct 31, 2024
1 parent da151c3 commit 56cd874
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
36 changes: 23 additions & 13 deletions functions/instant-modpack.php
Original file line number Diff line number Diff line change
Expand Up @@ -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."',
Expand All @@ -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();
3 changes: 2 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ function uri($uri) {
}
?>
<br />
<input autocomplete="off" id="modlist" required readonly class="form-control" type="text" name="modlist" placeholder="Mods to add" />
<input id="modlist" class="form-control" type="hidden" name="modlist" />
<input autocomplete="off" id="modliststr" required readonly class="form-control" type="text" name="modliststr" placeholder="Mods to add" />
<br />
<input type="submit" id="submit" disabled class="btn btn-primary btn-block" value="Create">
</form>
Expand Down
11 changes: 8 additions & 3 deletions resources/js/page_dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ $('#modsform').submit(function() {
}
});
var addedmodslist = [];
var addedmodsliststr = [];
mn = 1;
function againMods() {
$("#btn-done").attr("disabled",true);
$("#table-mods").html("");
$("#upload-card").show();
$("#u-mods").hide();
addedmodslist = [];
addedmodsliststr= [];
mn = 1;
}
function sendFile(file, i) {
Expand All @@ -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);
}
}
Expand Down

0 comments on commit 56cd874

Please sign in to comment.