mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-07-07 08:19:45 +03:00
Compare commits
30 commits
a6b9023f98
...
24f6b34e5a
Author | SHA1 | Date | |
---|---|---|---|
|
24f6b34e5a | ||
|
911ca1e69f | ||
|
90f74aaf25 | ||
|
880957fa9b | ||
|
2fea94071b | ||
|
b41e8db336 | ||
|
76570ddbe5 | ||
|
3a160b8124 | ||
|
8fb1dc275c | ||
|
95aed151e7 | ||
|
6934c37a33 | ||
|
5155c470c6 | ||
|
533dcfce14 | ||
|
d2f83d81eb | ||
|
2379398c30 | ||
|
f53c48a5ae | ||
|
394b64e22d | ||
|
7c15742478 | ||
|
d65fffade9 | ||
|
bb6c95ca12 | ||
|
9027987b29 | ||
|
d410533c8d | ||
|
af2c5c33e8 | ||
|
e67bb6a12f | ||
|
e2e0ef6ea4 | ||
|
05530b6664 | ||
|
8f20cbe104 | ||
|
66d8b9d9ca | ||
|
90ee90973e | ||
|
8bf58cff18 |
28 changed files with 320 additions and 80 deletions
3
.github/workflows/push.yml
vendored
3
.github/workflows/push.yml
vendored
|
@ -39,9 +39,12 @@ jobs:
|
|||
cp LaunchServer.jar ../../../artifacts/LaunchServer.jar
|
||||
cd ../../..
|
||||
cp ServerWrapper/build/libs/ServerWrapper.jar artifacts/ServerWrapper.jar
|
||||
cp ServerWrapper/build/libs/ServerWrapper-inline.jar artifacts/ServerWrapperInline.jar
|
||||
cp LauncherAuthlib/build/libs/LauncherAuthlib.jar artifacts/LauncherAuthlib.jar || true
|
||||
cp modules/*_module/build/libs/*.jar artifacts/modules || true
|
||||
cp modules/*_lmodule/build/libs/*.jar artifacts/modules || true
|
||||
cp javaargs.txt artifacts/javaargs.txt || true
|
||||
cp java24args.txt artifacts/java24args.txt || true
|
||||
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
bundleOnly
|
||||
bundle
|
||||
pack
|
||||
proguardPack
|
||||
bundleOnly.extendsFrom bundle
|
||||
api.extendsFrom bundle, pack
|
||||
}
|
||||
|
@ -36,11 +37,13 @@
|
|||
jar {
|
||||
dependsOn parent.childProjects.Launcher.tasks.assemble
|
||||
from { configurations.pack.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||
exclude("module-info.class")
|
||||
from(parent.childProjects.Launcher.tasks.shadowJar)
|
||||
from(parent.childProjects.Launcher.tasks.genRuntimeJS)
|
||||
manifest.attributes("Main-Class": mainClassName,
|
||||
"Premain-Class": mainAgentName,
|
||||
"Multi-Release": "true",
|
||||
"Automatic-Module-Name": "launchserver"
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -72,22 +75,25 @@
|
|||
|
||||
|
||||
dependencies {
|
||||
pack project(':LauncherAPI')
|
||||
pack(project(':LauncherAPI')) {
|
||||
exclude group: "com.google.code.gson"
|
||||
}
|
||||
bundle group: 'com.google.code.gson', name: 'gson', version: rootProject['verGson']
|
||||
bundle group: 'me.tongfei', name: 'progressbar', version: '0.10.1'
|
||||
bundle group: 'org.fusesource.jansi', name: 'jansi', version: rootProject['verJansi']
|
||||
bundle group: 'org.jline', name: 'jline', version: rootProject['verJline']
|
||||
bundle group: 'org.jline', name: 'jline-native', version: rootProject['verJline']
|
||||
bundle group: 'org.jline', name: 'jline-reader', version: rootProject['verJline']
|
||||
bundle group: 'org.jline', name: 'jline-terminal', version: rootProject['verJline']
|
||||
bundle group: 'org.jline', name: 'jline-terminal-ffm', version: rootProject['verJline']
|
||||
bundle group: 'org.bouncycastle', name: 'bcprov-jdk18on', version: rootProject['verBcpkix']
|
||||
bundle group: 'org.bouncycastle', name: 'bcpkix-jdk18on', version: rootProject['verBcpkix']
|
||||
bundle group: 'org.ow2.asm', name: 'asm-commons', version: rootProject['verAsm']
|
||||
bundle group: 'io.netty', name: 'netty-codec-http', version: rootProject['verNetty']
|
||||
bundle group: 'io.netty', name: 'netty-transport-classes-epoll', version: rootProject['verNetty']
|
||||
bundle group: 'io.netty', name: 'netty-transport-native-epoll', version: rootProject['verNetty'], classifier: 'linux-x86_64'
|
||||
bundle group: 'io.netty', name: 'netty-transport-native-epoll', version: rootProject['verNetty'], classifier: 'linux-aarch_64'
|
||||
//bundle group: 'io.netty', name: 'netty-transport-native-epoll', version: rootProject['verNetty'], classifier: 'linux-aarch_64'
|
||||
bundle group: 'io.netty', name: 'netty-transport-classes-io_uring', version: rootProject['verNetty']
|
||||
bundle group: 'io.netty', name: 'netty-transport-native-io_uring', version: rootProject['verNetty'], classifier: 'linux-x86_64'
|
||||
bundle group: 'io.netty', name: 'netty-transport-native-io_uring', version: rootProject['verNetty'], classifier: 'linux-aarch_64'
|
||||
//bundle group: 'io.netty', name: 'netty-transport-native-io_uring', version: rootProject['verNetty'], classifier: 'linux-aarch_64'
|
||||
// Netty
|
||||
bundle 'org.jboss.marshalling:jboss-marshalling:1.4.11.Final'
|
||||
bundle 'com.google.protobuf.nano:protobuf-javanano:3.1.0'
|
||||
|
@ -97,7 +103,7 @@ pack project(':LauncherAPI')
|
|||
bundle group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: rootProject['verMariaDBConn']
|
||||
bundle group: 'org.postgresql', name: 'postgresql', version: rootProject['verPostgreSQLConn']
|
||||
bundle group: 'com.h2database', name: 'h2', version: rootProject['verH2Conn']
|
||||
bundle group: 'com.guardsquare', name: 'proguard-base', version: rootProject['verProguard']
|
||||
proguardPack group: 'com.guardsquare', name: 'proguard-base', version: rootProject['verProguard']
|
||||
bundle group: 'org.apache.logging.log4j', name: 'log4j-core', version: rootProject['verLog4j']
|
||||
bundle group: 'org.apache.logging.log4j', name: 'log4j-slf4j2-impl', version: rootProject['verLog4j']
|
||||
bundle group: 'io.jsonwebtoken', name: 'jjwt-api', version: rootProject['verJwt']
|
||||
|
@ -121,6 +127,12 @@ pack project(':LauncherAPI')
|
|||
from configurations.bundleOnly
|
||||
}
|
||||
|
||||
tasks.register('dumpProguard', Copy) {
|
||||
duplicatesStrategy = 'EXCLUDE'
|
||||
into "$buildDir/libs/proguard"
|
||||
from configurations.proguardPack
|
||||
}
|
||||
|
||||
tasks.register('bundle', Zip) {
|
||||
duplicatesStrategy = 'EXCLUDE'
|
||||
dependsOn parent.childProjects.Launcher.tasks.build, tasks.dumpLibs, tasks.jar
|
||||
|
@ -137,7 +149,7 @@ pack project(':LauncherAPI')
|
|||
from parent.childProjects.Launcher.tasks.dumpLibs
|
||||
}
|
||||
|
||||
assemble.dependsOn tasks.dumpLibs, tasks.dumpClientLibs, tasks.bundle, tasks.cleanjar
|
||||
assemble.dependsOn tasks.dumpLibs, tasks.dumpClientLibs, tasks.bundle, tasks.cleanjar, tasks.dumpProguard
|
||||
|
||||
|
||||
publishing {
|
||||
|
|
|
@ -82,6 +82,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab
|
|||
public final Path launcherModulesDir;
|
||||
public final Path librariesDir;
|
||||
public final Path controlFile;
|
||||
public final Path proguardDir;
|
||||
/**
|
||||
* This object contains runtime configuration
|
||||
*/
|
||||
|
@ -138,6 +139,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La
|
|||
launcherModulesDir = directories.launcherModules;
|
||||
librariesDir = directories.librariesDir;
|
||||
controlFile = directories.controlFile;
|
||||
proguardDir = directories.proguardDir;
|
||||
this.shardId = shardId;
|
||||
if(!Files.isDirectory(launcherPack)) {
|
||||
Files.createDirectories(launcherPack);
|
||||
|
@ -462,13 +464,16 @@ public interface LaunchServerConfigManager {
|
|||
public static class LaunchServerDirectories {
|
||||
public static final String UPDATES_NAME = "updates",
|
||||
TRUSTSTORE_NAME = "truststore", LAUNCHERLIBRARIES_NAME = "launcher-libraries",
|
||||
LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack", KEY_NAME = ".keys", MODULES = "modules", LAUNCHER_MODULES = "launcher-modules", LIBRARIES = "libraries", CONTROL_FILE = "control-file";
|
||||
LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack",
|
||||
KEY_NAME = ".keys", MODULES = "modules", LAUNCHER_MODULES = "launcher-modules",
|
||||
LIBRARIES = "libraries", CONTROL_FILE = "control-file", PROGUARD_DIR = "proguard-libraries";
|
||||
public Path updatesDir;
|
||||
public Path librariesDir;
|
||||
public Path launcherLibrariesDir;
|
||||
public Path launcherLibrariesCompileDir;
|
||||
public Path launcherPackDir;
|
||||
public Path keyDirectory;
|
||||
public Path proguardDir;
|
||||
public Path dir;
|
||||
public Path trustStore;
|
||||
public Path tmpDir;
|
||||
|
@ -489,6 +494,7 @@ public void collect() {
|
|||
if (launcherModules == null) launcherModules = getPath(LAUNCHER_MODULES);
|
||||
if (librariesDir == null) librariesDir = getPath(LIBRARIES);
|
||||
if (controlFile == null) controlFile = getPath(CONTROL_FILE);
|
||||
if (proguardDir == null) proguardDir = getPath(PROGUARD_DIR);
|
||||
if (tmpDir == null)
|
||||
tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("launchserver-%s".formatted(SecurityHelper.randomStringToken()));
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
import java.util.stream.Stream;
|
||||
|
||||
public class Main {
|
||||
private static final List<String> classpathOnly = List.of("proguard", "jline", "progressbar", "kotlin");
|
||||
private static final List<String> classpathOnly = List.of("proguard", "progressbar", "kotlin");
|
||||
private static final String LOG4J_PROPERTY = "log4j2.configurationFile";
|
||||
private static final String DEBUG_PROPERTY = "launchserver.main.debug";
|
||||
private static final String LIBRARIES_PROPERTY = "launchserver.dir.libraries";
|
||||
|
@ -74,6 +74,8 @@ public static void main(String[] args) throws Throwable {
|
|||
classpath.add(IOHelper.getCodeSource(LaunchServerStarter.class));
|
||||
options.moduleConf.modulePath.addAll(modulepath);
|
||||
options.moduleConf.modules.add("ALL-MODULE-PATH");
|
||||
options.moduleConf.enableNativeAccess.add("org.fusesource.jansi");
|
||||
options.moduleConf.enableNativeAccess.add("io.netty.common");
|
||||
ClassLoaderControl control = launch.init(classpath, "natives", options);
|
||||
control.clearLauncherPackages();
|
||||
control.addLauncherPackage("pro.gravit.utils.launch");
|
||||
|
|
|
@ -1,16 +1,17 @@
|
|||
package pro.gravit.launchserver.asm;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.jar.JarFile;
|
||||
|
||||
/**
|
||||
|
@ -18,14 +19,32 @@
|
|||
* чего угодно. Работает через поиск class-файлов в classpath.
|
||||
*/
|
||||
public class ClassMetadataReader implements Closeable {
|
||||
private final Logger logger = LogManager.getLogger(ClassMetadataReader.class);
|
||||
private final List<JarFile> cp;
|
||||
private final Map<String, Module> moduleClassFinder;
|
||||
|
||||
public ClassMetadataReader(List<JarFile> cp) {
|
||||
this.cp = cp;
|
||||
//var moduleLayer = ClassMetadataReader.class.getModule().getLayer() == null ? ModuleLayer.boot() : ClassMetadataReader.class.getModule().getLayer();
|
||||
var moduleLayer = ModuleLayer.boot();
|
||||
moduleClassFinder = collectModulePackages(moduleLayer);
|
||||
}
|
||||
|
||||
public ClassMetadataReader() {
|
||||
this.cp = new ArrayList<>();
|
||||
//var moduleLayer = ClassMetadataReader.class.getModule().getLayer() == null ? ModuleLayer.boot() : ClassMetadataReader.class.getModule().getLayer();
|
||||
var moduleLayer = ModuleLayer.boot();
|
||||
moduleClassFinder = collectModulePackages(moduleLayer);
|
||||
}
|
||||
|
||||
private Map<String, Module> collectModulePackages(ModuleLayer layer) {
|
||||
var map = new HashMap<String, Module>();
|
||||
for(var m : layer.modules()) {
|
||||
for(var p : m.getPackages()) {
|
||||
map.put(p, m);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public List<JarFile> getCp() {
|
||||
|
@ -58,7 +77,42 @@ public byte[] getClassData(String className) throws IOException {
|
|||
return bytes;
|
||||
}
|
||||
}
|
||||
return IOHelper.read(IOHelper.getResourceURL(className + ".class"));
|
||||
if(ClassMetadataReader.class.getModule().isNamed()) {
|
||||
String pkg = getClassPackage(className).replace('/', '.');
|
||||
var module = moduleClassFinder.get(pkg);
|
||||
if(module != null) {
|
||||
var cl = module.getClassLoader();
|
||||
if(cl == null) {
|
||||
cl = ClassLoader.getPlatformClassLoader();
|
||||
}
|
||||
var stream = cl.getResourceAsStream(className+".class");
|
||||
if(stream != null) {
|
||||
try(stream) {
|
||||
return IOHelper.read(stream);
|
||||
}
|
||||
} else {
|
||||
throw new FileNotFoundException("Class "+className + ".class");
|
||||
}
|
||||
} else {
|
||||
throw new FileNotFoundException("Package "+pkg);
|
||||
}
|
||||
}
|
||||
var stream = ClassLoader.getSystemClassLoader().getResourceAsStream(className+".class");
|
||||
if(stream != null) {
|
||||
try(stream) {
|
||||
return IOHelper.read(stream);
|
||||
}
|
||||
} else {
|
||||
throw new FileNotFoundException(className + ".class");
|
||||
}
|
||||
}
|
||||
|
||||
private String getClassPackage(String type) {
|
||||
int idx = type.lastIndexOf("/");
|
||||
if(idx <= 0) {
|
||||
return type;
|
||||
}
|
||||
return type.substring(0, idx);
|
||||
}
|
||||
|
||||
public String getSuperClass(String type) {
|
||||
|
@ -66,6 +120,7 @@ public String getSuperClass(String type) {
|
|||
try {
|
||||
return getSuperClassASM(type);
|
||||
} catch (Exception e) {
|
||||
logger.warn("getSuperClass: type {} not found ({}: {})", type, e.getClass().getName(), e.getMessage());
|
||||
return "java/lang/Object";
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +155,7 @@ private static class CheckSuperClassVisitor extends ClassVisitor {
|
|||
String superClassName;
|
||||
|
||||
public CheckSuperClassVisitor() {
|
||||
super(Opcodes.ASM7);
|
||||
super(Opcodes.ASM9);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
package pro.gravit.launchserver.auth.password;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.bouncycastle.crypto.digests.SHA256Digest;
|
||||
import org.bouncycastle.crypto.generators.PKCS5S2ParametersGenerator;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Base64;
|
||||
|
||||
public class DjangoPasswordVerifier extends PasswordVerifier {
|
||||
public final Integer DEFAULT_ITERATIONS = 10000;
|
||||
private static final Logger logger = LogManager.getLogger();
|
||||
private static final String algorithm = "pbkdf2_sha256";
|
||||
|
||||
public String getEncodedHash(String password, String salt, int iterations) {
|
||||
PKCS5S2ParametersGenerator generator = new PKCS5S2ParametersGenerator(new SHA256Digest());
|
||||
generator.init(password.getBytes(StandardCharsets.UTF_8), salt.getBytes(), iterations);
|
||||
byte[] dk = ((KeyParameter) generator.generateDerivedParameters(256)).getKey();
|
||||
byte[] hashBase64 = Base64.getEncoder().encode(dk);
|
||||
return new String(hashBase64);
|
||||
}
|
||||
|
||||
public String encode(String password, String salt, int iterations) {
|
||||
String hash = getEncodedHash(password, salt, iterations);
|
||||
return String.format("%s$%d$%s$%s", algorithm, iterations, salt, hash);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(String encryptedPassword, String password) {
|
||||
String[] params = encryptedPassword.split("\\$");
|
||||
if (params.length != 4) {
|
||||
logger.warn(" end 1 " + params.length);
|
||||
return false;
|
||||
}
|
||||
int iterations = Integer.parseInt(params[1]);
|
||||
String salt = params[2];
|
||||
String hash = encode(password, salt, iterations);
|
||||
return hash.equals(encryptedPassword);
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ public static void registerProviders() {
|
|||
providers.register("bcrypt", BCryptPasswordVerifier.class);
|
||||
providers.register("accept", AcceptPasswordVerifier.class);
|
||||
providers.register("reject", RejectPasswordVerifier.class);
|
||||
providers.register("django", DjangoPasswordVerifier.class);
|
||||
registeredProviders = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public static void apply(Path inputFile, Path addFile, ZipOutputStream output, L
|
|||
private static byte[] classFix(InputStream input, ClassMetadataReader reader, boolean stripNumbers) throws IOException {
|
||||
ClassReader cr = new ClassReader(input);
|
||||
ClassNode cn = new ClassNode();
|
||||
cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES);
|
||||
cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG) : 0);
|
||||
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
cn.accept(cw);
|
||||
return cw.toByteArray();
|
||||
|
|
|
@ -146,7 +146,7 @@ public byte[] transformClass(byte[] bytes, String classname, BuildContext contex
|
|||
asmTransformer.transform(cn, classname, context);
|
||||
continue;
|
||||
} else if (cn != null) {
|
||||
writer = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
writer = new SafeClassWriter(reader, 0);
|
||||
cn.accept(writer);
|
||||
result = writer.toByteArray();
|
||||
}
|
||||
|
@ -157,7 +157,7 @@ public byte[] transformClass(byte[] bytes, String classname, BuildContext contex
|
|||
}
|
||||
}
|
||||
if (cn != null) {
|
||||
writer = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
writer = new SafeClassWriter(reader, 0);
|
||||
cn.accept(writer);
|
||||
result = writer.toByteArray();
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ default byte[] transform(byte[] input, String classname, BuildContext context) {
|
|||
ClassNode cn = new ClassNode();
|
||||
reader.accept(cn, 0);
|
||||
transform(cn, classname, context);
|
||||
SafeClassWriter writer = new SafeClassWriter(context.task.reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
|
||||
SafeClassWriter writer = new SafeClassWriter(context.task.reader, 0);
|
||||
cn.accept(writer);
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
|
|
@ -213,7 +213,7 @@ public Path process(Path inputFile) throws IOException {
|
|||
args.add(IOHelper.resolveJavaBin(IOHelper.JVM_DIR).toAbsolutePath().toString());
|
||||
args.addAll(component.jvmArgs);
|
||||
args.add("-cp");
|
||||
try(Stream<Path> files = Files.walk(server.librariesDir, FileVisitOption.FOLLOW_LINKS)) {
|
||||
try(Stream<Path> files = Files.walk(server.proguardDir, FileVisitOption.FOLLOW_LINKS)) {
|
||||
args.add(files
|
||||
.filter(e -> e.getFileName().toString().endsWith(".jar"))
|
||||
.map(path -> path.toAbsolutePath().toString())
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import org.apache.logging.log4j.Logger;
|
||||
import pro.gravit.launcher.base.Launcher;
|
||||
import pro.gravit.launchserver.socket.NettyConnectContext;
|
||||
import pro.gravit.launchserver.socket.severlet.StatusSeverlet;
|
||||
import pro.gravit.utils.helper.IOHelper;
|
||||
|
||||
import java.net.URLDecoder;
|
||||
|
@ -34,6 +35,7 @@ public class NettyWebAPIHandler extends SimpleChannelInboundHandler<FullHttpRequ
|
|||
public NettyWebAPIHandler(NettyConnectContext context) {
|
||||
super();
|
||||
this.context = context;
|
||||
addNewSeverlet("status", new StatusSeverlet());
|
||||
}
|
||||
|
||||
public static void addNewSeverlet(String path, SimpleSeverletHandler callback) {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package pro.gravit.launchserver.socket.severlet;
|
||||
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import pro.gravit.launchserver.socket.NettyConnectContext;
|
||||
import pro.gravit.launchserver.socket.handlers.NettyWebAPIHandler;
|
||||
|
||||
public class StatusSeverlet implements NettyWebAPIHandler.SimpleSeverletHandler {
|
||||
@Override
|
||||
public void handle(ChannelHandlerContext ctx, FullHttpRequest msg, NettyConnectContext context) {
|
||||
sendHttpResponse(ctx, new DefaultFullHttpResponse(msg.protocolVersion(), HttpResponseStatus.OK));
|
||||
}
|
||||
}
|
|
@ -28,6 +28,7 @@ public class DebugMain {
|
|||
public static String webSocketURL = System.getProperty("launcherdebug.websocket", "ws://localhost:9274/api");
|
||||
public static String projectName = System.getProperty("launcherdebug.projectname", "Minecraft");
|
||||
public static String unlockSecret = System.getProperty("launcherdebug.unlocksecret", "");
|
||||
public static boolean disableConsole = Boolean.getBoolean("launcherdebug.disableConsole");
|
||||
public static boolean offlineMode = Boolean.getBoolean("launcherdebug.offlinemode");
|
||||
public static boolean disableAutoRefresh = Boolean.getBoolean("launcherdebug.disableautorefresh");
|
||||
public static String[] moduleClasses = System.getProperty("launcherdebug.modules", "").split(",");
|
||||
|
@ -37,6 +38,14 @@ public class DebugMain {
|
|||
public static void main(String[] args) throws Throwable {
|
||||
LogHelper.printVersion("Launcher");
|
||||
LogHelper.printLicense("Launcher");
|
||||
initialize();
|
||||
LogHelper.debug("Initialization LauncherEngine");
|
||||
LauncherEngine instance = LauncherEngine.newInstance(false, ClientRuntimeProvider.class);
|
||||
instance.start(args);
|
||||
LauncherEngine.exitLauncher(0);
|
||||
}
|
||||
|
||||
public static void initialize() throws Exception {
|
||||
IS_DEBUG.set(true);
|
||||
LogHelper.info("Launcher start in DEBUG mode (Only for developers)");
|
||||
LogHelper.debug("Initialization LauncherConfig");
|
||||
|
@ -56,7 +65,9 @@ public static void main(String[] args) throws Throwable {
|
|||
}
|
||||
LauncherEngine.modulesManager.initModules(null);
|
||||
LauncherEngine.initGson(LauncherEngine.modulesManager);
|
||||
if(!disableConsole) {
|
||||
ConsoleManager.initConsole();
|
||||
}
|
||||
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
|
||||
RequestService service;
|
||||
if (offlineMode) {
|
||||
|
@ -72,10 +83,6 @@ public static void main(String[] args) throws Throwable {
|
|||
if(!disableAutoRefresh) {
|
||||
Request.startAutoRefresh();
|
||||
}
|
||||
LogHelper.debug("Initialization LauncherEngine");
|
||||
LauncherEngine instance = LauncherEngine.newInstance(false, ClientRuntimeProvider.class);
|
||||
instance.start(args);
|
||||
LauncherEngine.exitLauncher(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package pro.gravit.launcher.runtime.debug;
|
||||
|
||||
public class DebugMainInlineInitializer {
|
||||
public static void run() throws Exception {
|
||||
DebugMain.initialize();
|
||||
}
|
||||
}
|
|
@ -116,15 +116,6 @@ private static void realMain(String[] args) throws Throwable {
|
|||
|
||||
// Verify ClientLauncher sign and classpath
|
||||
LogHelper.debug("Verifying ClientLauncher sign and classpath");
|
||||
Set<Path> ignoredPath = new HashSet<>();
|
||||
List<Path> classpath = resolveClassPath(ignoredPath, clientDir, params.actions, params.profile)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
if(LogHelper.isDevEnabled()) {
|
||||
for(var e : classpath) {
|
||||
LogHelper.dev("Classpath entry %s", e);
|
||||
}
|
||||
}
|
||||
List<URL> classpathURLs = classpath.stream().map(IOHelper::toURL).toList();
|
||||
// Start client with WatchService monitoring
|
||||
RequestService service;
|
||||
if (params.offlineMode) {
|
||||
|
@ -158,6 +149,18 @@ private static void realMain(String[] args) throws Throwable {
|
|||
System.load(Paths.get(params.nativesDir).resolve(ClientService.findLibrary(e)).toAbsolutePath().toString());
|
||||
}
|
||||
}
|
||||
Set<Path> ignoredPath = new HashSet<>();
|
||||
if(options.moduleConf != null && options.moduleConf.modulePath != null) {
|
||||
List<Path> resolvedModulePath = resolveClassPath(ignoredPath, clientDir, null, params.profile).toList();
|
||||
}
|
||||
List<Path> classpath = resolveClassPath(ignoredPath, clientDir, params.actions, params.profile)
|
||||
.collect(Collectors.toCollection(ArrayList::new));
|
||||
if(LogHelper.isDevEnabled()) {
|
||||
for(var e : classpath) {
|
||||
LogHelper.dev("Classpath entry %s", e);
|
||||
}
|
||||
}
|
||||
List<URL> classpathURLs = classpath.stream().map(IOHelper::toURL).toList();
|
||||
if (classLoaderConfig == ClientProfile.ClassLoaderConfig.LAUNCHER || classLoaderConfig == ClientProfile.ClassLoaderConfig.MODULE) {
|
||||
if(JVMHelper.JVM_VERSION <= 11) {
|
||||
launch = new LegacyLaunch();
|
||||
|
@ -274,10 +277,12 @@ private static Stream<Path> resolveClassPathStream(Set<Path> ignorePaths, Path c
|
|||
|
||||
public static Stream<Path> resolveClassPath(Set<Path> ignorePaths, Path clientDir, Set<OptionalAction> actions, ClientProfile profile) throws IOException {
|
||||
Stream<Path> result = resolveClassPathStream(ignorePaths, clientDir, profile.getClassPath());
|
||||
if(actions != null) {
|
||||
for (OptionalAction a : actions) {
|
||||
if (a instanceof OptionalActionClassPath)
|
||||
result = Stream.concat(result, resolveClassPathStream(ignorePaths, clientDir, ((OptionalActionClassPath) a).args));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ public final class Version implements Comparable<Version> {
|
|||
|
||||
public static final int MAJOR = 5;
|
||||
public static final int MINOR = 6;
|
||||
public static final int PATCH = 11;
|
||||
public static final int PATCH = 14;
|
||||
public static final int BUILD = 1;
|
||||
public static final Version.Type RELEASE = Type.STABLE;
|
||||
public final int major;
|
||||
|
|
|
@ -14,5 +14,6 @@ public static final class ModuleConf {
|
|||
public Map<String, String> exports = new HashMap<>();
|
||||
public Map<String, String> opens = new HashMap<>();
|
||||
public Map<String, String> reads = new HashMap<>();
|
||||
public List<String> enableNativeAccess = new ArrayList<>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,18 @@ public class ModuleLaunch implements Launch {
|
|||
private ModuleLayer layer;
|
||||
private MethodHandles.Lookup hackLookup;
|
||||
private boolean disablePackageDelegateSupport;
|
||||
private static final MethodHandle ENABLE_NATIVE_ACCESS;
|
||||
|
||||
static {
|
||||
MethodHandle mh;
|
||||
try {
|
||||
mh = MethodHandles.lookup().findVirtual(ModuleLayer.Controller.class, "enableNativeAccess", MethodType.methodType(ModuleLayer.Controller.class, Module.class));
|
||||
} catch (NoSuchMethodException | IllegalAccessException e) {
|
||||
mh = null;
|
||||
}
|
||||
ENABLE_NATIVE_ACCESS = mh;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassLoaderControl init(List<Path> files, String nativePath, LaunchOptions options) {
|
||||
this.disablePackageDelegateSupport = options.disablePackageDelegateSupport;
|
||||
|
@ -120,6 +132,20 @@ public ClassLoaderControl init(List<Path> files, String nativePath, LaunchOption
|
|||
controller.addReads(source, target);
|
||||
}
|
||||
}
|
||||
for(var e : options.moduleConf.enableNativeAccess) {
|
||||
LogHelper.dev("Enable Native Access %s", e);
|
||||
Module source = layer.findModule(e).orElse(null);
|
||||
if(source == null) {
|
||||
throw new RuntimeException(String.format("Module %s not found", e));
|
||||
}
|
||||
if(ENABLE_NATIVE_ACCESS != null) {
|
||||
try {
|
||||
ENABLE_NATIVE_ACCESS.invoke(controller, source);
|
||||
} catch (Throwable ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
moduleClassLoader.initializeWithLayer(layer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,21 @@ pack project(':LauncherAPI')
|
|||
exclude 'module-info.class'
|
||||
}
|
||||
|
||||
tasks.register('inlinejar', Jar) {
|
||||
dependsOn configurations.runtimeClasspath
|
||||
from {
|
||||
configurations.runtimeClasspath.filter {! (it.name =~ /gson.*\.jar/ || it.name =~ /error_prone_annotations.*\.jar/)}.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
from {
|
||||
sourceSets.main.output
|
||||
}
|
||||
archiveClassifier.set('inline')
|
||||
manifest.attributes("Main-Class": mainClassName,
|
||||
"Automatic-Module-Name": "ServerWrapper"
|
||||
)
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
|
||||
publishing {
|
||||
publications {
|
||||
serverwrapperapi(MavenPublication) {
|
||||
|
@ -94,4 +109,4 @@ pack project(':LauncherAPI')
|
|||
sign publishing.publications.serverwrapperapi
|
||||
}
|
||||
|
||||
assemble.dependsOn tasks.shadowJar
|
||||
assemble.dependsOn tasks.shadowJar, tasks.inlinejar
|
||||
|
|
|
@ -25,15 +25,18 @@
|
|||
import pro.gravit.utils.launch.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.invoke.MethodHandle;
|
||||
import java.lang.invoke.MethodHandles;
|
||||
import java.lang.invoke.MethodType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class ServerWrapper extends JsonConfigurable<ServerWrapper.Config> {
|
||||
public static final Path configFile = Paths.get(System.getProperty("serverwrapper.configFile", "ServerWrapperConfig.json"));
|
||||
|
@ -100,31 +103,20 @@ public void getProfiles() throws Exception {
|
|||
}
|
||||
}
|
||||
|
||||
public void run(String... args) throws Throwable {
|
||||
|
||||
public void initialize() throws Exception {
|
||||
initGson();
|
||||
AuthRequest.registerProviders();
|
||||
GetAvailabilityAuthRequest.registerProviders();
|
||||
OptionalAction.registerProviders();
|
||||
OptionalTrigger.registerProviders();
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("setup") && !disableSetup) {
|
||||
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||
loadConfig();
|
||||
ServerWrapperSetup setup = new ServerWrapperSetup();
|
||||
setup.run();
|
||||
System.exit(0);
|
||||
}
|
||||
if (args.length > 1 && args[0].equalsIgnoreCase("installAuthlib") && !disableSetup) {
|
||||
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||
loadConfig();
|
||||
InstallAuthlib command = new InstallAuthlib();
|
||||
command. run(args[1]);
|
||||
System.exit(0);
|
||||
}
|
||||
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||
loadConfig();
|
||||
|
||||
public void connect() throws Exception {
|
||||
config.applyEnv();
|
||||
updateLauncherConfig();
|
||||
Launcher.applyLauncherEnv(Objects.requireNonNullElse(config.env, LauncherConfig.LauncherEnvironment.STD));
|
||||
StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get();
|
||||
service.reconnectCallback = () ->
|
||||
{
|
||||
|
@ -136,11 +128,6 @@ public void run(String... args) throws Throwable {
|
|||
LogHelper.error(e);
|
||||
}
|
||||
};
|
||||
if(config.properties != null) {
|
||||
for(Map.Entry<String, String> e : config.properties.entrySet()) {
|
||||
System.setProperty(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
Request.setRequestService(service);
|
||||
if (config.logFile != null) LogHelper.addOutput(IOHelper.newWriter(Paths.get(config.logFile), true));
|
||||
{
|
||||
|
@ -153,6 +140,47 @@ public void run(String... args) throws Throwable {
|
|||
if(config.encodedServerEcPublicKey != null) {
|
||||
KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey);
|
||||
}
|
||||
ClientService.nativePath = config.nativesDir;
|
||||
ConfigService.serverName = config.serverName;
|
||||
if(config.configServiceSettings != null) {
|
||||
config.configServiceSettings.apply();
|
||||
}
|
||||
}
|
||||
|
||||
public void runCompatClasses() throws Throwable {
|
||||
if(config.compatClasses != null) {
|
||||
for (String e : config.compatClasses) {
|
||||
Class<?> clazz = classLoaderControl == null ? Class.forName(e) : classLoaderControl.getClass(e);
|
||||
MethodHandle runMethod = MethodHandles.lookup().findStatic(clazz, "run", MethodType.methodType(void.class, ClassLoaderControl.class));
|
||||
runMethod.invoke(classLoaderControl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void run(String... args) throws Throwable {
|
||||
initialize();
|
||||
if (args.length > 0 && args[0].equalsIgnoreCase("setup") && !disableSetup) {
|
||||
ServerWrapperSetup setup = new ServerWrapperSetup();
|
||||
setup.run();
|
||||
System.exit(0);
|
||||
}
|
||||
if (args.length > 1 && args[0].equalsIgnoreCase("installAuthlib") && !disableSetup) {
|
||||
InstallAuthlib command = new InstallAuthlib();
|
||||
command. run(args[1]);
|
||||
System.exit(0);
|
||||
}
|
||||
connect();
|
||||
if(config.properties != null) {
|
||||
for(Map.Entry<String, String> e : config.properties.entrySet()) {
|
||||
System.setProperty(e.getKey(), e.getValue());
|
||||
}
|
||||
}
|
||||
if(config.encodedServerRsaPublicKey != null) {
|
||||
KeyService.serverRsaPublicKey = SecurityHelper.toPublicRSAKey(config.encodedServerRsaPublicKey);
|
||||
}
|
||||
if(config.encodedServerEcPublicKey != null) {
|
||||
KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey);
|
||||
}
|
||||
String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass;
|
||||
if (classname.isEmpty()) {
|
||||
LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.json or first commandline argument");
|
||||
|
@ -182,8 +210,6 @@ public void run(String... args) throws Throwable {
|
|||
System.arraycopy(args, 1, real_args, 0, args.length - 1);
|
||||
} else real_args = args;
|
||||
Launch launch;
|
||||
ClientService.nativePath = config.nativesDir;
|
||||
ConfigService.serverName = config.serverName;
|
||||
if(config.loadNatives != null) {
|
||||
for(String e : config.loadNatives) {
|
||||
System.load(Paths.get(config.nativesDir).resolve(ClientService.findLibrary(e)).toAbsolutePath().toString());
|
||||
|
@ -209,24 +235,27 @@ public void run(String... args) throws Throwable {
|
|||
LaunchOptions options = new LaunchOptions();
|
||||
options.enableHacks = config.enableHacks;
|
||||
options.moduleConf = config.moduleConf;
|
||||
classLoaderControl = launch.init(config.classpath.stream().map(Paths::get).collect(Collectors.toCollection(ArrayList::new)), config.nativesDir, options);
|
||||
classLoaderControl = launch.init(config.classpath.stream()
|
||||
.map(Paths::get)
|
||||
.flatMap(p -> {
|
||||
if(!Files.isDirectory(p)) {
|
||||
return Stream.of(p);
|
||||
}
|
||||
try {
|
||||
return Files.walk(p).filter(e -> e.getFileName().toString().endsWith(".jar"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
})
|
||||
.collect(Collectors.toCollection(ArrayList::new)), config.nativesDir, options);
|
||||
if(ServerAgent.isAgentStarted()) {
|
||||
ClientService.instrumentation = ServerAgent.inst;
|
||||
}
|
||||
ClientService.classLoaderControl = classLoaderControl;
|
||||
ClientService.baseURLs = classLoaderControl.getURLs();
|
||||
if(config.configServiceSettings != null) {
|
||||
config.configServiceSettings.apply();
|
||||
}
|
||||
LogHelper.info("Start Minecraft Server");
|
||||
try {
|
||||
if(config.compatClasses != null) {
|
||||
for (String e : config.compatClasses) {
|
||||
Class<?> clazz = classLoaderControl.getClass(e);
|
||||
MethodHandle runMethod = MethodHandles.lookup().findStatic(clazz, "run", MethodType.methodType(void.class, ClassLoaderControl.class));
|
||||
runMethod.invoke(classLoaderControl);
|
||||
}
|
||||
}
|
||||
runCompatClasses();
|
||||
LogHelper.debug("Invoke main method %s with %s", classname, launch.getClass().getName());
|
||||
launch.launch(config.mainclass, config.mainmodule, Arrays.asList(real_args));
|
||||
} catch (Throwable e) {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package pro.gravit.launcher.server;
|
||||
|
||||
public class ServerWrapperInlineInitializer {
|
||||
public static void run() throws Throwable {
|
||||
ServerWrapper.wrapper = new ServerWrapper(ServerWrapper.Config.class, ServerWrapper.configFile);
|
||||
ServerWrapper.wrapper.initialize();
|
||||
ServerWrapper.wrapper.connect();
|
||||
ServerWrapper.wrapper.runCompatClasses();
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
id 'org.openjfx.javafxplugin' version '0.1.0' apply false
|
||||
}
|
||||
group = 'pro.gravit.launcher'
|
||||
version = '5.6.11'
|
||||
version = '5.6.14'
|
||||
|
||||
apply from: 'props.gradle'
|
||||
|
||||
|
@ -71,10 +71,6 @@
|
|||
repositories {
|
||||
maven {
|
||||
url = version.endsWith('SNAPSHOT') ? getProperty('mavenSnapshotRepository') : getProperty('mavenReleaseRepository')
|
||||
credentials {
|
||||
username getProperty('mavenUsername')
|
||||
password getProperty('mavenPassword')
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,6 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
|
||||
networkTimeout=10000
|
||||
validateDistributionUrl=true
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
|
|
2
gradlew
vendored
2
gradlew
vendored
|
@ -205,7 +205,7 @@ fi
|
|||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Collect all arguments for the java command:
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||
# and any embedded shellness will be escaped.
|
||||
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||
# treated as '${Hostname}' itself on the command line.
|
||||
|
|
2
java24args.txt
Normal file
2
java24args.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
--enable-native-access=org.fusesource.jansi
|
||||
--enable-native-access=io.netty.common
|
4
javaargs.txt
Normal file
4
javaargs.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
--add-opens java.base/java.lang.invoke=launchserver
|
||||
--add-modules java.net.http
|
||||
-Dlauncher.useSlf4j=true
|
||||
-Dio.netty.noUnsafe=true
|
2
modules
2
modules
|
@ -1 +1 @@
|
|||
Subproject commit eeea07098281c5cc98feffaae9b5a01677ca2eb7
|
||||
Subproject commit a2c3ccecadb7f864039b88e6269583c4b77fba13
|
Loading…
Reference in a new issue