Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lgsm/config-default/config-lgsm/mcserver/_default.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ startparameters="nogui"
extraparams=""

## Release Settings | https://docs.linuxgsm.com/game-servers/minecraft#release-settings
# Variant (vanilla|fabric|paper|purpur|folia|leaf)
# Variant (vanilla|fabric|forge|neoforge|paper|purpur|folia|leaf)
variant="vanilla"
# Branch (release|snapshot)
branch="release"
Expand Down
1 change: 1 addition & 0 deletions lgsm/modules/check_executable.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"

# Check if executable exists
execname=$(basename "${executable//\"/}")
execname="${execname#@}"
if [ ! -f "${executabledir}/${execname}" ]; then
fn_print_fail_nl "executable was not found"
echo -e "* ${executabledir}/${execname}"
Expand Down
27 changes: 23 additions & 4 deletions lgsm/modules/check_variant.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fn_variant_list() {
variantnames=()
variantinstalldefault=""
if [ "${shortname}" == "mc" ]; then
variants=("vanilla" "fabric" "paper" "purpur" "folia" "leaf")
variantnames=("Vanilla" "Fabric" "PaperMC" "Purpur" "Folia" "Leaf")
variants=("vanilla" "fabric" "forge" "neoforge" "paper" "purpur" "folia" "leaf")
variantnames=("Vanilla" "Fabric" "Forge" "NeoForge" "PaperMC" "Purpur" "Folia" "Leaf")
elif [ "${shortname}" == "mohaa" ]; then
variants=("alliedassault-reborn" "alliedassault-vanilla" "alliedassault-openmohaa" "spearhead-vanilla" "spearhead-openmohaa" "breakthrough-openmohaa")
variantnames=("Allied Assault (Reborn)" "Allied Assault (Vanilla)" "Allied Assault (OpenMoHAA)" "Spearhead (Vanilla)" "Spearhead (OpenMoHAA)" "Breakthrough (OpenMoHAA)")
Expand All @@ -30,6 +30,9 @@ fn_variant_settings() {
variantexecutable="./minecraft_server.jar"
elif [ "${variant}" == "fabric" ]; then
variantexecutable="./fabric-server-launch.jar"
elif [ "${variant}" == "forge" ] || [ "${variant}" == "neoforge" ]; then
variantexecutable="@unix_args.txt"
variantjvmargs="@user_jvm_args.txt"
elif [ "${variant}" == "paper" ]; then
variantexecutable="./paper.jar"
elif [ "${variant}" == "purpur" ]; then
Expand Down Expand Up @@ -68,6 +71,19 @@ fn_variant_settings() {
fi
}

# Applies variant start settings again after fn_reload_startparameters.
fn_variant_startparameters() {
if [ -n "${variantstartparameters}" ]; then
startparameters="${variantstartparameters} ${startparameters}"
fi
if [ -n "${variantbasepath}" ]; then
startparameters="${startparameters} +set fs_basepath ${variantbasepath}"
fi
if [ -n "${variantjvmargs}" ] && [[ "${preexecutable}" == *" -jar" ]]; then
preexecutable="${preexecutable% -jar} ${variantjvmargs}"
fi
}

# Installs files a variant needs that an existing install does not have.
fn_variant_files() {
if [ "${shortname}" == "mohaa" ] && [ -d "${serverfiles}/main" ]; then
Expand Down Expand Up @@ -282,11 +298,14 @@ fn_variant_record() {
# Warns about data that does not carry across a variant change.
fn_variant_change_warning() {
if [ "${shortname}" == "mc" ]; then
if [[ "${installedvariant}" =~ ^(paper|purpur|folia|leaf)$ ]] && [[ "${variant}" =~ ^(vanilla|fabric)$ ]]; then
if [[ "${installedvariant}" =~ ^(paper|purpur|folia|leaf)$ ]] && [[ "${variant}" =~ ^(vanilla|fabric|forge|neoforge)$ ]]; then
fn_print_warning_nl "${installedvariantname} keeps the Nether and End in world_nether and world_the_end. ${variantname} does not load them from there."
fn_script_log_warn "${installedvariantname} keeps the Nether and End in world_nether and world_the_end. ${variantname} does not load them from there."
fi
if [ "${installedvariant}" == "fabric" ] || [ "${variant}" == "fabric" ]; then
if [[ "${installedvariant}" =~ ^(fabric|forge|neoforge)$ ]] && [[ "${variant}" =~ ^(fabric|forge|neoforge)$ ]]; then
fn_print_warning_nl "${installedvariantname} mods in the mods directory do not load on ${variantname}. Replace them with ${variantname} builds."
fn_script_log_warn "${installedvariantname} mods in the mods directory do not load on ${variantname}."
elif [[ "${installedvariant}" =~ ^(fabric|forge|neoforge)$ ]] || [[ "${variant}" =~ ^(fabric|forge|neoforge)$ ]]; then
fn_print_warning_nl "Mods and plugins are not shared between ${installedvariantname} and ${variantname}."
fn_script_log_warn "Mods and plugins are not shared between ${installedvariantname} and ${variantname}."
fi
Expand Down
7 changes: 1 addition & 6 deletions lgsm/modules/command_debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,7 @@ if [ "${serverpassword}" ]; then
fi

fn_reload_startparameters
if [ -n "${variantstartparameters}" ]; then
startparameters="${variantstartparameters} ${startparameters}"
fi
if [ -n "${variantbasepath}" ]; then
startparameters="${startparameters} +set fs_basepath ${variantbasepath}"
fi
fn_variant_startparameters
echo -e "${lightblue}Start parameters:${default}"
if [ "${engine}" == "source" ] || [ "${engine}" == "goldsrc" ]; then
echo -e "${executable} ${startparameters} -debug"
Expand Down
7 changes: 1 addition & 6 deletions lgsm/modules/command_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,7 @@ fn_start_tmux() {
date '+%s' > "${lockdir:?}/${selfname}-starting.lock"

fn_reload_startparameters
if [ -n "${variantstartparameters}" ]; then
startparameters="${variantstartparameters} ${startparameters}"
fi
if [ -n "${variantbasepath}" ]; then
startparameters="${startparameters} +set fs_basepath ${variantbasepath}"
fi
fn_variant_startparameters

# Hytale: with no saved server login file, have the server start its login (OAuth device code) on boot.
# A saved login that can't be used is handled after boot by fn_start_hyt_login.
Expand Down
7 changes: 1 addition & 6 deletions lgsm/modules/info_messages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -754,12 +754,7 @@ fn_info_messages_commandlineparms() {
unset serverpassword
fi
fn_reload_startparameters
if [ -n "${variantstartparameters}" ]; then
startparameters="${variantstartparameters} ${startparameters}"
fi
if [ -n "${variantbasepath}" ]; then
startparameters="${startparameters} +set fs_basepath ${variantbasepath}"
fi
fn_variant_startparameters
echo -e "${preexecutable} ${executable} ${startparameters}"
}

Expand Down
92 changes: 91 additions & 1 deletion lgsm/modules/update_mc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ moduleselfname="$(basename "$(readlink -f "${BASH_SOURCE[0]}")")"
fn_update_dl() {
# Download and extract files to serverfiles.
fn_fetch_file "${remotebuildurl}" "" "" "" "${tmpdir}" "${remotebuildfilename}" "chmodx" "norun" "noforce" "${remotebuildhash:-nohash}"
cp -f "${tmpdir}/${remotebuildfilename}" "${serverfiles}/${variantexecutable#./}"
if [ "${variant}" == "forge" ] || [ "${variant}" == "neoforge" ]; then
fn_update_dl_installer
else
cp -f "${tmpdir}/${remotebuildfilename}" "${serverfiles}/${variantexecutable#./}"
fi
if [ "${variant}" != "vanilla" ]; then
echo "${remotebuild}" > "${serverfiles}/build.txt"
fi
Expand All @@ -22,6 +26,26 @@ fn_update_dl() {
fn_clear_tmp
}

fn_update_dl_installer() {
# Forge and NeoForge install the server with their installer, which writes the launch arguments to unix_args.txt.
if [ "${variant}" == "forge" ]; then
argsfile="${serverfiles}/libraries/net/minecraftforge/forge/${remotebuild}/unix_args.txt"
else
argsfile="${serverfiles}/libraries/net/neoforged/neoforge/${remotebuild}/unix_args.txt"
fi
fn_print_dots "Running ${variantname} installer"
if (cd "${tmpdir}" && ${javabin} -jar "${remotebuildfilename}" --installServer "${serverfiles}" > "${tmpdir}/installer.log" 2>&1) && [ -f "${argsfile}" ] && cp -f "${argsfile}" "${serverfiles}/unix_args.txt"; then
fn_print_ok_nl "Running ${variantname} installer"
fn_script_log_pass "Running ${variantname} installer"
else
fn_print_fail_nl "Running ${variantname} installer"
tail -n 20 "${tmpdir}/installer.log" 2> /dev/null
fn_script_log_fail "Running ${variantname} installer"
fn_clear_tmp
core_exit.sh
fi
}

fn_update_localbuild() {
# Gets local build info.
fn_print_dots "Checking local build: ${remotelocation}"
Expand Down Expand Up @@ -92,6 +116,64 @@ fn_update_remotebuild_fabric() {
remotebuildhash="nohash"
}

fn_update_remotebuild_forge() {
apiurl="https://files.minecraftforge.net/net/minecraftforge/forge/promotions_slim.json"
remotebuildresponse=$(curl -s "${apiurl}")
if [ "${mcversion}" == "latest" ]; then
remotebuildmcversion=$(echo "${remotebuildresponse}" | jq -r '.promos | keys[] | sub("-(latest|recommended)$"; "")' | sort -Vu | tail -n 1)
else
remotebuildmcversion="${mcversion}"
fi
if [ -n "${remotebuildmcversion}" ] && [ "$(printf '%s\n' "1.17" "${remotebuildmcversion}" | sort -V | head -n 1)" != "1.17" ]; then
fn_print_fail_nl "Forge for Minecraft ${remotebuildmcversion} is not supported. Use Minecraft 1.17 or newer."
fn_script_log_fail "Forge for Minecraft ${remotebuildmcversion} is not supported"
core_exit.sh
fi
# Uses the recommended build, or the latest build when there is no recommended build.
remotebuildforge=$(echo "${remotebuildresponse}" | jq -r --arg mcversion "${remotebuildmcversion}" '.promos[$mcversion + "-recommended"] // .promos[$mcversion + "-latest"] // empty')
if [ -n "${remotebuildforge}" ]; then
# Combines Minecraft: Java Edition version and Forge version. e.g 26.3-66.1.8
remotebuild="${remotebuildmcversion}-${remotebuildforge}"
remotebuildfilename="forge-${remotebuild}-installer.jar"
remotebuildurl="https://maven.minecraftforge.net/net/minecraftforge/forge/${remotebuild}/${remotebuildfilename}"
remotebuildhash=$(curl -s "${remotebuildurl}.sha1")
fi
if [[ ! "${remotebuildhash}" =~ ^[0-9a-f]{40}$ ]]; then
remotebuildhash="nohash"
fi
}

fn_update_remotebuild_neoforge() {
apiurl="https://maven.neoforged.net/api/maven/versions/releases/net/neoforged/neoforge"
remotebuildresponse=$(curl -s "${apiurl}" | jq -r '.versions[]')
# Beta builds are only used on the snapshot branch.
if [ "${branch}" != "snapshot" ]; then
remotebuildresponse=$(echo "${remotebuildresponse}" | grep -v -- "-")
fi
if [ "${mcversion}" == "latest" ]; then
remotebuild=$(echo "${remotebuildresponse}" | sort -V | tail -n 1)
else
# NeoForge versions follow the Minecraft version. e.g 1.21.10 is 21.10.x and 26.3 is 26.3.0.x
remotebuildprefix="${mcversion#1.}"
if [ "${remotebuildprefix}" != "${mcversion}" ]; then
if [[ "${remotebuildprefix}" != *.* ]]; then
remotebuildprefix="${remotebuildprefix}.0"
fi
elif [[ "${remotebuildprefix}" != *.*.* ]]; then
remotebuildprefix="${remotebuildprefix}.0"
fi
remotebuild=$(echo "${remotebuildresponse}" | awk -v prefix="${remotebuildprefix}." 'index($0, prefix) == 1' | sort -V | tail -n 1)
fi
if [ -n "${remotebuild}" ]; then
remotebuildfilename="neoforge-${remotebuild}-installer.jar"
remotebuildurl="https://maven.neoforged.net/releases/net/neoforged/neoforge/${remotebuild}/${remotebuildfilename}"
remotebuildhash=$(curl -s "${remotebuildurl}.sha1")
fi
if [[ ! "${remotebuildhash}" =~ ^[0-9a-f]{40}$ ]]; then
remotebuildhash="nohash"
fi
}

fn_update_remotebuild_purpur() {
apiurl="https://api.purpurmc.org/v2/purpur"
remotebuildresponse=$(curl -s "${apiurl}")
Expand Down Expand Up @@ -134,6 +216,10 @@ fn_update_remotebuild() {
unset remotebuild remotebuildurl remotebuildhash
if [ "${variant}" == "fabric" ]; then
fn_update_remotebuild_fabric
elif [ "${variant}" == "forge" ]; then
fn_update_remotebuild_forge
elif [ "${variant}" == "neoforge" ]; then
fn_update_remotebuild_neoforge
elif [ "${variant}" == "purpur" ]; then
fn_update_remotebuild_purpur
elif [ "${variant}" == "leaf" ]; then
Expand Down Expand Up @@ -256,6 +342,10 @@ fi
# The location where the builds are checked and downloaded.
if [ "${variant}" == "fabric" ]; then
remotelocation="fabricmc.net"
elif [ "${variant}" == "forge" ]; then
remotelocation="minecraftforge.net"
elif [ "${variant}" == "neoforge" ]; then
remotelocation="neoforged.net"
elif [ "${variant}" == "purpur" ]; then
remotelocation="purpurmc.org"
elif [ "${variant}" == "leaf" ]; then
Expand Down
Loading