From 584acdb8c382e63ed2eb8faab953ed5b52dd5fdb Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:15:22 +0700 Subject: [PATCH 01/33] [ANY] Update dependencies --- LaunchServer/build.gradle | 10 ++-------- .../manangers/LaunchServerGsonManager.java | 4 ---- LauncherCore/build.gradle | 1 - props.gradle | 6 ++---- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index fbf36cdc..bfed90ec 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -71,7 +71,6 @@ dependencies { pack project(':LauncherAPI') bundle group: 'me.tongfei', name: 'progressbar', version: '0.10.1' - bundle group: 'com.github.Marcono1234', name: 'gson-record-type-adapter-factory', version: 'v0.3.0' 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-reader', version: rootProject['verJline'] @@ -96,17 +95,12 @@ pack project(':LauncherAPI') annotationProcessor(group: 'org.apache.logging.log4j', name: 'log4j-core', version: rootProject['verLog4j']) testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: rootProject['verJunit'] - hikari 'io.micrometer:micrometer-core:1.8.4' - hikari('com.zaxxer:HikariCP:5.0.1') { + hikari 'io.micrometer:micrometer-core:1.13.1' + hikari('com.zaxxer:HikariCP:5.1.0') { exclude group: 'javassist' exclude group: 'io.micrometer' exclude group: 'org.slf4j' } - - compileOnlyA group: 'com.google.guava', name: 'guava', version: rootProject['verGuavaC'] - // Do not update (laggy deps). - compileOnlyA 'log4j:log4j:1.2.17' - compileOnlyA 'org.apache.logging.log4j:log4j-core:2.14.1' } tasks.register('hikari', Copy) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index 07deb093..7f26c486 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -1,7 +1,6 @@ package pro.gravit.launchserver.manangers; import com.google.gson.GsonBuilder; -import marcono1234.gson.recordadapter.RecordTypeAdapterFactory; import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; import pro.gravit.launcher.core.managers.GsonManager; import pro.gravit.launcher.base.modules.events.PreGsonPhase; @@ -34,9 +33,6 @@ public LaunchServerGsonManager(LaunchServerModulesManager modulesManager) { @Override public void registerAdapters(GsonBuilder builder) { super.registerAdapters(builder); - builder.registerTypeAdapterFactory(RecordTypeAdapterFactory.builder() - .allowMissingComponentValues() - .create()); builder.registerTypeAdapter(ClientProfile.Version.class, new ClientProfile.Version.GsonSerializer()); builder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers)); builder.registerTypeAdapter(AuthCoreProvider.class, new UniversalJsonAdapter<>(AuthCoreProvider.providers)); diff --git a/LauncherCore/build.gradle b/LauncherCore/build.gradle index efd55c0a..068bbf70 100644 --- a/LauncherCore/build.gradle +++ b/LauncherCore/build.gradle @@ -6,7 +6,6 @@ compileOnly group: 'org.jline', name: 'jline', version: rootProject['verJline'] compileOnly group: 'org.jline', name: 'jline-reader', version: rootProject['verJline'] compileOnly group: 'org.jline', name: 'jline-terminal', version: rootProject['verJline'] - compileOnly group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: rootProject['verBcprov'] compileOnly group: 'org.slf4j', name: 'slf4j-api', version: rootProject['verSlf4j'] api group: 'com.google.code.gson', name: 'gson', version: rootProject['verGson'] testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: rootProject['verJunit'] diff --git a/props.gradle b/props.gradle index 8b85574d..af811c06 100644 --- a/props.gradle +++ b/props.gradle @@ -1,18 +1,16 @@ project.ext { verAsm = '9.7' - verNetty = '4.1.110.Final' + verNetty = '4.1.111.Final' verOshiCore = '6.6.1' verJunit = '5.10.2' - verGuavaC = '30.1.1-jre' verJansi = '2.4.1' verJline = '3.26.1' verJwt = '0.12.5' - verBcprov = '1.70' verGson = '2.11.0' verBcpkix = '1.78.1' verSlf4j = '2.0.13' verLog4j = '2.23.1' - verMySQLConn = '8.4.0' + verMySQLConn = '9.0.0' verMariaDBConn = '3.4.0' verPostgreSQLConn = '42.7.3' verH2Conn = '2.2.224' From 78be60602904459a08086e62a77324c05cd70c70 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:27:45 +0700 Subject: [PATCH 02/33] [FIX] FabricLoader main class --- .../java/pro/gravit/launchserver/helper/MakeProfileHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java index 50cf3ba9..4423cc1b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java @@ -203,7 +203,7 @@ public static String getMainClassByVersion(ClientProfile.Version version, MakePr return "cpw.mods.modlauncher.Launcher"; } if (findOption(options, MakeProfileOptionFabric.class).isPresent()) { - return "net.fabricmc.loader.launch.knot.KnotClient"; + return "net.fabricmc.loader.impl.launch.knot.KnotClient"; } if(findOption(options, MakeProfilesOptionsQuilt.class).isPresent()) { return "org.quiltmc.loader.impl.launch.knot.KnotClient"; From 353b663e123b28c9613b5a0ccf3aa1fc401ba7c8 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:38:45 +0700 Subject: [PATCH 03/33] [FEATURE] Support command execute by args --- LaunchServer/build.gradle | 1 - .../launchserver/LaunchServerStarter.java | 20 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index bfed90ec..c12ca9a3 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -61,7 +61,6 @@ dependsOn jar archiveClassifier.set('clean') manifest.attributes("Main-Class": mainClassName, - "Premain-Class": mainAgentName, "Automatic-Module-Name": "launchserver" ) from sourceSets.main.output diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index addab8f3..0ddb43b3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -34,6 +34,7 @@ import java.nio.file.Path; import java.security.Security; import java.security.cert.CertificateException; +import java.util.ArrayList; import java.util.List; public class LaunchServerStarter { @@ -135,7 +136,24 @@ public static void main(String[] args) throws Exception { .setLaunchServerConfigManager(launchServerConfigManager) .setCertificateManager(certificateManager) .build(); - if (!prepareMode) { + List allArgs = List.of(args); + boolean isPrepareMode = prepareMode || allArgs.contains("--prepare"); + boolean isRunCommand = false; + String runCommand = null; + for(var e : allArgs) { + if(e.equals("--run")) { + isRunCommand = true; + continue; + } + if(isRunCommand) { + runCommand = e; + isRunCommand = false; + } + } + if(runCommand != null) { + localCommandHandler.eval(runCommand, false); + } + if (!isPrepareMode) { server.run(); } else { server.close(); From ef9cbfe0dad0bb2e355d6f582798300a0643cf85 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:38:57 +0700 Subject: [PATCH 04/33] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index a52b9cc8..a7719962 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit a52b9cc8552445167b95e8933f4289bbaa70677d +Subproject commit a771996282dc64c0227ce7c5f4057bc8ed143dbc From 3b22b76278b963cc32ba1b8816990f4e1cafc655 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:55:10 +0700 Subject: [PATCH 05/33] [FIX] Cleanroom install --- .../java/pro/gravit/launchserver/helper/MakeProfileHelper.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java index 4423cc1b..cf09323a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java @@ -196,6 +196,9 @@ public static String getMainClassByVersion(ClientProfile.Version version, MakePr if(version.compareTo(ClientProfileVersions.MINECRAFT_1_7_10) == 0) { return "com.gtnewhorizons.retrofuturabootstrap.Main"; } + if(version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) == 0) { + return "top.outlands.foundation.boot.Foundation"; // Cleanroom + } if (findOption(options, MakeProfileOptionLaunchWrapper.class).isPresent()) { return "net.minecraft.launchwrapper.Launch"; } From 51411c5838e9ad348dbe1eddf3d3b7c0bffb490c Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 5 Jul 2024 14:55:21 +0700 Subject: [PATCH 06/33] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index a7719962..cd2e4cbc 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit a771996282dc64c0227ce7c5f4057bc8ed143dbc +Subproject commit cd2e4cbcec932601e4f6814b92da5ee9edf9f8dc From bbc5f1722b7aad48a7e5db590c3aafa404b0fc98 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:30:03 +0700 Subject: [PATCH 07/33] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index cd2e4cbc..d0e00fd0 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit cd2e4cbcec932601e4f6814b92da5ee9edf9f8dc +Subproject commit d0e00fd09c6f9192976b62bbf5909947afb95b08 From 78b4f1e3aa870d1a7a0b8dc18f1da844820fe878 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 5 Jul 2024 15:55:54 +0700 Subject: [PATCH 08/33] [FIX] Gson version --- LaunchServer/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index c12ca9a3..303c086f 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -91,6 +91,7 @@ pack project(':LauncherAPI') bundle group: 'io.jsonwebtoken', name: 'jjwt-api', version: rootProject['verJwt'] bundle group: 'io.jsonwebtoken', name: 'jjwt-impl', version: rootProject['verJwt'] bundle group: 'io.jsonwebtoken', name: 'jjwt-gson', version: rootProject['verJwt'] + bundle group: 'com.google.code.gson', name: 'gson', version: rootProject['verGson'] annotationProcessor(group: 'org.apache.logging.log4j', name: 'log4j-core', version: rootProject['verLog4j']) testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: rootProject['verJunit'] From 8c11ab0cbebc23b70ea4d8cdb5108c37c83dac2f Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 5 Jul 2024 16:27:50 +0700 Subject: [PATCH 09/33] [FIX] Disable Sodium lwjgl check --- .../java/pro/gravit/launchserver/helper/MakeProfileHelper.java | 1 + 1 file changed, 1 insertion(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java index cf09323a..5b139d12 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java @@ -103,6 +103,7 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti } if (fabric.isPresent()) { builder.setAltClassPath(fabric.orElseThrow().getAltClassPath()); + jvmArgs.add("-Dsodium.checks.issue2561=false"); // Please don't check LWJL3 version (Sodium: https://github.com/CaffeineMC/sodium-fabric/issues/2561 ) } if(quilt.isPresent()) { builder.setClassLoaderConfig(ClientProfile.ClassLoaderConfig.SYSTEM_ARGS); From c261496af88555d44e05eeb7dfc8614cb574f45e Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sat, 6 Jul 2024 01:55:10 +0700 Subject: [PATCH 10/33] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index d0e00fd0..b6efad9a 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit d0e00fd09c6f9192976b62bbf5909947afb95b08 +Subproject commit b6efad9aa66b5df9b6d59def76aeb7d3c82a79d1 From 03d53d4a097bb495728f878eb941181893c9b9cd Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sat, 6 Jul 2024 02:59:36 +0700 Subject: [PATCH 11/33] [FEATURE] Support -Dlaunchserver.dir.libraries --- LaunchServer/src/main/java/pro/gravit/launchserver/Main.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java b/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java index 8ca8b467..aabf4fe1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java @@ -21,6 +21,7 @@ public class Main { private static final List classpathOnly = List.of("proguard", "jline", "progressbar", "kotlin", "epoll"); 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"; private static boolean isClasspathOnly(Path path) { var fileName = path.getFileName().toString(); for(var e : classpathOnly) { @@ -56,8 +57,9 @@ public static void main(String[] args) throws Throwable { ModuleLaunch launch = new ModuleLaunch(); LaunchOptions options = new LaunchOptions(); options.moduleConf = new LaunchOptions.ModuleConf(); + Path librariesPath = Path.of(System.getProperty(LIBRARIES_PROPERTY, "libraries")); List libraries; - try(Stream files = Files.walk(Path.of("libraries"), FileVisitOption.FOLLOW_LINKS)) { + try(Stream files = Files.walk(librariesPath, FileVisitOption.FOLLOW_LINKS)) { libraries = new ArrayList<>(files.filter(e -> e.getFileName().toString().endsWith(".jar")).toList()); } List classpath = new ArrayList<>(); From df9d05a49c33b85a0708944c1eb0a579f6ba25a6 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sat, 6 Jul 2024 03:24:02 +0700 Subject: [PATCH 12/33] [FEATURE] Support -Dlaunchserver.dir.modules and -Dlaunchserver.dir.launcher-modules --- .../java/pro/gravit/launchserver/LaunchServer.java | 10 +++++++++- .../pro/gravit/launchserver/LaunchServerStarter.java | 9 +++++---- .../launchermodules/LauncherModuleLoader.java | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index d3a435ea..1e283ffd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -82,6 +82,8 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab */ public final Path profilesDir; public final Path tmpDir; + public final Path modulesDir; + public final Path launcherModulesDir; /** * This object contains runtime configuration */ @@ -136,6 +138,8 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La launcherLibraries = directories.launcherLibrariesDir; launcherLibrariesCompile = directories.launcherLibrariesCompileDir; launcherPack = directories.launcherPackDir; + modulesDir = directories.modules; + launcherModulesDir = directories.launcherModules; this.shardId = shardId; if(!Files.isDirectory(launcherPack)) { Files.createDirectories(launcherPack); @@ -488,7 +492,7 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public static class LaunchServerDirectories { public static final String UPDATES_NAME = "updates", PROFILES_NAME = "profiles", TRUSTSTORE_NAME = "truststore", LAUNCHERLIBRARIES_NAME = "launcher-libraries", - LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack", KEY_NAME = ".keys"; + LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack", KEY_NAME = ".keys", MODULES = "modules", LAUNCHER_MODULES = "launcher-modules"; public Path updatesDir; public Path profilesDir; public Path launcherLibrariesDir; @@ -498,6 +502,8 @@ public static class LaunchServerDirectories { public Path dir; public Path trustStore; public Path tmpDir; + public Path modules; + public Path launcherModules; public void collect() { if (updatesDir == null) updatesDir = getPath(UPDATES_NAME); @@ -509,6 +515,8 @@ public void collect() { if(launcherPackDir == null) launcherPackDir = getPath(LAUNCHERPACK_NAME); if (keyDirectory == null) keyDirectory = getPath(KEY_NAME); + if (modules == null) modules = getPath(MODULES); + if (launcherModules == null) launcherModules = getPath(LAUNCHER_MODULES); if (tmpDir == null) tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("launchserver-%s".formatted(SecurityHelper.randomStringToken())); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 0ddb43b3..061ebaaa 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -52,10 +52,13 @@ public static void main(String[] args) throws Exception { try { Class.forName("org.bouncycastle.jce.provider.BouncyCastleProvider"); Security.addProvider(new BouncyCastleProvider()); - } catch (ClassNotFoundException ex) { + } catch (ClassNotFoundException | NoClassDefFoundError ex) { LogHelper.error("Library BouncyCastle not found! Is directory 'libraries' empty?"); return; } + LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); + directories.dir = dir; + directories.collect(); CertificateManager certificateManager = new CertificateManager(); try { certificateManager.readTrustStore(dir.resolve("truststore")); @@ -79,7 +82,7 @@ public static void main(String[] args) throws Exception { LaunchServerRuntimeConfig runtimeConfig; LaunchServerConfig config; LaunchServer.LaunchServerEnv env = LaunchServer.LaunchServerEnv.PRODUCTION; - LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(dir.resolve("modules"), dir.resolve("config"), certificateManager.trustManager); + LaunchServerModulesManager modulesManager = new LaunchServerModulesManager(directories.modules, dir.resolve("config"), certificateManager.trustManager); modulesManager.autoload(); modulesManager.initModules(null); registerAll(); @@ -124,8 +127,6 @@ public static void main(String[] args) throws Exception { } LaunchServer.LaunchServerConfigManager launchServerConfigManager = new BasicLaunchServerConfigManager(configFile, runtimeConfigFile); - LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); - directories.dir = dir; LaunchServer server = new LaunchServerBuilder() .setDirectories(directories) .setEnv(env) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java index f50945a5..922efc05 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java @@ -33,7 +33,7 @@ public class LauncherModuleLoader { public LauncherModuleLoader(LaunchServer server) { this.server = server; - modulesDir = server.dir.resolve("launcher-modules"); + modulesDir = server.launcherModulesDir; } public void init() { From c7781b30bed90d3ef7e9e7b72a840e0a9e1f108c Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sat, 6 Jul 2024 22:34:20 +0700 Subject: [PATCH 13/33] [FIX] launcher-libraries-compile not found --- .../gravit/launchserver/binary/tasks/PrepareBuildTask.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/PrepareBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/PrepareBuildTask.java index 09473e54..e509edf3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/PrepareBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/PrepareBuildTask.java @@ -37,7 +37,9 @@ public Path process(Path inputFile) throws IOException { server.launcherBinary.addonLibs.clear(); server.launcherBinary.files.clear(); IOHelper.walk(server.launcherLibraries, new ListFileVisitor(server.launcherBinary.coreLibs), false); - IOHelper.walk(server.launcherLibrariesCompile, new ListFileVisitor(server.launcherBinary.addonLibs), false); + if(Files.isDirectory(server.launcherLibrariesCompile)) { + IOHelper.walk(server.launcherLibrariesCompile, new ListFileVisitor(server.launcherBinary.addonLibs), false); + } try(Stream stream = Files.walk(server.launcherPack).filter((e) -> { try { return !Files.isDirectory(e) && !Files.isHidden(e); From 1bebd8de2cc2485f65fe22aff3a935c14077fd7c Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Mon, 8 Jul 2024 21:22:44 +0700 Subject: [PATCH 14/33] [FIX] classLoaderConfig is null --- .../pro/gravit/launcher/base/profiles/ClientProfileBuilder.java | 1 + 1 file changed, 1 insertion(+) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileBuilder.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileBuilder.java index 3b156f50..2839dc03 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileBuilder.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileBuilder.java @@ -79,6 +79,7 @@ public ClientProfileBuilder(ClientProfile profile) { this.loadNatives = new ArrayList<>(profile.getLoadNatives()); this.properties = new HashMap<>(profile.getProperties()); this.servers = new ArrayList<>(profile.getServers()); + this.classLoaderConfig = profile.getClassLoaderConfig(); this.flags = new ArrayList<>(profile.getFlags()); this.recommendJavaVersion = profile.getRecommendJavaVersion(); this.minJavaVersion = profile.getMinJavaVersion(); From ec526a343d5cb507cd9322f36f3b2771958553ea Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Mon, 8 Jul 2024 21:29:40 +0700 Subject: [PATCH 15/33] [FIX] OptionalView.fixDependencies throw out of range --- .../gravit/launcher/base/profiles/optional/OptionalView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalView.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalView.java index 80df3666..7837a127 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalView.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalView.java @@ -88,7 +88,7 @@ public Set getEnabledActions() { public void fixDependencies() { Set disabled = all.stream().filter(t -> !isEnabled(t)).collect(Collectors.toSet()); for (OptionalFile file : disabled) { - if (file.group != null && Arrays.stream(file.group).noneMatch(this::isEnabled)) { + if (file.group != null && file.group.length > 0 && Arrays.stream(file.group).noneMatch(this::isEnabled)) { enable(file.group[0], false, null); } } From 925007015f96a5c2b7a64477f63b071d930be555 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 9 Jul 2024 20:57:52 +0700 Subject: [PATCH 16/33] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index b6efad9a..0b9e8819 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit b6efad9aa66b5df9b6d59def76aeb7d3c82a79d1 +Subproject commit 0b9e8819db5c3d7db874b334cfa629a73daabf01 From 0894e0b9c3e1f06aac7d7ca60fa351711801e821 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 16 Jul 2024 17:11:12 +0700 Subject: [PATCH 17/33] [FIX] Sync profiles before updates --- .../java/pro/gravit/launchserver/LaunchServer.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 1e283ffd..d3adfbae 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -355,14 +355,17 @@ public void run() { // Sync updates dir CommonHelper.newThread("Profiles and updates sync", true, () -> { try { - if (!IOHelper.isDir(updatesDir)) - Files.createDirectory(updatesDir); - updatesManager.readUpdatesDir(); - // Sync profiles dir if (!IOHelper.isDir(profilesDir)) Files.createDirectory(profilesDir); syncProfilesDir(); + + // Sync updates dir + if (!IOHelper.isDir(updatesDir)) + Files.createDirectory(updatesDir); + updatesManager.readUpdatesDir(); + + modulesManager.invokeEvent(new LaunchServerProfilesSyncEvent(this)); } catch (IOException e) { logger.error("Updates/Profiles not synced", e); From accbbe6b133a42fd431525dcf51f9f63c5f07e9b Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 16 Jul 2024 21:54:59 +0700 Subject: [PATCH 18/33] [FEATURE] Support port in launchserver address in first run --- .../gravit/launchserver/LaunchServerStarter.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 061ebaaa..c3097c0c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -220,7 +220,7 @@ public static void generateConfigIfNotExists(Path configFile, CommandHandler com address = System.getProperty("launchserver.address", null); } if (address == null) { - System.out.println("LaunchServer address(default: localhost): "); + System.out.println("External launchServer address:port (default: localhost:9274): "); address = commandHandler.readLine(); } String projectName = System.getenv("PROJECTNAME"); @@ -234,18 +234,18 @@ public static void generateConfigIfNotExists(Path configFile, CommandHandler com newConfig.setProjectName(projectName); } if (address == null || address.isEmpty()) { - logger.error("Address null. Using localhost"); - address = "localhost"; + logger.error("Address null. Using localhost:9274"); + address = "localhost:9274"; } if (newConfig.projectName == null || newConfig.projectName.isEmpty()) { logger.error("ProjectName null. Using MineCraft"); newConfig.projectName = "MineCraft"; } - newConfig.netty.address = "ws://" + address + ":9274/api"; - newConfig.netty.downloadURL = "http://" + address + ":9274/%dirname%/"; - newConfig.netty.launcherURL = "http://" + address + ":9274/Launcher.jar"; - newConfig.netty.launcherEXEURL = "http://" + address + ":9274/Launcher.exe"; + newConfig.netty.address = "ws://" + address + "/api"; + newConfig.netty.downloadURL = "http://" + address + "/%dirname%/"; + newConfig.netty.launcherURL = "http://" + address + "/Launcher.jar"; + newConfig.netty.launcherEXEURL = "http://" + address + "/Launcher.exe"; // Write LaunchServer config logger.info("Writing LaunchServer config file"); From 992d31c8832dbe071756cd52d982a6f8c9df6dc2 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:05:13 +0700 Subject: [PATCH 19/33] [FEATURE] Set netty bind port in first run --- .../gravit/launchserver/LaunchServerStarter.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index c3097c0c..16542fb6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -241,11 +241,22 @@ public static void generateConfigIfNotExists(Path configFile, CommandHandler com logger.error("ProjectName null. Using MineCraft"); newConfig.projectName = "MineCraft"; } - + int port = 9274; + if(address.contains(":")) { + String portString = address.substring(address.indexOf(':')+1); + try { + port = Integer.parseInt(portString); + } catch (NumberFormatException e) { + logger.warn("Unknown port {}, using 9274", portString); + } + } else { + logger.info("Address {} doesn't contains port (you want to use nginx?)", address); + } newConfig.netty.address = "ws://" + address + "/api"; newConfig.netty.downloadURL = "http://" + address + "/%dirname%/"; newConfig.netty.launcherURL = "http://" + address + "/Launcher.jar"; newConfig.netty.launcherEXEURL = "http://" + address + "/Launcher.exe"; + newConfig.netty.binds[0].port = port; // Write LaunchServer config logger.info("Writing LaunchServer config file"); From 1bd5d8854c584eab5c688227247e6194f2040986 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Wed, 17 Jul 2024 01:32:51 +0700 Subject: [PATCH 20/33] [FIX] ProGuard and launchserver.dir.libraries --- .../main/java/pro/gravit/launchserver/LaunchServer.java | 8 ++++++-- .../gravit/launchserver/components/ProGuardComponent.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index d3adfbae..6a50ae8e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -84,6 +84,7 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab public final Path tmpDir; public final Path modulesDir; public final Path launcherModulesDir; + public final Path librariesDir; /** * This object contains runtime configuration */ @@ -140,6 +141,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La launcherPack = directories.launcherPackDir; modulesDir = directories.modules; launcherModulesDir = directories.launcherModules; + librariesDir = directories.launcherLibrariesDir; this.shardId = shardId; if(!Files.isDirectory(launcherPack)) { Files.createDirectories(launcherPack); @@ -495,9 +497,10 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO public static class LaunchServerDirectories { public static final String UPDATES_NAME = "updates", PROFILES_NAME = "profiles", 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"; + LAUNCHERLIBRARIESCOMPILE_NAME = "launcher-libraries-compile", LAUNCHERPACK_NAME = "launcher-pack", KEY_NAME = ".keys", MODULES = "modules", LAUNCHER_MODULES = "launcher-modules", LIBRARIES = "libraries"; public Path updatesDir; public Path profilesDir; + public Path librariesDir; public Path launcherLibrariesDir; public Path launcherLibrariesCompileDir; public Path launcherPackDir; @@ -515,11 +518,12 @@ public void collect() { if (launcherLibrariesDir == null) launcherLibrariesDir = getPath(LAUNCHERLIBRARIES_NAME); if (launcherLibrariesCompileDir == null) launcherLibrariesCompileDir = getPath(LAUNCHERLIBRARIESCOMPILE_NAME); - if(launcherPackDir == null) + if (launcherPackDir == null) launcherPackDir = getPath(LAUNCHERPACK_NAME); if (keyDirectory == null) keyDirectory = getPath(KEY_NAME); if (modules == null) modules = getPath(MODULES); if (launcherModules == null) launcherModules = getPath(LAUNCHER_MODULES); + if (librariesDir == null) librariesDir = getPath(LIBRARIES); if (tmpDir == null) tmpDir = Paths.get(System.getProperty("java.io.tmpdir")).resolve("launchserver-%s".formatted(SecurityHelper.randomStringToken())); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java index 97a36b49..9b1586bb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java @@ -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 files = Files.walk(Path.of("libraries"), FileVisitOption.FOLLOW_LINKS)) { + try(Stream files = Files.walk(server.librariesDir, FileVisitOption.FOLLOW_LINKS)) { args.add(files .filter(e -> e.getFileName().toString().endsWith(".jar")) .map(path -> path.toAbsolutePath().toString()) From c8c83c0dba9ea9076eb4d19dc319fc5830033081 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 18 Jul 2024 15:54:45 +0700 Subject: [PATCH 21/33] [ANY] 5.6.3-stable --- LauncherCore/src/main/java/pro/gravit/utils/Version.java | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 6c9a7360..73b08ab8 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -8,7 +8,7 @@ public final class Version implements Comparable { public static final int MINOR = 6; public static final int PATCH = 3; public static final int BUILD = 1; - public static final Version.Type RELEASE = Type.DEV; + public static final Version.Type RELEASE = Type.STABLE; public final int major; public final int minor; public final int patch; diff --git a/build.gradle b/build.gradle index 211d7b5d..4de8fcae 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.1.0' apply false } group = 'pro.gravit.launcher' -version = '5.6.2' +version = '5.6.3' apply from: 'props.gradle' From 5bf92d9a00798bae66be44720c7557f5725682a7 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 18 Jul 2024 20:34:31 +0700 Subject: [PATCH 22/33] [FIX] ProGuard librariesDir --- .../src/main/java/pro/gravit/launchserver/LaunchServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 6a50ae8e..3745386f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -141,7 +141,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La launcherPack = directories.launcherPackDir; modulesDir = directories.modules; launcherModulesDir = directories.launcherModules; - librariesDir = directories.launcherLibrariesDir; + librariesDir = directories.librariesDir; this.shardId = shardId; if(!Files.isDirectory(launcherPack)) { Files.createDirectories(launcherPack); From 20f713be0520d817c33e867e45e67553270c9ab2 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 18 Jul 2024 20:35:26 +0700 Subject: [PATCH 23/33] 5.6.4-stable --- LauncherCore/src/main/java/pro/gravit/utils/Version.java | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 73b08ab8..61f4deea 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -6,7 +6,7 @@ public final class Version implements Comparable { public static final int MAJOR = 5; public static final int MINOR = 6; - public static final int PATCH = 3; + public static final int PATCH = 4; public static final int BUILD = 1; public static final Version.Type RELEASE = Type.STABLE; public final int major; diff --git a/build.gradle b/build.gradle index 4de8fcae..2009e0fa 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.1.0' apply false } group = 'pro.gravit.launcher' -version = '5.6.3' +version = '5.6.4' apply from: 'props.gradle' From 9c82d767817e1534e33491612191f10f7e79c31a Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:19:41 +0700 Subject: [PATCH 24/33] [FEATURE][REFACTOR] Refactoring GenerateCertificateModule --- .../pro/gravit/launchserver/manangers/KeyAgreementManager.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/KeyAgreementManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/KeyAgreementManager.java index 4ddee0cc..4f42c5e3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/KeyAgreementManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/KeyAgreementManager.java @@ -22,6 +22,7 @@ public class KeyAgreementManager { public final RSAPublicKey rsaPublicKey; public final RSAPrivateKey rsaPrivateKey; public final String legacySalt; + public final Path keyDirectory; public KeyAgreementManager(ECPublicKey ecdsaPublicKey, ECPrivateKey ecdsaPrivateKey, RSAPublicKey rsaPublicKey, RSAPrivateKey rsaPrivateKey, String legacySalt) { this.ecdsaPublicKey = ecdsaPublicKey; @@ -29,9 +30,11 @@ public KeyAgreementManager(ECPublicKey ecdsaPublicKey, ECPrivateKey ecdsaPrivate this.rsaPublicKey = rsaPublicKey; this.rsaPrivateKey = rsaPrivateKey; this.legacySalt = legacySalt; + this.keyDirectory = null; } public KeyAgreementManager(Path keyDirectory) throws IOException, InvalidKeySpecException { + this.keyDirectory = keyDirectory; Path ecdsaPublicKeyPath = keyDirectory.resolve("ecdsa_id.pub"), ecdsaPrivateKeyPath = keyDirectory.resolve("ecdsa_id"); Logger logger = LogManager.getLogger(); if (IOHelper.isFile(ecdsaPublicKeyPath) && IOHelper.isFile(ecdsaPrivateKeyPath)) { From c2926b5b40d753e5860792216bfeddb3470f4b4f Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sat, 20 Jul 2024 19:20:12 +0700 Subject: [PATCH 25/33] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 0b9e8819..9f1ccd0b 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 0b9e8819db5c3d7db874b334cfa629a73daabf01 +Subproject commit 9f1ccd0bbc767d04a8a2d2909cc050980c8a458f From 7d7485afdc46dab38aac869e25eeed3b275aaa00 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sun, 21 Jul 2024 19:48:55 +0700 Subject: [PATCH 26/33] [FIX] Downloader downloadList truncate file --- .../src/main/java/pro/gravit/launcher/base/Downloader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java index 6eecdc21..6fb5bd20 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java @@ -256,7 +256,7 @@ protected HttpRequest makeHttpRequest(URI baseUri, String filePath) throws URISy } protected ProgressTrackingBodyHandler makeBodyHandler(Path file, DownloadCallback callback) { - return new ProgressTrackingBodyHandler<>(HttpResponse.BodyHandlers.ofFile(file, StandardOpenOption.CREATE, StandardOpenOption.WRITE), callback); + return new ProgressTrackingBodyHandler<>(HttpResponse.BodyHandlers.ofFile(file, StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING), callback); } public interface DownloadCallback { From 68e9affbe0ee27985a3866472fb8d6ea3a618fb4 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sun, 21 Jul 2024 20:17:51 +0700 Subject: [PATCH 27/33] [ANY] 5.6.5-stable --- LauncherCore/src/main/java/pro/gravit/utils/Version.java | 2 +- build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 61f4deea..8201c010 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -6,7 +6,7 @@ public final class Version implements Comparable { public static final int MAJOR = 5; public static final int MINOR = 6; - public static final int PATCH = 4; + public static final int PATCH = 5; public static final int BUILD = 1; public static final Version.Type RELEASE = Type.STABLE; public final int major; diff --git a/build.gradle b/build.gradle index 2009e0fa..473b0c47 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.1.0' apply false } group = 'pro.gravit.launcher' -version = '5.6.4' +version = '5.6.5' apply from: 'props.gradle' From 88f1eaf750140547014f63a2510c1cf3327c3875 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Sun, 21 Jul 2024 20:39:18 +0700 Subject: [PATCH 28/33] [ANY] Update modules --- modules | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules b/modules index 9f1ccd0b..c5087d40 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 9f1ccd0bbc767d04a8a2d2909cc050980c8a458f +Subproject commit c5087d40c9dd5b065fccedeac21afb967a25e112 From d720328bc4236d5d0d5de138c231d60505187f6f Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 25 Jul 2024 15:51:43 +0700 Subject: [PATCH 29/33] [FEATURE] moduleConf in SYSTEM_ARGS --- .../runtime/client/ClientLauncherProcess.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Launcher/src/main/java/pro/gravit/launcher/runtime/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/ClientLauncherProcess.java index aaf4c5be..22b1b843 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/runtime/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/ClientLauncherProcess.java @@ -145,7 +145,22 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.AGENT) { processArgs.add("-javaagent:".concat(IOHelper.getCodeSource(ClientLauncherEntryPoint.class).toAbsolutePath().toString())); } else if (params.profile.getClassLoaderConfig() == ClientProfile.ClassLoaderConfig.SYSTEM_ARGS) { - systemClassPath.addAll(ClientLauncherEntryPoint.resolveClassPath(new HashSet<>(), workDir, params.actions, params.profile) + Set ignorePath = new HashSet<>(); + var moduleConf = params.profile.getModuleConf(); + if(moduleConf != null) { + if(moduleConf.modulePath != null && !moduleConf.modulePath.isEmpty()) { + processArgs.add("-p"); + for(var e : moduleConf.modulePath) { + ignorePath.add(Path.of(e)); + } + processArgs.add(String.join(File.pathSeparator, moduleConf.modulePath)); + } + if(moduleConf.modules != null && !moduleConf.modules.isEmpty()) { + processArgs.add("--add-modules"); + processArgs.add(String.join(",", moduleConf.modules)); + } + } + systemClassPath.addAll(ClientLauncherEntryPoint.resolveClassPath(ignorePath, workDir, params.actions, params.profile) .map(Path::toString) .toList()); } From ef4f14f9b4c63310f53373989ce25950a70b3c46 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:33:49 +0700 Subject: [PATCH 30/33] [FIX] Add netty epoll lib for aarch64 (ARM) --- LaunchServer/build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index 303c086f..d03cc45d 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -80,6 +80,7 @@ pack project(':LauncherAPI') 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: 'org.slf4j', name: 'slf4j-api', version: rootProject['verSlf4j'] bundle group: 'com.mysql', name: 'mysql-connector-j', version: rootProject['verMySQLConn'] bundle group: 'org.mariadb.jdbc', name: 'mariadb-java-client', version: rootProject['verMariaDBConn'] From 4be299f6ca8e47750ba522dc9d79f89c0fe08e94 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 25 Jul 2024 16:43:00 +0700 Subject: [PATCH 31/33] [FIX] Add ClassLoader.registerAsParallelCapable() --- .../src/main/java/pro/gravit/utils/launch/LegacyLaunch.java | 4 ++++ .../src/main/java/pro/gravit/utils/launch/ModuleLaunch.java | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java index 1a155fe4..a7511ad9 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java @@ -54,6 +54,10 @@ private class LegacyClassLoader extends URLClassLoader { private final Map> classMap = new ConcurrentHashMap<>(); private String nativePath; + static { + ClassLoader.registerAsParallelCapable(); + } + private final List packages = new ArrayList<>(); public LegacyClassLoader(URL[] urls) { super(urls); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java index 5a414ea8..d83e3c44 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java @@ -164,6 +164,11 @@ private class ModuleClassLoader extends URLClassLoader { private String nativePath; private final List packages = new ArrayList<>(); + + static { + ClassLoader.registerAsParallelCapable(); + } + public ModuleClassLoader(URL[] urls, ClassLoader parent) { super("LAUNCHER", urls, parent); packages.add("pro.gravit.launcher."); From 9bffe07d369921850574cfcb408cc2514187852d Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 25 Jul 2024 22:20:48 +0700 Subject: [PATCH 32/33] [FEATURE] ProfileProvider --- .../pro/gravit/launchserver/LaunchServer.java | 51 ++-------- .../launchserver/LaunchServerStarter.java | 2 + .../auth/profiles/LocalProfileProvider.java | 93 +++++++++++++++++++ .../auth/profiles/ProfileProvider.java | 76 +++++++++++++++ .../command/hash/DownloadClientCommand.java | 5 +- .../command/profiles/CloneProfileCommand.java | 19 ++-- .../profiles/DeleteProfileCommand.java | 21 ++--- .../command/profiles/MakeProfileCommand.java | 4 +- .../command/profiles/SaveProfilesCommand.java | 30 ++---- .../config/LaunchServerConfig.java | 12 +++ .../manangers/LaunchServerGsonManager.java | 2 + 11 files changed, 218 insertions(+), 97 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/ProfileProvider.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index 3745386f..595d1cdb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -80,7 +80,6 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab /** * The path to the folder with profiles */ - public final Path profilesDir; public final Path tmpDir; public final Path modulesDir; public final Path launcherModulesDir; @@ -119,8 +118,6 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab private final Logger logger = LogManager.getLogger(); public final int shardId; public LaunchServerConfig config; - // Updates and profiles - private volatile Set profilesList; public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, LaunchServerConfig config, LaunchServerRuntimeConfig runtimeConfig, LaunchServerConfigManager launchServerConfigManager, LaunchServerModulesManager modulesManager, KeyAgreementManager keyAgreementManager, CommandHandler commandHandler, CertificateManager certificateManager, int shardId) throws IOException { this.dir = directories.dir; @@ -129,7 +126,6 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La this.config = config; this.launchServerConfigManager = launchServerConfigManager; this.modulesManager = modulesManager; - this.profilesDir = directories.profilesDir; this.updatesDir = directories.updatesDir; this.keyAgreementManager = keyAgreementManager; this.commandHandler = commandHandler; @@ -326,12 +322,14 @@ public void close() throws Exception { logger.info("LaunchServer stopped"); } + @Deprecated public Set getProfiles() { - return profilesList; + return config.profileProvider.getProfiles(); } + @Deprecated public void setProfiles(Set profilesList) { - this.profilesList = Collections.unmodifiableSet(profilesList); + throw new UnsupportedOperationException(); } public void rebindNettyServerSocket() { @@ -358,8 +356,6 @@ public void run() { CommonHelper.newThread("Profiles and updates sync", true, () -> { try { // Sync profiles dir - if (!IOHelper.isDir(profilesDir)) - Files.createDirectory(profilesDir); syncProfilesDir(); // Sync updates dir @@ -402,12 +398,7 @@ public void syncLauncherBinaries() throws IOException { public void syncProfilesDir() throws IOException { logger.info("Syncing profiles dir"); - List newProfies = new LinkedList<>(); - IOHelper.walk(profilesDir, new ProfilesFileVisitor(newProfies), false); - - // Sort and set new profiles - newProfies.sort(Comparator.comparing(a -> a)); - profilesList = Set.copyOf(newProfies); + config.profileProvider.sync(); if (config.netty.sendProfileUpdatesEvent) { sendUpdateProfilesEvent(); } @@ -422,7 +413,7 @@ private void sendUpdateProfilesEvent() { if (client == null || !client.isAuth) { return; } - ProfilesRequestEvent event = new ProfilesRequestEvent(ProfilesResponse.getListVisibleProfiles(this, client)); + ProfilesRequestEvent event = new ProfilesRequestEvent(config.profileProvider.getProfiles(client)); event.requestUUID = RequestEvent.eventUUID; handler.service.sendObject(ch, event); }); @@ -468,38 +459,11 @@ public interface LaunchServerConfigManager { void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException; } - private static final class ProfilesFileVisitor extends SimpleFileVisitor { - private final Collection result; - private final Logger logger = LogManager.getLogger(); - - private ProfilesFileVisitor(Collection result) { - this.result = result; - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - logger.info("Syncing '{}' profile", IOHelper.getFileName(file)); - - // Read profile - ClientProfile profile; - try (BufferedReader reader = IOHelper.newReader(file)) { - profile = Launcher.gsonManager.gson.fromJson(reader, ClientProfile.class); - } - profile.verify(); - profile.setProfileFilePath(file); - - // Add SIGNED profile to result list - result.add(profile); - return super.visitFile(file, attrs); - } - } - public static class LaunchServerDirectories { - public static final String UPDATES_NAME = "updates", PROFILES_NAME = "profiles", + 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"; public Path updatesDir; - public Path profilesDir; public Path librariesDir; public Path launcherLibrariesDir; public Path launcherLibrariesCompileDir; @@ -513,7 +477,6 @@ public static class LaunchServerDirectories { public void collect() { if (updatesDir == null) updatesDir = getPath(UPDATES_NAME); - if (profilesDir == null) profilesDir = getPath(PROFILES_NAME); if (trustStore == null) trustStore = getPath(TRUSTSTORE_NAME); if (launcherLibrariesDir == null) launcherLibrariesDir = getPath(LAUNCHERLIBRARIES_NAME); if (launcherLibrariesCompileDir == null) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 16542fb6..ac26c218 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -13,6 +13,7 @@ import pro.gravit.launchserver.auth.core.AuthCoreProvider; import pro.gravit.launchserver.auth.mix.MixProvider; import pro.gravit.launchserver.auth.password.PasswordVerifier; +import pro.gravit.launchserver.auth.profiles.ProfileProvider; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.texture.TextureProvider; import pro.gravit.launchserver.components.Component; @@ -178,6 +179,7 @@ public static void registerAll() { OptionalAction.registerProviders(); OptionalTrigger.registerProviders(); MixProvider.registerProviders(); + ProfileProvider.registerProviders(); } private static void printExperimentalBranch() { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java new file mode 100644 index 00000000..6fe18d54 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java @@ -0,0 +1,93 @@ +package pro.gravit.launchserver.auth.profiles; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.utils.helper.IOHelper; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.IOException; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; +import java.util.*; + +public class LocalProfileProvider extends ProfileProvider { + public String profilesDir = "profiles"; + private transient volatile Map profilesMap; + private transient volatile Set profilesList; // Cache + @Override + public void sync() throws IOException { + Path profilesDirPath = Path.of(profilesDir); + if (!IOHelper.isDir(profilesDirPath)) + Files.createDirectory(profilesDirPath); + Map newProfiles = new HashMap<>(); + IOHelper.walk(profilesDirPath, new ProfilesFileVisitor(newProfiles), false); + Set newProfilesList = new HashSet<>(newProfiles.values()); + profilesMap = newProfiles; + profilesList = newProfilesList; + } + + @Override + public Set getProfiles() { + return profilesList; + } + + @Override + public void addProfile(ClientProfile profile) throws IOException { + Path profilesDirPath = Path.of(profilesDir); + Path target = IOHelper.resolveIncremental(profilesDirPath, + profile.getDir(), "json"); + try (BufferedWriter writer = IOHelper.newWriter(target)) { + Launcher.gsonManager.configGson.toJson(profile, writer); + } + addProfile(target, profile); + } + + @Override + public void deleteProfile(ClientProfile profile) throws IOException { + for(var e : profilesMap.entrySet()) { + if(e.getValue().getUUID().equals(profile.getUUID())) { + Files.deleteIfExists(e.getKey()); + profilesMap.remove(e.getKey()); + profilesList.remove(e.getValue()); + break; + } + } + } + + private void addProfile(Path path, ClientProfile profile) { + profilesMap.put(path, profile); + profilesList.add(profile); + } + + private static final class ProfilesFileVisitor extends SimpleFileVisitor { + private final Map result; + private final Logger logger = LogManager.getLogger(); + + private ProfilesFileVisitor(Map result) { + this.result = result; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + logger.info("Syncing '{}' profile", IOHelper.getFileName(file)); + + // Read profile + ClientProfile profile; + try (BufferedReader reader = IOHelper.newReader(file)) { + profile = Launcher.gsonManager.gson.fromJson(reader, ClientProfile.class); + } + profile.verify(); + profile.setProfileFilePath(file); + + // Add SIGNED profile to result list + result.put(file, profile); + return super.visitFile(file, attrs); + } + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/ProfileProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/ProfileProvider.java new file mode 100644 index 00000000..b5580021 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/ProfileProvider.java @@ -0,0 +1,76 @@ +package pro.gravit.launchserver.auth.profiles; + +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.utils.ProviderMap; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; +import java.util.UUID; + +public abstract class ProfileProvider { + public static final ProviderMap providers = new ProviderMap<>("ProfileProvider"); + private static boolean registredProviders = false; + protected transient LaunchServer server; + + public static void registerProviders() { + if (!registredProviders) { + providers.register("local", LocalProfileProvider.class); + registredProviders = true; + } + } + + public void init(LaunchServer server) { + this.server = server; + } + + public abstract void sync() throws IOException; + + public abstract Set getProfiles(); + + public abstract void addProfile(ClientProfile profile) throws IOException; + + public abstract void deleteProfile(ClientProfile profile) throws IOException; + + public void close() { + + } + + public ClientProfile getProfile(UUID uuid) { + for(var e : getProfiles()) { + if(e.getUUID().equals(uuid)) { + return e; + } + } + return null; + } + + public ClientProfile getProfile(String title) { + for(var e : getProfiles()) { + if(e.getTitle().equals(title)) { + return e; + } + } + return null; + } + + public List getProfiles(Client client) { + List profileList; + Set serverProfiles = getProfiles(); + if (server.config.protectHandler instanceof ProfilesProtectHandler protectHandler) { + profileList = new ArrayList<>(4); + for (ClientProfile profile : serverProfiles) { + if (protectHandler.canGetProfile(profile, client)) { + profileList.add(profile); + } + } + } else { + profileList = List.copyOf(serverProfiles); + } + return profileList; + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java index 9da32e9c..3b331e25 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadClientCommand.java @@ -97,10 +97,7 @@ public void invoke(String... args) throws IOException, CommandException { isMirrorClientDownload = true; } } - try (BufferedWriter writer = IOHelper.newWriter(IOHelper.resolveIncremental(server.profilesDir, - dirName, "json"))) { - Launcher.gsonManager.configGson.toJson(clientProfile, writer); - } + server.config.profileProvider.addProfile(clientProfile); // Finished server.syncProfilesDir(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/CloneProfileCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/CloneProfileCommand.java index e943aa05..1b33cd43 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/CloneProfileCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/CloneProfileCommand.java @@ -7,6 +7,7 @@ import pro.gravit.launcher.base.profiles.ClientProfileBuilder; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.IOHelper; import java.io.IOException; @@ -26,7 +27,7 @@ public CloneProfileCommand(LaunchServer server) { @Override public String getArgsDescription() { - return "[profile file name] [new profile title]"; + return "[profile title/uuid] [new profile title]"; } @Override @@ -37,13 +38,12 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { verifyArgs(args, 2); - var profilePath = server.profilesDir.resolve(args[0].concat(".json")); - if(!Files.exists(profilePath)) { - logger.error("File {} not found", profilePath); - } ClientProfile profile; - try(Reader reader = IOHelper.newReader(profilePath)) { - profile = Launcher.gsonManager.gson.fromJson(reader, ClientProfile.class); + try { + UUID uuid = UUID.fromString(args[0]); + profile = server.config.profileProvider.getProfile(uuid); + } catch (IllegalArgumentException ex) { + profile = server.config.profileProvider.getProfile(args[0]); } var builder = new ClientProfileBuilder(profile); builder.setTitle(args[1]); @@ -65,10 +65,7 @@ public void invoke(String... args) throws Exception { } builder.setDir(args[1]); profile = builder.createClientProfile(); - var targetPath = server.profilesDir.resolve(args[1].concat(".json")); - try(Writer writer = IOHelper.newWriter(targetPath)) { - Launcher.gsonManager.gson.toJson(profile, writer); - } + server.config.profileProvider.addProfile(profile); logger.info("Profile {} cloned from {}", args[1], args[0]); server.syncProfilesDir(); server.syncUpdatesDir(List.of(args[1])); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/DeleteProfileCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/DeleteProfileCommand.java index 642a115c..034d791b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/DeleteProfileCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/DeleteProfileCommand.java @@ -8,6 +8,7 @@ import pro.gravit.utils.helper.IOHelper; import java.nio.file.Files; +import java.util.UUID; public class DeleteProfileCommand extends Command { private final transient Logger logger = LogManager.getLogger(ListProfilesCommand.class); @@ -28,12 +29,12 @@ public String getUsageDescription() { @Override public void invoke(String... args) throws Exception { verifyArgs(args, 1); - ClientProfile profile = null; - for(var p : server.getProfiles()) { - if(p.getUUID().toString().equals(args[0]) || p.getTitle().equals(args[0])) { - profile = p; - break; - } + ClientProfile profile; + try { + UUID uuid = UUID.fromString(args[0]); + profile = server.config.profileProvider.getProfile(uuid); + } catch (IllegalArgumentException ex) { + profile = server.config.profileProvider.getProfile(args[0]); } if(profile == null) { logger.error("Profile {} not found", args[0]); @@ -44,13 +45,9 @@ public void invoke(String... args) throws Exception { if(!showApplyDialog("Continue?")) { return; } + logger.info("Delete {} ({})", profile.getTitle(), profile.getUUID()); + server.config.profileProvider.deleteProfile(profile); logger.info("Delete {}", clientDir); IOHelper.deleteDir(clientDir, true); - var profileFile = profile.getProfileFilePath(); - if(profileFile == null) { - profileFile = server.profilesDir.resolve(profile.getTitle().concat(".json")); - } - logger.info("Delete {}", profileFile); - Files.deleteIfExists(profileFile); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/MakeProfileCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/MakeProfileCommand.java index ad57670c..7a010c64 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/MakeProfileCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/MakeProfileCommand.java @@ -37,9 +37,7 @@ public void invoke(String... args) throws Exception { logger.info("Detected option {}", option); } ClientProfile profile = MakeProfileHelper.makeProfile(version, args[0], options); - try (Writer writer = IOHelper.newWriter(server.profilesDir.resolve(args[0].concat(".json")))) { - Launcher.gsonManager.configGson.toJson(profile, writer); - } + server.config.profileProvider.addProfile(profile); logger.info("Profile {} created", args[0]); server.syncProfilesDir(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java index 7aba43a4..ab677c9c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java @@ -22,20 +22,6 @@ public SaveProfilesCommand(LaunchServer server) { super(server); } - public static void saveProfile(ClientProfile profile, Path path) throws IOException { - if (profile.getServers().isEmpty()) { - ClientProfile.ServerProfile serverProfile = new ClientProfile.ServerProfile(); - serverProfile.isDefault = true; - serverProfile.name = profile.getTitle(); - serverProfile.serverAddress = profile.getServerAddress(); - serverProfile.serverPort = profile.getServerPort(); - profile.getServers().add(serverProfile); - } - try (Writer w = IOHelper.newWriter(path)) { - Launcher.gsonManager.configGson.toJson(profile, w); - } - } - @Override public String getArgsDescription() { return "[profile names...]"; @@ -51,17 +37,15 @@ public void invoke(String... args) throws Exception { verifyArgs(args, 1); if (args.length > 0) { for (String profileName : args) { - Path profilePath = server.profilesDir.resolve(profileName.concat(".json")); - if (!Files.exists(profilePath)) { - logger.error("Profile {} not found", profilePath.toString()); - return; - } ClientProfile profile; - try (Reader reader = IOHelper.newReader(profilePath)) { - profile = Launcher.gsonManager.configGson.fromJson(reader, ClientProfile.class); + try { + UUID uuid = UUID.fromString(profileName); + profile = server.config.profileProvider.getProfile(uuid); + } catch (IllegalArgumentException ex) { + profile = server.config.profileProvider.getProfile(profileName); } - saveProfile(profile, profilePath); - logger.info("Profile {} save successful", profilePath.toString()); + server.config.profileProvider.deleteProfile(profile); + server.config.profileProvider.addProfile(profile); } server.syncProfilesDir(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java index ecba3a95..562460c7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -9,6 +9,8 @@ import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.RejectAuthCoreProvider; +import pro.gravit.launchserver.auth.profiles.LocalProfileProvider; +import pro.gravit.launchserver.auth.profiles.ProfileProvider; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.protect.StdProtectHandler; import pro.gravit.launchserver.auth.texture.RequestTextureProvider; @@ -36,6 +38,7 @@ public final class LaunchServerConfig { // Handlers & Providers public ProtectHandler protectHandler; public Map components; + public ProfileProvider profileProvider = new LocalProfileProvider(); public NettyConfig netty; public LauncherConf launcher; public JarSignerConf sign; @@ -85,6 +88,7 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { newConfig.components.put("authLimiter", authLimiterComponent); ProGuardComponent proGuardComponent = new ProGuardComponent(); newConfig.components.put("proguard", proGuardComponent); + newConfig.profileProvider = new LocalProfileProvider(); return newConfig; } @@ -166,6 +170,10 @@ public void init(LaunchServer.ReloadType type) { server.registerObject("protectHandler", protectHandler); protectHandler.init(server); } + if(profileProvider != null) { + server.registerObject("profileProvider", profileProvider); + profileProvider.init(server); + } if (components != null) { components.forEach((k, v) -> server.registerObject("component.".concat(k), v)); } @@ -206,6 +214,10 @@ public void close(LaunchServer.ReloadType type) { server.unregisterObject("protectHandler", protectHandler); protectHandler.close(); } + if(profileProvider != null) { + server.unregisterObject("profileProvider", profileProvider); + profileProvider.close(); + } } public static class JarSignerConf { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java index 7f26c486..74a6ba98 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -14,6 +14,7 @@ import pro.gravit.launchserver.auth.core.AuthCoreProvider; import pro.gravit.launchserver.auth.mix.MixProvider; import pro.gravit.launchserver.auth.password.PasswordVerifier; +import pro.gravit.launchserver.auth.profiles.ProfileProvider; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.texture.TextureProvider; import pro.gravit.launchserver.components.Component; @@ -46,6 +47,7 @@ public void registerAdapters(GsonBuilder builder) { builder.registerTypeAdapter(OptionalAction.class, new UniversalJsonAdapter<>(OptionalAction.providers)); builder.registerTypeAdapter(OptionalTrigger.class, new UniversalJsonAdapter<>(OptionalTrigger.providers)); builder.registerTypeAdapter(MixProvider.class, new UniversalJsonAdapter<>(MixProvider.providers)); + builder.registerTypeAdapter(ProfileProvider.class, new UniversalJsonAdapter<>(ProfileProvider.providers)); modulesManager.invokeEvent(new PreGsonPhase(builder)); //ClientWebSocketService.appendTypeAdapters(builder); } From af2dcec8cd77f0ad45dbb970882fc5f9229bb982 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Thu, 25 Jul 2024 22:28:26 +0700 Subject: [PATCH 33/33] [FIX] ProfileProvider support overwrite profile --- .../auth/profiles/LocalProfileProvider.java | 32 ++++++++++++++----- .../command/profiles/SaveProfilesCommand.java | 1 - .../launcher/base/profiles/ClientProfile.java | 9 ------ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java index 6fe18d54..5c3725ea 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/profiles/LocalProfileProvider.java @@ -9,10 +9,7 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; -import java.nio.file.FileVisitResult; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.SimpleFileVisitor; +import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.*; @@ -40,8 +37,21 @@ public Set getProfiles() { @Override public void addProfile(ClientProfile profile) throws IOException { Path profilesDirPath = Path.of(profilesDir); - Path target = IOHelper.resolveIncremental(profilesDirPath, - profile.getDir(), "json"); + ClientProfile oldProfile; + Path target = null; + for(var e : profilesMap.entrySet()) { + if(e.getValue().getUUID().equals(profile.getUUID())) { + target = e.getKey(); + } + } + if(target == null) { + target = IOHelper.resolveIncremental(profilesDirPath, + profile.getTitle(), "json"); + oldProfile = profilesMap.get(target); + if(oldProfile != null && !oldProfile.getUUID().equals(profile.getUUID())) { + throw new FileAlreadyExistsException(target.toString()); + } + } try (BufferedWriter writer = IOHelper.newWriter(target)) { Launcher.gsonManager.configGson.toJson(profile, writer); } @@ -61,6 +71,13 @@ public void deleteProfile(ClientProfile profile) throws IOException { } private void addProfile(Path path, ClientProfile profile) { + for(var e : profilesMap.entrySet()) { + if(e.getValue().getUUID().equals(profile.getUUID())) { + profilesMap.remove(e.getKey()); + profilesList.remove(e.getValue()); + break; + } + } profilesMap.put(path, profile); profilesList.add(profile); } @@ -83,10 +100,9 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO profile = Launcher.gsonManager.gson.fromJson(reader, ClientProfile.class); } profile.verify(); - profile.setProfileFilePath(file); // Add SIGNED profile to result list - result.put(file, profile); + result.put(file.toAbsolutePath(), profile); return super.visitFile(file, attrs); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java index ab677c9c..9d796c1e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java @@ -44,7 +44,6 @@ public void invoke(String... args) throws Exception { } catch (IllegalArgumentException ex) { profile = server.config.profileProvider.getProfile(profileName); } - server.config.profileProvider.deleteProfile(profile); server.config.profileProvider.addProfile(profile); } server.syncProfilesDir(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java index 5d55896d..0e4bab59 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java @@ -18,7 +18,6 @@ public final class ClientProfile implements Comparable { private static final FileNameMatcher ASSET_MATCHER = new FileNameMatcher( new String[0], new String[]{"indexes", "objects"}, new String[0]); - private transient Path profileFilePath; @LauncherNetworkAPI private String title; @LauncherNetworkAPI @@ -392,14 +391,6 @@ public List getFlags() { return flags; } - public Path getProfileFilePath() { - return profileFilePath; - } - - public void setProfileFilePath(Path profileFilePath) { - this.profileFilePath = profileFilePath; - } - public enum ClassLoaderConfig { AGENT, LAUNCHER, MODULE, SYSTEM_ARGS }