Compare commits

..

1 commit

Author SHA1 Message Date
Metall
a6b9023f98
Merge 05530b6664 into 18419fcd3a 2025-04-24 02:41:55 +03:00
26 changed files with 80 additions and 277 deletions

View file

@ -39,12 +39,9 @@ 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

View file

@ -29,7 +29,6 @@
bundleOnly
bundle
pack
proguardPack
bundleOnly.extendsFrom bundle
api.extendsFrom bundle, pack
}
@ -37,13 +36,11 @@
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"
)
}
@ -75,25 +72,22 @@
dependencies {
pack(project(':LauncherAPI')) {
exclude group: "com.google.code.gson"
}
bundle group: 'com.google.code.gson', name: 'gson', version: rootProject['verGson']
pack project(':LauncherAPI')
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-native', version: rootProject['verJline']
bundle group: 'org.jline', name: 'jline', version: rootProject['verJline']
bundle group: 'org.jline', name: 'jline-reader', version: rootProject['verJline']
bundle group: 'org.jline', name: 'jline-terminal-ffm', version: rootProject['verJline']
bundle group: 'org.jline', name: 'jline-terminal', 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'
@ -103,7 +97,7 @@
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']
proguardPack group: 'com.guardsquare', name: 'proguard-base', version: rootProject['verProguard']
bundle 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']
@ -127,12 +121,6 @@
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
@ -149,7 +137,7 @@
from parent.childProjects.Launcher.tasks.dumpLibs
}
assemble.dependsOn tasks.dumpLibs, tasks.dumpClientLibs, tasks.bundle, tasks.cleanjar, tasks.dumpProguard
assemble.dependsOn tasks.dumpLibs, tasks.dumpClientLibs, tasks.bundle, tasks.cleanjar
publishing {

View file

@ -82,7 +82,6 @@ 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
*/
@ -139,7 +138,6 @@ 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);
@ -464,16 +462,13 @@ 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", PROGUARD_DIR = "proguard-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";
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;
@ -494,7 +489,6 @@ 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()));
}

View file

