Class ModLoaderService
- Namespace
- McServerLauncher.Services
- Assembly
- McServerLauncher.dll
Installs a mod loader — Fabric, Forge or NeoForge — into a server folder.
public class ModLoaderService
- Inheritance
-
ModLoaderService
- Inherited Members
Remarks
The three are not installed the same way and cannot be made to be. Fabric publishes a server jar
that is downloaded and run as-is; Forge and NeoForge publish an installer that has to be
executed with java -jar and leaves behind an args file rather than a runnable jar, which
is what ModLoaderService.ForgeInstallResult reports back and LoaderPaths knows how to
find again.
What each download is trusted on differs too, and each case is argued where it is enforced:
Fabric's meta endpoint publishes no checksum at all, so its jar is validated structurally
instead; Forge's maven publishes a .sha1 and NeoForge's a .sha256, both from the
same server as the artifact, so the check catches corruption rather than a compromised source —
and a missing hash means no install, because what follows is java -jar.
Methods
DownloadFabricServerAsync(string, string, string, IProgress<string>?, CancellationToken)
Downloads the Fabric server launcher jar. KNOWN LIMITATION: unlike Mojang/Paper/Adoptium/ Modrinth, Fabric's meta endpoint publishes no checksum for this artifact, so a true integrity check isn't possible without changing the source; TLS is the only transport protection. As a structural safety net the downloaded jar is opened and required to carry the install.properties every Fabric server launcher embeds, with exactly the game/loader versions that were requested — a corrupted or swapped file is deleted and rejected instead of being executed later.
public Task DownloadFabricServerAsync(string gameVersion, string loaderVersion, string destPath, IProgress<string>? log, CancellationToken ct = default)
Parameters
Returns
GetLatestFabricLoaderVersionAsync(CancellationToken)
public Task<string> GetLatestFabricLoaderVersionAsync(CancellationToken ct = default)
Parameters
Returns
GetNeoForgeVersionAsync(string, CancellationToken)
The NeoForge build to install for a Minecraft version, or null when there is none.
public Task<NeoForgeVersions.Choice?> GetNeoForgeVersionAsync(string mcVersion, CancellationToken ct = default)
Parameters
mcVersionstringctCancellationToken
Returns
Remarks
NeoForge publishes no equivalent of Forge's promotions feed — just one flat list of every build, with the Minecraft version encoded inside the build number. The choosing is done by NeoForgeVersions, which is pure and tested; this only fetches the list.
GetRecommendedForgeVersionAsync(string, CancellationToken)
Recommended (or latest) Forge version for a Minecraft version, from Forge's promotions feed. Returns null if there is no Forge build for that version.
public Task<string?> GetRecommendedForgeVersionAsync(string mcVersion, CancellationToken ct = default)
Parameters
mcVersionstringctCancellationToken
Returns
InstallForgeServerAsync(string, string, string, string, IProgress<string>?, CancellationToken)
Downloads the Forge installer and runs it with --installServer in folder.
Detects the launch method: modern Forge (1.17+) yields an args file (returns its id), older Forge
yields a runnable forge-*.jar (returns its file name).
public Task<ModLoaderService.ForgeInstallResult> InstallForgeServerAsync(string folder, string mcVersion, string forgeVersion, string javaPath, IProgress<string>? log, CancellationToken ct = default)
Parameters
folderstringmcVersionstringforgeVersionstringjavaPathstringlogIProgress<string>ctCancellationToken
Returns
InstallNeoForgeServerAsync(string, string, string, IProgress<string>?, CancellationToken)
Downloads the NeoForge installer and runs it with --installServer.
public Task<ModLoaderService.ForgeInstallResult> InstallNeoForgeServerAsync(string folder, string neoForgeVersion, string javaPath, IProgress<string>? log, CancellationToken ct = default)
Parameters
Returns
Remarks
The same shape as the Forge path, with one difference worth having: NeoForge's maven
publishes a .sha256 beside each artifact, so this verifies with SHA-256 rather than
the SHA-1 that is all Forge offers. The trust assumption is otherwise identical — the hash
comes from the same server as the jar, so it protects against a corrupted download, not
against a compromised maven — and, as there, a missing hash means no install at all,
because what follows is java -jar.
ValidateFabricServerJar(string, string, string)
Structural validation of a downloaded Fabric server jar (see DownloadFabricServerAsync(string, string, string, IProgress<string>?, CancellationToken)): it must be a readable jar whose install.properties matches the requested game and loader versions. On failure the file is deleted (so a bad download can't linger and get executed) and an exception is thrown.
public static void ValidateFabricServerJar(string jarPath, string expectedGameVersion, string expectedLoaderVersion)
Parameters
ValidateForgeInstallerJar(string)
Structural validation of a downloaded Forge installer before it is executed: it must be a
readable jar that actually looks like a Forge installer — carrying the install_profile.json
every Forge installer embeds, or (fallback for exotic/legacy layouts) a manifest whose
Main-Class names the installer. On failure the file is deleted and an exception is thrown,
so a swapped or truncated download never reaches java -jar.
public static void ValidateForgeInstallerJar(string jarPath)
Parameters
jarPathstring