Skip to content

Hidden Modpacks

fireboyev edited this page Sep 6, 2020 · 7 revisions

It is possible to create modpacks that only appear if the user enters a special "key."

If you have PHP support, the Modpack Creator can generate a package listing file for you automatically to support this feature. See Creating Modpacks.

Launcher Setup

Make sure that in launcher.properties, you configure the packageListUrl parameter so it has a "%s" that will be replaced with a (URL-encoded) copy of the game key that the user can set in the settings.

How It Works

For example, if your properties file looked like:

packageListUrl=http://example.com/packages.json?key=%s

And in options, the user set this:

Options

It would load the following URL:

http://example.com/packages.json?key=secret

Manual Package Listing File

You can also manually set up the feature with the PHP script provided below. Your website needs PHP scripting support. Dropbox will not work.

Example PHP Script

The following is an example PHP script that reads the key parameter to show an extra modpack:

<?php
// This file automatically generates packages.json

function getPackageData($pathname) {
    $data = json_decode(file_get_contents($pathname));
    if (isset($data->name) && isset($data->version)) {
        return [
            'name' => $data->name,
            'title' => isset($data->title) ? $data->title : $data->name,
            'version' => $data->version,
            'location' => $pathname,
            'priority' => 1,
        ];
    } else {
        return null;
    }
}

$key = isset($_GET['key']) ? $_GET['key'] : "";
$files = glob("*.json");

if ($files === false) {
    $files = [];
}

$document = [
    'minimumVersion' => 1,
    'packages' => [],
];

// Get packages in the same folder
foreach ($files as $file) {
    $data = getPackageData($file);
    if ($data !== null) {
        $document['packages'][] = $data;
    }
}

// If the key is 'secret', then add the package from 'private/beta.json'
if ($key == "secret") {
    $document['packages'][] = getPackageData("private/beta.json");
}

header("Content-Type: text/plain");
echo json_encode($document, JSON_PRETTY_PRINT);