@ -18,7 +18,7 @@
import java.util.stream.Stream;
public class Main {
private static final List<String> classpathOnly = List.of("proguard", "progressbar", "kotlin");
private static final List<String> classpathOnly = List.of("proguard", "jline", "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,8 +74,6 @@ 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");

View file

@ -1,17 +1,16 @@
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.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.jar.JarFile;
/**
@ -19,32 +18,14 @@
* чего угодно. Работает через поиск 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() {
@ -77,42 +58,7 @@ public byte[] getClassData(String className) throws IOException {
return bytes;
}
}
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);
return IOHelper.read(IOHelper.getResourceURL(className + ".class"));
}
public String getSuperClass(String type) {
@ -120,7 +66,6 @@ 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";
}
}
@ -155,7 +100,7 @@ private static class CheckSuperClassVisitor extends ClassVisitor {
String superClassName;
public CheckSuperClassVisitor() {
super(Opcodes.ASM9);
super(Opcodes.ASM7);
}
@Override

View file

@ -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) : 0);
cr.accept(cn, stripNumbers ? (ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES) : ClassReader.SKIP_FRAMES);
ClassWriter cw = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();

View file

@ -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, 0);
writer = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
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, 0);
writer = new SafeClassWriter(reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
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, 0);
SafeClassWriter writer = new SafeClassWriter(context.task.reader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cn.accept(writer);
return writer.toByteArray();
}

View file

@ -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.proguardDir, FileVisitOption.FOLLOW_LINKS)) {
try(Stream<Path> files = Files.walk(server.librariesDir, FileVisitOption.FOLLOW_LINKS)) {
args.add(files
.filter(e -> e.getFileName().toString().endsWith(".jar"))
.map(path -> path.toAbsolutePath().toString())

View file

@ -9,7 +9,6 @@
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;
@ -35,7 +34,6 @@ 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) {

View file

@ -1,15 +0,0 @@
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));
}
}

View file

@ -28,7 +28,6 @@ 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(",");
@ -38,14 +37,6 @@ 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");
@ -65,9 +56,7 @@ public static void initialize() throws Exception {
}
LauncherEngine.modulesManager.initModules(null);
LauncherEngine.initGson(LauncherEngine.modulesManager);
if(!disableConsole) {
ConsoleManager.initConsole();
}
ConsoleManager.initConsole();
LauncherEngine.modulesManager.invokeEvent(new PreConfigPhase());
RequestService service;
if (offlineMode) {
@ -83,6 +72,10 @@ public static void initialize() throws Exception {
if(!disableAutoRefresh) {
Request.startAutoRefresh();
}
LogHelper.debug("Initialization LauncherEngine");
LauncherEngine instance = LauncherEngine.newInstance(false, ClientRuntimeProvider.class);
instance.start(args);
LauncherEngine.exitLauncher(0);
}
@SuppressWarnings("unchecked")

View file

@ -1,7 +0,0 @@
package pro.gravit.launcher.runtime.debug;
public class DebugMainInlineInitializer {
public static void run() throws Exception {
DebugMain.initialize();
}
}

View file

@ -116,6 +116,15 @@ 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) {
@ -149,18 +158,6 @@ 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();
@ -277,11 +274,9 @@ 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));
}
for (OptionalAction a : actions) {
if (a instanceof OptionalActionClassPath)
result = Stream.concat(result, resolveClassPathStream(ignorePaths, clientDir, ((OptionalActionClassPath) a).args));
}
return result;
}

View file

@ -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 = 14;
public static final int PATCH = 11;
public static final int BUILD = 1;
public static final Version.Type RELEASE = Type.STABLE;
public final int major;

View file

@ -14,6 +14,5 @@ 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<>();
}
}

View file

@ -29,18 +29,6 @@ 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;
@ -132,20 +120,6 @@ 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);
}
}

View file

@ -48,21 +48,6 @@ 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) {
@ -109,4 +94,4 @@ pack project(':LauncherAPI')
sign publishing.publications.serverwrapperapi
}
assemble.dependsOn tasks.shadowJar, tasks.inlinejar
assemble.dependsOn tasks.shadowJar

View file

@ -25,18 +25,15 @@
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"));
@ -103,20 +100,31 @@ public void getProfiles() throws Exception {
}
}
public void initialize() throws Exception {
public void run(String... args) throws Throwable {
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 = () ->
{
@ -128,6 +136,11 @@ public void connect() throws Exception {
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));
{
@ -140,47 +153,6 @@ public void connect() throws Exception {
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");
@ -210,6 +182,8 @@ 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());
@ -235,27 +209,24 @@ 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)
.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);
classLoaderControl = launch.init(config.classpath.stream().map(Paths::get).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 {
runCompatClasses();
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);
}
}
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) {

View file

@ -1,10 +0,0 @@
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();
}
}

View file

@ -5,7 +5,7 @@
id 'org.openjfx.javafxplugin' version '0.1.0' apply false
}
group = 'pro.gravit.launcher'
version = '5.6.14'
version = '5.6.11'
apply from: 'props.gradle'
@ -71,6 +71,10 @@
repositories {
maven {
url = version.endsWith('SNAPSHOT') ? getProperty('mavenSnapshotRepository') : getProperty('mavenReleaseRepository')
credentials {
username getProperty('mavenUsername')
password getProperty('mavenPassword')
}
}
}
}

Binary file not shown.

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME

2
gradlew vendored
View file

@ -205,7 +205,7 @@ fi
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# * DEFAULT_JVM_OPTS, JAVA_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.

View file

@ -1,2 +0,0 @@
--enable-native-access=org.fusesource.jansi
--enable-native-access=io.netty.common

View file

@ -1,4 +0,0 @@
--add-opens java.base/java.lang.invoke=launchserver
--add-modules java.net.http
-Dlauncher.useSlf4j=true
-Dio.netty.noUnsafe=true

@ -1 +1 @@
Subproject commit a2c3ccecadb7f864039b88e6269583c4b77fba13
Subproject commit eeea07098281c5cc98feffaae9b5a01677ca2eb7