[FEATURE] InstallAuthlib support 'download-context'

This commit is contained in:
Gravita 2022-06-19 17:04:44 +07:00
parent bc3c7ba171
commit 08fe9b2eb4
2 changed files with 31 additions and 0 deletions

View file

@ -0,0 +1,30 @@
package pro.gravit.launcher.server.authlib;
import pro.gravit.utils.helper.LogHelper;
import pro.gravit.utils.helper.SecurityHelper;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
public class DownloadContextModifier implements LibrariesHashFileModifier {
@Override
public byte[] apply(byte[] data, InstallAuthlib.InstallAuthlibContext context) throws IOException {
String[] lines = new String(data).split("\n");
for(int i=0;i<lines.length;++i) {
if(lines[i].contains("mojang_")) {
String[] separated = lines[i].split("\t");
Path path = context.workdir.resolve("cache").resolve(separated[2]);
if(Files.notExists(path)) {
LogHelper.warning("Unable to find %s. Maybe you should start the server at least once?", path);
return data;
}
separated[0] = SecurityHelper.toHex(SecurityHelper.digest(SecurityHelper.DigestAlgorithm.SHA256, path));
lines[i] = String.join("\t", separated);
}
}
return String.join("\n", lines).getBytes(StandardCharsets.UTF_8);
}
}

View file

@ -19,6 +19,7 @@ public class InstallAuthlib {
modifierMap = new HashMap<>();
modifierMap.put("META-INF/libraries.list", new LibrariesLstModifier());
modifierMap.put("patch.properties", new PatchPropertiesModifier());
modifierMap.put("META-INF/download-context", new DownloadContextModifier());
}
public void run(String... args) throws Exception {
boolean deleteAuthlibAfterInstall = false;