diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index e432fedc..00c8687f 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -26,6 +26,8 @@ jobs: - name: Build with Gradle run: ./gradlew build + - name: Generate and submit dependency graph + uses: gradle/actions/dependency-submission@417ae3ccd767c252f5661f1ace9f835f9654f2b5 - name: Create artifacts run: | diff --git a/LaunchServer/build.gradle b/LaunchServer/build.gradle index b522f651..6743d5ec 100644 --- a/LaunchServer/build.gradle +++ b/LaunchServer/build.gradle @@ -1,4 +1,4 @@ -def mainClassName = "pro.gravit.launchserver.LaunchServerStarter" +def mainClassName = "pro.gravit.launchserver.Main" def mainAgentName = "pro.gravit.launchserver.StarterAgent" evaluationDependsOn(':Launcher') @@ -37,9 +37,6 @@ manifest.attributes("Main-Class": mainClassName, "Premain-Class": mainAgentName, "Multi-Release": "true", - "Can-Redefine-Classes": "true", - "Can-Retransform-Classes": "true", - "Can-Set-Native-Method-Prefix": "true" ) } @@ -65,9 +62,7 @@ archiveClassifier.set('clean') manifest.attributes("Main-Class": mainClassName, "Premain-Class": mainAgentName, - "Can-Redefine-Classes": "true", - "Can-Retransform-Classes": "true", - "Can-Set-Native-Method-Prefix": "true" + "Automatic-Module-Name": "launchserver" ) from sourceSets.main.output } @@ -75,7 +70,6 @@ dependencies { pack project(':LauncherAPI') - pack project(':LauncherModernCore') bundle group: 'me.tongfei', name: 'progressbar', version: '0.9.2' bundle group: 'com.github.Marcono1234', name: 'gson-record-type-adapter-factory', version: 'v0.2.0' bundle group: 'org.fusesource.jansi', name: 'jansi', version: rootProject['verJansi'] @@ -84,13 +78,15 @@ pack project(':LauncherModernCore') bundle group: 'org.jline', name: 'jline-terminal', version: rootProject['verJline'] bundle group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: rootProject['verBcpkix'] bundle group: 'org.ow2.asm', name: 'asm-commons', version: rootProject['verAsm'] - bundle group: 'io.netty', name: 'netty-all', version: rootProject['verNetty'] + 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: 'org.slf4j', name: 'slf4j-api', version: rootProject['verSlf4j'] bundle group: 'com.mysql', name: 'mysql-connector-j', version: rootProject['verMySQLConn'] bundle group: 'org.postgresql', name: 'postgresql', version: rootProject['verPostgreSQLConn'] 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-slf4j-impl', 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'] bundle group: 'io.jsonwebtoken', name: 'jjwt-impl', version: rootProject['verJwt'] bundle group: 'io.jsonwebtoken', name: 'jjwt-gson', version: rootProject['verJwt'] @@ -104,16 +100,6 @@ pack project(':LauncherModernCore') exclude group: 'org.slf4j' } - launch4j('net.sf.launch4j:launch4j:' + rootProject['verLaunch4j']) { - exclude group: 'org.apache.ant' - exclude group: 'net.java.abeille' - exclude group: 'foxtrot' - exclude group: 'com.jgoodies' - exclude group: 'org.slf4j' - } - launch4j('net.sf.launch4j:launch4j:' + rootProject['verLaunch4j'] + ':workdir-win32') { transitive = false } - launch4j('net.sf.launch4j:launch4j:' + rootProject['verLaunch4j'] + ':workdir-linux64') { transitive = false } - compileOnlyA group: 'com.google.guava', name: 'guava', version: rootProject['verGuavaC'] // Do not update (laggy deps). compileOnlyA 'log4j:log4j:1.2.17' @@ -126,27 +112,9 @@ pack project(':LauncherModernCore') from configurations.hikari } -tasks.register('launch4j', Copy) { - duplicatesStrategy = 'EXCLUDE' - into "$buildDir/libs/libraries/launch4j" - from(configurations.launch4j.collect { - it.isDirectory() ? it : ((it.getName().startsWith("launch4j") && it.getName().contains("workdir")) ? zipTree(it) : it) - }) - includeEmptyDirs false - eachFile { FileCopyDetails fcp -> - if (fcp.relativePath.pathString.startsWith("launch4j-") && - fcp.relativePath.pathString.contains("workdir")) { - def segments = fcp.relativePath.segments - def pathSegments = segments[1..-1] as String[] - fcp.relativePath = new RelativePath(!fcp.file.isDirectory(), pathSegments) - } else if (fcp.relativePath.pathString.contains("META-INF")) fcp.exclude() - fcp.mode = 0755 - } -} - tasks.register('dumpLibs', Copy) { duplicatesStrategy = 'EXCLUDE' - dependsOn tasks.hikari, tasks.launch4j + dependsOn tasks.hikari into "$buildDir/libs/libraries" from configurations.bundleOnly } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/HttpRequester.java b/LaunchServer/src/main/java/pro/gravit/launchserver/HttpRequester.java index 9bac27ff..fac90dfb 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/HttpRequester.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/HttpRequester.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver; import com.google.gson.JsonElement; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.launchserver.helper.HttpHelper; import java.io.IOException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index d016db56..d3a435ea 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -2,15 +2,13 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.events.request.ProfilesRequestEvent; -import pro.gravit.launcher.managers.ConfigManager; -import pro.gravit.launcher.modules.events.ClosePhase; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.events.request.ProfilesRequestEvent; +import pro.gravit.launcher.base.modules.events.ClosePhase; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.RejectAuthCoreProvider; -import pro.gravit.launchserver.binary.EXEL4JLauncherBinary; import pro.gravit.launchserver.binary.EXELauncherBinary; import pro.gravit.launchserver.binary.JARLauncherBinary; import pro.gravit.launchserver.binary.LauncherBinary; @@ -36,7 +34,6 @@ import java.io.BufferedReader; import java.io.IOException; -import java.lang.ProcessBuilder.Redirect; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.security.KeyStore; @@ -117,11 +114,12 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab public final AtomicBoolean started = new AtomicBoolean(false); public final LauncherModuleLoader launcherModuleLoader; 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) throws IOException { + 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; this.tmpDir = directories.tmpDir; this.env = env; @@ -138,6 +136,7 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La launcherLibraries = directories.launcherLibrariesDir; launcherLibrariesCompile = directories.launcherLibrariesCompileDir; launcherPack = directories.launcherPackDir; + this.shardId = shardId; if(!Files.isDirectory(launcherPack)) { Files.createDirectories(launcherPack); } @@ -268,7 +267,7 @@ public void invoke(String... args) throws Exception { } pair.core.close(); pair.core = new RejectAuthCoreProvider(); - pair.core.init(instance); + pair.core.init(instance, pair); } }; commands.put("resetauth", resetauth); @@ -300,12 +299,6 @@ private LauncherBinary binary() { if(event.binary != null) { return event.binary; } - try { - Class.forName("net.sf.launch4j.Builder"); - if (config.launch4j.enabled) return new EXEL4JLauncherBinary(this); - } catch (ClassNotFoundException ignored) { - logger.warn("Launch4J isn't in classpath."); - } return new EXELauncherBinary(this); } @@ -393,7 +386,7 @@ public void syncLauncherBinaries() throws IOException { // Syncing launcher EXE binary logger.info("Syncing launcher EXE binary file"); - if (!launcherEXEBinary.sync() && config.launch4j.enabled) + if (!launcherEXEBinary.sync()) logger.warn("Missing launcher EXE binary file"); } @@ -430,21 +423,6 @@ public void syncUpdatesDir(Collection dirs) throws IOException { updatesManager.syncUpdatesDir(dirs); } - public void restart() { - ProcessBuilder builder = new ProcessBuilder(); - if (config.startScript != null) builder.command(Collections.singletonList(config.startScript)); - else throw new IllegalArgumentException("Please create start script and link it as startScript in config."); - builder.directory(this.dir.toFile()); - builder.inheritIO(); - builder.redirectErrorStream(true); - builder.redirectOutput(Redirect.PIPE); - try { - builder.start(); - } catch (IOException e) { - logger.error("Restart failed", e); - } - } - public void registerObject(String name, Object object) { if (object instanceof Reconfigurable) { reconfigurableManager.registerReconfigurable(name, (Reconfigurable) object); @@ -457,11 +435,6 @@ public void unregisterObject(String name, Object object) { } } - public void fullyRestart() { - restart(); - JVMHelper.RUNTIME.exit(0); - } - public enum ReloadType { NO_AUTH, @@ -504,6 +477,7 @@ 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.add(profile); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java index 20d32a2c..3082eecf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerBuilder.java @@ -19,6 +19,7 @@ public class LaunchServerBuilder { private KeyAgreementManager keyAgreementManager; private CertificateManager certificateManager; private LaunchServer.LaunchServerConfigManager launchServerConfigManager; + private Integer shardId; public LaunchServerBuilder setConfig(LaunchServerConfig config) { this.config = config; @@ -55,6 +56,11 @@ public LaunchServerBuilder setDir(Path dir) { return this; } + public LaunchServerBuilder setShardId(Integer shardId) { + this.shardId = shardId; + return this; + } + public LaunchServerBuilder setLaunchServerConfigManager(LaunchServer.LaunchServerConfigManager launchServerConfigManager) { this.launchServerConfigManager = launchServerConfigManager; return this; @@ -63,32 +69,15 @@ public LaunchServerBuilder setLaunchServerConfigManager(LaunchServer.LaunchServe public LaunchServer build() throws Exception { directories.collect(); if (launchServerConfigManager == null) { - launchServerConfigManager = new LaunchServer.LaunchServerConfigManager() { - @Override - public LaunchServerConfig readConfig() { - throw new UnsupportedOperationException(); - } - - @Override - public LaunchServerRuntimeConfig readRuntimeConfig() { - throw new UnsupportedOperationException(); - } - - @Override - public void writeConfig(LaunchServerConfig config) { - throw new UnsupportedOperationException(); - } - - @Override - public void writeRuntimeConfig(LaunchServerRuntimeConfig config) { - throw new UnsupportedOperationException(); - } - }; + launchServerConfigManager = new NullLaunchServerConfigManager(); } if (keyAgreementManager == null) { keyAgreementManager = new KeyAgreementManager(directories.keyDirectory); } - return new LaunchServer(directories, env, config, runtimeConfig, launchServerConfigManager, modulesManager, keyAgreementManager, commandHandler, certificateManager); + if(shardId == null) { + shardId = Integer.parseInt(System.getProperty("launchserver.shardId", "0")); + } + return new LaunchServer(directories, env, config, runtimeConfig, launchServerConfigManager, modulesManager, keyAgreementManager, commandHandler, certificateManager, shardId); } public LaunchServerBuilder setCertificateManager(CertificateManager certificateManager) { @@ -99,4 +88,26 @@ public LaunchServerBuilder setCertificateManager(CertificateManager certificateM public void setKeyAgreementManager(KeyAgreementManager keyAgreementManager) { this.keyAgreementManager = keyAgreementManager; } + + private static class NullLaunchServerConfigManager implements LaunchServer.LaunchServerConfigManager { + @Override + public LaunchServerConfig readConfig() { + throw new UnsupportedOperationException(); + } + + @Override + public LaunchServerRuntimeConfig readRuntimeConfig() { + throw new UnsupportedOperationException(); + } + + @Override + public void writeConfig(LaunchServerConfig config) { + throw new UnsupportedOperationException(); + } + + @Override + public void writeRuntimeConfig(LaunchServerRuntimeConfig config) { + throw new UnsupportedOperationException(); + } + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java index 19b7b01d..addab8f3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServerStarter.java @@ -3,13 +3,13 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bouncycastle.jce.provider.BouncyCastleProvider; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherTrustManager; -import pro.gravit.launcher.modules.events.PreConfigPhase; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; -import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.modules.events.PreConfigPhase; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.optional.triggers.OptionalTrigger; +import pro.gravit.launcher.base.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.GetAvailabilityAuthRequest; import pro.gravit.launchserver.auth.core.AuthCoreProvider; import pro.gravit.launchserver.auth.mix.MixProvider; import pro.gravit.launchserver.auth.password.PasswordVerifier; @@ -42,15 +42,10 @@ public class LaunchServerStarter { private static final Logger logger = LogManager.getLogger(); public static void main(String[] args) throws Exception { - JVMHelper.checkStackTrace(LaunchServerStarter.class); - JVMHelper.verifySystemProperties(LaunchServer.class, true); + JVMHelper.verifySystemProperties(LaunchServer.class, false); //LogHelper.addOutput(IOHelper.WORKING_DIR.resolve("LaunchServer.log")); LogHelper.printVersion("LaunchServer"); LogHelper.printLicense("LaunchServer"); - if (!StarterAgent.isAgentStarted()) { - LogHelper.error("StarterAgent is not started!"); - LogHelper.error("You should add to JVM options this option: `-javaagent:LaunchServer.jar`"); - } Path dir = IOHelper.WORKING_DIR; Path configFile, runtimeConfigFile; try { @@ -127,57 +122,7 @@ public static void main(String[] args) throws Exception { } } - LaunchServer.LaunchServerConfigManager launchServerConfigManager = new LaunchServer.LaunchServerConfigManager() { - @Override - public LaunchServerConfig readConfig() throws IOException { - LaunchServerConfig config1; - try (BufferedReader reader = IOHelper.newReader(configFile)) { - config1 = Launcher.gsonManager.gson.fromJson(reader, LaunchServerConfig.class); - } - return config1; - } - - @Override - public LaunchServerRuntimeConfig readRuntimeConfig() throws IOException { - LaunchServerRuntimeConfig config1; - try (BufferedReader reader = IOHelper.newReader(runtimeConfigFile)) { - config1 = Launcher.gsonManager.gson.fromJson(reader, LaunchServerRuntimeConfig.class); - } - return config1; - } - - @Override - public void writeConfig(LaunchServerConfig config) throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - try (Writer writer = IOHelper.newWriter(output)) { - if (Launcher.gsonManager.configGson != null) { - Launcher.gsonManager.configGson.toJson(config, writer); - } else { - logger.error("Error writing LaunchServer config file. Gson is null"); - } - } - byte[] bytes = output.toByteArray(); - if(bytes.length > 0) { - IOHelper.write(configFile, bytes); - } - } - - @Override - public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException { - ByteArrayOutputStream output = new ByteArrayOutputStream(); - try (Writer writer = IOHelper.newWriter(output)) { - if (Launcher.gsonManager.configGson != null) { - Launcher.gsonManager.configGson.toJson(config, writer); - } else { - logger.error("Error writing LaunchServer runtime config file. Gson is null"); - } - } - byte[] bytes = output.toByteArray(); - if(bytes.length > 0) { - IOHelper.write(runtimeConfigFile, bytes); - } - } - }; + LaunchServer.LaunchServerConfigManager launchServerConfigManager = new BasicLaunchServerConfigManager(configFile, runtimeConfigFile); LaunchServer.LaunchServerDirectories directories = new LaunchServer.LaunchServerDirectories(); directories.dir = dir; LaunchServer server = new LaunchServerBuilder() @@ -289,4 +234,64 @@ public static void generateConfigIfNotExists(Path configFile, CommandHandler com Launcher.gsonManager.configGson.toJson(newConfig, writer); } } + + private static class BasicLaunchServerConfigManager implements LaunchServer.LaunchServerConfigManager { + private final Path configFile; + private final Path runtimeConfigFile; + + public BasicLaunchServerConfigManager(Path configFile, Path runtimeConfigFile) { + this.configFile = configFile; + this.runtimeConfigFile = runtimeConfigFile; + } + + @Override + public LaunchServerConfig readConfig() throws IOException { + LaunchServerConfig config1; + try (BufferedReader reader = IOHelper.newReader(configFile)) { + config1 = Launcher.gsonManager.gson.fromJson(reader, LaunchServerConfig.class); + } + return config1; + } + + @Override + public LaunchServerRuntimeConfig readRuntimeConfig() throws IOException { + LaunchServerRuntimeConfig config1; + try (BufferedReader reader = IOHelper.newReader(runtimeConfigFile)) { + config1 = Launcher.gsonManager.gson.fromJson(reader, LaunchServerRuntimeConfig.class); + } + return config1; + } + + @Override + public void writeConfig(LaunchServerConfig config) throws IOException { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + try (Writer writer = IOHelper.newWriter(output)) { + if (Launcher.gsonManager.configGson != null) { + Launcher.gsonManager.configGson.toJson(config, writer); + } else { + logger.error("Error writing LaunchServer config file. Gson is null"); + } + } + byte[] bytes = output.toByteArray(); + if(bytes.length > 0) { + IOHelper.write(configFile, bytes); + } + } + + @Override + public void writeRuntimeConfig(LaunchServerRuntimeConfig config) throws IOException { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + try (Writer writer = IOHelper.newWriter(output)) { + if (Launcher.gsonManager.configGson != null) { + Launcher.gsonManager.configGson.toJson(config, writer); + } else { + logger.error("Error writing LaunchServer runtime config file. Gson is null"); + } + } + byte[] bytes = output.toByteArray(); + if(bytes.length > 0) { + IOHelper.write(runtimeConfigFile, bytes); + } + } + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java b/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java new file mode 100644 index 00000000..fc95cb72 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/Main.java @@ -0,0 +1,83 @@ +package pro.gravit.launchserver; + +import pro.gravit.launchserver.holder.LaunchServerControlHolder; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.launch.ClassLoaderControl; +import pro.gravit.utils.launch.LaunchOptions; +import pro.gravit.utils.launch.ModuleLaunch; + +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.FileVisitOption; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Stream; + +public class Main { + private static final List classpathOnly = List.of("proguard", "jline", "kotlin", "epoll"); + private static final String LOG4J_PROPERTY = "log4j2.configurationFile"; + private static boolean isClasspathOnly(Path path) { + var fileName = path.getFileName().toString(); + for(var e : classpathOnly) { + if(fileName.contains(e)) { + return true; + } + } + return false; + } + + private static void unpackLog4j() { + String log4jConfigurationFile = System.getProperty(LOG4J_PROPERTY); + if(log4jConfigurationFile == null) { + Path log4jConfigPath = Path.of("log4j2.xml"); + if(!Files.exists(log4jConfigPath)) { + try(FileOutputStream output = new FileOutputStream(log4jConfigPath.toFile())) { + try(InputStream input = Main.class.getResourceAsStream("/log4j2.xml")) { + if(input == null) { + return; + } + input.transferTo(output); + } + } catch (IOException e) { + throw new RuntimeException(e); + } + } + System.setProperty(LOG4J_PROPERTY, log4jConfigPath.toAbsolutePath().toString()); + } + } + + public static void main(String[] args) throws Throwable { + unpackLog4j(); + ModuleLaunch launch = new ModuleLaunch(); + LaunchOptions options = new LaunchOptions(); + options.moduleConf = new LaunchOptions.ModuleConf(); + List libraries; + try(Stream files = Files.walk(Path.of("libraries"), FileVisitOption.FOLLOW_LINKS)) { + libraries = new ArrayList<>(files.filter(e -> e.getFileName().toString().endsWith(".jar")).toList()); + } + List classpath = new ArrayList<>(); + List modulepath = new ArrayList<>(); + for(var l : libraries) { + if(isClasspathOnly(l)) { + classpath.add(l); + } else { + modulepath.add(l.toAbsolutePath().toString()); + } + } + classpath.add(IOHelper.getCodeSource(LaunchServerStarter.class)); + options.moduleConf.modulePath.addAll(modulepath); + options.moduleConf.modules.add("ALL-MODULE-PATH"); + ClassLoaderControl control = launch.init(classpath, "natives", options); + control.clearLauncherPackages(); + control.addLauncherPackage("pro.gravit.utils.launch"); + control.addLauncherPackage("pro.gravit.launchserver.holder"); + ModuleLayer.Controller controller = (ModuleLayer.Controller) control.getJava9ModuleController(); + LaunchServerControlHolder.setControl(control); + LaunchServerControlHolder.setController(controller); + launch.launch("pro.gravit.launchserver.LaunchServerStarter", null, Arrays.asList(args)); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java index a6edd6b3..484d754e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/StarterAgent.java @@ -1,13 +1,7 @@ package pro.gravit.launchserver; -import java.io.IOException; import java.lang.instrument.Instrumentation; import java.nio.file.*; -import java.nio.file.attribute.BasicFileAttributes; -import java.nio.file.attribute.PosixFileAttributeView; -import java.nio.file.attribute.PosixFilePermission; -import java.util.*; -import java.util.jar.JarFile; public final class StarterAgent { @@ -20,47 +14,6 @@ public static boolean isAgentStarted() { } public static void premain(String agentArgument, Instrumentation inst) { - StarterAgent.inst = inst; - libraries = Paths.get(Optional.ofNullable(agentArgument).map(String::trim).filter(e -> !e.isEmpty()).orElse("libraries")); - isStarted = true; - try { - Files.walkFileTree(libraries, Collections.singleton(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE, new StarterVisitor()); - } catch (IOException e) { - e.printStackTrace(System.err); - } - } - - private static final class StarterVisitor extends SimpleFileVisitor { - private static final Set DPERMS; - - static { - Set perms = new HashSet<>(Arrays.asList(PosixFilePermission.values())); - perms.remove(PosixFilePermission.OTHERS_WRITE); - perms.remove(PosixFilePermission.GROUP_WRITE); - DPERMS = Collections.unmodifiableSet(perms); - } - - private final boolean fixLib; - - private StarterVisitor() { - Path filef = StarterAgent.libraries.resolve(".libraries_chmoded"); - this.fixLib = !Files.exists(filef) && !Boolean.getBoolean("launcher.noLibrariesPosixPermsFix"); - if (fixLib) { - try { - Files.deleteIfExists(filef); - Files.createFile(filef); - } catch (Throwable ignored) { - } - } - } - - @Override - public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if (fixLib && Files.getFileAttributeView(file, PosixFileAttributeView.class) != null) - Files.setPosixFilePermissions(file, DPERMS); - if (file.toFile().getName().endsWith(".jar")) - inst.appendToSystemClassLoaderSearch(new JarFile(file.toFile())); - return super.visitFile(file, attrs); - } + throw new UnsupportedOperationException("Please remove -javaagent option from start.sh"); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java index c0e6d454..a673bbe0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/asm/InjectClassAcceptor.java @@ -4,8 +4,8 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.Type; import org.objectweb.asm.tree.*; -import pro.gravit.launcher.LauncherInject; -import pro.gravit.launcher.LauncherInjectionConstructor; +import pro.gravit.launcher.core.LauncherInject; +import pro.gravit.launcher.core.LauncherInjectionConstructor; import pro.gravit.launchserver.binary.BuildContext; import pro.gravit.launchserver.binary.tasks.MainBuildTask; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthException.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthException.java index 0fb5c766..e30f9842 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthException.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthException.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth; -import pro.gravit.launcher.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; import java.io.IOException; import java.io.Serial; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java index 9645fa01..5234718b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/AuthProviderPair.java @@ -57,7 +57,7 @@ public static void getFeatures(Class clazz, Set list) { } } - public final T isSupport(Class clazz) { + public T isSupport(Class clazz) { if (core == null) return null; T result = core.isSupport(clazz); if (result == null && mixes != null) { @@ -71,10 +71,10 @@ public final T isSupport(Class clazz) { return result; } - public final void init(LaunchServer srv, String name) { + public void init(LaunchServer srv, String name) { this.name = name; if (links != null) link(srv); - core.init(srv); + core.init(srv, this); features = new HashSet<>(); getFeatures(core.getClass(), features); if(mixes != null) { @@ -85,7 +85,7 @@ public final void init(LaunchServer srv, String name) { } } - public final void link(LaunchServer srv) { + public void link(LaunchServer srv) { links.forEach((k, v) -> { AuthProviderPair pair = srv.config.getAuthProviderPair(v); if (pair == null) { @@ -99,7 +99,7 @@ public final void link(LaunchServer srv) { }); } - public final void close() throws IOException { + public void close() throws IOException { core.close(); if (textureProvider != null) { textureProvider.close(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java index 274c6b85..857f9b7f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AbstractSQLCoreProvider.java @@ -4,13 +4,15 @@ import io.jsonwebtoken.JwtException; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.password.AuthPlainPassword; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.base.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.password.AuthPlainPassword; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.MySQLSourceConfig; import pro.gravit.launchserver.auth.SQLSourceConfig; +import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportSudo; import pro.gravit.launchserver.auth.password.PasswordVerifier; import pro.gravit.launchserver.helper.LegacySessionHelper; import pro.gravit.launchserver.manangers.AuthManager; @@ -32,7 +34,7 @@ import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.SECONDS; -public abstract class AbstractSQLCoreProvider extends AuthCoreProvider { +public abstract class AbstractSQLCoreProvider extends AuthCoreProvider implements AuthSupportSudo { public final transient Logger logger = LogManager.getLogger(); public long expireSeconds = HOURS.toSeconds(1); public String uuidColumn; @@ -66,7 +68,6 @@ public abstract class AbstractSQLCoreProvider extends AuthCoreProvider { public transient String updateAuthSQL; public transient String updateServerIDSQL; - public transient LaunchServer server; public abstract SQLSourceConfig getSQLConfig(); @@ -142,14 +143,12 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c if (user == null) { throw AuthException.userNotFound(); } - if (context != null) { - AuthPlainPassword plainPassword = (AuthPlainPassword) password; - if (plainPassword == null) { - throw AuthException.wrongPassword(); - } - if (!passwordVerifier.check(user.password, plainPassword.password)) { - throw AuthException.wrongPassword(); - } + AuthPlainPassword plainPassword = (AuthPlainPassword) password; + if (plainPassword == null) { + throw AuthException.wrongPassword(); + } + if (!passwordVerifier.check(user.password, plainPassword.password)) { + throw AuthException.wrongPassword(); } SQLUserSession session = createSession(user); var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(user, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey); @@ -163,6 +162,17 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c } } + @Override + public AuthManager.AuthReport sudo(User user, boolean shadow) throws IOException { + SQLUser sqlUser = (SQLUser) user; + SQLUserSession session = createSession(sqlUser); + var accessToken = LegacySessionHelper.makeAccessJwtTokenFromString(sqlUser, LocalDateTime.now(Clock.systemUTC()).plusSeconds(expireSeconds), server.keyAgreementManager.ecdsaPrivateKey); + var refreshToken = sqlUser.username.concat(".").concat(LegacySessionHelper.makeRefreshTokenFromPassword(sqlUser.username, sqlUser.password, server.keyAgreementManager.legacySalt)); + String minecraftAccessToken = SecurityHelper.randomStringToken(); + updateAuth(user, minecraftAccessToken); + return AuthManager.AuthReport.ofOAuthWithMinecraft(minecraftAccessToken, accessToken, refreshToken, SECONDS.toMillis(expireSeconds), session); + } + @Override public User checkServer(Client client, String username, String serverID) throws IOException { SQLUser user = (SQLUser) getUserByUsername(username); @@ -183,8 +193,8 @@ public boolean joinServer(Client client, String username, UUID uuid, String acce } @Override - public void init(LaunchServer server) { - this.server = server; + public void init(LaunchServer server, AuthProviderPair pair) { + super.init(server, pair); if (getSQLConfig() == null) logger.error("SQLHolder cannot be null"); if (uuidColumn == null) logger.error("uuidColumn cannot be null"); if (usernameColumn == null) logger.error("usernameColumn cannot be null"); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java index f1d8cf7d..b6e14d8d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/AuthCoreProvider.java @@ -3,19 +3,24 @@ import com.google.gson.reflect.TypeToken; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.details.AuthPasswordDetails; -import pro.gravit.launcher.request.auth.password.AuthPlainPassword; -import pro.gravit.launcher.request.secure.HardwareReportRequest; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; +import pro.gravit.launcher.base.profiles.PlayerProfile; +import pro.gravit.launcher.base.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.details.AuthPasswordDetails; +import pro.gravit.launcher.base.request.auth.password.AuthPlainPassword; +import pro.gravit.launcher.base.request.secure.HardwareReportRequest; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.Reconfigurable; import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportGetAllUsers; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportHardware; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportRegistration; +import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportSudo; import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.auth.AuthResponse; @@ -29,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.UUID; +import java.util.concurrent.atomic.AtomicBoolean; /* All-In-One provider @@ -37,6 +43,8 @@ public abstract class AuthCoreProvider implements AutoCloseable, Reconfigurable public static final ProviderMap providers = new ProviderMap<>("AuthCoreProvider"); private static final Logger logger = LogManager.getLogger(); private static boolean registredProviders = false; + protected transient LaunchServer server; + protected transient AuthProviderPair pair; public static void registerProviders() { if (!registredProviders) { @@ -71,7 +79,10 @@ public AuthManager.AuthReport authorize(User user, AuthResponse.AuthContext cont return authorize(user.getUsername(), context, password, minecraftAccess); } - public abstract void init(LaunchServer server); + public void init(LaunchServer server, AuthProviderPair pair) { + this.server = server; + this.pair = pair; + } public List getDetails(Client client) { return List.of(new AuthPasswordDetails()); @@ -260,6 +271,72 @@ public void invoke(String... args) throws Exception { }); } } + { + var instance = isSupport(AuthSupportSudo.class); + if(instance != null) { + map.put("sudo", new SubCommand("[connectUUID] [username/uuid] [isShadow] (CLIENT/API)", "Authorize connectUUID as another user without password") { + @Override + public void invoke(String... args) throws Exception { + verifyArgs(args, 3); + UUID connectUUID = UUID.fromString(args[0]); + String login = args[1]; + boolean isShadow = Boolean.parseBoolean(args[2]); + AuthResponse.ConnectTypes type; + if(args.length > 3) { + type = AuthResponse.ConnectTypes.valueOf(args[3]); + } else { + type = AuthResponse.ConnectTypes.CLIENT; + } + User user; + if(login.length() == 36) { + UUID uuid = UUID.fromString(login); + user = getUserByUUID(uuid); + } else { + user = getUserByUsername(login); + } + if(user == null) { + logger.error("User {} not found", login); + return; + } + AtomicBoolean founded = new AtomicBoolean(); + server.nettyServerSocketHandler.nettyServer.service.forEachActiveChannels((ch, fh) -> { + var client = fh.getClient(); + if(client == null || !connectUUID.equals(fh.getConnectUUID())) { + return; + } + logger.info("Found connectUUID {} with IP {}", fh.getConnectUUID(), fh.context == null ? "null" : fh.context.ip); + var lock = server.config.netty.performance.disableThreadSafeClientObject ? null : client.writeLock(); + if(lock != null) { + lock.lock(); + } + try { + var report = instance.sudo(user, isShadow); + User user1 = report.session().getUser(); + server.authManager.internalAuth(client, type, pair, user1.getUsername(), user1.getUUID(), user1.getPermissions(), true); + client.sessionObject = report.session(); + client.coreObject = report.session().getUser(); + PlayerProfile playerProfile = server.authManager.getPlayerProfile(client); + AuthRequestEvent request = new AuthRequestEvent(user1.getPermissions(), playerProfile, + report.minecraftAccessToken(), null, null, + new AuthRequestEvent.OAuthRequestEvent(report.oauthAccessToken(), report.oauthRefreshToken(), report.oauthExpire())); + request.requestUUID = RequestEvent.eventUUID; + server.nettyServerSocketHandler.nettyServer.service.sendObject(ch, request); + } catch (Throwable e) { + logger.error("Sudo error", e); + } finally { + if(lock != null) { + lock.unlock(); + } + founded.set(true); + } + }); + if(!founded.get()) { + logger.error("ConnectUUID {} not found", connectUUID); + } + } + }); + } + } return map; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MemoryAuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MemoryAuthCoreProvider.java index 01dc17ad..bae81df6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MemoryAuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MemoryAuthCoreProvider.java @@ -1,11 +1,11 @@ package pro.gravit.launchserver.auth.core; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.details.AuthLoginOnlyDetails; -import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; +import pro.gravit.launcher.base.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.details.AuthLoginOnlyDetails; import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportSudo; import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.auth.AuthResponse; @@ -18,7 +18,7 @@ import java.util.Objects; import java.util.UUID; -public class MemoryAuthCoreProvider extends AuthCoreProvider { +public class MemoryAuthCoreProvider extends AuthCoreProvider implements AuthSupportSudo { private transient final List memory = new ArrayList<>(16); @Override @@ -114,13 +114,13 @@ public boolean joinServer(Client client, String username, UUID uuid, String acce } @Override - public void init(LaunchServer server) { + public void close() { } @Override - public void close() { - + public AuthManager.AuthReport sudo(User user, boolean shadow) throws IOException { + return authorize(user.getUsername(), null, null, true); } public static class MemoryUser implements User { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java index fe0a26cc..e69eb086 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MergeAuthCoreProvider.java @@ -2,9 +2,10 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.AuthRequest; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; +import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.auth.AuthResponse; @@ -72,7 +73,7 @@ public boolean joinServer(Client client, String username, UUID uuid, String acce } @Override - public void init(LaunchServer server) { + public void init(LaunchServer server, AuthProviderPair pair1) { for(var e : list) { var pair = server.config.auth.get(e); if(pair != null) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java index ce093a2e..84c0ce3c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/MySQLCoreProvider.java @@ -1,8 +1,9 @@ package pro.gravit.launchserver.auth.core; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.request.secure.HardwareReportRequest; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.base.request.secure.HardwareReportRequest; import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.MySQLSourceConfig; import pro.gravit.launchserver.auth.SQLSourceConfig; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; @@ -41,8 +42,8 @@ public SQLSourceConfig getSQLConfig() { } @Override - public void init(LaunchServer server) { - super.init(server); + public void init(LaunchServer server, AuthProviderPair pair) { + super.init(server, pair); String userInfoCols = makeUserCols(); String hardwareInfoCols = "id, hwDiskId, baseboardSerialNumber, displayId, bitness, totalMemory, logicalProcessors, physicalProcessors, processorMaxFreq, battery, id, graphicCard, banned, publicKey"; if (sqlFindHardwareByPublicKey == null) @@ -332,7 +333,7 @@ public String toString() { } } - public class MySQLUser extends SQLUser { + public static class MySQLUser extends SQLUser { protected long hwidId; public MySQLUser(UUID uuid, String username, String accessToken, String serverId, String password, ClientPermissions permissions, long hwidId) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/RejectAuthCoreProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/RejectAuthCoreProvider.java index 0a95d12f..3358ad9b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/RejectAuthCoreProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/RejectAuthCoreProvider.java @@ -1,7 +1,6 @@ package pro.gravit.launchserver.auth.core; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launcher.base.request.auth.AuthRequest; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; @@ -41,11 +40,6 @@ public AuthManager.AuthReport authorize(String login, AuthResponse.AuthContext c throw new AuthException("Please configure AuthCoreProvider"); } - @Override - public void init(LaunchServer server) { - - } - @Override public User checkServer(Client client, String username, String serverID) throws IOException { return null; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/User.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/User.java index acf69db6..10e265f5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/User.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/User.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth.core; -import pro.gravit.launcher.ClientPermissions; +import pro.gravit.launcher.base.ClientPermissions; import java.util.UUID; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/UserHardware.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/UserHardware.java index 82934d0c..642836ab 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/UserHardware.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/UserHardware.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth.core.interfaces; -import pro.gravit.launcher.request.secure.HardwareReportRequest; +import pro.gravit.launcher.base.request.secure.HardwareReportRequest; public interface UserHardware { HardwareReportRequest.HardwareInfo getHardwareInfo(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java index f1978698..fe5a0cea 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportAssetUpload.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.auth.core.interfaces.provider; -import pro.gravit.launcher.events.request.AssetUploadInfoRequestEvent; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.events.request.GetAssetUploadUrlRequestEvent; +import pro.gravit.launcher.base.events.request.AssetUploadInfoRequestEvent; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.events.request.GetAssetUploadUrlRequestEvent; import pro.gravit.launchserver.auth.Feature; import pro.gravit.launchserver.auth.core.User; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java index fb188782..a0eb8365 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportExtendedCheckServer.java @@ -1,6 +1,5 @@ package pro.gravit.launchserver.auth.core.interfaces.provider; -import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.auth.core.UserSession; import pro.gravit.launchserver.socket.Client; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java index 943e4993..237a7aac 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportHardware.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth.core.interfaces.provider; -import pro.gravit.launcher.request.secure.HardwareReportRequest; +import pro.gravit.launcher.base.request.secure.HardwareReportRequest; import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.auth.core.UserSession; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRegistration.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRegistration.java index 6277ae2b..fbe098ad 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRegistration.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportRegistration.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth.core.interfaces.provider; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.AuthRequest; import pro.gravit.launchserver.auth.Feature; import pro.gravit.launchserver.auth.core.User; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportSudo.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportSudo.java new file mode 100644 index 00000000..377bbe7f --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/provider/AuthSupportSudo.java @@ -0,0 +1,10 @@ +package pro.gravit.launchserver.auth.core.interfaces.provider; + +import pro.gravit.launchserver.auth.core.User; +import pro.gravit.launchserver.manangers.AuthManager; + +import java.io.IOException; + +public interface AuthSupportSudo { + AuthManager.AuthReport sudo(User user, boolean shadow) throws IOException; +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportTextures.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportTextures.java index 214d759c..679c65e3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportTextures.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/core/interfaces/user/UserSupportTextures.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.auth.core.interfaces.user; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.Texture; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.Texture; import java.util.HashMap; import java.util.Map; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/mix/UploadAssetMixProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/mix/UploadAssetMixProvider.java index ef67994f..2e511a77 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/mix/UploadAssetMixProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/mix/UploadAssetMixProvider.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth.mix; -import pro.gravit.launcher.events.request.AssetUploadInfoRequestEvent; +import pro.gravit.launcher.base.events.request.AssetUploadInfoRequestEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.core.AuthCoreProvider; import pro.gravit.launchserver.auth.core.User; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/JsonPasswordVerifier.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/JsonPasswordVerifier.java index e43ae2a8..6b217028 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/JsonPasswordVerifier.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/password/JsonPasswordVerifier.java @@ -2,7 +2,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import java.io.InputStream; import java.io.InputStreamReader; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java index 83ce07e2..7bbc7930 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/AdvancedProtectHandler.java @@ -4,9 +4,9 @@ import io.jsonwebtoken.Jwts; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent; -import pro.gravit.launcher.events.request.HardwareReportRequestEvent; -import pro.gravit.launcher.events.request.VerifySecureLevelKeyRequestEvent; +import pro.gravit.launcher.base.events.request.GetSecureLevelInfoRequestEvent; +import pro.gravit.launcher.base.events.request.HardwareReportRequestEvent; +import pro.gravit.launcher.base.events.request.VerifySecureLevelKeyRequestEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; @@ -132,9 +132,9 @@ public static class HardwareInfoTokenVerifier implements RestoreResponse.Extende private final JwtParser parser; public HardwareInfoTokenVerifier(LaunchServer server) { - this.parser = Jwts.parserBuilder() + this.parser = Jwts.parser() .requireIssuer("LaunchServer") - .setSigningKey(server.keyAgreementManager.ecdsaPublicKey) + .verifyWith(server.keyAgreementManager.ecdsaPublicKey) .build(); } @@ -164,9 +164,9 @@ public static class PublicKeyTokenVerifier implements RestoreResponse.ExtendedTo private final JwtParser parser; public PublicKeyTokenVerifier(LaunchServer server) { - this.parser = Jwts.parserBuilder() + this.parser = Jwts.parser() .requireIssuer("LaunchServer") - .setSigningKey(server.keyAgreementManager.ecdsaPublicKey) + .verifyWith(server.keyAgreementManager.ecdsaPublicKey) .build(); } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java index 1b34b7ac..239857a7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/StdProtectHandler.java @@ -2,7 +2,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.profiles.ClientProfile; +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; @@ -22,7 +22,7 @@ public boolean allowGetAccessToken(AuthResponse.AuthContext context) { @Override public void init(LaunchServer server) { - if (profileWhitelist != null && profileWhitelist.size() > 0) { + if (profileWhitelist != null && !profileWhitelist.isEmpty()) { logger.warn("profileWhitelist deprecated. Please use permission 'launchserver.profile.PROFILE_UUID.show' and 'launchserver.profile.PROFILE_UUID.enter'"); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/ProfilesProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/ProfilesProtectHandler.java index 52f151b1..f2b2d325 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/ProfilesProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/ProfilesProtectHandler.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth.protect.interfaces; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.launchserver.socket.Client; public interface ProfilesProtectHandler { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java index 55444083..c5de4fd1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/protect/interfaces/SecureProtectHandler.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.auth.protect.interfaces; -import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent; -import pro.gravit.launcher.events.request.SecurityReportRequestEvent; -import pro.gravit.launcher.events.request.VerifySecureLevelKeyRequestEvent; +import pro.gravit.launcher.base.events.request.GetSecureLevelInfoRequestEvent; +import pro.gravit.launcher.base.events.request.SecurityReportRequestEvent; +import pro.gravit.launcher.base.events.request.VerifySecureLevelKeyRequestEvent; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.secure.SecurityReportResponse; import pro.gravit.utils.helper.SecurityHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/JsonTextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/JsonTextureProvider.java index 4f31c526..9a93022b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/JsonTextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/JsonTextureProvider.java @@ -3,7 +3,7 @@ import com.google.gson.reflect.TypeToken; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.profiles.Texture; +import pro.gravit.launcher.base.profiles.Texture; import pro.gravit.launchserver.HttpRequester; import pro.gravit.utils.helper.SecurityHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/NullTextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/NullTextureProvider.java index b5f785f1..2587a078 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/NullTextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/NullTextureProvider.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth.texture; -import pro.gravit.launcher.profiles.Texture; +import pro.gravit.launcher.base.profiles.Texture; import pro.gravit.utils.helper.VerifyHelper; import java.io.IOException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java index 4d8885b2..c40ff1ec 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/RequestTextureProvider.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.auth.texture; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.profiles.Texture; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.profiles.Texture; import pro.gravit.utils.helper.CommonHelper; import pro.gravit.utils.helper.IOHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java index 4519512a..d3cd82fd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/TextureProvider.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth.texture; -import pro.gravit.launcher.profiles.Texture; +import pro.gravit.launcher.base.profiles.Texture; import pro.gravit.utils.ProviderMap; import java.io.IOException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/VoidTextureProvider.java b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/VoidTextureProvider.java index ad3f3387..612ac9cf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/VoidTextureProvider.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/auth/texture/VoidTextureProvider.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.auth.texture; -import pro.gravit.launcher.profiles.Texture; +import pro.gravit.launcher.base.profiles.Texture; import java.util.UUID; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java index dec8e0e2..86fbf9c3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BinaryPipeline.java @@ -7,12 +7,10 @@ import pro.gravit.utils.helper.IOHelper; import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.concurrent.atomic.AtomicLong; import java.util.function.Predicate; import java.util.stream.Collectors; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java index 6d00a5cc..b00633f7 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/BuildContext.java @@ -2,9 +2,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.launcher.serialize.stream.StreamObject; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.core.serialize.HOutput; +import pro.gravit.launcher.core.serialize.stream.StreamObject; import pro.gravit.launchserver.binary.tasks.MainBuildTask; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.SecurityHelper; @@ -46,11 +46,14 @@ public class BuildContext { public final HashSet fileList; public final HashSet clientModules; public final HashSet legacyClientModules; + private Path runtimeDir; + private boolean deleteRuntimeDir; - public BuildContext(ZipOutputStream output, List readerClassPath, MainBuildTask task) { + public BuildContext(ZipOutputStream output, List readerClassPath, MainBuildTask task, Path runtimeDir) { this.output = output; this.readerClassPath = readerClassPath; this.task = task; + this.runtimeDir = runtimeDir; fileList = new HashSet<>(1024); clientModules = new HashSet<>(); legacyClientModules = new HashSet<>(); @@ -103,6 +106,14 @@ public void pushJarFile(Path jarfile, Predicate filter, Predicate filter, Predicate needTransform) throws IOException { try (ZipInputStream input = new ZipInputStream(IOHelper.newInput(jarfile))) { ZipEntry e = input.getNextEntry(); @@ -129,6 +140,16 @@ public void pushJarFile(URL jarfile, Predicate filter, Predicate { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java deleted file mode 100644 index 26a2b457..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/EXEL4JLauncherBinary.java +++ /dev/null @@ -1,17 +0,0 @@ -package pro.gravit.launchserver.binary; - -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.binary.tasks.exe.Launch4JTask; - -public final class EXEL4JLauncherBinary extends LauncherBinary { - - - public EXEL4JLauncherBinary(LaunchServer server) { - super(server, LauncherBinary.resolve(server, ".exe"), "Launcher-%s.exe"); - } - - @Override - public void init() { - tasks.add(new Launch4JTask(server)); - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java index b7bf3e0f..4a1d28b5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/JARLauncherBinary.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.binary; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.tasks.*; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java index 0d1f6e85..9475456f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/MainBuildTask.java @@ -8,8 +8,8 @@ import org.objectweb.asm.tree.AnnotationNode; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherConfig; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.LauncherConfig; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.asm.ClassMetadataReader; import pro.gravit.launchserver.asm.InjectClassAcceptor; @@ -53,7 +53,7 @@ public String getName() { public Path process(Path inputJar) throws IOException { Path outputJar = server.launcherBinary.nextPath(this); try (ZipOutputStream output = new ZipOutputStream(IOHelper.newOutput(outputJar))) { - BuildContext context = new BuildContext(output, reader.getCp(), this); + BuildContext context = new BuildContext(output, reader.getCp(), this, server.launcherBinary.runtimeDir); initProps(); preBuildHook.hook(context); properties.put("launcher.legacymodules", context.legacyClientModules.stream().map(e -> Type.getObjectType(e.replace('.', '/'))).collect(Collectors.toList())); @@ -69,9 +69,12 @@ public Path process(Path inputJar) throws IOException { Map runtime = new HashMap<>(256); // Write launcher guard dir if (server.config.launcher.encryptRuntime) { - context.pushEncryptedDir(server.launcherBinary.runtimeDir, Launcher.RUNTIME_DIR, server.runtime.runtimeEncryptKey, runtime, false); + context.pushEncryptedDir(context.getRuntimeDir(), Launcher.RUNTIME_DIR, server.runtime.runtimeEncryptKey, runtime, false); } else { - context.pushDir(server.launcherBinary.runtimeDir, Launcher.RUNTIME_DIR, runtime, false); + context.pushDir(context.getRuntimeDir(), Launcher.RUNTIME_DIR, runtime, false); + } + if(context.isDeleteRuntimeDir()) { + IOHelper.deleteDir(context.getRuntimeDir(), true); } LauncherConfig launcherConfig = new LauncherConfig(server.config.netty.address, server.keyAgreementManager.ecdsaPublicKey, server.keyAgreementManager.rsaPublicKey, runtime, server.config.projectName); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java b/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java deleted file mode 100644 index 400d529c..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/binary/tasks/exe/Launch4JTask.java +++ /dev/null @@ -1,125 +0,0 @@ -package pro.gravit.launchserver.binary.tasks.exe; - -import net.sf.launch4j.Builder; -import net.sf.launch4j.Log; -import net.sf.launch4j.config.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.binary.tasks.LauncherBuildTask; -import pro.gravit.utils.Version; -import pro.gravit.utils.helper.IOHelper; - -import java.io.IOException; -import java.nio.file.Path; - -public class Launch4JTask implements LauncherBuildTask, BuildExeMainTask { - public static final String DOWNLOAD_URL = "https://bell-sw.com/pages/downloads/?version=java-8-lts&os=Windows&package=jre-full"; // BellSoft - private static final String VERSION = Version.getVersion().getVersionString(); - private static final int BUILD = Version.getVersion().build; - private final Path faviconFile; - private final LaunchServer server; - private transient final Logger logger = LogManager.getLogger(); - - public Launch4JTask(LaunchServer launchServer) { - this.server = launchServer; - faviconFile = launchServer.dir.resolve("favicon.ico"); - } - - public static String formatVars(String mask) { - return mask.formatted(VERSION, BUILD); - } - - @Override - public String getName() { - return "launch4j"; - } - - @Override - public Path process(Path inputFile) throws IOException { - logger.info("Building launcher EXE binary file (Using Launch4J)"); - Path output = setConfig(); - - // Set favicon path - Config config = ConfigPersister.getInstance().getConfig(); - if (IOHelper.isFile(faviconFile)) - config.setIcon(faviconFile.toFile()); - else { - config.setIcon(null); - logger.warn("Missing favicon.ico file"); - } - - // Start building - Builder builder = new Builder(Launch4JLog.INSTANCE); - try { - builder.build(); - } catch (Throwable e) { - throw new IOException(e); - } - return output; - } - - private Path setConfig() { - Path path = server.launcherEXEBinary.nextPath(getName()); - Config config = new Config(); - // Set file options - config.setChdir("."); - config.setErrTitle("JVM Error"); - config.setDownloadUrl(server.config.launch4j.downloadUrl); - if (server.config.launch4j.supportURL != null) config.setSupportUrl(server.config.launch4j.supportURL); - // Set boolean options - config.setPriorityIndex(0); - config.setHeaderType(Config.GUI_HEADER); - config.setStayAlive(false); - config.setRestartOnCrash(false); - - // Prepare JRE - Jre jre = new Jre(); - jre.setMinVersion(server.config.launch4j.minVersion); - if (server.config.launch4j.setMaxVersion) - jre.setMaxVersion(server.config.launch4j.maxVersion); - jre.setPath(System.getProperty("java.home")); - config.setJre(jre); - - // Prepare version info (product) - VersionInfo info = new VersionInfo(); - info.setProductName(server.config.launch4j.productName); - info.setProductVersion(formatVars(server.config.launch4j.productVer)); - info.setFileDescription(server.config.launch4j.fileDesc); - info.setFileVersion(formatVars(server.config.launch4j.fileVer)); - info.setCopyright(server.config.launch4j.copyright); - info.setTrademarks(server.config.launch4j.trademarks); - info.setInternalName(formatVars(server.config.launch4j.internalName)); - // Prepare version info (file) - info.setTxtFileVersion(formatVars(server.config.launch4j.txtFileVersion)); - info.setTxtProductVersion(formatVars(server.config.launch4j.txtProductVersion)); - // Prepare version info (misc) - info.setOriginalFilename(path.getFileName().toString()); - info.setLanguage(LanguageID.RUSSIAN); - config.setVersionInfo(info); - - // Set JAR wrapping options - config.setDontWrapJar(false); - config.setJar(server.launcherBinary.syncBinaryFile.toFile()); - config.setOutfile(path.toFile()); - - // Return prepared config - ConfigPersister.getInstance().setAntConfig(config, null); - return path; - } - - private final static class Launch4JLog extends Log { - private static final Launch4JLog INSTANCE = new Launch4JLog(); - private static final Logger logger = LogManager.getLogger(); - - @Override - public void append(String s) { - logger.info(s); - } - - @Override - public void clear() { - // Do nothing - } - } -} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/Command.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/Command.java index b4f7f5a3..87d27f25 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/Command.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/Command.java @@ -3,9 +3,9 @@ import me.tongfei.progressbar.ProgressBar; import me.tongfei.progressbar.ProgressBarBuilder; import me.tongfei.progressbar.ProgressBarStyle; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.modern.Downloader; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.Downloader; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.launchserver.LaunchServer; import pro.gravit.utils.command.CommandException; @@ -47,6 +47,9 @@ protected boolean showApplyDialog(String text) throws IOException { protected Downloader downloadWithProgressBar(String taskName, List list, String baseUrl, Path targetDir) throws Exception { long total = 0; for (Downloader.SizedFile file : list) { + if(file.size < 0) { + continue; + } total += file.size; } long totalFiles = list.size(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RestartCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RestartCommand.java deleted file mode 100644 index 5c84d09b..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/basic/RestartCommand.java +++ /dev/null @@ -1,25 +0,0 @@ -package pro.gravit.launchserver.command.basic; - -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.command.Command; - -public final class RestartCommand extends Command { - public RestartCommand(LaunchServer server) { - super(server); - } - - @Override - public String getArgsDescription() { - return null; - } - - @Override - public String getUsageDescription() { - return "Restart LaunchServer"; - } - - @Override - public void invoke(String... args) { - server.fullyRestart(); - } -} \ No newline at end of file diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java index 1f3e41ac..bd8a8567 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/handler/CommandHandler.java @@ -5,7 +5,11 @@ import pro.gravit.launchserver.command.hash.*; import pro.gravit.launchserver.command.modules.LoadModuleCommand; import pro.gravit.launchserver.command.modules.ModulesCommand; +import pro.gravit.launchserver.command.profiles.ProfilesCommand; import pro.gravit.launchserver.command.service.*; +import pro.gravit.launchserver.command.sync.*; +import pro.gravit.launchserver.command.tools.SignDirCommand; +import pro.gravit.launchserver.command.tools.SignJarCommand; import pro.gravit.utils.command.BaseCommandCategory; import pro.gravit.utils.command.basic.ClearCommand; import pro.gravit.utils.command.basic.GCCommand; @@ -19,7 +23,6 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand basic.registerCommand("version", new VersionCommand(server)); basic.registerCommand("build", new BuildCommand(server)); basic.registerCommand("stop", new StopCommand(server)); - basic.registerCommand("restart", new RestartCommand(server)); basic.registerCommand("debug", new DebugCommand(server)); basic.registerCommand("clear", new ClearCommand(handler)); basic.registerCommand("gc", new GCCommand()); @@ -34,12 +37,8 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand updates.registerCommand("unindexAsset", new UnindexAssetCommand(server)); updates.registerCommand("downloadAsset", new DownloadAssetCommand(server)); updates.registerCommand("downloadClient", new DownloadClientCommand(server)); - updates.registerCommand("syncBinaries", new SyncBinariesCommand(server)); - updates.registerCommand("syncUpdates", new SyncUpdatesCommand(server)); - updates.registerCommand("syncProfiles", new SyncProfilesCommand(server)); - updates.registerCommand("syncUP", new SyncUPCommand(server)); - updates.registerCommand("saveProfiles", new SaveProfilesCommand(server)); - updates.registerCommand("makeProfile", new MakeProfileCommand(server)); + updates.registerCommand("sync", new SyncCommand(server)); + updates.registerCommand("profile", new ProfilesCommand(server)); Category updatesCategory = new Category(updates, "updates", "Update and Sync Management"); handler.registerCategory(updatesCategory); @@ -50,11 +49,16 @@ public static void registerCommands(pro.gravit.utils.command.CommandHandler hand service.registerCommand("notify", new NotifyCommand(server)); service.registerCommand("component", new ComponentCommand(server)); service.registerCommand("clients", new ClientsCommand(server)); - service.registerCommand("signJar", new SignJarCommand(server)); - service.registerCommand("signDir", new SignDirCommand(server)); service.registerCommand("securitycheck", new SecurityCheckCommand(server)); service.registerCommand("token", new TokenCommand(server)); Category serviceCategory = new Category(service, "service", "Managing LaunchServer Components"); handler.registerCategory(serviceCategory); + + //Register tools commands + BaseCommandCategory tools = new BaseCommandCategory(); + tools.registerCommand("signJar", new SignJarCommand(server)); + tools.registerCommand("signDir", new SignDirCommand(server)); + Category toolsCategory = new Category(tools, "tools", "Other tools"); + handler.registerCategory(toolsCategory); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java index 249ea173..ba005879 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/DownloadAssetCommand.java @@ -3,8 +3,8 @@ import com.google.gson.JsonObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.modern.Downloader; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.Downloader; import pro.gravit.launchserver.HttpRequester; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; 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 5ac22a87..b2e28cd2 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 @@ -3,9 +3,9 @@ import com.google.gson.JsonElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.ClientProfileVersions; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfileVersions; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.helper.MakeProfileHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java index aec64e36..8c7fe611 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/IndexAssetCommand.java @@ -3,7 +3,7 @@ import com.google.gson.JsonObject; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.command.CommandException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/modules/ModulesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/modules/ModulesCommand.java index d76c0b59..7519711b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/modules/ModulesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/modules/ModulesCommand.java @@ -2,9 +2,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.LauncherTrustManager; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.launchermodules.LauncherModuleLoader; 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 new file mode 100644 index 00000000..43e54f85 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/CloneProfileCommand.java @@ -0,0 +1,73 @@ +package pro.gravit.launchserver.command.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.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.helper.IOHelper; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.UUID; +import java.util.stream.Stream; + +public class CloneProfileCommand extends Command { + private final transient Logger logger = LogManager.getLogger(CloneProfileCommand.class); + public CloneProfileCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[profile file name] [new profile title]"; + } + + @Override + public String getUsageDescription() { + return "clone profile and profile dir"; + } + + @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); + } + profile.setTitle(args[1]); + profile.setUUID(UUID.randomUUID()); + if(profile.getServers().size() == 1) { + profile.getServers().getFirst().name = args[1]; + } + logger.info("Copy {} to {}", profile.getDir(), args[1]); + var src = server.updatesDir.resolve(profile.getDir()); + var dest = server.updatesDir.resolve(args[1]); + try (Stream stream = Files.walk(src)) { + stream.forEach(source -> { + try { + IOHelper.copy(source, dest.resolve(src.relativize(source))); + } catch (IOException e) { + throw new RuntimeException(e); + } + }); + } + profile.setDir(args[1]); + var targetPath = server.profilesDir.resolve(args[1].concat(".json")); + try(Writer writer = IOHelper.newWriter(targetPath)) { + Launcher.gsonManager.gson.toJson(profile, writer); + } + 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 new file mode 100644 index 00000000..642a115c --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/DeleteProfileCommand.java @@ -0,0 +1,56 @@ +package pro.gravit.launchserver.command.profiles; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; +import pro.gravit.utils.helper.IOHelper; + +import java.nio.file.Files; + +public class DeleteProfileCommand extends Command { + private final transient Logger logger = LogManager.getLogger(ListProfilesCommand.class); + public DeleteProfileCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return "[uuid/title]"; + } + + @Override + public String getUsageDescription() { + return "permanently delete profile"; + } + + @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; + } + } + if(profile == null) { + logger.error("Profile {} not found", args[0]); + return; + } + var clientDir = server.updatesDir.resolve(profile.getDir()).toAbsolutePath(); + logger.warn("THIS ACTION DELETE PROFILE AND ALL FILES IN {}", clientDir); + if(!showApplyDialog("Continue?")) { + return; + } + 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/ListProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ListProfilesCommand.java new file mode 100644 index 00000000..8eaa913e --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ListProfilesCommand.java @@ -0,0 +1,30 @@ +package pro.gravit.launchserver.command.profiles; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; + +public class ListProfilesCommand extends Command { + private final transient Logger logger = LogManager.getLogger(ListProfilesCommand.class); + public ListProfilesCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return null; + } + + @Override + public String getUsageDescription() { + return "show all profiles"; + } + + @Override + public void invoke(String... args) throws Exception { + for(var profile : server.getProfiles()) { + logger.info("{} ({}) {}", profile.getTitle(), profile.getVersion().toString(), profile.isLimited() ? "limited" : ""); + } + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/MakeProfileCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/MakeProfileCommand.java similarity index 91% rename from LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/MakeProfileCommand.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/MakeProfileCommand.java index 78f6973d..ad57670c 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/MakeProfileCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/MakeProfileCommand.java @@ -1,9 +1,9 @@ -package pro.gravit.launchserver.command.hash; +package pro.gravit.launchserver.command.profiles; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.helper.MakeProfileHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ProfilesCommand.java new file mode 100644 index 00000000..c9d7a2c7 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/ProfilesCommand.java @@ -0,0 +1,30 @@ +package pro.gravit.launchserver.command.profiles; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; + +public class ProfilesCommand extends Command { + public ProfilesCommand(LaunchServer server) { + super(server); + this.childCommands.put("make", new MakeProfileCommand(server)); + this.childCommands.put("save", new SaveProfilesCommand(server)); + this.childCommands.put("clone", new CloneProfileCommand(server)); + this.childCommands.put("list", new ListProfilesCommand(server)); + this.childCommands.put("delete", new DeleteProfileCommand(server)); + } + + @Override + public String getArgsDescription() { + return "[subcommand] [args...]"; + } + + @Override + public String getUsageDescription() { + return "manage profiles"; + } + + @Override + public void invoke(String... args) throws Exception { + invokeSubcommands(args); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java similarity index 92% rename from LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java index 151011ba..c0f0f5d0 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SaveProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/profiles/SaveProfilesCommand.java @@ -1,9 +1,9 @@ -package pro.gravit.launchserver.command.hash; +package pro.gravit.launchserver.command.profiles; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.utils.helper.IOHelper; @@ -24,7 +24,7 @@ public SaveProfilesCommand(LaunchServer server) { public static void saveProfile(ClientProfile profile, Path path) throws IOException { if (profile.getUUID() == null) profile.setUUID(UUID.randomUUID()); - if (profile.getServers().size() == 0) { + if (profile.getServers().isEmpty()) { ClientProfile.ServerProfile serverProfile = new ClientProfile.ServerProfile(); serverProfile.isDefault = true; serverProfile.name = profile.getTitle(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ComponentCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ComponentCommand.java index 39fd07aa..576a987b 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ComponentCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/ComponentCommand.java @@ -2,7 +2,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.components.Component; @@ -37,7 +37,6 @@ public void printHelp() { logger.info("Print help for component:"); logger.info("component unload [componentName]"); logger.info("component load [componentName] [filename]"); - logger.info("component gc [componentName]"); } @Override diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java index abf0e80b..74bc8fa8 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/NotifyCommand.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.command.service; -import pro.gravit.launcher.events.NotificationEvent; -import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launcher.base.events.NotificationEvent; +import pro.gravit.launcher.base.request.WebSocketEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.command.Command; import pro.gravit.launchserver.socket.WebSocketService; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SecurityCheckCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SecurityCheckCommand.java index 95d6cf99..88472600 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SecurityCheckCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SecurityCheckCommand.java @@ -2,7 +2,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.protect.AdvancedProtectHandler; import pro.gravit.launchserver.auth.protect.NoProtectHandler; @@ -60,19 +60,19 @@ public void invoke(String... args) { LaunchServerConfig config = server.config; config.auth.forEach((name, pair) -> { }); - if (config.protectHandler instanceof NoProtectHandler) { - printCheckResult("protectHandler", "protectHandler none", false); - } else if (config.protectHandler instanceof AdvancedProtectHandler) { - printCheckResult("protectHandler", "", true); - if (!((AdvancedProtectHandler) config.protectHandler).enableHardwareFeature) { - printCheckResult("protectHandler.hardwareId", "you can improve security by using hwid provider", null); - } else { - printCheckResult("protectHandler.hardwareId", "", true); + switch (config.protectHandler) { + case NoProtectHandler noProtectHandler -> printCheckResult("protectHandler", "protectHandler none", false); + case AdvancedProtectHandler advancedProtectHandler -> { + printCheckResult("protectHandler", "", true); + if (!advancedProtectHandler.enableHardwareFeature) { + printCheckResult("protectHandler.hardwareId", "you can improve security by using hwid provider", null); + } else { + printCheckResult("protectHandler.hardwareId", "", true); + } } - } else if (config.protectHandler instanceof StdProtectHandler) { - printCheckResult("protectHandler", "you can improve security by using advanced", null); - } else { - printCheckResult("protectHandler", "unknown protectHandler", null); + case StdProtectHandler stdProtectHandler -> + printCheckResult("protectHandler", "you can improve security by using advanced", null); + case null, default -> printCheckResult("protectHandler", "unknown protectHandler", null); } if (config.netty.address.startsWith("ws://")) { if (config.netty.ipForwarding) @@ -110,7 +110,7 @@ public void invoke(String... args) { KeyStore keyStore = SignHelper.getStore(new File(config.sign.keyStore).toPath(), config.sign.keyStorePass, config.sign.keyStoreType); Certificate[] certChainPlain = keyStore.getCertificateChain(config.sign.keyAlias); List certChain = Arrays.stream(certChainPlain).map(e -> (X509Certificate) e).toList(); - X509Certificate cert = certChain.get(0); + X509Certificate cert = certChain.getFirst(); cert.checkValidity(); if (certChain.size() == 1) { printCheckResult("sign", "certificate chain contains <2 element(recommend 2 and more)", false); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/TokenCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/TokenCommand.java index f6090469..6fd89943 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/TokenCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/TokenCommand.java @@ -3,7 +3,7 @@ import io.jsonwebtoken.Jwts; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.command.Command; @@ -18,15 +18,16 @@ public TokenCommand(LaunchServer server) { @Override public void invoke(String... args) throws Exception { verifyArgs(args, 1); - var parser = Jwts.parserBuilder().setSigningKey(server.keyAgreementManager.ecdsaPublicKey).build(); - var claims = parser.parseClaimsJws(args[0]); - logger.info("Token: {}", claims.getBody()); + var parser = Jwts.parser().verifyWith(server.keyAgreementManager.ecdsaPublicKey).build(); + var claims = parser.parseSignedClaims(args[0]); + logger.info("Token: {}", claims.getPayload()); } }); - this.childCommands.put("server", new SubCommand("[profileName] (authId)", "generate new server token") { + this.childCommands.put("server", new SubCommand("[profileName] (authId) (public only)", "generate new server token") { @Override public void invoke(String... args) { AuthProviderPair pair = args.length > 1 ? server.config.getAuthProviderPair(args[1]) : server.config.getAuthProviderPair(); + boolean publicOnly = args.length <= 2 || Boolean.parseBoolean(args[2]); ClientProfile profile = null; for (ClientProfile p : server.getProfiles()) { if (p.getTitle().equals(args[0]) || p.getUUID().toString().equals(args[0])) { @@ -41,7 +42,7 @@ public void invoke(String... args) { logger.error("AuthId {} not found", args[1]); return; } - String token = server.authManager.newCheckServerToken(profile != null ? profile.getUUID().toString() : args[0], pair.name); + String token = server.authManager.newCheckServerToken(profile != null ? profile.getUUID().toString() : args[0], pair.name, publicOnly); logger.info("Server token {} authId {}: {}", args[0], pair.name, token); } }); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncBinariesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncBinariesCommand.java similarity index 94% rename from LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncBinariesCommand.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncBinariesCommand.java index 487ee7f7..9997b520 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncBinariesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncBinariesCommand.java @@ -1,4 +1,4 @@ -package pro.gravit.launchserver.command.hash; +package pro.gravit.launchserver.command.sync; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncCommand.java new file mode 100644 index 00000000..099e6c25 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncCommand.java @@ -0,0 +1,31 @@ +package pro.gravit.launchserver.command.sync; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; + +public class SyncCommand extends Command { + public SyncCommand(LaunchServer server) { + super(server); + this.childCommands.put("profiles", new SyncProfilesCommand(server)); + this.childCommands.put("binaries", new SyncBinariesCommand(server)); + this.childCommands.put("updates", new SyncUpdatesCommand(server)); + this.childCommands.put("up", new SyncUPCommand(server)); + this.childCommands.put("launchermodules", new SyncLauncherModulesCommand(server)); + this.childCommands.put("updatescache", new SyncUpdatesCacheCommand(server)); + } + + @Override + public String getArgsDescription() { + return "[updates/profiles/up/binaries/launchermodules/updatescache] [args...]"; + } + + @Override + public String getUsageDescription() { + return "sync specified objects"; + } + + @Override + public void invoke(String... args) throws Exception { + invokeSubcommands(args); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/SyncLauncherModulesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncLauncherModulesCommand.java similarity index 63% rename from LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/SyncLauncherModulesCommand.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncLauncherModulesCommand.java index 290979d8..6831bf9a 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/SyncLauncherModulesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncLauncherModulesCommand.java @@ -1,31 +1,31 @@ -package pro.gravit.launchserver.launchermodules; +package pro.gravit.launchserver.command.sync; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.utils.command.Command; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; public class SyncLauncherModulesCommand extends Command { - private final LauncherModuleLoader mod; private transient final Logger logger = LogManager.getLogger(); - public SyncLauncherModulesCommand(LauncherModuleLoader mod) { - this.mod = mod; + public SyncLauncherModulesCommand(LaunchServer server) { + super(server); } @Override public String getArgsDescription() { - return "Resync launcher modules"; + return null; } @Override public String getUsageDescription() { - return "[]"; + return "Resync launcher modules"; } @Override public void invoke(String... args) throws Exception { - mod.syncModules(); + server.launcherModuleLoader.syncModules(); logger.info("Launcher Modules synced"); } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncProfilesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncProfilesCommand.java similarity index 94% rename from LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncProfilesCommand.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncProfilesCommand.java index d0e2f718..615036c3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncProfilesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncProfilesCommand.java @@ -1,4 +1,4 @@ -package pro.gravit.launchserver.command.hash; +package pro.gravit.launchserver.command.sync; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUPCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncUPCommand.java similarity index 94% rename from LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUPCommand.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncUPCommand.java index cf1bb2b2..b82a9460 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUPCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncUPCommand.java @@ -1,4 +1,4 @@ -package pro.gravit.launchserver.command.hash; +package pro.gravit.launchserver.command.sync; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncUpdatesCacheCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncUpdatesCacheCommand.java new file mode 100644 index 00000000..19c30fac --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncUpdatesCacheCommand.java @@ -0,0 +1,25 @@ +package pro.gravit.launchserver.command.sync; + +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.command.Command; + +public class SyncUpdatesCacheCommand extends Command { + public SyncUpdatesCacheCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return null; + } + + @Override + public String getUsageDescription() { + return "sync updates cache"; + } + + @Override + public void invoke(String... args) throws Exception { + server.updatesManager.readUpdatesFromCache(); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUpdatesCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncUpdatesCommand.java similarity index 95% rename from LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUpdatesCommand.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncUpdatesCommand.java index af30a328..1b294c97 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/hash/SyncUpdatesCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/sync/SyncUpdatesCommand.java @@ -1,4 +1,4 @@ -package pro.gravit.launchserver.command.hash; +package pro.gravit.launchserver.command.sync; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/tools/SignDirCommand.java similarity index 97% rename from LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/command/tools/SignDirCommand.java index 17a77710..09f5b1f4 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignDirCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/tools/SignDirCommand.java @@ -1,4 +1,4 @@ -package pro.gravit.launchserver.command.service; +package pro.gravit.launchserver.command.tools; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java b/LaunchServer/src/main/java/pro/gravit/launchserver/command/tools/SignJarCommand.java similarity index 97% rename from LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/command/tools/SignJarCommand.java index ecdfdf7f..ed2d0536 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/command/service/SignJarCommand.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/command/tools/SignJarCommand.java @@ -1,4 +1,4 @@ -package pro.gravit.launchserver.command.service; +package pro.gravit.launchserver.command.tools; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java index 3fd4f2eb..1c74307e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/AbstractLimiter.java @@ -90,7 +90,7 @@ public boolean check(T address) { } } - static class LimitEntry { + protected static class LimitEntry { long time; int trys; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/Component.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/Component.java index 5eb20ad1..857fce51 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/Component.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/Component.java @@ -11,7 +11,6 @@ public abstract class Component { public static void registerComponents() { if (!registredComp) { providers.register("authLimiter", AuthLimiterComponent.class); - providers.register("regLimiter", RegLimiterComponent.class); providers.register("commandRemover", CommandRemoverComponent.class); providers.register("proguard", ProGuardComponent.class); providers.register("whitelist", WhitelistComponent.class); 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 ee92b7e0..97a36b49 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/components/ProGuardComponent.java @@ -9,7 +9,6 @@ import pro.gravit.utils.command.SubCommand; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.UnpackHelper; @@ -20,7 +19,6 @@ import java.nio.file.Paths; import java.security.SecureRandom; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java deleted file mode 100644 index 7452c560..00000000 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/components/RegLimiterComponent.java +++ /dev/null @@ -1,34 +0,0 @@ -package pro.gravit.launchserver.components; - -import pro.gravit.launchserver.LaunchServer; -import pro.gravit.launchserver.manangers.hook.AuthHookManager; -import pro.gravit.utils.HookException; - -import java.util.ArrayList; -import java.util.List; - -public class RegLimiterComponent extends IPLimiter implements AutoCloseable { - - public transient LaunchServer launchServer; - public String message; - - public List excludeIps = new ArrayList<>(); - - @Override - public void init(LaunchServer launchServer) { - this.launchServer = launchServer; - launchServer.authHookManager.registraion.registerHook(this::registerHook); - } - - public boolean registerHook(AuthHookManager.RegContext context) { - if (!check(context.ip)) { - throw new HookException(message); - } - return false; - } - - @Override - public void close() { - launchServer.authHookManager.registraion.unregisterHook(this::registerHook); - } -} 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 502889f8..ecba3a95 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/config/LaunchServerConfig.java @@ -4,30 +4,27 @@ import io.netty.handler.logging.LogLevel; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherConfig; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.LauncherConfig; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.RejectAuthCoreProvider; import pro.gravit.launchserver.auth.protect.ProtectHandler; import pro.gravit.launchserver.auth.protect.StdProtectHandler; import pro.gravit.launchserver.auth.texture.RequestTextureProvider; -import pro.gravit.launchserver.binary.tasks.exe.Launch4JTask; import pro.gravit.launchserver.components.AuthLimiterComponent; import pro.gravit.launchserver.components.Component; import pro.gravit.launchserver.components.ProGuardComponent; -import pro.gravit.launchserver.components.RegLimiterComponent; -import pro.gravit.utils.Version; -import pro.gravit.utils.helper.JVMHelper; -import java.io.File; import java.util.*; import static java.util.concurrent.TimeUnit.HOURS; import static java.util.concurrent.TimeUnit.SECONDS; public final class LaunchServerConfig { - private final static List oldMirrorList = List.of("https://mirror.gravit.pro/5.2.x/", "https://mirror.gravit.pro/5.3.x/", "https://mirror.gravitlauncher.com/5.2.x/", "https://mirror.gravitlauncher.com/5.3.x/", "https://mirror.gravitlauncher.com/5.4.x/"); + private final static List oldMirrorList = List.of("https://mirror.gravit.pro/5.2.x/", "https://mirror.gravit.pro/5.3.x/", + "https://mirror.gravitlauncher.com/5.2.x/", "https://mirror.gravitlauncher.com/5.3.x/", "https://mirror.gravitlauncher.com/5.4.x/", + "https://mirror.gravitlauncher.com/5.5.x/"); private transient final Logger logger = LogManager.getLogger(); public String projectName; public String[] mirrors; @@ -39,31 +36,16 @@ public final class LaunchServerConfig { // Handlers & Providers public ProtectHandler protectHandler; public Map components; - public ExeConf launch4j; public NettyConfig netty; public LauncherConf launcher; public JarSignerConf sign; - public String startScript; private transient LaunchServer server = null; private transient AuthProviderPair authDefault; public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { LaunchServerConfig newConfig = new LaunchServerConfig(); - newConfig.mirrors = new String[]{"https://mirror.gravitlauncher.com/5.5.x/", "https://gravit-launcher-mirror.storage.googleapis.com/"}; - newConfig.launch4j = new LaunchServerConfig.ExeConf(); - newConfig.launch4j.enabled = false; - newConfig.launch4j.copyright = "© GravitLauncher Team"; - newConfig.launch4j.fileDesc = "GravitLauncher ".concat(Version.getVersion().getVersionString()); - newConfig.launch4j.fileVer = Version.getVersion().getVersionString().concat(".").concat(String.valueOf(Version.getVersion().patch)); - newConfig.launch4j.internalName = "Launcher"; - newConfig.launch4j.trademarks = "This product is licensed under GPLv3"; - newConfig.launch4j.txtFileVersion = "%s, build %d"; - newConfig.launch4j.txtProductVersion = "%s, build %d"; - newConfig.launch4j.productName = "GravitLauncher"; - newConfig.launch4j.productVer = newConfig.launch4j.fileVer; - newConfig.launch4j.maxVersion = "99.0.0"; + newConfig.mirrors = new String[]{"https://mirror.gravitlauncher.com/5.6.x/", "https://gravit-launcher-mirror.storage.googleapis.com/"}; newConfig.env = LauncherConfig.LauncherEnvironment.STD; - newConfig.startScript = JVMHelper.OS_TYPE.equals(JVMHelper.OS.MUSTDIE) ? "." + File.separator + "start.bat" : "." + File.separator + "start.sh"; newConfig.auth = new HashMap<>(); AuthProviderPair a = new AuthProviderPair(new RejectAuthCoreProvider(), new RequestTextureProvider("http://example.com/skins/%username%.png", "http://example.com/cloaks/%username%.png") @@ -91,6 +73,7 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { newConfig.launcher.compress = true; newConfig.launcher.deleteTempFiles = true; newConfig.launcher.stripLineNumbers = true; + newConfig.launcher.customJvmOptions.add("-Dfile.encoding=UTF-8"); newConfig.sign = new JarSignerConf(); @@ -100,11 +83,6 @@ public static LaunchServerConfig getDefault(LaunchServer.LaunchServerEnv env) { authLimiterComponent.rateLimitMillis = SECONDS.toMillis(8); authLimiterComponent.message = "Превышен лимит авторизаций"; newConfig.components.put("authLimiter", authLimiterComponent); - RegLimiterComponent regLimiterComponent = new RegLimiterComponent(); - regLimiterComponent.rateLimit = 3; - regLimiterComponent.rateLimitMillis = HOURS.toMillis(10); - regLimiterComponent.message = "Превышен лимит регистраций"; - newConfig.components.put("regLimiter", regLimiterComponent); ProGuardComponent proGuardComponent = new ProGuardComponent(); newConfig.components.put("proguard", proGuardComponent); return newConfig; @@ -142,7 +120,7 @@ public void setEnv(LauncherConfig.LauncherEnvironment env) { } public void verify() { - if (auth == null || auth.size() < 1) { + if (auth == null || auth.isEmpty()) { throw new NullPointerException("AuthProviderPair`s count should be at least one"); } @@ -171,8 +149,8 @@ public void verify() { if (!updateMirror) { for (int i = 0; i < mirrors.length; ++i) { if (mirrors[i] != null && oldMirrorList.contains(mirrors[i])) { - logger.warn("Replace mirror '{}' to 'https://mirror.gravitlauncher.com/5.5.x/'. If you really need to use original url, use '-Dlaunchserver.config.disableUpdateMirror=true'", mirrors[i]); - mirrors[i] = "https://mirror.gravitlauncher.com/5.5.x/"; + logger.warn("Replace mirror '{}' to 'https://mirror.gravitlauncher.com/5.6.x/'. If you really need to use original url, use '-Dlaunchserver.config.disableUpdateMirror=true'", mirrors[i]); + mirrors[i] = "https://mirror.gravitlauncher.com/5.6.x/"; } } } @@ -230,25 +208,6 @@ public void close(LaunchServer.ReloadType type) { } } - public static class ExeConf { - public boolean enabled; - public boolean setMaxVersion; - public String maxVersion; - public String minVersion = "17.0.0"; - public String supportURL = null; - public String downloadUrl = Launch4JTask.DOWNLOAD_URL; - public String productName; - public String productVer; - public String fileDesc; - public String fileVer; - public String internalName; - public String copyright; - public String trademarks; - - public String txtFileVersion; - public String txtProductVersion; - } - public static class JarSignerConf { public boolean enabled = false; public String keyStore = "pathToKey"; @@ -301,6 +260,12 @@ public static class NettyPerformanceConfig { public int workerThread; public int schedulerThread; public int maxWebSocketRequestBytes = 1024 * 1024; + public boolean disableThreadSafeClientObject; + public NettyExecutorType executorType = NettyExecutorType.VIRTUAL_THREADS; + + public enum NettyExecutorType { + NONE, DEFAULT, WORK_STEAL, VIRTUAL_THREADS + } } public static class NettyBindAddress { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/HttpHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/HttpHelper.java index 2e6a756a..3872fec2 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/HttpHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/HttpHelper.java @@ -3,8 +3,8 @@ import com.google.gson.JsonElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.request.RequestException; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.request.RequestException; import java.io.IOException; import java.io.InputStream; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/LegacySessionHelper.java b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/LegacySessionHelper.java index 9b4acb45..bc165fba 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/LegacySessionHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/LegacySessionHelper.java @@ -25,14 +25,14 @@ public static String makeAccessJwtTokenFromString(User user, LocalDateTime expir } public static JwtTokenInfo getJwtInfoFromAccessToken(String token, ECPublicKey publicKey) { - var parser = Jwts.parserBuilder() + var parser = Jwts.parser() .requireIssuer("LaunchServer") - .setClock(() -> new Date(Clock.systemUTC().millis())) - .setSigningKey(publicKey) + .clock(() -> new Date(Clock.systemUTC().millis())) + .verifyWith(publicKey) .build(); - var claims = parser.parseClaimsJws(token); - var uuid = UUID.fromString(claims.getBody().get("uuid", String.class)); - var username = claims.getBody().getSubject(); + var claims = parser.parseSignedClaims(token); + var uuid = UUID.fromString(claims.getPayload().get("uuid", String.class)); + var username = claims.getPayload().getSubject(); return new JwtTokenInfo(username, uuid); } 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 8bcac9bb..d627d3ed 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java @@ -1,12 +1,12 @@ package pro.gravit.launchserver.helper; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.ClientProfileBuilder; -import pro.gravit.launcher.profiles.ClientProfileVersions; -import pro.gravit.launcher.profiles.optional.OptionalFile; -import pro.gravit.launcher.profiles.optional.actions.OptionalActionFile; -import pro.gravit.launcher.profiles.optional.actions.OptionalActionJvmArgs; -import pro.gravit.launcher.profiles.optional.triggers.OSTrigger; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfileBuilder; +import pro.gravit.launcher.base.profiles.ClientProfileVersions; +import pro.gravit.launcher.base.profiles.optional.OptionalFile; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalActionFile; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalActionJvmArgs; +import pro.gravit.launcher.base.profiles.optional.triggers.OSTrigger; import pro.gravit.utils.helper.JVMHelper; import java.io.IOException; @@ -27,6 +27,7 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti builder.setMainClass(getMainClassByVersion(version, options)); builder.setServers(List.of(new ClientProfile.ServerProfile(title, "localhost", 25565))); // ------------ + var lwjgl3ify = findOption(options, Lwjgl3ifyOption.class); builder.setUpdateVerify(List.of("libraries", "natives", "mods", "minecraft.jar", "forge.jar", "liteloader.jar")); { List classPath = new ArrayList<>(5); @@ -44,8 +45,40 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti jvmArgs.add("-XX:+DisableAttachMechanism"); // Official Mojang launcher java arguments if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) <= 0) { - jvmArgs.add("-XX:+UseConcMarkSweepGC"); - jvmArgs.add("-XX:+CMSIncrementalMode"); + // lwjgl3ify arguments https://github.com/GTNewHorizons/lwjgl3ify + jvmArgs.add("-Djava.security.manager=allow"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/jdk.internal.loader=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.net=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.nio=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.io=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.lang=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.lang.reflect=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.text=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/java.util=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/jdk.internal.reflect=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.base/sun.nio.ch=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("jdk.naming.dns/com.sun.jndi.dns=ALL-UNNAMED,java.naming"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.desktop/sun.awt=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.desktop/sun.awt.image=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.desktop/com.sun.imageio.plugins.png=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("jdk.dynalink/jdk.dynalink.beans=ALL-UNNAMED"); + jvmArgs.add("--add-opens"); + jvmArgs.add("java.sql.rowset/javax.sql.rowset.serial=ALL-UNNAMED"); } else if (version.compareTo(ClientProfileVersions.MINECRAFT_1_18) <= 0) { // 1.13 - 1.16.5 jvmArgs.add("-XX:+UseG1GC"); jvmArgs.add("-XX:+UnlockExperimentalVMOptions"); @@ -116,14 +149,8 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti } } } - if (version.compareTo(ClientProfileVersions.MINECRAFT_1_17) >= 0 && version.compareTo(ClientProfileVersions.MINECRAFT_1_18) < 0) { - builder.setMinJavaVersion(16); - builder.setRecommendJavaVersion(16); - } - if (version.compareTo(ClientProfileVersions.MINECRAFT_1_18) >= 0) { - builder.setMinJavaVersion(17); - builder.setRecommendJavaVersion(17); - } + builder.setMinJavaVersion(17); + builder.setRecommendJavaVersion(17); if(version.compareTo(ClientProfileVersions.MINECRAFT_1_20_3) >= 0) { builder.setMinJavaVersion(21); builder.setRecommendJavaVersion(21); @@ -133,7 +160,10 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti builder.setJvmArgs(jvmArgs); builder.setUpdateOptional(optionals); List clientArgs = new ArrayList<>(); - if (findOption(options, MakeProfileOptionLaunchWrapper.class).isPresent()) { + if(version.compareTo(ClientProfileVersions.MINECRAFT_1_7_10) == 0) { + jvmArgs.add("-Drfb.skipClassLoaderCheck=true"); + } + if (findOption(options, MakeProfileOptionLaunchWrapper.class).isPresent() || findOption(options, MakeProfileRfbOption.class).isPresent()) { if (findOption(options, MakeProfileOptionLiteLoader.class).isPresent()) { clientArgs.add("--tweakClass"); clientArgs.add("com.mumfrey.liteloader.launch.LiteLoaderTweaker"); @@ -145,20 +175,9 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti } else { clientArgs.add("cpw.mods.fml.common.launcher.FMLTweaker"); } - if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) <= 0) { - builder.setMinJavaVersion(8); - builder.setRecommendJavaVersion(8); - builder.setMaxJavaVersion(8); - } } } else if (version.compareTo(ClientProfileVersions.MINECRAFT_1_12_2) > 0) { - if (forge.isPresent()) { - clientArgs.addAll(forge.get().makeClientArgs()); - builder.setClassLoaderConfig(ClientProfile.ClassLoaderConfig.SYSTEM_ARGS); - if (version.compareTo(ClientProfileVersions.MINECRAFT_1_16_5) <= 0) { - builder.setMaxJavaVersion(15); - } - } + forge.ifPresent(makeProfileOptionForge -> clientArgs.addAll(makeProfileOptionForge.makeClientArgs())); } builder.setClientArgs(clientArgs); @@ -171,6 +190,9 @@ private static Optional findOption(MakeProfileOption[] options, Class } public static String getMainClassByVersion(ClientProfile.Version version, MakeProfileOption... options) { + if(version.compareTo(ClientProfileVersions.MINECRAFT_1_7_10) == 0) { + return "com.gtnewhorizons.retrofuturabootstrap.Main"; + } if (findOption(options, MakeProfileOptionLaunchWrapper.class).isPresent()) { return "net.minecraft.launchwrapper.Launch"; } @@ -320,6 +342,13 @@ public static class MakeProfileOptionLaunchWrapper implements MakeProfileOption } + public static class MakeProfileRfbOption implements MakeProfileOption { + + } + + public record Lwjgl3ifyOption(String lwjgl3ifyForgePatches) implements MakeProfileOption { + } + public static class MakeProfileOptionFabric implements MakeProfileOption { public String jimfsPath; public String guavaPath; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/holder/LaunchServerControlHolder.java b/LaunchServer/src/main/java/pro/gravit/launchserver/holder/LaunchServerControlHolder.java new file mode 100644 index 00000000..a29d4cd4 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/holder/LaunchServerControlHolder.java @@ -0,0 +1,24 @@ +package pro.gravit.launchserver.holder; + +import pro.gravit.utils.launch.ClassLoaderControl; + +public class LaunchServerControlHolder { + private static ClassLoaderControl control; + private static ModuleLayer.Controller controller; + + public static ClassLoaderControl getControl() { + return control; + } + + public static void setControl(ClassLoaderControl control) { + LaunchServerControlHolder.control = control; + } + + public static ModuleLayer.Controller getController() { + return controller; + } + + public static void setController(ModuleLayer.Controller controller) { + LaunchServerControlHolder.controller = controller; + } +} 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 de2555f0..f50945a5 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/launchermodules/LauncherModuleLoader.java @@ -2,8 +2,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherTrustManager; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.core.LauncherTrustManager; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.launchserver.binary.tasks.MainBuildTask; @@ -44,7 +44,6 @@ public void init() { logger.error(e); } } - server.commandHandler.registerCommand("syncLauncherModules", new SyncLauncherModulesCommand(this)); MainBuildTask mainTask = server.launcherBinary.getTaskByClass(MainBuildTask.class).get(); mainTask.preBuildHook.registerHook((buildContext) -> { for (ModuleEntity e : launcherModules) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java index 5b7c3c21..fcfb4b20 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/AuthManager.java @@ -4,12 +4,12 @@ import io.jsonwebtoken.Jwts; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.password.*; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.PlayerProfile; +import pro.gravit.launcher.base.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.password.*; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthProviderPair; @@ -38,19 +38,20 @@ public class AuthManager { public AuthManager(LaunchServer server) { this.server = server; - this.checkServerTokenParser = Jwts.parserBuilder() + this.checkServerTokenParser = Jwts.parser() .requireIssuer("LaunchServer") .require("tokenType", "checkServer") - .setSigningKey(server.keyAgreementManager.ecdsaPublicKey) + .verifyWith(server.keyAgreementManager.ecdsaPublicKey) .build(); } - public String newCheckServerToken(String serverName, String authId) { + public String newCheckServerToken(String serverName, String authId, boolean publicOnly) { return Jwts.builder() - .setIssuer("LaunchServer") + .issuer("LaunchServer") .claim("serverName", serverName) .claim("authId", authId) .claim("tokenType", "checkServer") + .claim("isPublic", publicOnly) .signWith(server.keyAgreementManager.ecdsaPrivateKey) .compact(); } @@ -58,7 +59,8 @@ public String newCheckServerToken(String serverName, String authId) { public CheckServerTokenInfo parseCheckServerToken(String token) { try { var jwt = checkServerTokenParser.parseClaimsJws(token).getBody(); - return new CheckServerTokenInfo(jwt.get("serverName", String.class), jwt.get("authId", String.class)); + var isPublicClaim = jwt.get("isPublic", Boolean.class); + return new CheckServerTokenInfo(jwt.get("serverName", String.class), jwt.get("authId", String.class), isPublicClaim == null || isPublicClaim); } catch (Exception e) { return null; } @@ -301,7 +303,7 @@ private AuthRequest.AuthPasswordInterface tryDecryptPasswordPlain(AuthRequest.Au return password; } - public record CheckServerTokenInfo(String serverName, String authId) { + public record CheckServerTokenInfo(String serverName, String authId, boolean isPublic) { } public static class CheckServerVerifier implements RestoreResponse.ExtendedTokenProvider { @@ -321,7 +323,10 @@ public boolean accept(Client client, AuthProviderPair pair, String extendedToken client.auth = server.config.getAuthProviderPair(info.authId); if (client.permissions == null) client.permissions = new ClientPermissions(); client.permissions.addPerm("launchserver.checkserver"); - client.permissions.addPerm("launchserver.profile.%s.show".formatted(info.serverName)); + if(!info.isPublic) { + client.permissions.addPerm("launchserver.checkserver.extended"); + client.permissions.addPerm("launchserver.profile.%s.show".formatted(info.serverName)); + } client.setProperty("launchserver.serverName", info.serverName); return true; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java index 51f63436..fa822fcf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/CertificateManager.java @@ -11,7 +11,7 @@ import org.bouncycastle.util.io.pem.PemObject; import org.bouncycastle.util.io.pem.PemReader; import org.bouncycastle.util.io.pem.PemWriter; -import pro.gravit.launcher.LauncherTrustManager; +import pro.gravit.launcher.core.LauncherTrustManager; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/ConfigManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ConfigManager.java similarity index 93% rename from LauncherAPI/src/main/java/pro/gravit/launcher/managers/ConfigManager.java rename to LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ConfigManager.java index cda96970..fc5df469 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/ConfigManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/ConfigManager.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.managers; +package pro.gravit.launchserver.manangers; -import pro.gravit.launcher.config.JsonConfigurable; +import pro.gravit.launcher.base.config.JsonConfigurable; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.VerifyHelper; 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 8b5e3c14..07deb093 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java @@ -2,16 +2,16 @@ import com.google.gson.GsonBuilder; import marcono1234.gson.recordadapter.RecordTypeAdapterFactory; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; -import pro.gravit.launcher.managers.GsonManager; -import pro.gravit.launcher.modules.events.PreGsonPhase; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; -import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger; -import pro.gravit.launcher.request.JsonResultSerializeAdapter; -import pro.gravit.launcher.request.WebSocketEvent; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest; +import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; +import pro.gravit.launcher.core.managers.GsonManager; +import pro.gravit.launcher.base.modules.events.PreGsonPhase; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.optional.triggers.OptionalTrigger; +import pro.gravit.launcher.base.request.JsonResultSerializeAdapter; +import pro.gravit.launcher.base.request.WebSocketEvent; +import pro.gravit.launcher.base.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.GetAvailabilityAuthRequest; import pro.gravit.launchserver.auth.core.AuthCoreProvider; import pro.gravit.launchserver.auth.mix.MixProvider; import pro.gravit.launchserver.auth.password.PasswordVerifier; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java index 07932e2d..ddbd1eb9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/MirrorManager.java @@ -3,7 +3,7 @@ import com.google.gson.JsonElement; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.utils.helper.IOHelper; import java.io.IOException; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/UpdatesManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/UpdatesManager.java index 47e9f4f6..c2642d2e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/UpdatesManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/UpdatesManager.java @@ -2,9 +2,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.launcher.core.hasher.HashedDir; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.core.serialize.HOutput; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.modules.events.LaunchServerUpdatesSyncEvent; import pro.gravit.utils.helper.IOHelper; @@ -52,6 +52,10 @@ private void readCache(Path file) throws IOException { this.updatesDirMap = Collections.unmodifiableMap(updatesDirMap); } + public void readUpdatesFromCache() throws IOException { + readCache(cacheFile); + } + public void readUpdatesDir() throws IOException { if (server.config.cacheUpdates) { if (Files.exists(cacheFile)) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java index 8148e975..27b5a491 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/hook/AuthHookManager.java @@ -7,7 +7,6 @@ import pro.gravit.launchserver.socket.response.auth.JoinServerResponse; import pro.gravit.launchserver.socket.response.auth.SetProfileResponse; import pro.gravit.utils.BiHookSet; -import pro.gravit.utils.HookSet; public class AuthHookManager { public final BiHookSet preHook = new BiHookSet<>(); @@ -16,19 +15,4 @@ public class AuthHookManager { public final BiHookSet postCheckServerHook = new BiHookSet<>(); public final BiHookSet joinServerHook = new BiHookSet<>(); public final BiHookSet setProfileHook = new BiHookSet<>(); - public final HookSet registraion = new HookSet<>(); - - public static class RegContext { - public final String login; - public final String password; - public final String ip; - public final boolean trustContext; - - public RegContext(String login, String password, String ip, boolean trustContext) { - this.login = login; - this.password = password; - this.ip = ip; - this.trustContext = trustContext; - } - } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerFullInitEvent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerFullInitEvent.java index b619935b..cc5b7361 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerFullInitEvent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerFullInitEvent.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.modules.events; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; import pro.gravit.launchserver.LaunchServer; public class LaunchServerFullInitEvent extends LauncherModule.Event { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerInitPhase.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerInitPhase.java index da8903f1..773f8897 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerInitPhase.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerInitPhase.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.modules.events; -import pro.gravit.launcher.modules.events.InitPhase; +import pro.gravit.launcher.base.modules.events.InitPhase; import pro.gravit.launchserver.LaunchServer; public class LaunchServerInitPhase extends InitPhase { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerLauncherExeInit.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerLauncherExeInit.java index 48969876..5429f843 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerLauncherExeInit.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerLauncherExeInit.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.modules.events; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.binary.LauncherBinary; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerNettyFullInitEvent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerNettyFullInitEvent.java index dae7d45b..58f9695f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerNettyFullInitEvent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerNettyFullInitEvent.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.modules.events; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; import pro.gravit.launchserver.LaunchServer; public class LaunchServerNettyFullInitEvent extends LauncherModule.Event { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerPostInitPhase.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerPostInitPhase.java index e582bdf0..cb4ad282 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerPostInitPhase.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerPostInitPhase.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.modules.events; -import pro.gravit.launcher.modules.events.PostInitPhase; +import pro.gravit.launcher.base.modules.events.PostInitPhase; import pro.gravit.launchserver.LaunchServer; public class LaunchServerPostInitPhase extends PostInitPhase { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerProfilesSyncEvent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerProfilesSyncEvent.java index c49ff4a5..a8c1e89d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerProfilesSyncEvent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerProfilesSyncEvent.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.modules.events; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; import pro.gravit.launchserver.LaunchServer; public class LaunchServerProfilesSyncEvent extends LauncherModule.Event { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerUpdatesSyncEvent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerUpdatesSyncEvent.java index c8afddf8..811aae2f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerUpdatesSyncEvent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerUpdatesSyncEvent.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.modules.events; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; import pro.gravit.launchserver.LaunchServer; public class LaunchServerUpdatesSyncEvent extends LauncherModule.Event { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/NewLaunchServerInstanceEvent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/NewLaunchServerInstanceEvent.java index 1dc3a550..9ed2aaaf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/NewLaunchServerInstanceEvent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/NewLaunchServerInstanceEvent.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.modules.events; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; import pro.gravit.launchserver.LaunchServer; public class NewLaunchServerInstanceEvent extends LauncherModule.Event { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/security/SecurityReportModuleEvent.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/security/SecurityReportModuleEvent.java index 8fb01c62..39c85369 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/security/SecurityReportModuleEvent.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/security/SecurityReportModuleEvent.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.modules.events.security; -import pro.gravit.launcher.events.request.SecurityReportRequestEvent; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.events.request.SecurityReportRequestEvent; +import pro.gravit.launcher.base.modules.LauncherModule; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.secure.SecurityReportResponse; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerCoreModule.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerCoreModule.java index 6e54d9bb..798572c9 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerCoreModule.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerCoreModule.java @@ -1,9 +1,9 @@ package pro.gravit.launchserver.modules.impl; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; -import pro.gravit.launcher.modules.events.InitPhase; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.events.InitPhase; import pro.gravit.utils.Version; public class LaunchServerCoreModule extends LauncherModule { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerInitContext.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerInitContext.java index f33f8b5e..c3e35225 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerInitContext.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerInitContext.java @@ -1,6 +1,6 @@ package pro.gravit.launchserver.modules.impl; -import pro.gravit.launcher.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherInitContext; import pro.gravit.launchserver.LaunchServer; public class LaunchServerInitContext implements LauncherInitContext { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java index daa4b592..47dc112e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/impl/LaunchServerModulesManager.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.modules.impl; -import pro.gravit.launcher.LauncherTrustManager; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.impl.SimpleModuleManager; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.impl.SimpleModuleManager; import pro.gravit.launchserver.LaunchServer; import java.nio.file.Path; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java index 3853bf93..7ef57961 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/Client.java @@ -1,8 +1,7 @@ package pro.gravit.launchserver.socket; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.request.secure.HardwareReportRequest; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.interfaces.UserHardware; @@ -11,8 +10,12 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; public class Client { + ReadWriteLock lock = new ReentrantReadWriteLock(); public String auth_id; public long timestamp; public AuthResponse.ConnectTypes type; @@ -84,6 +87,14 @@ public pro.gravit.launchserver.auth.core.User getUser() { return coreObject; } + public Lock readLock() { + return lock.readLock(); + } + + public Lock writeLock() { + return lock.writeLock(); + } + public static class TrustLevel { public byte[] verifySecureKey; public boolean keyChecked; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java index 03de2060..ee46dc8f 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/WebSocketService.java @@ -8,11 +8,11 @@ import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.events.request.ErrorRequestEvent; -import pro.gravit.launcher.events.request.ExitRequestEvent; -import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.events.request.ErrorRequestEvent; +import pro.gravit.launcher.base.events.request.ExitRequestEvent; +import pro.gravit.launcher.base.request.WebSocketEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.handlers.WebSocketFrameHandler; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -21,6 +21,7 @@ import pro.gravit.launchserver.socket.response.cabinet.AssetUploadInfoResponse; import pro.gravit.launchserver.socket.response.cabinet.GetAssetUploadInfoResponse; import pro.gravit.launchserver.socket.response.management.FeaturesResponse; +import pro.gravit.launchserver.socket.response.management.GetConnectUUIDResponse; import pro.gravit.launchserver.socket.response.management.GetPublicKeyResponse; import pro.gravit.launchserver.socket.response.profile.BatchProfileByUsername; import pro.gravit.launchserver.socket.response.profile.ProfileByUUIDResponse; @@ -39,6 +40,8 @@ import java.lang.reflect.Type; import java.util.UUID; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import java.util.function.BiConsumer; public class WebSocketService { @@ -51,11 +54,18 @@ public class WebSocketService { private final LaunchServer server; private final Gson gson; private transient final Logger logger = LogManager.getLogger(); + private ExecutorService executors; public WebSocketService(ChannelGroup channels, LaunchServer server) { this.channels = channels; this.server = server; this.gson = Launcher.gsonManager.gson; + executors = switch (server.config.netty.performance.executorType) { + case NONE -> null; + case DEFAULT -> Executors.newCachedThreadPool(); + case WORK_STEAL -> Executors.newWorkStealingPool(); + case VIRTUAL_THREADS -> Executors.newVirtualThreadPerTaskExecutor(); + }; } public static void registerResponses() { @@ -85,6 +95,7 @@ public static void registerResponses() { providers.register("getPublicKey", GetPublicKeyResponse.class); providers.register("getAssetUploadUrl", GetAssetUploadInfoResponse.class); providers.register("assetUploadInfo", AssetUploadInfoResponse.class); + providers.register("getConnectUUID", GetConnectUUIDResponse.class); } public static String getIPFromContext(ChannelHandlerContext ctx) { @@ -112,9 +123,9 @@ public void forEachActiveChannels(BiConsumer cal } } - public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip) { + public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client client, String ip, UUID connectUUID) { String request = frame.text(); - WebSocketRequestContext context = new WebSocketRequestContext(ctx, request, client, ip); + WebSocketRequestContext context = new WebSocketRequestContext(ctx, request, client, ip, connectUUID); if(hookBeforeParsing.hook(context)) { return; } @@ -126,7 +137,39 @@ public void process(ChannelHandlerContext ctx, TextWebSocketFrame frame, Client sendObject(ctx.channel(), event, WebSocketEvent.class); return; } - process(context, response, client, ip); + var safeStatus = server.config.netty.performance.disableThreadSafeClientObject ? + WebSocketServerResponse.ThreadSafeStatus.NONE : response.getThreadSafeStatus(); + if(executors == null) { + process(safeStatus, client, ip, context, response); + } else { + executors.submit(() -> process(safeStatus, client, ip, context, response)); + } + } + + private void process(WebSocketServerResponse.ThreadSafeStatus safeStatus, Client client, String ip, WebSocketRequestContext context, WebSocketServerResponse response) { + switch (safeStatus) { + case NONE -> { + process(context, response, client, ip); + } + case READ -> { + var lock = client.lock.readLock(); + lock.lock(); + try { + process(context, response, client, ip); + } finally { + lock.unlock(); + } + } + case READ_WRITE -> { + var lock = client.lock.writeLock(); + lock.lock(); + try { + process(context, response, client, ip); + } finally { + lock.unlock(); + } + } + } } void process(WebSocketRequestContext context, WebSocketServerResponse response, Client client, String ip) { @@ -140,6 +183,7 @@ void process(WebSocketRequestContext context, WebSocketServerResponse response, simpleResponse.ctx = ctx; if (ip != null) simpleResponse.ip = ip; else simpleResponse.ip = IOHelper.getIP(ctx.channel().remoteAddress()); + simpleResponse.connectUUID = context.connectUUID; } try { response.execute(ctx, client); @@ -290,14 +334,16 @@ public static class WebSocketRequestContext { public final String text; public final Client client; public final String ip; + public final UUID connectUUID; public WebSocketServerResponse response; public Throwable exception; - public WebSocketRequestContext(ChannelHandlerContext context, String text, Client client, String ip) { + public WebSocketRequestContext(ChannelHandlerContext context, String text, Client client, String ip, UUID connectUUID) { this.context = context; this.text = text; this.client = client; this.ip = ip; + this.connectUUID = connectUUID; } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyWebAPIHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyWebAPIHandler.java index 46fa2fd4..ac4c0057 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyWebAPIHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/NettyWebAPIHandler.java @@ -7,7 +7,7 @@ import io.netty.handler.codec.http.*; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.launchserver.socket.NettyConnectContext; import pro.gravit.utils.helper.IOHelper; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java index 9d2c8dcd..9b5a25dc 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/WebSocketFrameHandler.java @@ -63,32 +63,36 @@ protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) { } catch (Throwable ex) { logger.error("WebSocket frame handler hook error", ex); } - if (frame instanceof TextWebSocketFrame textWebSocketFrame) { - if (logger.isTraceEnabled()) { - logger.trace("Message from {}: {}", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip, textWebSocketFrame.text()); - } - try { - service.process(ctx, textWebSocketFrame, client, context.ip); - } catch (Throwable ex) { - logger.warn("Client {} send invalid request. Connection force closed.", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip); + switch (frame) { + case TextWebSocketFrame textWebSocketFrame -> { if (logger.isTraceEnabled()) { - logger.trace("Client message: {}", textWebSocketFrame.text()); - logger.error("Process websockets request failed", ex); + logger.trace("Message from {}: {}", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip, textWebSocketFrame.text()); } + try { + service.process(ctx, textWebSocketFrame, client, context.ip, connectUUID); + } catch (Throwable ex) { + logger.warn("Client {} send invalid request. Connection force closed.", context.ip == null ? IOHelper.getIP(ctx.channel().remoteAddress()) : context.ip); + if (logger.isTraceEnabled()) { + logger.trace("Client message: {}", textWebSocketFrame.text()); + logger.error("Process websockets request failed", ex); + } + ctx.channel().close(); + } + } + case PingWebSocketFrame pingWebSocketFrame -> { + frame.content().retain(); + ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content())); + //return; + } + case PongWebSocketFrame pongWebSocketFrame -> logger.trace("WebSocket Client received pong"); + case CloseWebSocketFrame closeWebSocketFrame -> { + int statusCode = closeWebSocketFrame.statusCode(); ctx.channel().close(); } - } else if ((frame instanceof PingWebSocketFrame)) { - frame.content().retain(); - ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content())); - //return; - } else if (frame instanceof PongWebSocketFrame) { - logger.trace("WebSocket Client received pong"); - } else if (frame instanceof CloseWebSocketFrame closeWebSocketFrame) { - int statusCode = closeWebSocketFrame.statusCode(); - ctx.channel().close(); - } else { - String message = "unsupported frame type: " + frame.getClass().getName(); - logger.error(new UnsupportedOperationException(message)); // prevent strange crash here. + case null, default -> { + String message = "unsupported frame type: " + frame.getClass().getName(); + logger.error(new UnsupportedOperationException(message)); // prevent strange crash here. + } } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java index 393443cb..1030b973 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/handlers/fileserver/FileServerHandler.java @@ -7,13 +7,13 @@ import io.netty.handler.stream.ChunkedFile; import io.netty.util.CharsetUtil; import pro.gravit.launchserver.socket.handlers.ContentType; +import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.VerifyHelper; import java.io.File; import java.io.FileNotFoundException; import java.io.RandomAccessFile; -import java.net.URI; -import java.net.URISyntaxException; +import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; import java.time.Clock; @@ -152,7 +152,7 @@ private static void setDateAndCacheHeaders(HttpResponse response, File fileToCac response.headers().set(HttpHeaderNames.DATE, dateFormatter.format(time)); // Add cache headers - response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.plus(HTTP_CACHE_SECONDS, ChronoUnit.SECONDS))); + response.headers().set(HttpHeaderNames.EXPIRES, dateFormatter.format(time.plusSeconds(HTTP_CACHE_SECONDS))); response.headers().set(HttpHeaderNames.CACHE_CONTROL, "private, max-age=" + HTTP_CACHE_SECONDS); response.headers().set( HttpHeaderNames.LAST_MODIFIED, dateFormatter.format(Instant.ofEpochMilli(fileToCache.lastModified()))); @@ -182,12 +182,18 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest request) thr return; } - final String uri = request.uri(); + // URLDecoder tries to decode string as application/x-www-form-urlencoded which allows + character to be used as space escape therefore breaking file names with + + final String uri = IOHelper.urlDecodeStrict(request.uri()); final String path; + if (uri == null) { + sendError(ctx, NOT_FOUND); + return; + } + try { - path = Paths.get(new URI(uri).getPath()).normalize().toString().substring(1); - } catch (URISyntaxException e) { + path = Paths.get(IOHelper.getPathFromUrlFragment(uri)).normalize().toString().substring(1); + } catch (InvalidPathException e) { sendError(ctx, BAD_REQUEST); return; } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java index 87e15aed..97b097cd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/SimpleResponse.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.socket.response; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.events.request.ErrorRequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.events.request.ErrorRequestEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.WebSocketService; @@ -13,6 +13,7 @@ public abstract class SimpleResponse implements WebSocketServerResponse { public transient LaunchServer server; public transient WebSocketService service; public transient ChannelHandlerContext ctx; + public transient UUID connectUUID; public transient String ip; public void sendResult(RequestEvent result) { diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/WebSocketServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/WebSocketServerResponse.java index d4a769d8..fc65f6af 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/WebSocketServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/WebSocketServerResponse.java @@ -1,11 +1,19 @@ package pro.gravit.launchserver.socket.response; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; import pro.gravit.launchserver.socket.Client; public interface WebSocketServerResponse extends WebSocketRequest { String getType(); void execute(ChannelHandlerContext ctx, Client client) throws Exception; + + default ThreadSafeStatus getThreadSafeStatus() { + return ThreadSafeStatus.READ; + } + + enum ThreadSafeStatus { + NONE, READ, READ_WRITE + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AdditionalDataResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AdditionalDataResponse.java index b3a38e6b..a4a368b6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AdditionalDataResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AdditionalDataResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.auth; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.AdditionalDataRequestEvent; +import pro.gravit.launcher.base.events.request.AdditionalDataRequestEvent; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.auth.core.interfaces.user.UserSupportAdditionalData; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java index 58f1ea35..2ae4098d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/AuthResponse.java @@ -3,8 +3,8 @@ import io.netty.channel.ChannelHandlerContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.request.auth.AuthRequest; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.manangers.AuthManager; @@ -81,4 +81,9 @@ public AuthContext(Client client, String login, String profileName, String ip, C this.pair = pair; } } + + @Override + public ThreadSafeStatus getThreadSafeStatus() { + return ThreadSafeStatus.READ_WRITE; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java index 947e5dcb..f661b275 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CheckServerResponse.java @@ -3,7 +3,7 @@ import io.netty.channel.ChannelHandlerContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.events.request.CheckServerRequestEvent; +import pro.gravit.launcher.base.events.request.CheckServerRequestEvent; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportHardware; import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportProperties; @@ -40,7 +40,7 @@ public void execute(ChannelHandlerContext ctx, Client pClient) { } result.playerProfile = report.playerProfile; result.uuid = report.uuid; - if(report.session != null) { + if(pClient.permissions.hasPerm("launchserver.checkserver.extended") && report.session != null) { result.sessionId = report.session.getID(); if(needProperties && report.session instanceof UserSessionSupportProperties supportProperties) { result.sessionProperties = supportProperties.getProperties(); diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CurrentUserResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CurrentUserResponse.java index d1aaa064..560cf1cd 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CurrentUserResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/CurrentUserResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.auth; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.CurrentUserRequestEvent; +import pro.gravit.launcher.base.events.request.CurrentUserRequestEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java index af5d4d42..8853883e 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ExitResponse.java @@ -2,8 +2,8 @@ import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.events.request.ExitRequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.events.request.ExitRequestEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.core.UserSession; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportExit; @@ -43,6 +43,10 @@ public void execute(ChannelHandlerContext ctx, Client client) { return; } if (username == null) { + if(!client.isAuth || client.auth == null) { + sendError("You are not authorized"); + return; + } { WebSocketFrameHandler handler = ctx.pipeline().get(WebSocketFrameHandler.class); if (handler == null) { @@ -65,7 +69,6 @@ public void execute(ChannelHandlerContext ctx, Client client) { } sendResult(new ExitRequestEvent(ExitRequestEvent.ExitReason.CLIENT)); } - sendResult(new ExitRequestEvent(ExitRequestEvent.ExitReason.CLIENT)); } else { service.forEachActiveChannels(((channel, webSocketFrameHandler) -> { Client client1 = webSocketFrameHandler.getClient(); @@ -76,4 +79,9 @@ public void execute(ChannelHandlerContext ctx, Client client) { sendResult(new ExitRequestEvent(ExitRequestEvent.ExitReason.NO_EXIT)); } } + + @Override + public ThreadSafeStatus getThreadSafeStatus() { + return ThreadSafeStatus.READ_WRITE; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/FetchClientProfileKeyResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/FetchClientProfileKeyResponse.java index 92f191f5..6a0d04a3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/FetchClientProfileKeyResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/FetchClientProfileKeyResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.auth; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.FetchClientProfileKeyRequestEvent; +import pro.gravit.launcher.base.events.request.FetchClientProfileKeyRequestEvent; import pro.gravit.launchserver.auth.core.UserSession; import pro.gravit.launchserver.auth.core.interfaces.session.UserSessionSupportKeys; import pro.gravit.launchserver.socket.Client; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java index 913218c1..b5d24f81 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/GetAvailabilityAuthResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.auth; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; +import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java index 72a480a2..d1238639 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/JoinServerResponse.java @@ -3,7 +3,7 @@ import io.netty.channel.ChannelHandlerContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.events.request.JoinServerRequestEvent; +import pro.gravit.launcher.base.events.request.JoinServerRequestEvent; import pro.gravit.launchserver.auth.AuthException; import pro.gravit.launchserver.auth.protect.interfaces.JoinServerProtectHandler; import pro.gravit.launchserver.socket.Client; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java index 45067b2e..39058b76 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/ProfilesResponse.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.socket.response.auth; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.ProfilesRequestEvent; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.events.request.ProfilesRequestEvent; +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; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RefreshTokenResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RefreshTokenResponse.java index 892a4e3c..df02e059 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RefreshTokenResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RefreshTokenResponse.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.socket.response.auth; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.events.request.RefreshTokenRequestEvent; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.events.request.RefreshTokenRequestEvent; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.manangers.AuthManager; import pro.gravit.launchserver.socket.Client; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RestoreResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RestoreResponse.java index fa720e5c..3b70a898 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RestoreResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/RestoreResponse.java @@ -1,9 +1,9 @@ package pro.gravit.launchserver.socket.response.auth; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.events.request.LauncherRequestEvent; -import pro.gravit.launcher.events.request.RestoreRequestEvent; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.events.request.LauncherRequestEvent; +import pro.gravit.launcher.base.events.request.RestoreRequestEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.AuthCoreProvider; @@ -105,4 +105,9 @@ public void execute(ChannelHandlerContext ctx, Client client) throws Exception { public interface ExtendedTokenProvider { boolean accept(Client client, AuthProviderPair pair, String extendedToken); } + + @Override + public ThreadSafeStatus getThreadSafeStatus() { + return ThreadSafeStatus.READ_WRITE; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetProfileResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetProfileResponse.java index 423e4a68..b6cb4de1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetProfileResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/auth/SetProfileResponse.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.socket.response.auth; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.SetProfileRequestEvent; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.events.request.SetProfileRequestEvent; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -40,4 +40,9 @@ public void execute(ChannelHandlerContext ctx, Client client) { } sendError("Profile not found"); } + + @Override + public ThreadSafeStatus getThreadSafeStatus() { + return ThreadSafeStatus.READ_WRITE; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/GetAssetUploadInfoResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/GetAssetUploadInfoResponse.java index 60260f11..5136a389 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/GetAssetUploadInfoResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/cabinet/GetAssetUploadInfoResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.cabinet; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.GetAssetUploadUrlRequestEvent; +import pro.gravit.launcher.base.events.request.GetAssetUploadUrlRequestEvent; import pro.gravit.launchserver.auth.core.interfaces.provider.AuthSupportAssetUpload; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/FeaturesResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/FeaturesResponse.java index 74ccf493..02323dd1 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/FeaturesResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/FeaturesResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.management; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.FeaturesRequestEvent; +import pro.gravit.launcher.base.events.request.FeaturesRequestEvent; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetConnectUUIDResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetConnectUUIDResponse.java new file mode 100644 index 00000000..2bcd2c0d --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetConnectUUIDResponse.java @@ -0,0 +1,18 @@ +package pro.gravit.launchserver.socket.response.management; + +import io.netty.channel.ChannelHandlerContext; +import pro.gravit.launcher.base.events.request.GetConnectUUIDRequestEvent; +import pro.gravit.launchserver.socket.Client; +import pro.gravit.launchserver.socket.response.SimpleResponse; + +public class GetConnectUUIDResponse extends SimpleResponse { + @Override + public String getType() { + return "getConnectUUID"; + } + + @Override + public void execute(ChannelHandlerContext ctx, Client client) throws Exception { + sendResult(new GetConnectUUIDRequestEvent(connectUUID, server.shardId)); + } +} diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetPublicKeyResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetPublicKeyResponse.java index 398dc3e4..3e18caff 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetPublicKeyResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/management/GetPublicKeyResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.management; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.GetPublicKeyRequestEvent; +import pro.gravit.launcher.base.events.request.GetPublicKeyRequestEvent; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java index 3193d940..bfdb81ac 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/BatchProfileByUsername.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.socket.response.profile; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; -import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.base.events.request.BatchProfileByUsernameRequestEvent; +import pro.gravit.launcher.base.profiles.PlayerProfile; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java index 90f59088..9bf4ec16 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUUIDResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.profile; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.ProfileByUUIDRequestEvent; +import pro.gravit.launcher.base.events.request.ProfileByUUIDRequestEvent; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.core.User; import pro.gravit.launchserver.socket.Client; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUsername.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUsername.java index d19c301a..50b9efe6 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUsername.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/profile/ProfileByUsername.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.socket.response.profile; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent; -import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.base.events.request.ProfileByUsernameRequestEvent; +import pro.gravit.launcher.base.profiles.PlayerProfile; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java index defe4630..5afd95cf 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/GetSecureLevelInfoResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.secure; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent; +import pro.gravit.launcher.base.events.request.GetSecureLevelInfoRequestEvent; import pro.gravit.launchserver.auth.protect.interfaces.SecureProtectHandler; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -31,4 +31,9 @@ public void execute(ChannelHandlerContext ctx, Client client) { response.enabled = true; sendResult(secureProtectHandler.onGetSecureLevelInfo(response)); } + + @Override + public ThreadSafeStatus getThreadSafeStatus() { + return ThreadSafeStatus.READ_WRITE; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java index b23e5ecb..5b0e25f3 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/HardwareReportResponse.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.socket.response.secure; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.HardwareReportRequestEvent; -import pro.gravit.launcher.request.secure.HardwareReportRequest; +import pro.gravit.launcher.base.events.request.HardwareReportRequestEvent; +import pro.gravit.launcher.base.request.secure.HardwareReportRequest; import pro.gravit.launchserver.auth.protect.interfaces.HardwareProtectHandler; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; @@ -31,4 +31,9 @@ public void execute(ChannelHandlerContext ctx, Client client) { sendResult(new HardwareReportRequestEvent()); } } + + @Override + public ThreadSafeStatus getThreadSafeStatus() { + return ThreadSafeStatus.READ_WRITE; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/SecurityReportResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/SecurityReportResponse.java index de64309a..a7ff6784 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/SecurityReportResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/SecurityReportResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.secure; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.SecurityReportRequestEvent; +import pro.gravit.launcher.base.events.request.SecurityReportRequestEvent; import pro.gravit.launchserver.auth.protect.interfaces.SecureProtectHandler; import pro.gravit.launchserver.modules.events.security.SecurityReportModuleEvent; import pro.gravit.launchserver.socket.Client; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java index 7530995e..46e41a8d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/secure/VerifySecureLevelKeyResponse.java @@ -44,4 +44,9 @@ public void execute(ChannelHandlerContext ctx, Client client) { } } + + @Override + public ThreadSafeStatus getThreadSafeStatus() { + return ThreadSafeStatus.READ_WRITE; + } } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java index 8849c61a..05e6c958 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/LauncherResponse.java @@ -6,7 +6,7 @@ import io.netty.channel.ChannelHandlerContext; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import pro.gravit.launcher.events.request.LauncherRequestEvent; +import pro.gravit.launcher.base.events.request.LauncherRequestEvent; import pro.gravit.launchserver.LaunchServer; import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.socket.Client; @@ -89,8 +89,8 @@ public static class LauncherTokenVerifier implements RestoreResponse.ExtendedTok private final Logger logger = LogManager.getLogger(); public LauncherTokenVerifier(LaunchServer server) { - parser = Jwts.parserBuilder() - .setSigningKey(server.keyAgreementManager.ecdsaPublicKey) + parser = Jwts.parser() + .verifyWith(server.keyAgreementManager.ecdsaPublicKey) .requireIssuer("LaunchServer") .build(); } @@ -110,4 +110,9 @@ public boolean accept(Client client, AuthProviderPair pair, String extendedToken } } + @Override + public ThreadSafeStatus getThreadSafeStatus() { + return ThreadSafeStatus.READ_WRITE; + } + } diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java index bda0328b..5d3d7d67 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateListResponse.java @@ -1,7 +1,7 @@ package pro.gravit.launchserver.socket.response.update; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.UpdateListRequestEvent; +import pro.gravit.launcher.base.events.request.UpdateListRequestEvent; import pro.gravit.launchserver.socket.Client; import pro.gravit.launchserver.socket.response.SimpleResponse; diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java index 47f12185..9f92517d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/socket/response/update/UpdateResponse.java @@ -1,8 +1,8 @@ package pro.gravit.launchserver.socket.response.update; import io.netty.channel.ChannelHandlerContext; -import pro.gravit.launcher.events.request.UpdateRequestEvent; -import pro.gravit.launcher.hasher.HashedDir; +import pro.gravit.launcher.base.events.request.UpdateRequestEvent; +import pro.gravit.launcher.core.hasher.HashedDir; import pro.gravit.launchserver.auth.protect.interfaces.ProfilesProtectHandler; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.socket.Client; diff --git a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg index 03507d17..2f89b1a5 100644 --- a/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg +++ b/LaunchServer/src/main/resources/pro/gravit/launchserver/defaults/proguard.cfg @@ -14,21 +14,21 @@ -keepattributes Signature -adaptresourcefilecontents META-INF/MANIFEST.MF --keeppackagenames com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.**, pro.gravit.utils.**, pro.gravit.launcher.request.**, pro.gravit.launcher.events.**, pro.gravit.launcher.profiles.** +-keeppackagenames com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.runtime.api.**, pro.gravit.launcher.base.api.**, pro.gravit.launcher.client.api.**, pro.gravit.utils.**, pro.gravit.launcher.base.request.**, pro.gravit.launcher.base.events.**, pro.gravit.launcher.base.profiles.** --keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.api.**, pro.gravit.utils.**, pro.gravit.launcher.request.**, pro.gravit.launcher.events.**, pro.gravit.launcher.profiles.**, pro.gravit.launcher.LauncherEngineWrapper { +-keep class com.mojang.**,net.minecraftforge.fml.**,cpw.mods.fml.**,com.google.gson.**,pro.gravit.repackage.**,org.fusesource.**, pro.gravit.launcher.client.api.**, pro.gravit.utils.**, pro.gravit.launcher.base.request.**, pro.gravit.launcher.base.events.**, pro.gravit.launcher.base.profiles.**, pro.gravit.launcher.runtime.LauncherEngineWrapper { *; } --keepclassmembers @pro.gravit.launcher.LauncherNetworkAPI class ** { +-keepclassmembers @pro.gravit.launcher.core.LauncherNetworkAPI class ** { ; ; } -keepclassmembers class ** { - @pro.gravit.launcher.LauncherNetworkAPI + @pro.gravit.launcher.core.LauncherNetworkAPI ; - @pro.gravit.launcher.LauncherNetworkAPI + @pro.gravit.launcher.core.LauncherNetworkAPI ; } diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java index 112fbc13..1d9d8e2d 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/ASMTransformersTest.java @@ -6,7 +6,7 @@ import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; -import pro.gravit.launcher.LauncherInject; +import pro.gravit.launcher.core.LauncherInject; import pro.gravit.launchserver.asm.InjectClassAcceptor; import pro.gravit.utils.helper.JarHelper; diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/ConfigurationTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/ConfigurationTest.java index 89ce58eb..bf2d51a5 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/ConfigurationTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/ConfigurationTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; import pro.gravit.launchserver.impl.TestLaunchServerConfigManager; diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java index f222f818..670d95a2 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/FeatureCollectionTest.java @@ -5,8 +5,6 @@ import pro.gravit.launchserver.auth.AuthProviderPair; import pro.gravit.launchserver.auth.Feature; -import java.util.List; - public class FeatureCollectionTest { public static class TestClass1 implements TextInterface1 { diff --git a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java index 88b8762a..9c663b15 100644 --- a/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java +++ b/LaunchServer/src/test/java/pro/gravit/launchserver/StartLaunchServerTest.java @@ -5,7 +5,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.launchserver.config.LaunchServerConfig; import pro.gravit.launchserver.config.LaunchServerRuntimeConfig; import pro.gravit.launchserver.impl.TestLaunchServerConfigManager; diff --git a/Launcher/build.gradle b/Launcher/build.gradle index b2a0c82b..a2253345 100644 --- a/Launcher/build.gradle +++ b/Launcher/build.gradle @@ -1,18 +1,13 @@ -apply plugin: 'org.openjfx.javafxplugin' apply plugin: 'com.github.johnrengelman.shadow' -String mainClassName = "pro.gravit.launcher.ClientLauncherWrapper" -String mainAgentName = "pro.gravit.launcher.LauncherAgent" +String mainClassName = "pro.gravit.launcher.start.ClientLauncherWrapper" +String mainAgentName = "pro.gravit.launcher.runtime.LauncherAgent" repositories { maven { url "https://repo.spring.io/plugins-release/" } } -javafx { - version = "12" - modules = ['javafx.controls', 'javafx.fxml'] -} sourceCompatibility = '17' targetCompatibility = '17' @@ -50,11 +45,9 @@ dependencies { pack project(':LauncherAPI') - pack project(':LauncherModernCore') pack project(':LauncherClient') pack project(':LauncherStart') - bundle group: 'com.github.oshi', name: 'oshi-core', version: rootProject['verOshiCore'] - pack group: 'io.netty', name: 'netty-codec-http', version: rootProject['verNetty'] + bundle(group: 'com.github.oshi', name: 'oshi-core', version: rootProject['verOshiCore']) } tasks.register('genRuntimeJS', Zip) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/LauncherEngine.java similarity index 87% rename from Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/LauncherEngine.java index 6acaa780..8de18308 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngine.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/LauncherEngine.java @@ -1,26 +1,31 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.runtime; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.LauncherConfig; import pro.gravit.launcher.client.*; -import pro.gravit.launcher.client.events.ClientEngineInitPhase; +import pro.gravit.launcher.runtime.client.*; +import pro.gravit.launcher.runtime.client.events.ClientEngineInitPhase; import pro.gravit.launcher.client.events.ClientExitPhase; -import pro.gravit.launcher.client.events.ClientPreGuiPhase; -import pro.gravit.launcher.console.GetPublicKeyCommand; -import pro.gravit.launcher.console.ModulesCommand; -import pro.gravit.launcher.console.SignDataCommand; -import pro.gravit.launcher.gui.NoRuntimeProvider; -import pro.gravit.launcher.gui.RuntimeProvider; -import pro.gravit.launcher.managers.ConsoleManager; -import pro.gravit.launcher.modules.events.OfflineModeEvent; -import pro.gravit.launcher.modules.events.PreConfigPhase; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; -import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestException; -import pro.gravit.launcher.request.RequestService; -import pro.gravit.launcher.request.auth.*; -import pro.gravit.launcher.request.websockets.OfflineRequestService; -import pro.gravit.launcher.request.websockets.StdWebSocketService; -import pro.gravit.launcher.utils.NativeJVMHalt; +import pro.gravit.launcher.runtime.client.events.ClientPreGuiPhase; +import pro.gravit.launcher.runtime.console.GetPublicKeyCommand; +import pro.gravit.launcher.runtime.console.ModulesCommand; +import pro.gravit.launcher.runtime.console.SignDataCommand; +import pro.gravit.launcher.runtime.gui.NoRuntimeProvider; +import pro.gravit.launcher.runtime.gui.RuntimeProvider; +import pro.gravit.launcher.runtime.managers.ConsoleManager; +import pro.gravit.launcher.client.utils.NativeJVMHalt; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.modules.events.OfflineModeEvent; +import pro.gravit.launcher.base.modules.events.PreConfigPhase; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.optional.triggers.OptionalTrigger; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.RequestException; +import pro.gravit.launcher.base.request.RequestService; +import pro.gravit.launcher.base.request.auth.*; +import pro.gravit.launcher.base.request.websockets.OfflineRequestService; +import pro.gravit.launcher.base.request.websockets.StdWebSocketService; +import pro.gravit.launcher.start.RuntimeModuleManager; import pro.gravit.utils.helper.*; import java.io.IOException; diff --git a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngineWrapper.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/LauncherEngineWrapper.java similarity index 94% rename from Launcher/src/main/java/pro/gravit/launcher/LauncherEngineWrapper.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/LauncherEngineWrapper.java index a637a571..b0cd6306 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/LauncherEngineWrapper.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/LauncherEngineWrapper.java @@ -1,5 +1,6 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.runtime; +import pro.gravit.launcher.core.LauncherNetworkAPI; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.launch.LaunchOptions; import pro.gravit.utils.launch.ModuleLaunch; diff --git a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/NewLauncherSettings.java similarity index 54% rename from Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/NewLauncherSettings.java index e7019d0a..a58108ac 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/NewLauncherSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/NewLauncherSettings.java @@ -1,12 +1,9 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.runtime; -import pro.gravit.launcher.client.UserSettings; -import pro.gravit.launcher.hasher.HashedDir; +import pro.gravit.launcher.runtime.client.UserSettings; +import pro.gravit.launcher.core.LauncherNetworkAPI; -import java.nio.file.Path; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; public class NewLauncherSettings { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/ClientLauncherProcess.java similarity index 85% rename from Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/ClientLauncherProcess.java index 7352126b..9f8b3293 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/ClientLauncherProcess.java @@ -1,22 +1,25 @@ -package pro.gravit.launcher.client; +package pro.gravit.launcher.runtime.client; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.LauncherEngine; -import pro.gravit.launcher.client.events.client.ClientProcessBuilderCreateEvent; -import pro.gravit.launcher.client.events.client.ClientProcessBuilderLaunchedEvent; -import pro.gravit.launcher.client.events.client.ClientProcessBuilderParamsWrittedEvent; -import pro.gravit.launcher.client.events.client.ClientProcessBuilderPreLaunchEvent; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.launcher.profiles.optional.OptionalView; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; -import pro.gravit.launcher.profiles.optional.actions.OptionalActionJvmArgs; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.LauncherConfig; +import pro.gravit.launcher.client.ClientLauncherEntryPoint; +import pro.gravit.launcher.client.ClientParams; +import pro.gravit.launcher.runtime.LauncherEngine; +import pro.gravit.launcher.runtime.client.events.ClientProcessBuilderCreateEvent; +import pro.gravit.launcher.runtime.client.events.ClientProcessBuilderLaunchedEvent; +import pro.gravit.launcher.runtime.client.events.ClientProcessBuilderParamsWrittedEvent; +import pro.gravit.launcher.runtime.client.events.ClientProcessBuilderPreLaunchEvent; +import pro.gravit.launcher.core.hasher.HashedDir; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.PlayerProfile; +import pro.gravit.launcher.base.profiles.optional.OptionalView; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalActionJvmArgs; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.core.serialize.HOutput; import pro.gravit.utils.helper.*; +import javax.crypto.CipherOutputStream; import java.io.File; import java.io.IOException; import java.net.ServerSocket; @@ -28,7 +31,6 @@ import java.util.stream.Collectors; public class ClientLauncherProcess { - public final List pre = new LinkedList<>(); public final ClientParams params = new ClientParams(); public final List jvmArgs = new LinkedList<>(); @@ -75,6 +77,7 @@ public ClientLauncherProcess(Path clientDir, Path assetDir, JavaHelper.JavaVersi this.params.clientDir = this.workDir.toString(); this.params.resourcePackDir = resourcePackDir.toAbsolutePath().toString(); this.params.assetDir = assetDir.toAbsolutePath().toString(); + this.params.timestamp = System.currentTimeMillis(); Path nativesPath; if(profile.hasFlag(ClientProfile.CompatibilityFlags.LEGACY_NATIVES_DIR)) { nativesPath = workDir.resolve("natives"); @@ -147,7 +150,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { systemClassPath.addAll(ClientLauncherEntryPoint.resolveClassPath(workDir, params.actions, params.profile) .filter(x -> !params.profile.getModulePath().contains(workDir.relativize(x).toString())) .map(Path::toString) - .collect(Collectors.toList())); + .toList()); } if (Launcher.getConfig().environment != LauncherConfig.LauncherEnvironment.PROD) { processArgs.add(JVMHelper.jvmProperty(LogHelper.DEV_PROPERTY, String.valueOf(LogHelper.isDevEnabled()))); @@ -175,7 +178,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { var env = processBuilder.environment(); // https://github.com/Admicos/minecraft-wayland/issues/55 env.put("__GL_THREADED_OPTIMIZATIONS", "0"); - if(params.lwjglGlfwWayland) { + if(params.lwjglGlfwWayland && !params.profile.hasFlag(ClientProfile.CompatibilityFlags.WAYLAND_USE_CUSTOM_GLFW)) { env.remove("DISPLAY"); // No X11 } } @@ -197,18 +200,18 @@ private void applyJava9Params(List processArgs) { StringBuilder modulesPath = new StringBuilder(); StringBuilder modulesAdd = new StringBuilder(); for (String moduleName : jvmModules) { - if (modulesAdd.length() > 0) modulesAdd.append(","); + if (!modulesAdd.isEmpty()) modulesAdd.append(","); modulesAdd.append(moduleName); } for (String modulePath : jvmModulesPaths) { - if (modulesPath.length() > 0) modulesPath.append(File.pathSeparator); + if (!modulesPath.isEmpty()) modulesPath.append(File.pathSeparator); modulesPath.append(modulePath); } - if (modulesAdd.length() > 0) { + if (!modulesAdd.isEmpty()) { processArgs.add("--add-modules"); processArgs.add(modulesAdd.toString()); } - if (modulesPath.length() > 0) { + if (!modulesPath.isEmpty()) { processArgs.add("--module-path"); processArgs.add(modulesPath.toString()); } @@ -222,7 +225,7 @@ public void runWriteParams(SocketAddress address) throws IOException { waitWriteParams.notifyAll(); } Socket socket = serverSocket.accept(); - try (HOutput output = new HOutput(socket.getOutputStream())) { + try (HOutput output = new HOutput(new CipherOutputStream(socket.getOutputStream(), SecurityHelper.newAESEncryptCipher(SecurityHelper.fromHex(Launcher.getConfig().secretKeyClient))))) { byte[] serializedMainParams = IOHelper.encode(Launcher.gsonManager.gson.toJson(params)); output.writeByteArray(serializedMainParams, 0); params.clientHDir.write(output); @@ -233,6 +236,8 @@ public void runWriteParams(SocketAddress address) throws IOException { output.writeBoolean(true); params.javaHDir.write(output); } + } catch (Exception e) { + throw new IOException(e); } } LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderParamsWrittedEvent(this)); diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/DirBridge.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/DirBridge.java similarity index 97% rename from LauncherClient/src/main/java/pro/gravit/launcher/client/DirBridge.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/DirBridge.java index 397c056d..f5e6c4fa 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/DirBridge.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/DirBridge.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.client; +package pro.gravit.launcher.runtime.client; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/RuntimeGsonManager.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/RuntimeGsonManager.java similarity index 69% rename from Launcher/src/main/java/pro/gravit/launcher/client/RuntimeGsonManager.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/RuntimeGsonManager.java index b8789cf4..6f31c359 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/RuntimeGsonManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/RuntimeGsonManager.java @@ -1,9 +1,10 @@ -package pro.gravit.launcher.client; +package pro.gravit.launcher.runtime.client; import com.google.gson.GsonBuilder; -import pro.gravit.launcher.managers.GsonManager; -import pro.gravit.launcher.modules.events.PreGsonPhase; -import pro.gravit.launcher.request.websockets.ClientWebSocketService; +import pro.gravit.launcher.start.RuntimeModuleManager; +import pro.gravit.launcher.core.managers.GsonManager; +import pro.gravit.launcher.base.modules.events.PreGsonPhase; +import pro.gravit.launcher.base.request.websockets.ClientWebSocketService; import pro.gravit.utils.UniversalJsonAdapter; public class RuntimeGsonManager extends GsonManager { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/ServerPinger.java similarity index 97% rename from Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/ServerPinger.java index c798f3d3..53f113b2 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ServerPinger.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/ServerPinger.java @@ -1,12 +1,12 @@ -package pro.gravit.launcher.client; +package pro.gravit.launcher.runtime.client; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.ClientProfileVersions; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfileVersions; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.core.serialize.HOutput; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.VerifyHelper; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/UserSettings.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/UserSettings.java similarity index 77% rename from Launcher/src/main/java/pro/gravit/launcher/client/UserSettings.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/UserSettings.java index 1f6fb9b5..37f4a105 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/UserSettings.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/UserSettings.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.client; +package pro.gravit.launcher.runtime.client; import pro.gravit.utils.ProviderMap; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientEngineInitPhase.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientEngineInitPhase.java similarity index 54% rename from Launcher/src/main/java/pro/gravit/launcher/client/events/ClientEngineInitPhase.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientEngineInitPhase.java index b877971f..51f78965 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientEngineInitPhase.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientEngineInitPhase.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events; +package pro.gravit.launcher.runtime.client.events; -import pro.gravit.launcher.LauncherEngine; -import pro.gravit.launcher.modules.events.InitPhase; +import pro.gravit.launcher.runtime.LauncherEngine; +import pro.gravit.launcher.base.modules.events.InitPhase; public class ClientEngineInitPhase extends InitPhase { public final LauncherEngine engine; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientGuiPhase.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientGuiPhase.java similarity index 58% rename from Launcher/src/main/java/pro/gravit/launcher/client/events/ClientGuiPhase.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientGuiPhase.java index 2e70f857..54fe9305 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientGuiPhase.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientGuiPhase.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events; +package pro.gravit.launcher.runtime.client.events; -import pro.gravit.launcher.gui.RuntimeProvider; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.runtime.gui.RuntimeProvider; +import pro.gravit.launcher.base.modules.LauncherModule; public class ClientGuiPhase extends LauncherModule.Event { public final RuntimeProvider runtimeProvider; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientPreGuiPhase.java similarity index 58% rename from Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientPreGuiPhase.java index ebbad380..39572c9b 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientPreGuiPhase.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientPreGuiPhase.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events; +package pro.gravit.launcher.runtime.client.events; -import pro.gravit.launcher.gui.RuntimeProvider; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.runtime.gui.RuntimeProvider; +import pro.gravit.launcher.base.modules.LauncherModule; public class ClientPreGuiPhase extends LauncherModule.Event { public RuntimeProvider runtimeProvider; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderCreateEvent.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderCreateEvent.java similarity index 61% rename from Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderCreateEvent.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderCreateEvent.java index 2fe33846..d0d1ebc7 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderCreateEvent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderCreateEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events.client; +package pro.gravit.launcher.runtime.client.events; -import pro.gravit.launcher.client.ClientLauncherProcess; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.runtime.client.ClientLauncherProcess; +import pro.gravit.launcher.base.modules.LauncherModule; public class ClientProcessBuilderCreateEvent extends LauncherModule.Event { public final ClientLauncherProcess processBuilder; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderLaunchedEvent.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderLaunchedEvent.java similarity index 61% rename from Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderLaunchedEvent.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderLaunchedEvent.java index dc5e4ffc..3d9559fd 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderLaunchedEvent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderLaunchedEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events.client; +package pro.gravit.launcher.runtime.client.events; -import pro.gravit.launcher.client.ClientLauncherProcess; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.runtime.client.ClientLauncherProcess; +import pro.gravit.launcher.base.modules.LauncherModule; public class ClientProcessBuilderLaunchedEvent extends LauncherModule.Event { public final ClientLauncherProcess processBuilder; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderParamsWrittedEvent.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderParamsWrittedEvent.java similarity index 59% rename from Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderParamsWrittedEvent.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderParamsWrittedEvent.java index bb535568..c3a808e8 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderParamsWrittedEvent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderParamsWrittedEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events.client; +package pro.gravit.launcher.runtime.client.events; -import pro.gravit.launcher.client.ClientLauncherProcess; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.runtime.client.ClientLauncherProcess; +import pro.gravit.launcher.base.modules.LauncherModule; public class ClientProcessBuilderParamsWrittedEvent extends LauncherModule.Event { public final ClientLauncherProcess process; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderPreLaunchEvent.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderPreLaunchEvent.java similarity index 61% rename from Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderPreLaunchEvent.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderPreLaunchEvent.java index 2b9b1025..ce013aa2 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderPreLaunchEvent.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/client/events/ClientProcessBuilderPreLaunchEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events.client; +package pro.gravit.launcher.runtime.client.events; -import pro.gravit.launcher.client.ClientLauncherProcess; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.runtime.client.ClientLauncherProcess; +import pro.gravit.launcher.base.modules.LauncherModule; public class ClientProcessBuilderPreLaunchEvent extends LauncherModule.Event { public final ClientLauncherProcess processBuilder; diff --git a/Launcher/src/main/java/pro/gravit/launcher/runtime/console/GetConnectUUIDCommand.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/GetConnectUUIDCommand.java new file mode 100644 index 00000000..ae3b0e11 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/GetConnectUUIDCommand.java @@ -0,0 +1,23 @@ +package pro.gravit.launcher.runtime.console; + +import pro.gravit.launcher.base.request.management.GetConnectUUIDRequest; +import pro.gravit.utils.command.Command; +import pro.gravit.utils.helper.LogHelper; + +public class GetConnectUUIDCommand extends Command { + @Override + public String getArgsDescription() { + return null; + } + + @Override + public String getUsageDescription() { + return "Get your connectUUID"; + } + + @Override + public void invoke(String... args) throws Exception { + var response = new GetConnectUUIDRequest().request(); + LogHelper.info("Your connectUUID: %s | shardId %d", response.connectUUID.toString(), response.shardId); + } +} diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/GetPublicKeyCommand.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/GetPublicKeyCommand.java similarity index 87% rename from Launcher/src/main/java/pro/gravit/launcher/console/GetPublicKeyCommand.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/console/GetPublicKeyCommand.java index e20313fc..2d2e1ec1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/GetPublicKeyCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/GetPublicKeyCommand.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.console; +package pro.gravit.launcher.runtime.console; -import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.runtime.LauncherEngine; import pro.gravit.utils.command.Command; import pro.gravit.utils.helper.LogHelper; diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/ModulesCommand.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/ModulesCommand.java similarity index 84% rename from Launcher/src/main/java/pro/gravit/launcher/console/ModulesCommand.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/console/ModulesCommand.java index 94b03799..060903e9 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/ModulesCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/ModulesCommand.java @@ -1,10 +1,10 @@ -package pro.gravit.launcher.console; +package pro.gravit.launcher.runtime.console; -import pro.gravit.launcher.LauncherEngine; -import pro.gravit.launcher.LauncherTrustManager; -import pro.gravit.launcher.managers.ConsoleManager; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.runtime.LauncherEngine; +import pro.gravit.launcher.runtime.managers.ConsoleManager; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.utils.command.Command; import pro.gravit.utils.helper.LogHelper; diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/SignDataCommand.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/SignDataCommand.java similarity index 89% rename from Launcher/src/main/java/pro/gravit/launcher/console/SignDataCommand.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/console/SignDataCommand.java index 2757a64a..7be082d0 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/SignDataCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/SignDataCommand.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.console; +package pro.gravit.launcher.runtime.console; -import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.runtime.LauncherEngine; import pro.gravit.utils.command.Command; import pro.gravit.utils.helper.LogHelper; diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/UnlockCommand.java similarity index 83% rename from Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/console/UnlockCommand.java index 6d678051..424949fb 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/UnlockCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/UnlockCommand.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.console; +package pro.gravit.launcher.runtime.console; -import pro.gravit.launcher.managers.ConsoleManager; -import pro.gravit.launcher.managers.SettingsManager; +import pro.gravit.launcher.runtime.managers.ConsoleManager; +import pro.gravit.launcher.runtime.managers.SettingsManager; import pro.gravit.utils.command.Command; import pro.gravit.utils.helper.LogHelper; diff --git a/Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/test/PrintHardwareInfoCommand.java similarity index 96% rename from Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/console/test/PrintHardwareInfoCommand.java index 93bbe490..675026f1 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/console/test/PrintHardwareInfoCommand.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/console/test/PrintHardwareInfoCommand.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.console.test; +package pro.gravit.launcher.runtime.console.test; -import pro.gravit.launcher.utils.HWIDProvider; +import pro.gravit.launcher.runtime.utils.HWIDProvider; import pro.gravit.utils.command.Command; import pro.gravit.utils.helper.LogHelper; diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/ClientRuntimeProvider.java similarity index 91% rename from Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/debug/ClientRuntimeProvider.java index f9a1a682..cac5dc09 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/debug/ClientRuntimeProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/ClientRuntimeProvider.java @@ -1,17 +1,17 @@ -package pro.gravit.launcher.debug; +package pro.gravit.launcher.runtime.debug; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherEngine; -import pro.gravit.launcher.api.AuthService; -import pro.gravit.launcher.api.ClientService; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.events.request.ProfilesRequestEvent; -import pro.gravit.launcher.gui.RuntimeProvider; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.update.ProfilesRequest; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.api.AuthService; +import pro.gravit.launcher.base.api.ClientService; +import pro.gravit.launcher.runtime.LauncherEngine; +import pro.gravit.launcher.runtime.gui.RuntimeProvider; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.events.request.ProfilesRequestEvent; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.update.ProfilesRequest; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.launch.*; diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugLauncherTrustManager.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugLauncherTrustManager.java similarity index 90% rename from Launcher/src/main/java/pro/gravit/launcher/debug/DebugLauncherTrustManager.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugLauncherTrustManager.java index e49d79d2..cfebabde 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugLauncherTrustManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugLauncherTrustManager.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.debug; +package pro.gravit.launcher.runtime.debug; -import pro.gravit.launcher.LauncherTrustManager; +import pro.gravit.launcher.core.LauncherTrustManager; import java.security.cert.X509Certificate; diff --git a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMain.java similarity index 83% rename from Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMain.java index e3529e76..1d3ee6c3 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/debug/DebugMain.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/debug/DebugMain.java @@ -1,19 +1,19 @@ -package pro.gravit.launcher.debug; +package pro.gravit.launcher.runtime.debug; -import pro.gravit.launcher.ClientLauncherMethods; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.LauncherConfig; +import pro.gravit.launcher.client.ClientLauncherMethods; +import pro.gravit.launcher.runtime.LauncherEngine; import pro.gravit.launcher.client.RuntimeLauncherCoreModule; -import pro.gravit.launcher.client.RuntimeModuleManager; -import pro.gravit.launcher.managers.ConsoleManager; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.events.OfflineModeEvent; -import pro.gravit.launcher.modules.events.PreConfigPhase; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestService; -import pro.gravit.launcher.request.websockets.OfflineRequestService; -import pro.gravit.launcher.request.websockets.StdWebSocketService; +import pro.gravit.launcher.runtime.managers.ConsoleManager; +import pro.gravit.launcher.start.RuntimeModuleManager; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.events.OfflineModeEvent; +import pro.gravit.launcher.base.modules.events.PreConfigPhase; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.RequestService; +import pro.gravit.launcher.base.request.websockets.OfflineRequestService; +import pro.gravit.launcher.base.request.websockets.StdWebSocketService; import pro.gravit.utils.helper.LogHelper; import java.lang.invoke.MethodHandles; diff --git a/Launcher/src/main/java/pro/gravit/launcher/gui/NoRuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/gui/NoRuntimeProvider.java similarity index 90% rename from Launcher/src/main/java/pro/gravit/launcher/gui/NoRuntimeProvider.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/gui/NoRuntimeProvider.java index 14e75afb..cb44fbab 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/gui/NoRuntimeProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/gui/NoRuntimeProvider.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.gui; +package pro.gravit.launcher.runtime.gui; import javax.swing.*; diff --git a/Launcher/src/main/java/pro/gravit/launcher/gui/RuntimeProvider.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/gui/RuntimeProvider.java similarity index 75% rename from Launcher/src/main/java/pro/gravit/launcher/gui/RuntimeProvider.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/gui/RuntimeProvider.java index bee04f48..2a99899d 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/gui/RuntimeProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/gui/RuntimeProvider.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.gui; +package pro.gravit.launcher.runtime.gui; public interface RuntimeProvider { void run(String[] args); diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/managers/ConsoleManager.java similarity index 84% rename from Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/managers/ConsoleManager.java index bffca63e..1c0945de 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/ConsoleManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/managers/ConsoleManager.java @@ -1,10 +1,11 @@ -package pro.gravit.launcher.managers; +package pro.gravit.launcher.runtime.managers; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherEngine; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.runtime.LauncherEngine; import pro.gravit.launcher.client.events.ClientUnlockConsoleEvent; -import pro.gravit.launcher.console.UnlockCommand; -import pro.gravit.launcher.console.test.PrintHardwareInfoCommand; +import pro.gravit.launcher.runtime.console.GetConnectUUIDCommand; +import pro.gravit.launcher.runtime.console.UnlockCommand; +import pro.gravit.launcher.runtime.console.test.PrintHardwareInfoCommand; import pro.gravit.utils.command.CommandHandler; import pro.gravit.utils.command.JLineCommandHandler; import pro.gravit.utils.command.StdCommandHandler; @@ -46,6 +47,7 @@ public static void registerCommands() { handler.registerCommand("clear", new ClearCommand(handler)); handler.registerCommand("unlock", new UnlockCommand()); handler.registerCommand("printhardware", new PrintHardwareInfoCommand()); + handler.registerCommand("getconnectuuid", new GetConnectUUIDCommand()); } public static boolean checkUnlockKey(String key) { diff --git a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/managers/SettingsManager.java similarity index 60% rename from Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/managers/SettingsManager.java index 54185d6f..86ea4813 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/managers/SettingsManager.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/managers/SettingsManager.java @@ -1,21 +1,10 @@ -package pro.gravit.launcher.managers; +package pro.gravit.launcher.runtime.managers; -import pro.gravit.launcher.NewLauncherSettings; -import pro.gravit.launcher.client.DirBridge; -import pro.gravit.launcher.config.JsonConfigurable; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.utils.helper.IOHelper; +import pro.gravit.launcher.runtime.NewLauncherSettings; +import pro.gravit.launcher.runtime.client.DirBridge; +import pro.gravit.launcher.base.config.JsonConfigurable; import pro.gravit.utils.helper.LogHelper; -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; - public class SettingsManager extends JsonConfigurable { public static NewLauncherSettings settings; diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/utils/HWIDProvider.java similarity index 93% rename from Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/utils/HWIDProvider.java index 2cc8dd06..9154a793 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/HWIDProvider.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/utils/HWIDProvider.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.utils; +package pro.gravit.launcher.runtime.utils; import oshi.SystemInfo; import oshi.hardware.*; import oshi.software.os.OperatingSystem; -import pro.gravit.launcher.request.secure.HardwareReportRequest; +import pro.gravit.launcher.base.request.secure.HardwareReportRequest; import java.util.List; @@ -41,7 +41,7 @@ public int getProcessorLogicalCount() { public boolean isBattery() { List powerSources = hardware.getPowerSources(); - return powerSources != null && powerSources.size() != 0; + return powerSources != null && !powerSources.isEmpty(); } //Hardware Information @@ -93,7 +93,7 @@ public long getGraphicCardMemory() { public byte[] getDisplayID() { List displays = hardware.getDisplays(); - if (displays == null || displays.size() == 0) return null; + if (displays == null || displays.isEmpty()) return null; for (Display display : displays) { return display.getEdid(); } diff --git a/Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java b/Launcher/src/main/java/pro/gravit/launcher/runtime/utils/LauncherUpdater.java similarity index 91% rename from Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java rename to Launcher/src/main/java/pro/gravit/launcher/runtime/utils/LauncherUpdater.java index f2712a0e..27d9edee 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/utils/LauncherUpdater.java +++ b/Launcher/src/main/java/pro/gravit/launcher/runtime/utils/LauncherUpdater.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.utils; +package pro.gravit.launcher.runtime.utils; -import pro.gravit.launcher.LauncherEngine; -import pro.gravit.launcher.LauncherInject; -import pro.gravit.launcher.request.update.LauncherRequest; +import pro.gravit.launcher.runtime.LauncherEngine; +import pro.gravit.launcher.core.LauncherInject; +import pro.gravit.launcher.base.request.update.LauncherRequest; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; @@ -22,7 +22,7 @@ import java.util.Arrays; import java.util.List; -import static pro.gravit.launcher.modern.Downloader.makeSSLSocketFactory; +import static pro.gravit.launcher.base.Downloader.makeSSLSocketFactory; public class LauncherUpdater { @LauncherInject("launcher.certificatePinning") diff --git a/LauncherAPI/build.gradle b/LauncherAPI/build.gradle index 8a418fc6..d66ee2a7 100644 --- a/LauncherAPI/build.gradle +++ b/LauncherAPI/build.gradle @@ -1,9 +1,8 @@ -sourceCompatibility = '1.8' -targetCompatibility = '1.8' +sourceCompatibility = '17' +targetCompatibility = '17' dependencies { api project(':LauncherCore') - compileOnly group: 'io.netty', name: 'netty-codec-http', version: rootProject['verNetty'] testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter', version: rootProject['verJunit'] } @@ -14,29 +13,10 @@ api project(':LauncherCore') } } -sourceSets { - java11 { - java { - srcDirs = ['src/main/java11'] - } - dependencies { - java11Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava } - } - } -} - jar { - into('META-INF/versions/11') { - from sourceSets.java11.output - } archiveClassifier.set('clean') } -compileJava11Java { - sourceCompatibility = 11 - targetCompatibility = 11 -} - tasks.register('sourcesJar', Jar) { from sourceSets.main.allJava archiveClassifier.set('sources') diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/api/ClientService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/api/ClientService.java deleted file mode 100644 index 50c3a8da..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/api/ClientService.java +++ /dev/null @@ -1,19 +0,0 @@ -package pro.gravit.launcher.api; - -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.launch.ClassLoaderControl; - -import java.lang.instrument.Instrumentation; -import java.net.URL; - -public class ClientService { - public static Instrumentation instrumentation; - public static ClassLoaderControl classLoaderControl; - public static String nativePath; - public static URL[] baseURLs; - - public static String findLibrary(String name) { - return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(JVMHelper.NATIVE_PREFIX).concat(name).concat(JVMHelper.NATIVE_EXTENSION); - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/ClientPermissions.java similarity index 98% rename from LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/ClientPermissions.java index e42164cc..bfa23a50 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/ClientPermissions.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/ClientPermissions.java @@ -1,4 +1,6 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.base; + +import pro.gravit.launcher.core.LauncherNetworkAPI; import java.util.*; diff --git a/LauncherModernCore/src/main/java/pro/gravit/launcher/modern/Downloader.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java similarity index 83% rename from LauncherModernCore/src/main/java/pro/gravit/launcher/modern/Downloader.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java index 6cecfc9e..6eecdc21 100644 --- a/LauncherModernCore/src/main/java/pro/gravit/launcher/modern/Downloader.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/Downloader.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.modern; +package pro.gravit.launcher.base; -import pro.gravit.launcher.CertificatePinningTrustManager; -import pro.gravit.launcher.LauncherInject; +import pro.gravit.launcher.core.CertificatePinningTrustManager; +import pro.gravit.launcher.core.LauncherInject; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; @@ -21,6 +21,7 @@ import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.cert.CertificateException; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Queue; @@ -54,6 +55,24 @@ public static ThreadFactory getDaemonThreadFactory(String name) { }; } + public static HttpClient.Builder newHttpClientBuilder() { + try { + if(isCertificatePinning) { + return HttpClient.newBuilder() + .sslContext(makeSSLContext()) + .version(isNoHttp2 ? HttpClient.Version.HTTP_1_1 : HttpClient.Version.HTTP_2) + .followRedirects(HttpClient.Redirect.NORMAL); + } else { + return HttpClient.newBuilder() + .version(isNoHttp2 ? HttpClient.Version.HTTP_1_1 : HttpClient.Version.HTTP_2) + .followRedirects(HttpClient.Redirect.NORMAL); + } + } catch (NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException | + KeyManagementException e) { + throw new RuntimeException(e); + } + } + public static SSLSocketFactory makeSSLSocketFactory() throws NoSuchAlgorithmException, CertificateException, KeyStoreException, IOException, KeyManagementException { if (sslSocketFactory != null) return sslSocketFactory; SSLContext sslContext = makeSSLContext(); @@ -78,9 +97,7 @@ public static Downloader downloadFile(URI uri, Path path, ExecutorService execut downloader.future = downloader.downloadFile(uri, path); if (closeExecutor) { ExecutorService finalExecutor = executor; - downloader.future = downloader.future.thenAccept((e) -> { - finalExecutor.shutdownNow(); - }).exceptionallyCompose((ex) -> { + downloader.future = downloader.future.thenAccept((e) -> finalExecutor.shutdownNow()).exceptionallyCompose((ex) -> { finalExecutor.shutdownNow(); return CompletableFuture.failedFuture(ex); }); @@ -99,9 +116,7 @@ public static Downloader downloadList(List files, String baseURL, Pat downloader.future = downloader.downloadFiles(files, baseURL, targetDir, callback, executor, threads); if (closeExecutor) { ExecutorService finalExecutor = executor; - downloader.future = downloader.future.thenAccept((e) -> { - finalExecutor.shutdownNow(); - }).exceptionallyCompose((ex) -> { + downloader.future = downloader.future.thenAccept((e) -> finalExecutor.shutdownNow()).exceptionallyCompose((ex) -> { finalExecutor.shutdownNow(); return CompletableFuture.failedFuture(ex); }); @@ -113,17 +128,8 @@ public static Downloader newDownloader(ExecutorService executor) { if (executor == null) { throw new NullPointerException(); } - HttpClient.Builder builder = HttpClient.newBuilder() - .version(isNoHttp2 ? HttpClient.Version.HTTP_1_1 : HttpClient.Version.HTTP_2) - .followRedirects(HttpClient.Redirect.NORMAL) + HttpClient.Builder builder = newHttpClientBuilder() .executor(executor); - if (isCertificatePinning) { - try { - builder.sslContext(makeSSLContext()); - } catch (Exception e) { - throw new SecurityException(e); - } - } HttpClient client = builder.build(); return new Downloader(client, executor); } @@ -163,6 +169,16 @@ public CompletableFuture downloadFile(URI uri, Path path) { }); } + public CompletableFuture downloadFile(String url, Path path, DownloadCallback callback, ExecutorService executor) throws Exception { + return downloadFiles(new ArrayList<>(List.of(new SizedFile(url, path.getFileName().toString()))), null, + path.getParent(), callback, executor, 1); + } + + public CompletableFuture downloadFile(String url, Path path, long size, DownloadCallback callback, ExecutorService executor) throws Exception { + return downloadFiles(new ArrayList<>(List.of(new SizedFile(url, path.getFileName().toString(), size))), null, + path.getParent(), callback, executor, 1); + } + public CompletableFuture downloadFiles(List files, String baseURL, Path targetDir, DownloadCallback callback, ExecutorService executor, int threads) throws Exception { // URI scheme URI baseUri = baseURL == null ? null : new URI(baseURL); @@ -183,7 +199,13 @@ public CompletableFuture downloadFiles(List files, String baseU } try { DownloadTask task = sendAsync(file, baseUri, targetDir, callback); - task.completableFuture.thenAccept(consumerObject.next).exceptionally(ec -> { + task.completableFuture.thenCompose((res) -> { + if(res.statusCode() < 200 || res.statusCode() >= 300) { + return CompletableFuture.failedFuture(new IOException(String.format("Failed to download %s: code %d", + file.urlPath != null ? file.urlPath /* TODO: baseUri */ : file.filePath, res.statusCode()))); + } + return CompletableFuture.completedFuture(res); + }).thenAccept(consumerObject.next).exceptionally(ec -> { future.completeExceptionally(ec); return null; }); @@ -359,5 +381,11 @@ public SizedFile(String urlPath, String filePath, long size) { this.filePath = filePath; this.size = size; } + + public SizedFile(String urlPath, String filePath) { + this.urlPath = urlPath; + this.filePath = filePath; + this.size = -1; + } } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/Launcher.java similarity index 94% rename from LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/Launcher.java index 165f2bfb..2c7e98b4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/Launcher.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/Launcher.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.base; -import pro.gravit.launcher.managers.GsonManager; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.serialize.HInput; +import pro.gravit.launcher.core.managers.GsonManager; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.core.serialize.HInput; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/LauncherConfig.java similarity index 91% rename from LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/LauncherConfig.java index 10fbcea4..b0f92c46 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/LauncherConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/LauncherConfig.java @@ -1,10 +1,13 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.base; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModulesManager; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.launcher.serialize.stream.StreamObject; +import pro.gravit.launcher.core.LauncherInject; +import pro.gravit.launcher.core.LauncherInjectionConstructor; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModulesManager; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.core.serialize.HOutput; +import pro.gravit.launcher.core.serialize.stream.StreamObject; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; @@ -93,7 +96,7 @@ public LauncherConfig(String address, ECPublicKey ecdsaPublicKey, RSAPublicKey r this.address = address; this.ecdsaPublicKey = ecdsaPublicKey; this.rsaPublicKey = rsaPublicKey; - this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); + this.runtime = Map.copyOf(runtime); this.projectName = projectName; this.clientPort = 32148; environment = LauncherEnvironment.STD; @@ -106,7 +109,7 @@ public LauncherConfig(String address, ECPublicKey ecdsaPublicKey, RSAPublicKey r public LauncherConfig(String address, Map runtime, String projectName, LauncherEnvironment env, LauncherTrustManager trustManager) { this.address = address; - this.runtime = Collections.unmodifiableMap(new HashMap<>(runtime)); + this.runtime = Map.copyOf(runtime); this.projectName = projectName; this.clientPort = 32148; this.trustManager = trustManager; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/api/AuthService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/api/AuthService.java similarity index 80% rename from LauncherAPI/src/main/java/pro/gravit/launcher/api/AuthService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/api/AuthService.java index e96152a3..70750c57 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/api/AuthService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/api/AuthService.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.api; +package pro.gravit.launcher.base.api; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.base.profiles.ClientProfile; import java.util.List; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/api/ClientService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/api/ClientService.java new file mode 100644 index 00000000..4bcf9e88 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/api/ClientService.java @@ -0,0 +1,32 @@ +package pro.gravit.launcher.base.api; + +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.launch.ClassLoaderControl; + +import java.lang.instrument.Instrumentation; +import java.net.URL; + +public class ClientService { + public static Instrumentation instrumentation; + public static ClassLoaderControl classLoaderControl; + public static String nativePath; + public static URL[] baseURLs; + + public static String findLibrary(String name) { + if(name == null) { + return null; + } + var needExt = !name.endsWith(JVMHelper.NATIVE_EXTENSION); + var needPrefix = !name.startsWith(JVMHelper.NATIVE_PREFIX); + if(needExt && needPrefix) { + return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(JVMHelper.NATIVE_PREFIX).concat(name).concat(JVMHelper.NATIVE_EXTENSION); + } else if(needExt) { + return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(name).concat(JVMHelper.NATIVE_EXTENSION); + } else if(needPrefix) { + return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(JVMHelper.NATIVE_PREFIX).concat(name); + } else { + return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(name); + } + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/api/ConfigService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/api/ConfigService.java similarity index 89% rename from LauncherAPI/src/main/java/pro/gravit/launcher/api/ConfigService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/api/ConfigService.java index 01bafb3d..52809b6e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/api/ConfigService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/api/ConfigService.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.api; +package pro.gravit.launcher.base.api; public class ConfigService { public static boolean disableLogging; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/api/KeyService.java similarity index 85% rename from LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/api/KeyService.java index 5976d4f8..69354de3 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/api/KeyService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/api/KeyService.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.api; +package pro.gravit.launcher.base.api; import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPublicKey; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/config/JsonConfigurable.java similarity index 93% rename from LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/config/JsonConfigurable.java index 482258d0..de468bf9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurable.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/config/JsonConfigurable.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.config; +package pro.gravit.launcher.base.config; import java.lang.reflect.Type; import java.nio.file.Path; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/config/JsonConfigurableInterface.java similarity index 96% rename from LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/config/JsonConfigurableInterface.java index 65c15c92..39686bbb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/JsonConfigurableInterface.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/config/JsonConfigurableInterface.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.config; +package pro.gravit.launcher.base.config; import com.google.gson.Gson; -import pro.gravit.launcher.Launcher; +import pro.gravit.launcher.base.Launcher; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/config/SimpleConfig.java similarity index 96% rename from LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/config/SimpleConfig.java index 1ac1398c..78d3a380 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfig.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/config/SimpleConfig.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.config; +package pro.gravit.launcher.base.config; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/config/SimpleConfigurable.java similarity index 95% rename from LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/config/SimpleConfigurable.java index 7306728f..01def3d9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/config/SimpleConfigurable.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/config/SimpleConfigurable.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.config; +package pro.gravit.launcher.base.config; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ExtendedTokenRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/ExtendedTokenRequestEvent.java similarity index 78% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/ExtendedTokenRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/ExtendedTokenRequestEvent.java index 084d4a72..228392ae 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/ExtendedTokenRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/ExtendedTokenRequestEvent.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.events; +package pro.gravit.launcher.base.events; public interface ExtendedTokenRequestEvent { String getExtendedTokenName(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/NotificationEvent.java similarity index 83% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/NotificationEvent.java index a5fef64b..51e9e19a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/NotificationEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/NotificationEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.events; +package pro.gravit.launcher.base.events; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.request.WebSocketEvent; public class NotificationEvent implements WebSocketEvent { @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/RequestEvent.java similarity index 70% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/RequestEvent.java index 60323f61..89c11b24 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/RequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/RequestEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.events; +package pro.gravit.launcher.base.events; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.request.WebSocketEvent; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AdditionalDataRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/AdditionalDataRequestEvent.java similarity index 77% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AdditionalDataRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/AdditionalDataRequestEvent.java index a0680b10..2308702b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AdditionalDataRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/AdditionalDataRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; import java.util.Map; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AssetUploadInfoRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/AssetUploadInfoRequestEvent.java similarity index 83% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AssetUploadInfoRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/AssetUploadInfoRequestEvent.java index 34446fcc..1b2046cb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AssetUploadInfoRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/AssetUploadInfoRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; import java.util.Set; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/AuthRequestEvent.java similarity index 91% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/AuthRequestEvent.java index 3881ebe7..a03007d3 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/AuthRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/AuthRequestEvent.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.profiles.PlayerProfile; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/BatchProfileByUsernameRequestEvent.java similarity index 68% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/BatchProfileByUsernameRequestEvent.java index c6d57f94..7acc3677 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/BatchProfileByUsernameRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/BatchProfileByUsernameRequestEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.profiles.PlayerProfile; public class BatchProfileByUsernameRequestEvent extends RequestEvent { @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CheckServerRequestEvent.java similarity index 78% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CheckServerRequestEvent.java index 47a78f93..17576643 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CheckServerRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CheckServerRequestEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.profiles.PlayerProfile; import java.util.Map; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CurrentUserRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CurrentUserRequestEvent.java similarity index 68% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CurrentUserRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CurrentUserRequestEvent.java index e2aa68ba..f9c67018 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/CurrentUserRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/CurrentUserRequestEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.profiles.PlayerProfile; public class CurrentUserRequestEvent extends RequestEvent { public final UserInfo userInfo; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ErrorRequestEvent.java similarity index 71% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ErrorRequestEvent.java index e8c3b822..5fad1217 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ErrorRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ErrorRequestEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExitRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ExitRequestEvent.java similarity index 76% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExitRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ExitRequestEvent.java index 084615c4..f1acc2ee 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ExitRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ExitRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; public class ExitRequestEvent extends RequestEvent { public final ExitReason reason; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FeaturesRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/FeaturesRequestEvent.java similarity index 77% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FeaturesRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/FeaturesRequestEvent.java index d6151b19..cec02ffc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FeaturesRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/FeaturesRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; import java.util.Map; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FetchClientProfileKeyRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/FetchClientProfileKeyRequestEvent.java similarity index 91% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FetchClientProfileKeyRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/FetchClientProfileKeyRequestEvent.java index 82958bac..c93fa7a9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/FetchClientProfileKeyRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/FetchClientProfileKeyRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; import java.security.PrivateKey; import java.security.PublicKey; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAssetUploadUrlRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetAssetUploadUrlRequestEvent.java similarity index 83% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAssetUploadUrlRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetAssetUploadUrlRequestEvent.java index 9d4a7e66..a911df7b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAssetUploadUrlRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetAssetUploadUrlRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; public class GetAssetUploadUrlRequestEvent extends RequestEvent { public static final String FEATURE_NAME = "assetupload"; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetAvailabilityAuthRequestEvent.java similarity index 91% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetAvailabilityAuthRequestEvent.java index c0768207..efe0fbca 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetAvailabilityAuthRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetAvailabilityAuthRequestEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; import pro.gravit.utils.TypeSerializeInterface; import java.util.List; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetConnectUUIDRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetConnectUUIDRequestEvent.java new file mode 100644 index 00000000..28fad350 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetConnectUUIDRequestEvent.java @@ -0,0 +1,20 @@ +package pro.gravit.launcher.base.events.request; + +import pro.gravit.launcher.base.events.RequestEvent; + +import java.util.UUID; + +public class GetConnectUUIDRequestEvent extends RequestEvent { + public UUID connectUUID; + public int shardId; + + public GetConnectUUIDRequestEvent(UUID connectUUID, int shardId) { + this.connectUUID = connectUUID; + this.shardId = shardId; + } + + @Override + public String getType() { + return "getConnectUUID"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetPublicKeyRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetPublicKeyRequestEvent.java similarity index 87% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetPublicKeyRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetPublicKeyRequestEvent.java index aef691ca..068e5388 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetPublicKeyRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetPublicKeyRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; import java.security.interfaces.ECPublicKey; import java.security.interfaces.RSAPublicKey; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureLevelInfoRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetSecureLevelInfoRequestEvent.java similarity index 83% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureLevelInfoRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetSecureLevelInfoRequestEvent.java index 2b8fa051..cd583424 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/GetSecureLevelInfoRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/GetSecureLevelInfoRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; public class GetSecureLevelInfoRequestEvent extends RequestEvent { public final byte[] verifySecureKey; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/HardwareReportRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/HardwareReportRequestEvent.java similarity index 81% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/HardwareReportRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/HardwareReportRequestEvent.java index e9198109..e0126fdb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/HardwareReportRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/HardwareReportRequestEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.ExtendedTokenRequestEvent; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.ExtendedTokenRequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; public class HardwareReportRequestEvent extends RequestEvent implements ExtendedTokenRequestEvent { public String extendedToken; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/JoinServerRequestEvent.java similarity index 73% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/JoinServerRequestEvent.java index dc13f759..3edef722 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/JoinServerRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/JoinServerRequestEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/LauncherRequestEvent.java similarity index 88% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/LauncherRequestEvent.java index 17d94488..1cd8cc56 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/LauncherRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/LauncherRequestEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.ExtendedTokenRequestEvent; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.ExtendedTokenRequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ProfileByUUIDRequestEvent.java similarity index 73% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ProfileByUUIDRequestEvent.java index b2bad307..dbdd3cfb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUUIDRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ProfileByUUIDRequestEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.profiles.PlayerProfile; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ProfileByUsernameRequestEvent.java similarity index 72% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ProfileByUsernameRequestEvent.java index 6c3c532c..3e532500 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfileByUsernameRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ProfileByUsernameRequestEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.profiles.PlayerProfile; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ProfilesRequestEvent.java similarity index 71% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ProfilesRequestEvent.java index 383becab..bf182554 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/ProfilesRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/ProfilesRequestEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.profiles.ClientProfile; import java.util.List; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/RefreshTokenRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/RefreshTokenRequestEvent.java similarity index 75% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/RefreshTokenRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/RefreshTokenRequestEvent.java index 0f1a5806..73a910a1 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/RefreshTokenRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/RefreshTokenRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; public class RefreshTokenRequestEvent extends RequestEvent { public AuthRequestEvent.OAuthRequestEvent oauth; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/RestoreRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/RestoreRequestEvent.java similarity index 87% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/RestoreRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/RestoreRequestEvent.java index 6c9dd5a0..748a7e46 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/RestoreRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/RestoreRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; import java.util.List; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/SecurityReportRequestEvent.java similarity index 88% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/SecurityReportRequestEvent.java index 2c9af856..ba7c1a91 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SecurityReportRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/SecurityReportRequestEvent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; public class SecurityReportRequestEvent extends RequestEvent { public final ReportAction action; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/SetProfileRequestEvent.java similarity index 69% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/SetProfileRequestEvent.java index 6596ac9a..b3a92dbb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/SetProfileRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/SetProfileRequestEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.profiles.ClientProfile; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/UpdateListRequestEvent.java similarity index 75% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/UpdateListRequestEvent.java index 5f54432c..ba5962dc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateListRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/UpdateListRequestEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; import java.util.HashSet; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/UpdateRequestEvent.java similarity index 78% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/UpdateRequestEvent.java index e5f357f8..18ec2229 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/UpdateRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/UpdateRequestEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.hasher.HashedDir; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.core.hasher.HashedDir; public class UpdateRequestEvent extends RequestEvent { @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureLevelKeyRequestEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/VerifySecureLevelKeyRequestEvent.java similarity index 86% rename from LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureLevelKeyRequestEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/VerifySecureLevelKeyRequestEvent.java index 2c818107..754f3020 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/events/request/VerifySecureLevelKeyRequestEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/events/request/VerifySecureLevelKeyRequestEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.events.request; +package pro.gravit.launcher.base.events.request; -import pro.gravit.launcher.events.ExtendedTokenRequestEvent; -import pro.gravit.launcher.events.RequestEvent; +import pro.gravit.launcher.base.events.ExtendedTokenRequestEvent; +import pro.gravit.launcher.base.events.RequestEvent; public class VerifySecureLevelKeyRequestEvent extends RequestEvent implements ExtendedTokenRequestEvent { public boolean needHardwareInfo; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherInitContext.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherInitContext.java similarity index 50% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherInitContext.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherInitContext.java index 7738c826..6edbb6ce 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherInitContext.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherInitContext.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.modules; +package pro.gravit.launcher.base.modules; public interface LauncherInitContext { } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModule.java similarity index 97% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModule.java index 65ed59a4..86d032b8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModule.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModule.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.modules; +package pro.gravit.launcher.base.modules; -import pro.gravit.launcher.LauncherTrustManager; +import pro.gravit.launcher.core.LauncherTrustManager; import pro.gravit.utils.Version; import java.util.ArrayList; @@ -83,6 +83,10 @@ protected final T requireModule(Class cl return module; } + protected LauncherModulesContext getContext() { + return context; + } + private void requireModule(LauncherModule module, Version minVersion, String requiredModuleName) { if (module == null) throw new RuntimeException(String.format("Module %s required %s v%s or higher", moduleInfo.name, requiredModuleName, minVersion.getVersionString())); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModuleInfo.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModuleInfo.java similarity index 97% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModuleInfo.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModuleInfo.java index 0237a9ee..5b9e484b 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModuleInfo.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModuleInfo.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.modules; +package pro.gravit.launcher.base.modules; import pro.gravit.utils.Version; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesContext.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModulesContext.java similarity index 61% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesContext.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModulesContext.java index 317e2d31..b648faa8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesContext.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModulesContext.java @@ -1,7 +1,11 @@ -package pro.gravit.launcher.modules; +package pro.gravit.launcher.base.modules; + +import java.net.URL; public interface LauncherModulesContext { LauncherModulesManager getModulesManager(); ModulesConfigManager getModulesConfigManager(); + + void addURL(URL url); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModulesManager.java similarity index 97% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModulesManager.java index 0ac63a2c..4d3a30be 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/LauncherModulesManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModulesManager.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.modules; +package pro.gravit.launcher.base.modules; import pro.gravit.utils.Version; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/ModulesConfigManager.java similarity index 87% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/ModulesConfigManager.java index 570059a7..ee1364ce 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/ModulesConfigManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/ModulesConfigManager.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.modules; +package pro.gravit.launcher.base.modules; -import pro.gravit.launcher.config.SimpleConfigurable; +import pro.gravit.launcher.base.config.SimpleConfigurable; import java.nio.file.Path; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/ClosePhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/ClosePhase.java new file mode 100644 index 00000000..43235a4f --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/ClosePhase.java @@ -0,0 +1,6 @@ +package pro.gravit.launcher.base.modules.events; + +import pro.gravit.launcher.base.modules.LauncherModule; + +public class ClosePhase extends LauncherModule.Event { +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/InitPhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/InitPhase.java new file mode 100644 index 00000000..e2d18caf --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/InitPhase.java @@ -0,0 +1,6 @@ +package pro.gravit.launcher.base.modules.events; + +import pro.gravit.launcher.base.modules.LauncherModule; + +public class InitPhase extends LauncherModule.Event { +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/OfflineModeEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/OfflineModeEvent.java similarity index 54% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/OfflineModeEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/OfflineModeEvent.java index 28a92579..9c083864 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/OfflineModeEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/OfflineModeEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.modules.events; +package pro.gravit.launcher.base.modules.events; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.request.RequestService; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.request.RequestService; public class OfflineModeEvent extends LauncherModule.Event { public RequestService service; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/PostInitPhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/PostInitPhase.java new file mode 100644 index 00000000..7fe2de69 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/PostInitPhase.java @@ -0,0 +1,6 @@ +package pro.gravit.launcher.base.modules.events; + +import pro.gravit.launcher.base.modules.LauncherModule; + +public class PostInitPhase extends LauncherModule.Event { +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/PreConfigPhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/PreConfigPhase.java new file mode 100644 index 00000000..5d5e1e06 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/PreConfigPhase.java @@ -0,0 +1,6 @@ +package pro.gravit.launcher.base.modules.events; + +import pro.gravit.launcher.base.modules.LauncherModule; + +public class PreConfigPhase extends LauncherModule.Event { +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/PreGsonPhase.java similarity index 69% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/PreGsonPhase.java index b47f2a6b..470a6fbf 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreGsonPhase.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/events/PreGsonPhase.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.modules.events; +package pro.gravit.launcher.base.modules.events; import com.google.gson.GsonBuilder; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; public class PreGsonPhase extends LauncherModule.Event { public final GsonBuilder gsonBuilder; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleContext.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleContext.java similarity index 54% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleContext.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleContext.java index b6b2348d..2d1bc257 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleContext.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleContext.java @@ -1,8 +1,10 @@ -package pro.gravit.launcher.modules.impl; +package pro.gravit.launcher.base.modules.impl; -import pro.gravit.launcher.modules.LauncherModulesContext; -import pro.gravit.launcher.modules.LauncherModulesManager; -import pro.gravit.launcher.modules.ModulesConfigManager; +import pro.gravit.launcher.base.modules.LauncherModulesContext; +import pro.gravit.launcher.base.modules.LauncherModulesManager; +import pro.gravit.launcher.base.modules.ModulesConfigManager; + +import java.net.URL; public class SimpleModuleContext implements LauncherModulesContext { public final LauncherModulesManager modulesManager; @@ -13,6 +15,15 @@ public SimpleModuleContext(LauncherModulesManager modulesManager, ModulesConfigM this.configManager = configManager; } + @Override + public void addURL(URL url) { + if(modulesManager instanceof SimpleModuleManager s) { + s.addUrlToClassLoader(url); + } else { + throw new UnsupportedOperationException(); + } + } + @Override public LauncherModulesManager getModulesManager() { return modulesManager; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java similarity index 93% rename from LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java index 773e2f72..bb510661 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java @@ -1,9 +1,7 @@ -package pro.gravit.launcher.modules.impl; +package pro.gravit.launcher.base.modules.impl; -import pro.gravit.launcher.LauncherTrustManager; -import pro.gravit.launcher.managers.SimpleModulesConfigManager; -import pro.gravit.launcher.modules.*; -import pro.gravit.utils.PublicURLClassLoader; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.modules.*; import pro.gravit.utils.Version; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; @@ -12,6 +10,7 @@ import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -33,9 +32,13 @@ public class SimpleModuleManager implements LauncherModulesManager { protected final ModulesConfigManager modulesConfigManager; protected final Path modulesDir; protected final LauncherTrustManager trustManager; - protected final PublicURLClassLoader classLoader = new PublicURLClassLoader(new URL[]{}); + protected final ModulesClassLoader classLoader = createClassLoader(); protected LauncherInitContext initContext; + protected ModulesClassLoader createClassLoader() { + return new ModulesClassLoader(new URL[]{}, SimpleModuleManager.class.getClassLoader()); + } + public SimpleModuleManager(Path modulesDir, Path configDir) { modulesConfigManager = new SimpleModulesConfigManager(configDir); context = new SimpleModuleContext(this, modulesConfigManager); @@ -269,6 +272,10 @@ public ModulesConfigManager getConfigManager() { return modulesConfigManager; } + void addUrlToClassLoader(URL url) { + classLoader.addURL(url); + } + protected final class ModulesVisitor extends SimpleFileVisitor { private ModulesVisitor() { } @@ -280,4 +287,16 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO return super.visitFile(file, attrs); } } + + protected static class ModulesClassLoader extends URLClassLoader { + + public ModulesClassLoader(URL[] urls, ClassLoader parent) { + super("MODULES", urls, parent); + } + + @Override + public void addURL(URL url) { + super.addURL(url); + } + } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModulesConfigManager.java similarity index 87% rename from LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModulesConfigManager.java index 4e954886..9ac9b5df 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/managers/SimpleModulesConfigManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModulesConfigManager.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.managers; +package pro.gravit.launcher.base.modules.impl; -import pro.gravit.launcher.config.SimpleConfigurable; -import pro.gravit.launcher.modules.ModulesConfigManager; +import pro.gravit.launcher.base.config.SimpleConfigurable; +import pro.gravit.launcher.base.modules.ModulesConfigManager; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java similarity index 97% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java index 681ba5b4..3c268cac 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfile.java @@ -1,23 +1,24 @@ -package pro.gravit.launcher.profiles; +package pro.gravit.launcher.base.profiles; import com.google.gson.*; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.hasher.FileNameMatcher; -import pro.gravit.launcher.profiles.optional.OptionalDepend; -import pro.gravit.launcher.profiles.optional.OptionalFile; -import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.core.hasher.FileNameMatcher; +import pro.gravit.launcher.base.profiles.optional.OptionalDepend; +import pro.gravit.launcher.base.profiles.optional.OptionalFile; +import pro.gravit.launcher.base.profiles.optional.triggers.OptionalTrigger; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.VerifyHelper; import pro.gravit.utils.launch.LaunchOptions; import java.lang.reflect.Type; import java.net.InetSocketAddress; +import java.nio.file.Path; import java.util.*; 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 @@ -461,6 +462,14 @@ 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 } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileBuilder.java similarity index 98% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileBuilder.java index 5e6a09d6..a518db5c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileBuilder.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileBuilder.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.profiles; +package pro.gravit.launcher.base.profiles; -import pro.gravit.launcher.profiles.optional.OptionalFile; +import pro.gravit.launcher.base.profiles.optional.OptionalFile; import java.util.*; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileVersions.java similarity index 97% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileVersions.java index e1c70b82..5d21aced 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/ClientProfileVersions.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/ClientProfileVersions.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.profiles; +package pro.gravit.launcher.base.profiles; public class ClientProfileVersions { private ClientProfileVersions() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/PlayerProfile.java similarity index 97% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/PlayerProfile.java index b08cff5d..e0190993 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/PlayerProfile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/PlayerProfile.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.profiles; +package pro.gravit.launcher.base.profiles; import pro.gravit.utils.helper.IOHelper; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/Texture.java similarity index 87% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/Texture.java index f4a070d9..568f1d14 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/Texture.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/Texture.java @@ -1,14 +1,15 @@ -package pro.gravit.launcher.profiles; +package pro.gravit.launcher.base.profiles; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.launcher.serialize.stream.StreamObject; +import pro.gravit.launcher.core.serialize.HOutput; +import pro.gravit.launcher.core.serialize.stream.StreamObject; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.SecurityHelper; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.net.URL; +import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Path; import java.util.Arrays; import java.util.Map; @@ -29,8 +30,10 @@ public Texture(String url, boolean cloak, Map metadata) throws I // Fetch texture byte[] texture; - try (InputStream input = IOHelper.newInput(new URL(url))) { + try (InputStream input = IOHelper.newInput(new URI(url).toURL())) { texture = IOHelper.read(input); + } catch (URISyntaxException e) { + throw new IOException(e); } try (ByteArrayInputStream input = new ByteArrayInputStream(texture)) { IOHelper.readTexture(input, cloak); // Verify texture diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalDepend.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalDepend.java new file mode 100644 index 00000000..53feb0ee --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalDepend.java @@ -0,0 +1,8 @@ +package pro.gravit.launcher.base.profiles.optional; + +import pro.gravit.launcher.core.LauncherNetworkAPI; + +public class OptionalDepend { + @LauncherNetworkAPI + public String name; +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalFile.java similarity index 84% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalFile.java index 36b57c83..4d49cf23 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalFile.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.profiles.optional; +package pro.gravit.launcher.base.profiles.optional; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; import java.util.List; import java.util.Objects; @@ -18,7 +18,7 @@ public class OptionalFile { @LauncherNetworkAPI public String info; @LauncherNetworkAPI - public List triggersList; + public List triggersList; @LauncherNetworkAPI public OptionalDepend[] dependenciesFile; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalView.java similarity index 93% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalView.java index 25fdb266..80df3666 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalView.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/OptionalView.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.profiles.optional; +package pro.gravit.launcher.base.profiles.optional; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; import java.util.HashMap; import java.util.HashSet; @@ -126,11 +126,7 @@ public void enable(OptionalFile file, boolean manual, BiConsumer new OptionalFileInstallInfo()); installInfo.isManual = manual; if (file.dependencies != null) { for (OptionalFile dep : file.dependencies) { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalAction.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalAction.java similarity index 91% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalAction.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalAction.java index aabc8ccc..dd2a7437 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalAction.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalAction.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.profiles.optional.actions; +package pro.gravit.launcher.base.profiles.optional.actions; import pro.gravit.utils.ProviderMap; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClassPath.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionClassPath.java similarity index 87% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClassPath.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionClassPath.java index a9093ff2..51a09abf 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClassPath.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionClassPath.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.profiles.optional.actions; +package pro.gravit.launcher.base.profiles.optional.actions; public class OptionalActionClassPath extends OptionalAction { public String[] args; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClientArgs.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionClientArgs.java similarity index 81% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClientArgs.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionClientArgs.java index 90bf980d..be164f6c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionClientArgs.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionClientArgs.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.profiles.optional.actions; +package pro.gravit.launcher.base.profiles.optional.actions; import java.util.List; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionFile.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionFile.java similarity index 92% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionFile.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionFile.java index e2999b22..00b0c3e8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionFile.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionFile.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.profiles.optional.actions; +package pro.gravit.launcher.base.profiles.optional.actions; -import pro.gravit.launcher.hasher.HashedDir; +import pro.gravit.launcher.core.hasher.HashedDir; import pro.gravit.utils.helper.LogHelper; import java.util.Map; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionJvmArgs.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionJvmArgs.java similarity index 80% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionJvmArgs.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionJvmArgs.java index 328a224c..900e78bc 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/actions/OptionalActionJvmArgs.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/actions/OptionalActionJvmArgs.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.profiles.optional.actions; +package pro.gravit.launcher.base.profiles.optional.actions; import java.util.List; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/ArchTrigger.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/ArchTrigger.java similarity index 70% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/ArchTrigger.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/ArchTrigger.java index b507186a..19ea42f6 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/ArchTrigger.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/ArchTrigger.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.profiles.optional.triggers; +package pro.gravit.launcher.base.profiles.optional.triggers; -import pro.gravit.launcher.profiles.optional.OptionalFile; +import pro.gravit.launcher.base.profiles.optional.OptionalFile; import pro.gravit.utils.helper.JVMHelper; public class ArchTrigger extends OptionalTrigger { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/JavaTrigger.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/JavaTrigger.java similarity index 89% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/JavaTrigger.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/JavaTrigger.java index 46c08852..aa5e356f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/JavaTrigger.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/JavaTrigger.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.profiles.optional.triggers; +package pro.gravit.launcher.base.profiles.optional.triggers; -import pro.gravit.launcher.profiles.optional.OptionalFile; +import pro.gravit.launcher.base.profiles.optional.OptionalFile; import pro.gravit.utils.helper.JavaHelper; public class JavaTrigger extends OptionalTrigger { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/OSTrigger.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/OSTrigger.java similarity index 73% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/OSTrigger.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/OSTrigger.java index edbd4590..00bcd3a1 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/OSTrigger.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/OSTrigger.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.profiles.optional.triggers; +package pro.gravit.launcher.base.profiles.optional.triggers; -import pro.gravit.launcher.profiles.optional.OptionalFile; +import pro.gravit.launcher.base.profiles.optional.OptionalFile; import pro.gravit.utils.helper.JVMHelper; public class OSTrigger extends OptionalTrigger { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/OptionalTrigger.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/OptionalTrigger.java similarity index 88% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/OptionalTrigger.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/OptionalTrigger.java index 8ba54011..36419867 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/OptionalTrigger.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/OptionalTrigger.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.profiles.optional.triggers; +package pro.gravit.launcher.base.profiles.optional.triggers; -import pro.gravit.launcher.profiles.optional.OptionalFile; +import pro.gravit.launcher.base.profiles.optional.OptionalFile; import pro.gravit.utils.ProviderMap; public abstract class OptionalTrigger { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/OptionalTriggerContext.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/OptionalTriggerContext.java similarity index 62% rename from LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/OptionalTriggerContext.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/OptionalTriggerContext.java index 46598ff2..cb6b3839 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/triggers/OptionalTriggerContext.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/profiles/optional/triggers/OptionalTriggerContext.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.profiles.optional.triggers; +package pro.gravit.launcher.base.profiles.optional.triggers; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.PlayerProfile; +import pro.gravit.launcher.base.ClientPermissions; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.PlayerProfile; import pro.gravit.utils.helper.JavaHelper; public interface OptionalTriggerContext { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/JsonResultSerializeAdapter.java similarity index 93% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/JsonResultSerializeAdapter.java index 3a46e1d3..b70471b6 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/JsonResultSerializeAdapter.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/JsonResultSerializeAdapter.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.request; +package pro.gravit.launcher.base.request; import com.google.gson.*; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/PingRequest.java similarity index 76% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/PingRequest.java index ee526029..249e567f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/PingRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/PingRequest.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.request; +package pro.gravit.launcher.base.request; public final class PingRequest extends Request { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/Request.java similarity index 93% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/Request.java index 47de5f3a..d91f646f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/Request.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/Request.java @@ -1,14 +1,14 @@ -package pro.gravit.launcher.request; +package pro.gravit.launcher.base.request; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.events.request.CurrentUserRequestEvent; -import pro.gravit.launcher.events.request.RefreshTokenRequestEvent; -import pro.gravit.launcher.events.request.RestoreRequestEvent; -import pro.gravit.launcher.request.auth.RefreshTokenRequest; -import pro.gravit.launcher.request.auth.RestoreRequest; -import pro.gravit.launcher.request.websockets.StdWebSocketService; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.events.request.CurrentUserRequestEvent; +import pro.gravit.launcher.base.events.request.RefreshTokenRequestEvent; +import pro.gravit.launcher.base.events.request.RestoreRequestEvent; +import pro.gravit.launcher.base.request.auth.RefreshTokenRequest; +import pro.gravit.launcher.base.request.auth.RestoreRequest; +import pro.gravit.launcher.base.request.websockets.StdWebSocketService; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.LogHelper; import java.util.*; @@ -203,12 +203,12 @@ public static synchronized RequestRestoreReport restore(boolean needUserInfo, bo } RestoreRequestEvent event = request.request(); List invalidTokens = null; - if (event.invalidTokens != null && event.invalidTokens.size() > 0) { + if (event.invalidTokens != null && !event.invalidTokens.isEmpty()) { Map tokens = makeNewTokens(event.invalidTokens); if (!tokens.isEmpty()) { request = new RestoreRequest(authId, null, tokens, false); event = request.request(); - if (event.invalidTokens != null && event.invalidTokens.size() > 0) { + if (event.invalidTokens != null && !event.invalidTokens.isEmpty()) { LogHelper.warning("Tokens %s not restored", String.join(",", event.invalidTokens)); } } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/RequestException.java similarity index 92% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/RequestException.java index 93285c79..429b0c73 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestException.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/RequestException.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.request; +package pro.gravit.launcher.base.request; import java.io.IOException; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/RequestService.java similarity index 96% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/RequestService.java index 41142326..bad2ebd1 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/RequestService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/RequestService.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.request; +package pro.gravit.launcher.base.request; import java.io.IOException; import java.util.concurrent.CompletableFuture; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/WebSocketEvent.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/WebSocketEvent.java similarity index 83% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/WebSocketEvent.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/WebSocketEvent.java index 59d259d4..f72b8113 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/WebSocketEvent.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/WebSocketEvent.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.request; +package pro.gravit.launcher.base.request; import pro.gravit.utils.TypeSerializeInterface; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AdditionalDataRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/AdditionalDataRequest.java similarity index 70% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AdditionalDataRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/AdditionalDataRequest.java index 32d10863..56e4037c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AdditionalDataRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/AdditionalDataRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.events.request.AdditionalDataRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.AdditionalDataRequestEvent; +import pro.gravit.launcher.base.request.Request; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/AuthRequest.java similarity index 86% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/AuthRequest.java index 679ae5bb..5cbc489f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/AuthRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/AuthRequest.java @@ -1,10 +1,10 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.auth.password.*; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.auth.password.*; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; import pro.gravit.utils.ProviderMap; public final class AuthRequest extends Request implements WebSocketRequest { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/CheckServerRequest.java similarity index 76% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/CheckServerRequest.java index 9e3ff5f6..aa23f58c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CheckServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/CheckServerRequest.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.CheckServerRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.CheckServerRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.VerifyHelper; public final class CheckServerRequest extends Request implements WebSocketRequest { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/CurrentUserRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/CurrentUserRequest.java new file mode 100644 index 00000000..0ed74fa0 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/CurrentUserRequest.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.base.request.auth; + +import pro.gravit.launcher.base.events.request.CurrentUserRequestEvent; +import pro.gravit.launcher.base.request.Request; + +public class CurrentUserRequest extends Request { + @Override + public String getType() { + return "currentUser"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/ExitRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/ExitRequest.java similarity index 77% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/ExitRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/ExitRequest.java index 240c27a3..d0c2c3bf 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/ExitRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/ExitRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.events.request.ExitRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.ExitRequestEvent; +import pro.gravit.launcher.base.request.Request; public class ExitRequest extends Request { public final boolean exitAll; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/FetchClientProfileKeyRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/FetchClientProfileKeyRequest.java similarity index 56% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/FetchClientProfileKeyRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/FetchClientProfileKeyRequest.java index 32fcf698..96104ce8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/FetchClientProfileKeyRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/FetchClientProfileKeyRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.events.request.FetchClientProfileKeyRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.FetchClientProfileKeyRequestEvent; +import pro.gravit.launcher.base.request.Request; public class FetchClientProfileKeyRequest extends Request { public FetchClientProfileKeyRequest() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/GetAvailabilityAuthRequest.java similarity index 61% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/GetAvailabilityAuthRequest.java index 15092d2a..75e856f6 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetAvailabilityAuthRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/GetAvailabilityAuthRequest.java @@ -1,12 +1,12 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.auth.details.AuthLoginOnlyDetails; -import pro.gravit.launcher.request.auth.details.AuthPasswordDetails; -import pro.gravit.launcher.request.auth.details.AuthTotpDetails; -import pro.gravit.launcher.request.auth.details.AuthWebViewDetails; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.auth.details.AuthLoginOnlyDetails; +import pro.gravit.launcher.base.request.auth.details.AuthPasswordDetails; +import pro.gravit.launcher.base.request.auth.details.AuthTotpDetails; +import pro.gravit.launcher.base.request.auth.details.AuthWebViewDetails; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; import pro.gravit.utils.ProviderMap; public class GetAvailabilityAuthRequest extends Request implements WebSocketRequest { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetPublicKeyRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/GetPublicKeyRequest.java similarity index 54% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetPublicKeyRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/GetPublicKeyRequest.java index 5119696c..3e6ae226 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/GetPublicKeyRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/GetPublicKeyRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.events.request.GetPublicKeyRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.GetPublicKeyRequestEvent; +import pro.gravit.launcher.base.request.Request; public class GetPublicKeyRequest extends Request { public GetPublicKeyRequest() { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/JoinServerRequest.java similarity index 77% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/JoinServerRequest.java index 54c8df02..41232121 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/JoinServerRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/JoinServerRequest.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.JoinServerRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.JoinServerRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.VerifyHelper; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RefreshTokenRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/RefreshTokenRequest.java similarity index 68% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RefreshTokenRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/RefreshTokenRequest.java index 0daa585e..5b48a8cb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RefreshTokenRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/RefreshTokenRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.events.request.RefreshTokenRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.RefreshTokenRequestEvent; +import pro.gravit.launcher.base.request.Request; public class RefreshTokenRequest extends Request { public String authId; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/RestoreRequest.java similarity index 78% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/RestoreRequest.java index d23942b9..ff7b6471 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/RestoreRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/RestoreRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.events.request.RestoreRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.RestoreRequestEvent; +import pro.gravit.launcher.base.request.Request; import java.util.Map; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/SetProfileRequest.java similarity index 50% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/SetProfileRequest.java index 3c72b502..8e99693f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/SetProfileRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/SetProfileRequest.java @@ -1,10 +1,10 @@ -package pro.gravit.launcher.request.auth; +package pro.gravit.launcher.base.request.auth; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.SetProfileRequestEvent; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.SetProfileRequestEvent; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; public class SetProfileRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthLoginOnlyDetails.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthLoginOnlyDetails.java similarity index 57% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthLoginOnlyDetails.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthLoginOnlyDetails.java index 01b049b4..a5813a17 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthLoginOnlyDetails.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthLoginOnlyDetails.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.details; +package pro.gravit.launcher.base.request.auth.details; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; +import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; public class AuthLoginOnlyDetails implements GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails { @Override diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthPasswordDetails.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthPasswordDetails.java similarity index 57% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthPasswordDetails.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthPasswordDetails.java index 1f1022fb..825fa36f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthPasswordDetails.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthPasswordDetails.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.details; +package pro.gravit.launcher.base.request.auth.details; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; +import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; public class AuthPasswordDetails implements GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails { @Override diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthTotpDetails.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthTotpDetails.java similarity index 77% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthTotpDetails.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthTotpDetails.java index df0c5ce2..80c4048e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthTotpDetails.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthTotpDetails.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.details; +package pro.gravit.launcher.base.request.auth.details; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; +import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; public class AuthTotpDetails implements GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails { public final String alg; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthWebViewDetails.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthWebViewDetails.java similarity index 85% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthWebViewDetails.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthWebViewDetails.java index 25d30cec..3090d251 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/details/AuthWebViewDetails.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/details/AuthWebViewDetails.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.details; +package pro.gravit.launcher.base.request.auth.details; -import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent; +import pro.gravit.launcher.base.events.request.GetAvailabilityAuthRequestEvent; public class AuthWebViewDetails implements GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails { public final String url; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/Auth2FAPassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/Auth2FAPassword.java similarity index 81% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/Auth2FAPassword.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/Auth2FAPassword.java index d6b7baa5..05672942 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/Auth2FAPassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/Auth2FAPassword.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.password; +package pro.gravit.launcher.base.request.auth.password; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.AuthRequest; public class Auth2FAPassword implements AuthRequest.AuthPasswordInterface { public AuthRequest.AuthPasswordInterface firstPassword; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthAESPassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthAESPassword.java similarity index 65% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthAESPassword.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthAESPassword.java index 974afbec..7ecfb921 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthAESPassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthAESPassword.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.auth.password; +package pro.gravit.launcher.base.request.auth.password; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.request.auth.AuthRequest; public class AuthAESPassword implements AuthRequest.AuthPasswordInterface { @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthCodePassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthCodePassword.java similarity index 69% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthCodePassword.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthCodePassword.java index d9595e34..5b3c6e03 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthCodePassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthCodePassword.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.password; +package pro.gravit.launcher.base.request.auth.password; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.AuthRequest; public class AuthCodePassword implements AuthRequest.AuthPasswordInterface { public final String code; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthMultiPassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthMultiPassword.java similarity index 79% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthMultiPassword.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthMultiPassword.java index ddc9871c..829b57dd 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthMultiPassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthMultiPassword.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.password; +package pro.gravit.launcher.base.request.auth.password; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.AuthRequest; import java.util.List; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthOAuthPassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthOAuthPassword.java similarity index 87% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthOAuthPassword.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthOAuthPassword.java index 9c72e5b0..810f8aaf 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthOAuthPassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthOAuthPassword.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.password; +package pro.gravit.launcher.base.request.auth.password; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.AuthRequest; public class AuthOAuthPassword implements AuthRequest.AuthPasswordInterface { public final String accessToken; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthPlainPassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthPlainPassword.java similarity index 64% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthPlainPassword.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthPlainPassword.java index 9e83e6a2..41f4caf4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthPlainPassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthPlainPassword.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.auth.password; +package pro.gravit.launcher.base.request.auth.password; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.request.auth.AuthRequest; public class AuthPlainPassword implements AuthRequest.AuthPasswordInterface { @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthRSAPassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthRSAPassword.java similarity index 72% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthRSAPassword.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthRSAPassword.java index cf126905..aeae77bb 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthRSAPassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthRSAPassword.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.password; +package pro.gravit.launcher.base.request.auth.password; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.AuthRequest; public class AuthRSAPassword implements AuthRequest.AuthPasswordInterface { public final byte[] password; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthSignaturePassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthSignaturePassword.java similarity index 78% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthSignaturePassword.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthSignaturePassword.java index 7a2f4eae..cb3ccbe0 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthSignaturePassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthSignaturePassword.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.password; +package pro.gravit.launcher.base.request.auth.password; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.AuthRequest; public class AuthSignaturePassword implements AuthRequest.AuthPasswordInterface { public byte[] signature; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthTOTPPassword.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthTOTPPassword.java similarity index 60% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthTOTPPassword.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthTOTPPassword.java index 96679d29..4ddccec6 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/password/AuthTOTPPassword.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/auth/password/AuthTOTPPassword.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.request.auth.password; +package pro.gravit.launcher.base.request.auth.password; -import pro.gravit.launcher.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.AuthRequest; public class AuthTOTPPassword implements AuthRequest.AuthPasswordInterface { public String totp; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/cabinet/AssetUploadInfoRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/cabinet/AssetUploadInfoRequest.java new file mode 100644 index 00000000..be28f937 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/cabinet/AssetUploadInfoRequest.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.base.request.cabinet; + +import pro.gravit.launcher.base.events.request.AssetUploadInfoRequestEvent; +import pro.gravit.launcher.base.request.Request; + +public class AssetUploadInfoRequest extends Request { + @Override + public String getType() { + return "assetUploadInfo"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/GetAssetUploadUrl.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/cabinet/GetAssetUploadUrl.java similarity index 63% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/GetAssetUploadUrl.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/cabinet/GetAssetUploadUrl.java index 56d9d976..fb1ef584 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/GetAssetUploadUrl.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/cabinet/GetAssetUploadUrl.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.cabinet; +package pro.gravit.launcher.base.request.cabinet; -import pro.gravit.launcher.events.request.GetAssetUploadUrlRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.GetAssetUploadUrlRequestEvent; +import pro.gravit.launcher.base.request.Request; public class GetAssetUploadUrl extends Request { public String name; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/management/FeaturesRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/management/FeaturesRequest.java new file mode 100644 index 00000000..3e3ced73 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/management/FeaturesRequest.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.base.request.management; + +import pro.gravit.launcher.base.events.request.FeaturesRequestEvent; +import pro.gravit.launcher.base.request.Request; + +public class FeaturesRequest extends Request { + @Override + public String getType() { + return "features"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/management/GetConnectUUIDRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/management/GetConnectUUIDRequest.java new file mode 100644 index 00000000..a56bf98e --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/management/GetConnectUUIDRequest.java @@ -0,0 +1,11 @@ +package pro.gravit.launcher.base.request.management; + +import pro.gravit.launcher.base.events.request.GetConnectUUIDRequestEvent; +import pro.gravit.launcher.base.request.Request; + +public class GetConnectUUIDRequest extends Request { + @Override + public String getType() { + return "getConnectUUID"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/GetSecureLevelInfoRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/GetSecureLevelInfoRequest.java similarity index 50% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/GetSecureLevelInfoRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/GetSecureLevelInfoRequest.java index 47eb594e..b788d807 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/GetSecureLevelInfoRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/GetSecureLevelInfoRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.secure; +package pro.gravit.launcher.base.request.secure; -import pro.gravit.launcher.events.request.GetSecureLevelInfoRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.GetSecureLevelInfoRequestEvent; +import pro.gravit.launcher.base.request.Request; public class GetSecureLevelInfoRequest extends Request { @Override diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/HardwareReportRequest.java similarity index 89% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/HardwareReportRequest.java index 1b7e2cb9..ebe1434f 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/HardwareReportRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/HardwareReportRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.secure; +package pro.gravit.launcher.base.request.secure; -import pro.gravit.launcher.events.request.HardwareReportRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.HardwareReportRequestEvent; +import pro.gravit.launcher.base.request.Request; import java.util.Base64; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/SecurityReportRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/SecurityReportRequest.java similarity index 93% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/SecurityReportRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/SecurityReportRequest.java index 6048353a..eb4e2fc4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/SecurityReportRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/SecurityReportRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.secure; +package pro.gravit.launcher.base.request.secure; -import pro.gravit.launcher.events.request.SecurityReportRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.SecurityReportRequestEvent; +import pro.gravit.launcher.base.request.Request; public final class SecurityReportRequest extends Request { public final String reportType; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/VerifySecureLevelKeyRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/VerifySecureLevelKeyRequest.java similarity index 69% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/VerifySecureLevelKeyRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/VerifySecureLevelKeyRequest.java index b1d0bdb9..31b3e70c 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/secure/VerifySecureLevelKeyRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/secure/VerifySecureLevelKeyRequest.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.request.secure; +package pro.gravit.launcher.base.request.secure; -import pro.gravit.launcher.events.request.VerifySecureLevelKeyRequestEvent; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.events.request.VerifySecureLevelKeyRequestEvent; +import pro.gravit.launcher.base.request.Request; public class VerifySecureLevelKeyRequest extends Request { public final byte[] publicKey; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/LauncherRequest.java similarity index 77% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/LauncherRequest.java index b2345410..f84bd812 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/LauncherRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/LauncherRequest.java @@ -1,11 +1,11 @@ -package pro.gravit.launcher.request.update; +package pro.gravit.launcher.base.request.update; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.LauncherRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestService; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.LauncherRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.RequestService; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/ProfilesRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/ProfilesRequest.java new file mode 100644 index 00000000..758831b4 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/ProfilesRequest.java @@ -0,0 +1,13 @@ +package pro.gravit.launcher.base.request.update; + +import pro.gravit.launcher.base.events.request.ProfilesRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; + +public final class ProfilesRequest extends Request implements WebSocketRequest { + + @Override + public String getType() { + return "profiles"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/UpdateListRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/UpdateListRequest.java new file mode 100644 index 00000000..1406e132 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/UpdateListRequest.java @@ -0,0 +1,13 @@ +package pro.gravit.launcher.base.request.update; + +import pro.gravit.launcher.base.events.request.UpdateListRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; + +public final class UpdateListRequest extends Request implements WebSocketRequest { + + @Override + public String getType() { + return "updateList"; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/UpdateRequest.java similarity index 53% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/UpdateRequest.java index 9f82311b..f4ad831e 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/update/UpdateRequest.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.request.update; +package pro.gravit.launcher.base.request.update; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.UpdateRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.UpdateRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; public final class UpdateRequest extends Request implements WebSocketRequest { diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/uuid/BatchProfileByUsernameRequest.java similarity index 72% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/uuid/BatchProfileByUsernameRequest.java index a3f1ab2e..01e5067a 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/BatchProfileByUsernameRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/uuid/BatchProfileByUsernameRequest.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.request.uuid; +package pro.gravit.launcher.base.request.uuid; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.BatchProfileByUsernameRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.BatchProfileByUsernameRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; import pro.gravit.utils.helper.IOHelper; import java.io.IOException; @@ -27,7 +27,7 @@ public String getType() { return "batchProfileByUsername"; } - static class Entry { + public static class Entry { @LauncherNetworkAPI String username; @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/uuid/ProfileByUUIDRequest.java similarity index 58% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/uuid/ProfileByUUIDRequest.java index 4531f85c..cebec5a4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUUIDRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/uuid/ProfileByUUIDRequest.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.request.uuid; +package pro.gravit.launcher.base.request.uuid; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.ProfileByUUIDRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.ProfileByUUIDRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; import java.util.Objects; import java.util.UUID; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUsernameRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/uuid/ProfileByUsernameRequest.java similarity index 55% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUsernameRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/uuid/ProfileByUsernameRequest.java index d164b28e..4638b574 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/uuid/ProfileByUsernameRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/uuid/ProfileByUsernameRequest.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.request.uuid; +package pro.gravit.launcher.base.request.uuid; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.base.events.request.ProfileByUsernameRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.websockets.WebSocketRequest; public final class ProfileByUsernameRequest extends Request implements WebSocketRequest { @LauncherNetworkAPI diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientJSONPoint.java new file mode 100644 index 00000000..ffdab6c6 --- /dev/null +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientJSONPoint.java @@ -0,0 +1,121 @@ +package pro.gravit.launcher.base.request.websockets; + +import pro.gravit.launcher.base.Downloader; +import pro.gravit.launcher.core.LauncherInject; +import pro.gravit.utils.helper.LogHelper; + +import javax.net.ssl.SSLException; +import java.io.IOException; +import java.net.URI; +import java.net.http.HttpClient; +import java.net.http.WebSocket; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.time.Duration; +import java.util.concurrent.CompletionStage; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Consumer; + +public abstract class ClientJSONPoint implements WebSocket.Listener { + @LauncherInject("launcher.certificatePinning") + private static boolean isCertificatePinning; + private static final AtomicInteger counter = new AtomicInteger(); + private final URI uri; + public boolean isClosed; + private final WebSocket.Builder webSocketBuilder; + protected HttpClient httpClient; + protected WebSocket webSocket; + protected boolean ssl = false; + protected int port; + private final Object syncObject = new Object(); + private final Object sendSyncObject = new Object(); + private volatile StringBuilder builder = new StringBuilder(); + + public ClientJSONPoint(final String uri) throws SSLException { + this(URI.create(uri)); + } + + public ClientJSONPoint(URI uri) { + this.uri = uri; + String protocol = uri.getScheme(); + if (!"ws".equals(protocol) && !"wss".equals(protocol)) { + throw new IllegalArgumentException("Unsupported protocol: " + protocol); + } + if ("wss".equals(protocol)) { + ssl = true; + } + if (uri.getPort() == -1) { + if ("ws".equals(protocol)) port = 80; + else port = 443; + } else port = uri.getPort(); + try { + var httpClientBuilder = HttpClient.newBuilder(); + if(isCertificatePinning) { + httpClientBuilder = httpClientBuilder.sslContext(Downloader.makeSSLContext()); + } + httpClient = httpClientBuilder.build(); + webSocketBuilder = httpClient.newWebSocketBuilder().connectTimeout(Duration.ofSeconds(30)); + } catch (NoSuchAlgorithmException | CertificateException | KeyStoreException | IOException | + KeyManagementException e) { + throw new RuntimeException(e); + } + } + + public void open() throws Exception { + webSocket = webSocketBuilder.buildAsync(uri, this).get(); + } + + public void openAsync(Runnable onConnect, Consumer onFail) { + webSocketBuilder.buildAsync(uri, this).thenAccept((e) -> { + this.webSocket = e; + onConnect.run(); + }).exceptionally((ex) -> { + onFail.accept(ex); + return null; + }); + } + + @Override + public CompletionStage onText(WebSocket webSocket, CharSequence data, boolean last) { + synchronized (syncObject) { + builder.append(data); + if(last) { + String message = builder.toString(); + builder = new StringBuilder(); + LogHelper.dev("Received %s", message); + onMessage(message); + } + } + return WebSocket.Listener.super.onText(webSocket, data, last); + } + + @Override + public CompletionStage onClose(WebSocket webSocket, int statusCode, String reason) { + onDisconnect(statusCode, reason); + return WebSocket.Listener.super.onClose(webSocket, statusCode, reason); + } + + @Override + public void onError(WebSocket webSocket, Throwable error) { + LogHelper.error(error); + WebSocket.Listener.super.onError(webSocket, error); + } + + public void send(String text) { + LogHelper.dev("Send %s", text); + webSocket.sendText(text, true); + } + + abstract void onMessage(String message); + + abstract void onDisconnect(int statusCode, String reason); + + abstract void onOpen(); + + public void close() throws InterruptedException { + webSocket.abort(); + } + +} \ No newline at end of file diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientWebSocketService.java similarity index 83% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientWebSocketService.java index c7c269fa..11fd7493 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientWebSocketService.java @@ -1,18 +1,18 @@ -package pro.gravit.launcher.request.websockets; +package pro.gravit.launcher.base.request.websockets; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.events.NotificationEvent; -import pro.gravit.launcher.events.request.*; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.hasher.HashedEntryAdapter; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; -import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger; -import pro.gravit.launcher.request.WebSocketEvent; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.events.NotificationEvent; +import pro.gravit.launcher.base.events.request.*; +import pro.gravit.launcher.core.hasher.HashedEntry; +import pro.gravit.launcher.core.hasher.HashedEntryAdapter; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.optional.triggers.OptionalTrigger; +import pro.gravit.launcher.base.request.WebSocketEvent; +import pro.gravit.launcher.base.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.GetAvailabilityAuthRequest; import pro.gravit.utils.ProviderMap; import pro.gravit.utils.UniversalJsonAdapter; import pro.gravit.utils.helper.LogHelper; @@ -67,9 +67,9 @@ void onMessage(String message) { public abstract void eventHandle(T event); @Override - void onDisconnect() { - LogHelper.info("WebSocket client disconnect"); - if (onCloseCallback != null) onCloseCallback.onClose(0, "unsupported param", !isClosed); + void onDisconnect(int statusCode, String reason) { + LogHelper.info("WebSocket disconnected: %d: %s", statusCode, reason); + if (onCloseCallback != null) onCloseCallback.onClose(statusCode, reason, !isClosed); } @Override @@ -113,6 +113,7 @@ public void registerResults() { results.register("getPublicKey", GetPublicKeyRequestEvent.class); results.register("getAssetUploadUrl", GetAssetUploadUrlRequestEvent.class); results.register("assetUploadInfo", AssetUploadInfoRequestEvent.class); + results.register("getConnectUUID", GetConnectUUIDRequestEvent.class); resultsRegistered = true; } } @@ -122,13 +123,13 @@ public void waitIfNotConnected() { public void sendObject(Object obj) throws IOException { waitIfNotConnected(); - if (ch == null || !ch.isActive()) reconnectCallback.onReconnect(); + if (webSocket == null || webSocket.isInputClosed()) reconnectCallback.onReconnect(); send(gson.toJson(obj, WebSocketRequest.class)); } public void sendObject(Object obj, Type type) throws IOException { waitIfNotConnected(); - if (ch == null || !ch.isActive()) reconnectCallback.onReconnect(); + if (webSocket == null || webSocket.isInputClosed()) reconnectCallback.onReconnect(); send(gson.toJson(obj, type)); } diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/OfflineRequestService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/OfflineRequestService.java similarity index 88% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/OfflineRequestService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/OfflineRequestService.java index 66fb69e5..d995b73d 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/OfflineRequestService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/OfflineRequestService.java @@ -1,10 +1,10 @@ -package pro.gravit.launcher.request.websockets; +package pro.gravit.launcher.base.request.websockets; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestException; -import pro.gravit.launcher.request.RequestService; -import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.RequestException; +import pro.gravit.launcher.base.request.RequestService; +import pro.gravit.launcher.base.request.WebSocketEvent; import pro.gravit.utils.helper.LogHelper; import java.util.HashSet; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/StdWebSocketService.java similarity index 90% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/StdWebSocketService.java index 1ee786f8..fe6dade9 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/StdWebSocketService.java @@ -1,11 +1,11 @@ -package pro.gravit.launcher.request.websockets; +package pro.gravit.launcher.base.request.websockets; -import pro.gravit.launcher.events.RequestEvent; -import pro.gravit.launcher.events.request.ErrorRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestException; -import pro.gravit.launcher.request.RequestService; -import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launcher.base.events.RequestEvent; +import pro.gravit.launcher.base.events.request.ErrorRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.RequestException; +import pro.gravit.launcher.base.request.RequestService; +import pro.gravit.launcher.base.request.WebSocketEvent; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; @@ -72,8 +72,7 @@ public void processEventHandlers(T event) { @SuppressWarnings({"unchecked"}) public void eventHandle(T webSocketEvent) { - if (webSocketEvent instanceof RequestEvent) { - RequestEvent event = (RequestEvent) webSocketEvent; + if (webSocketEvent instanceof RequestEvent event) { if (event.requestUUID == null) { LogHelper.warning("Request event type %s.requestUUID is null", event.getType() == null ? "null" : event.getType()); return; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/VoidRequestService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/VoidRequestService.java similarity index 76% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/VoidRequestService.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/VoidRequestService.java index 4d098833..0e26a494 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/VoidRequestService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/VoidRequestService.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.request.websockets; +package pro.gravit.launcher.base.request.websockets; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestException; -import pro.gravit.launcher.request.RequestService; -import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.RequestException; +import pro.gravit.launcher.base.request.RequestService; +import pro.gravit.launcher.base.request.WebSocketEvent; import java.util.concurrent.CompletableFuture; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/WebSocketRequest.java similarity index 72% rename from LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketRequest.java rename to LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/WebSocketRequest.java index 05d3e899..69389897 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketRequest.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/WebSocketRequest.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.request.websockets; +package pro.gravit.launcher.base.request.websockets; import pro.gravit.utils.TypeSerializeInterface; diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/ClosePhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/ClosePhase.java deleted file mode 100644 index b924d4c0..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/ClosePhase.java +++ /dev/null @@ -1,6 +0,0 @@ -package pro.gravit.launcher.modules.events; - -import pro.gravit.launcher.modules.LauncherModule; - -public class ClosePhase extends LauncherModule.Event { -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/InitPhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/InitPhase.java deleted file mode 100644 index b4f24adb..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/InitPhase.java +++ /dev/null @@ -1,6 +0,0 @@ -package pro.gravit.launcher.modules.events; - -import pro.gravit.launcher.modules.LauncherModule; - -public class InitPhase extends LauncherModule.Event { -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PostInitPhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PostInitPhase.java deleted file mode 100644 index 88d097a5..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PostInitPhase.java +++ /dev/null @@ -1,6 +0,0 @@ -package pro.gravit.launcher.modules.events; - -import pro.gravit.launcher.modules.LauncherModule; - -public class PostInitPhase extends LauncherModule.Event { -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreConfigPhase.java b/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreConfigPhase.java deleted file mode 100644 index 01630a53..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/modules/events/PreConfigPhase.java +++ /dev/null @@ -1,6 +0,0 @@ -package pro.gravit.launcher.modules.events; - -import pro.gravit.launcher.modules.LauncherModule; - -public class PreConfigPhase extends LauncherModule.Event { -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalDepend.java b/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalDepend.java deleted file mode 100644 index c5acde22..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/profiles/optional/OptionalDepend.java +++ /dev/null @@ -1,8 +0,0 @@ -package pro.gravit.launcher.profiles.optional; - -import pro.gravit.launcher.LauncherNetworkAPI; - -public class OptionalDepend { - @LauncherNetworkAPI - public String name; -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CurrentUserRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CurrentUserRequest.java deleted file mode 100644 index 4a4437f5..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/auth/CurrentUserRequest.java +++ /dev/null @@ -1,11 +0,0 @@ -package pro.gravit.launcher.request.auth; - -import pro.gravit.launcher.events.request.CurrentUserRequestEvent; -import pro.gravit.launcher.request.Request; - -public class CurrentUserRequest extends Request { - @Override - public String getType() { - return "currentUser"; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/AssetUploadInfoRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/AssetUploadInfoRequest.java deleted file mode 100644 index 3827e762..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/cabinet/AssetUploadInfoRequest.java +++ /dev/null @@ -1,11 +0,0 @@ -package pro.gravit.launcher.request.cabinet; - -import pro.gravit.launcher.events.request.AssetUploadInfoRequestEvent; -import pro.gravit.launcher.request.Request; - -public class AssetUploadInfoRequest extends Request { - @Override - public String getType() { - return "assetUploadInfo"; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/FeaturesRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/FeaturesRequest.java deleted file mode 100644 index d203cdff..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/management/FeaturesRequest.java +++ /dev/null @@ -1,11 +0,0 @@ -package pro.gravit.launcher.request.management; - -import pro.gravit.launcher.events.request.FeaturesRequestEvent; -import pro.gravit.launcher.request.Request; - -public class FeaturesRequest extends Request { - @Override - public String getType() { - return "features"; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/ProfilesRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/ProfilesRequest.java deleted file mode 100644 index 06f28ebc..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/ProfilesRequest.java +++ /dev/null @@ -1,13 +0,0 @@ -package pro.gravit.launcher.request.update; - -import pro.gravit.launcher.events.request.ProfilesRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; - -public final class ProfilesRequest extends Request implements WebSocketRequest { - - @Override - public String getType() { - return "profiles"; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateListRequest.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateListRequest.java deleted file mode 100644 index 463b58ed..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/update/UpdateListRequest.java +++ /dev/null @@ -1,13 +0,0 @@ -package pro.gravit.launcher.request.update; - -import pro.gravit.launcher.events.request.UpdateListRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.websockets.WebSocketRequest; - -public final class UpdateListRequest extends Request implements WebSocketRequest { - - @Override - public String getType() { - return "updateList"; - } -} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java deleted file mode 100644 index 255c3267..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/ClientJSONPoint.java +++ /dev/null @@ -1,155 +0,0 @@ -package pro.gravit.launcher.request.websockets; - -import io.netty.bootstrap.Bootstrap; -import io.netty.channel.*; -import io.netty.channel.nio.NioEventLoopGroup; -import io.netty.channel.socket.SocketChannel; -import io.netty.channel.socket.nio.NioSocketChannel; -import io.netty.handler.codec.http.EmptyHttpHeaders; -import io.netty.handler.codec.http.HttpClientCodec; -import io.netty.handler.codec.http.HttpObjectAggregator; -import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; -import io.netty.handler.codec.http.websocketx.TextWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory; -import io.netty.handler.codec.http.websocketx.WebSocketVersion; -import io.netty.handler.ssl.SslContext; -import io.netty.handler.ssl.SslContextBuilder; -import pro.gravit.launcher.CertificatePinningTrustManager; -import pro.gravit.launcher.LauncherInject; -import pro.gravit.utils.helper.LogHelper; - -import javax.net.ssl.SSLException; -import java.io.IOException; -import java.net.URI; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Consumer; - -public abstract class ClientJSONPoint { - private static final AtomicInteger counter = new AtomicInteger(); - private static final ThreadFactory threadFactory = (runnable) -> { - Thread t = new Thread(runnable); - t.setName(String.format("Netty Thread #%d", counter.incrementAndGet())); - t.setDaemon(true); - return t; - }; - private static final EventLoopGroup group = new NioEventLoopGroup(threadFactory); - @LauncherInject("launcher.certificatePinning") - private static boolean isCertificatePinning; - protected final Bootstrap bootstrap = new Bootstrap(); - private final URI uri; - public boolean isClosed; - protected Channel ch; - protected WebSocketClientHandler webSocketClientHandler; - protected boolean ssl = false; - protected int port; - - public ClientJSONPoint(final String uri) throws SSLException { - this(URI.create(uri)); - } - - public ClientJSONPoint(URI uri) throws SSLException { - this.uri = uri; - String protocol = uri.getScheme(); - if (!"ws".equals(protocol) && !"wss".equals(protocol)) { - throw new IllegalArgumentException("Unsupported protocol: " + protocol); - } - if ("wss".equals(protocol)) { - ssl = true; - } - if (uri.getPort() == -1) { - if ("ws".equals(protocol)) port = 80; - else port = 443; - } else port = uri.getPort(); - final SslContext sslCtx; - if (ssl) { - SslContextBuilder sslContextBuilder = SslContextBuilder.forClient(); - if (isCertificatePinning) { - try { - sslContextBuilder.trustManager(CertificatePinningTrustManager.getTrustManager()); - } catch (KeyStoreException | NoSuchAlgorithmException | IOException | CertificateException e) { - LogHelper.error(e); - sslContextBuilder.trustManager(); - } - } - sslCtx = sslContextBuilder.build(); - } else sslCtx = null; - bootstrap.group(group) - .channel(NioSocketChannel.class) - .handler(new ChannelInitializer() { - @Override - public void initChannel(SocketChannel ch) { - ChannelPipeline pipeline = ch.pipeline(); - if (sslCtx != null) { - pipeline.addLast(sslCtx.newHandler(ch.alloc(), uri.getHost(), port)); - } - pipeline.addLast("http-codec", new HttpClientCodec()); - pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); - pipeline.addLast("ws-handler", webSocketClientHandler); - } - }); - } - - public void open() throws Exception { - //System.out.println("WebSocket Client connecting"); - webSocketClientHandler = - new WebSocketClientHandler( - WebSocketClientHandshakerFactory.newHandshaker( - uri, WebSocketVersion.V13, null, false, EmptyHttpHeaders.INSTANCE, 12800000), this); - ch = bootstrap.connect(uri.getHost(), port).sync().channel(); - webSocketClientHandler.handshakeFuture().sync(); - } - - public void openAsync(Runnable onConnect, Consumer onFail) { - //System.out.println("WebSocket Client connecting"); - webSocketClientHandler = - new WebSocketClientHandler( - WebSocketClientHandshakerFactory.newHandshaker( - uri, WebSocketVersion.V13, null, false, EmptyHttpHeaders.INSTANCE, 12800000), this); - ChannelFuture future = bootstrap.connect(uri.getHost(), port); - future.addListener((l) -> { - if (l.isSuccess()) { - ch = future.channel(); - webSocketClientHandler.handshakeFuture().addListener((e) -> { - if (e.isSuccess()) { - onConnect.run(); - } else { - onFail.accept(webSocketClientHandler.handshakeFuture().cause()); - } - }); - } else { - onFail.accept(future.cause()); - } - }); - } - - public void send(String text) { - LogHelper.dev("Send: %s", text); - ch.writeAndFlush(new TextWebSocketFrame(text), ch.voidPromise()); - } - - abstract void onMessage(String message); - - abstract void onDisconnect(); - - abstract void onOpen(); - - public void close() throws InterruptedException { - //System.out.println("WebSocket Client sending close"); - isClosed = true; - if (ch != null && ch.isActive()) { - ch.writeAndFlush(new CloseWebSocketFrame(), ch.voidPromise()); - ch.closeFuture().sync(); - } - - group.shutdownGracefully(); - } - - public void eval(final String text) { - ch.writeAndFlush(new TextWebSocketFrame(text), ch.voidPromise()); - } - -} \ No newline at end of file diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java deleted file mode 100644 index 1fa99c11..00000000 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/WebSocketClientHandler.java +++ /dev/null @@ -1,91 +0,0 @@ -package pro.gravit.launcher.request.websockets; - -import io.netty.channel.*; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.websocketx.*; -import io.netty.util.CharsetUtil; -import pro.gravit.utils.helper.LogHelper; - -import java.util.concurrent.TimeUnit; - -public class WebSocketClientHandler extends SimpleChannelInboundHandler { - - private final WebSocketClientHandshaker handshaker; - private final ClientJSONPoint clientJSONPoint; - private ChannelPromise handshakeFuture; - - public WebSocketClientHandler(final WebSocketClientHandshaker handshaker, ClientJSONPoint clientJSONPoint) { - this.handshaker = handshaker; - this.clientJSONPoint = clientJSONPoint; - } - - public ChannelFuture handshakeFuture() { - return handshakeFuture; - } - - @Override - public void handlerAdded(final ChannelHandlerContext ctx) { - handshakeFuture = ctx.newPromise(); - } - - @Override - public void channelActive(final ChannelHandlerContext ctx) { - handshaker.handshake(ctx.channel()); - clientJSONPoint.onOpen(); - ctx.executor().scheduleWithFixedDelay(() -> ctx.channel().writeAndFlush(new PingWebSocketFrame()), 20L, 20L, TimeUnit.SECONDS); - } - - @Override - public void channelInactive(final ChannelHandlerContext ctx) { - //System.out.println("WebSocket Client disconnected!"); - clientJSONPoint.onDisconnect(); - } - - @Override - protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { - final Channel ch = ctx.channel(); - if (!handshaker.isHandshakeComplete()) { - // web socket client connected - handshaker.finishHandshake(ch, (FullHttpResponse) msg); - handshakeFuture.setSuccess(); - return; - } - - if (msg instanceof FullHttpResponse) { - final FullHttpResponse response = (FullHttpResponse) msg; - throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.status() + ", content=" - + response.content().toString(CharsetUtil.UTF_8) + ')'); - } - - final WebSocketFrame frame = (WebSocketFrame) msg; - if (frame instanceof TextWebSocketFrame) { - final TextWebSocketFrame textFrame = (TextWebSocketFrame) frame; - if (LogHelper.isDevEnabled()) { - LogHelper.dev("Message: %s", textFrame.text()); - } - clientJSONPoint.onMessage(textFrame.text()); - // uncomment to print request - // logger.info(textFrame.text()); - } else if ((frame instanceof PingWebSocketFrame)) { - frame.content().retain(); - ch.writeAndFlush(new PongWebSocketFrame(frame.content()), ch.voidPromise()); - //return; - } else if (frame instanceof PongWebSocketFrame) { - } else if (frame instanceof CloseWebSocketFrame) - ch.close(); - else if (frame instanceof BinaryWebSocketFrame) { - // uncomment to print request - // logger.info(frame.content().toString()); - } - } - - @Override - public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) { - if (!handshakeFuture.isDone()) { - handshakeFuture.setFailure(cause); - } else { - LogHelper.error(cause); - } - ctx.close(); - } -} \ No newline at end of file diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/ClientVersionTest.java b/LauncherAPI/src/test/java/pro/gravit/launcher/ClientVersionTest.java index 205b495a..81ff8a28 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/ClientVersionTest.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/ClientVersionTest.java @@ -2,7 +2,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfile; public class ClientVersionTest { @Test diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/ModulesTest.java b/LauncherAPI/src/test/java/pro/gravit/launcher/ModulesTest.java index c228df09..0f9ea313 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/ModulesTest.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/ModulesTest.java @@ -7,8 +7,8 @@ import pro.gravit.launcher.impl.*; import pro.gravit.launcher.impl.event.CancelEvent; import pro.gravit.launcher.impl.event.NormalEvent; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.impl.SimpleModuleManager; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.impl.SimpleModuleManager; import java.nio.file.Path; diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/PermissionTest.java b/LauncherAPI/src/test/java/pro/gravit/launcher/PermissionTest.java index 74baf10c..581b5015 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/PermissionTest.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/PermissionTest.java @@ -2,6 +2,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import pro.gravit.launcher.base.ClientPermissions; public class PermissionTest { @Test diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Cyclic2DependModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Cyclic2DependModule.java index fa321bce..3d144bec 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Cyclic2DependModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Cyclic2DependModule.java @@ -1,8 +1,8 @@ package pro.gravit.launcher.impl; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.utils.Version; public class Cyclic2DependModule extends LauncherModule { diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/CyclicDependModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/CyclicDependModule.java index c13d8b58..090ce42a 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/CyclicDependModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/CyclicDependModule.java @@ -1,8 +1,8 @@ package pro.gravit.launcher.impl; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.utils.Version; public class CyclicDependModule extends LauncherModule { diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend1Module.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend1Module.java index a3f046b7..99da57e2 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend1Module.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend1Module.java @@ -1,9 +1,9 @@ package pro.gravit.launcher.impl; import org.junit.jupiter.api.Assertions; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.utils.Version; public class Depend1Module extends LauncherModule { diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend2Module.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend2Module.java index 2b50e4c1..466053d6 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend2Module.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend2Module.java @@ -1,9 +1,9 @@ package pro.gravit.launcher.impl; import org.junit.jupiter.api.Assertions; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.utils.Version; public class Depend2Module extends LauncherModule { diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend3Module.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend3Module.java index 3e63503a..bf264cc8 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend3Module.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/Depend3Module.java @@ -1,8 +1,8 @@ package pro.gravit.launcher.impl; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; public class Depend3Module extends LauncherModule { public Depend3Module() { diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/InternalModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/InternalModule.java index 1cbe663e..acd36fca 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/InternalModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/InternalModule.java @@ -1,8 +1,8 @@ package pro.gravit.launcher.impl; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; public class InternalModule extends LauncherModule { public InternalModule() { diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/MainModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/MainModule.java index 22248da6..e4993574 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/MainModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/MainModule.java @@ -1,9 +1,9 @@ package pro.gravit.launcher.impl; import org.junit.jupiter.api.Assertions; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.utils.Version; public class MainModule extends LauncherModule { diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/ProvidedModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/ProvidedModule.java index dd201374..68fb5c0c 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/ProvidedModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/ProvidedModule.java @@ -1,8 +1,8 @@ package pro.gravit.launcher.impl; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.utils.Version; public class ProvidedModule extends LauncherModule implements VirtualInterface { diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/TestModule.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/TestModule.java index 9f247324..18500f2b 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/TestModule.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/TestModule.java @@ -2,9 +2,9 @@ import pro.gravit.launcher.impl.event.CancelEvent; import pro.gravit.launcher.impl.event.NormalEvent; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; public class TestModule extends LauncherModule { diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/event/CancelEvent.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/event/CancelEvent.java index 4220f5f1..adb68520 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/event/CancelEvent.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/event/CancelEvent.java @@ -1,6 +1,6 @@ package pro.gravit.launcher.impl.event; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; public class CancelEvent extends LauncherModule.Event { } diff --git a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/event/NormalEvent.java b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/event/NormalEvent.java index 210b88e2..84bc7d62 100644 --- a/LauncherAPI/src/test/java/pro/gravit/launcher/impl/event/NormalEvent.java +++ b/LauncherAPI/src/test/java/pro/gravit/launcher/impl/event/NormalEvent.java @@ -1,6 +1,6 @@ package pro.gravit.launcher.impl.event; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; public class NormalEvent extends LauncherModule.Event { public boolean passed; diff --git a/LauncherClient/build.gradle b/LauncherClient/build.gradle index 5c62ac48..9a59ce29 100644 --- a/LauncherClient/build.gradle +++ b/LauncherClient/build.gradle @@ -8,8 +8,8 @@ url "https://repo.spring.io/plugins-release/" } } -sourceCompatibility = '1.8' -targetCompatibility = '1.8' +sourceCompatibility = '17' +targetCompatibility = '17' jar { archiveClassifier.set('clean') diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/BasicLauncherEventHandler.java similarity index 53% rename from LauncherClient/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/BasicLauncherEventHandler.java index 3e5e5cd2..6269c269 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/BasicLauncherEventHandler.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/BasicLauncherEventHandler.java @@ -1,20 +1,19 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.client; -import pro.gravit.launcher.api.DialogService; -import pro.gravit.launcher.events.ExtendedTokenRequestEvent; -import pro.gravit.launcher.events.NotificationEvent; -import pro.gravit.launcher.events.request.SecurityReportRequestEvent; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestService; -import pro.gravit.launcher.request.WebSocketEvent; +import pro.gravit.launcher.client.api.DialogService; +import pro.gravit.launcher.base.events.ExtendedTokenRequestEvent; +import pro.gravit.launcher.base.events.NotificationEvent; +import pro.gravit.launcher.base.events.request.SecurityReportRequestEvent; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.RequestService; +import pro.gravit.launcher.base.request.WebSocketEvent; import pro.gravit.utils.helper.LogHelper; public class BasicLauncherEventHandler implements RequestService.EventHandler { @Override public boolean eventHandle(T event) { - if (event instanceof SecurityReportRequestEvent) { - SecurityReportRequestEvent event1 = (SecurityReportRequestEvent) event; + if (event instanceof SecurityReportRequestEvent event1) { if (event1.action == SecurityReportRequestEvent.ReportAction.TOKEN_EXPIRED) { try { Request.restore(); @@ -22,14 +21,12 @@ public boolean eventHandle(T event) { LogHelper.error(e); } } - } else if (event instanceof ExtendedTokenRequestEvent) { - ExtendedTokenRequestEvent event1 = (ExtendedTokenRequestEvent) event; + } else if (event instanceof ExtendedTokenRequestEvent event1) { String token = event1.getExtendedToken(); if (token != null) { Request.addExtendedToken(event1.getExtendedTokenName(), new Request.ExtendedToken(event1.getExtendedToken(), event1.getExtendedTokenExpire())); } - } else if (event instanceof NotificationEvent) { - NotificationEvent n = (NotificationEvent) event; + } else if (event instanceof NotificationEvent n) { if (DialogService.isNotificationsAvailable()) { DialogService.createNotification(n.icon, n.head, n.message); } diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientGsonManager.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientGsonManager.java index bcd99ccc..7a4ce733 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientGsonManager.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientGsonManager.java @@ -1,9 +1,9 @@ package pro.gravit.launcher.client; import com.google.gson.GsonBuilder; -import pro.gravit.launcher.managers.GsonManager; -import pro.gravit.launcher.modules.events.PreGsonPhase; -import pro.gravit.launcher.request.websockets.ClientWebSocketService; +import pro.gravit.launcher.core.managers.GsonManager; +import pro.gravit.launcher.base.modules.events.PreGsonPhase; +import pro.gravit.launcher.base.request.websockets.ClientWebSocketService; public class ClientGsonManager extends GsonManager { private final ClientModuleManager moduleManager; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherCoreModule.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherCoreModule.java index 21e3c8af..9cfe8ddc 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherCoreModule.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherCoreModule.java @@ -1,8 +1,8 @@ package pro.gravit.launcher.client; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.utils.Version; public class ClientLauncherCoreModule extends LauncherModule { diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java index b90f7958..6c83934e 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherEntryPoint.java @@ -1,28 +1,30 @@ package pro.gravit.launcher.client; -import pro.gravit.launcher.*; -import pro.gravit.launcher.api.AuthService; -import pro.gravit.launcher.api.ClientService; -import pro.gravit.launcher.api.KeyService; -import pro.gravit.launcher.client.events.client.*; -import pro.gravit.launcher.hasher.FileNameMatcher; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.modules.events.PreConfigPhase; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.ClientProfileVersions; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; -import pro.gravit.launcher.profiles.optional.actions.OptionalActionClassPath; -import pro.gravit.launcher.profiles.optional.actions.OptionalActionClientArgs; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.RequestException; -import pro.gravit.launcher.request.RequestService; -import pro.gravit.launcher.request.websockets.StdWebSocketService; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.utils.DirWatcher; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.LauncherConfig; +import pro.gravit.launcher.base.api.AuthService; +import pro.gravit.launcher.base.api.ClientService; +import pro.gravit.launcher.base.api.KeyService; +import pro.gravit.launcher.client.events.*; +import pro.gravit.launcher.core.hasher.FileNameMatcher; +import pro.gravit.launcher.core.hasher.HashedDir; +import pro.gravit.launcher.core.hasher.HashedEntry; +import pro.gravit.launcher.base.modules.events.PreConfigPhase; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfileVersions; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalActionClassPath; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalActionClientArgs; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.RequestException; +import pro.gravit.launcher.base.request.RequestService; +import pro.gravit.launcher.base.request.websockets.StdWebSocketService; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.client.utils.DirWatcher; import pro.gravit.utils.helper.*; import pro.gravit.utils.launch.*; +import javax.crypto.CipherInputStream; import java.io.File; import java.io.IOException; import java.lang.invoke.MethodHandle; @@ -49,7 +51,7 @@ public class ClientLauncherEntryPoint { private static ClientParams readParams(SocketAddress address) throws IOException { try (Socket socket = IOHelper.newSocket()) { socket.connect(address); - try (HInput input = new HInput(socket.getInputStream())) { + try (HInput input = new HInput(new CipherInputStream(socket.getInputStream(), SecurityHelper.newAESDecryptCipher(SecurityHelper.fromHex(Launcher.getConfig().secretKeyClient))))) { byte[] serialized = input.readByteArray(0); ClientParams params = Launcher.gsonManager.gson.fromJson(IOHelper.decode(serialized), ClientParams.class); params.clientHDir = new HashedDir(input); @@ -87,6 +89,11 @@ private static void realMain(String[] args) throws Throwable { if (params.profile.getClassLoaderConfig() != ClientProfile.ClassLoaderConfig.AGENT) { ClientLauncherMethods.verifyNoAgent(); } + if(params.timestamp > System.currentTimeMillis() || params.timestamp + 30*1000 < System.currentTimeMillis() ) { + LogHelper.error("Timestamp failed. Exit"); + ClientLauncherMethods.exitLauncher(-662); + return; + } ClientProfile profile = params.profile; Launcher.profile = profile; AuthService.profile = profile; @@ -114,6 +121,11 @@ private static void realMain(String[] args) throws Throwable { List classpath = resolveClassPath(clientDir, params.actions, params.profile) .filter(x -> !profile.getModulePath().contains(clientDir.relativize(x).toString())) .collect(Collectors.toCollection(ArrayList::new)); + if(LogHelper.isDevEnabled()) { + for(var e : classpath) { + LogHelper.dev("Classpath entry %s", e); + } + } List classpathURLs = classpath.stream().map(IOHelper::toURL).collect(Collectors.toList()); // Start client with WatchService monitoring RequestService service; @@ -249,7 +261,12 @@ private static Stream resolveClassPathStream(Path clientDir, String... cla for (String classPathEntry : classPath) { Path path = clientDir.resolve(IOHelper.toPath(classPathEntry.replace(IOHelper.CROSS_SEPARATOR, IOHelper.PLATFORM_SEPARATOR))); if (IOHelper.isDir(path)) { // Recursive walking and adding - IOHelper.walk(path, new ClassPathFileVisitor(builder), false); + List jars = new ArrayList<>(32); + IOHelper.walk(path, new ClassPathFileVisitor(jars), false); + Collections.sort(jars); + for(var e : jars) { + builder.accept(e); + } continue; } builder.accept(path); @@ -315,16 +332,16 @@ private static void launch(ClientProfile profile, ClientParams params) throws Th } private static final class ClassPathFileVisitor extends SimpleFileVisitor { - private final Stream.Builder result; + private final List result; - private ClassPathFileVisitor(Stream.Builder result) { + private ClassPathFileVisitor(List result) { this.result = result; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (IOHelper.hasExtension(file, "jar") || IOHelper.hasExtension(file, "zip")) - result.accept(file); + result.add(file); return super.visitFile(file, attrs); } } diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/ClientLauncherMethods.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherMethods.java similarity index 80% rename from LauncherClient/src/main/java/pro/gravit/launcher/ClientLauncherMethods.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherMethods.java index 3715b1e5..09d8aef5 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/ClientLauncherMethods.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientLauncherMethods.java @@ -1,27 +1,25 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.client; -import pro.gravit.launcher.client.ClientGsonManager; -import pro.gravit.launcher.client.ClientLauncherEntryPoint; -import pro.gravit.launcher.client.ClientModuleManager; -import pro.gravit.launcher.client.ClientParams; +import pro.gravit.launcher.base.Launcher; import pro.gravit.launcher.client.events.ClientExitPhase; -import pro.gravit.launcher.events.request.*; -import pro.gravit.launcher.modules.LauncherModulesManager; -import pro.gravit.launcher.modules.events.OfflineModeEvent; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; -import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger; -import pro.gravit.launcher.request.RequestException; -import pro.gravit.launcher.request.RequestService; -import pro.gravit.launcher.request.auth.*; -import pro.gravit.launcher.request.auth.details.AuthLoginOnlyDetails; -import pro.gravit.launcher.request.management.FeaturesRequest; -import pro.gravit.launcher.request.secure.GetSecureLevelInfoRequest; -import pro.gravit.launcher.request.secure.SecurityReportRequest; -import pro.gravit.launcher.request.update.LauncherRequest; -import pro.gravit.launcher.request.uuid.ProfileByUUIDRequest; -import pro.gravit.launcher.request.uuid.ProfileByUsernameRequest; -import pro.gravit.launcher.request.websockets.OfflineRequestService; -import pro.gravit.launcher.utils.NativeJVMHalt; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.events.request.*; +import pro.gravit.launcher.base.modules.LauncherModulesManager; +import pro.gravit.launcher.base.modules.events.OfflineModeEvent; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.optional.triggers.OptionalTrigger; +import pro.gravit.launcher.base.request.RequestException; +import pro.gravit.launcher.base.request.RequestService; +import pro.gravit.launcher.base.request.auth.*; +import pro.gravit.launcher.base.request.auth.details.AuthLoginOnlyDetails; +import pro.gravit.launcher.base.request.management.FeaturesRequest; +import pro.gravit.launcher.base.request.secure.GetSecureLevelInfoRequest; +import pro.gravit.launcher.base.request.secure.SecurityReportRequest; +import pro.gravit.launcher.base.request.update.LauncherRequest; +import pro.gravit.launcher.base.request.uuid.ProfileByUUIDRequest; +import pro.gravit.launcher.base.request.uuid.ProfileByUsernameRequest; +import pro.gravit.launcher.base.request.websockets.OfflineRequestService; +import pro.gravit.launcher.client.utils.NativeJVMHalt; import pro.gravit.utils.helper.JVMHelper; import java.security.cert.X509Certificate; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java index 648685e7..bbcefeeb 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java @@ -1,9 +1,9 @@ package pro.gravit.launcher.client; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherTrustManager; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.impl.SimpleModuleManager; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.impl.SimpleModuleManager; import java.nio.file.Path; import java.util.Collections; @@ -34,7 +34,12 @@ public List getModules() { } @Override - public final boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { + protected ModulesClassLoader createClassLoader() { + return null; + } + + @Override + public boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { return result.type == LauncherTrustManager.CheckClassResultType.SUCCESS; } } diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientParams.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientParams.java index da72aba6..9f259dcb 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientParams.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientParams.java @@ -1,19 +1,20 @@ package pro.gravit.launcher.client; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.ClientProfileVersions; -import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; -import pro.gravit.launcher.profiles.optional.actions.OptionalActionClientArgs; -import pro.gravit.launcher.request.Request; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.core.hasher.HashedDir; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfileVersions; +import pro.gravit.launcher.base.profiles.PlayerProfile; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalActionClientArgs; +import pro.gravit.launcher.base.request.Request; import pro.gravit.utils.Version; import java.util.*; public class ClientParams { + public long timestamp; public String assetDir; public String clientDir; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/LauncherAgent.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/LauncherAgent.java similarity index 95% rename from LauncherClient/src/main/java/pro/gravit/launcher/LauncherAgent.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/LauncherAgent.java index 63d96485..0683af97 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/LauncherAgent.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/LauncherAgent.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.client; -import pro.gravit.launcher.utils.NativeJVMHalt; +import pro.gravit.launcher.client.utils.NativeJVMHalt; import pro.gravit.utils.helper.LogHelper; import java.io.File; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/RuntimeLauncherCoreModule.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/RuntimeLauncherCoreModule.java similarity index 66% rename from Launcher/src/main/java/pro/gravit/launcher/client/RuntimeLauncherCoreModule.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/RuntimeLauncherCoreModule.java index 76b85182..a4366843 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/RuntimeLauncherCoreModule.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/RuntimeLauncherCoreModule.java @@ -1,8 +1,8 @@ package pro.gravit.launcher.client; -import pro.gravit.launcher.modules.LauncherInitContext; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.LauncherModuleInfo; +import pro.gravit.launcher.base.modules.LauncherInitContext; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModuleInfo; import pro.gravit.utils.Version; public class RuntimeLauncherCoreModule extends LauncherModule { diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/api/CertificateService.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/api/CertificateService.java similarity index 79% rename from LauncherClient/src/main/java/pro/gravit/launcher/api/CertificateService.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/api/CertificateService.java index b21cb0b5..ada1e6ac 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/api/CertificateService.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/api/CertificateService.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.api; +package pro.gravit.launcher.client.api; -import pro.gravit.launcher.ClientLauncherMethods; -import pro.gravit.launcher.LauncherTrustManager; -import pro.gravit.launcher.utils.ApiBridgeService; +import pro.gravit.launcher.client.ClientLauncherMethods; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.client.utils.ApiBridgeService; import java.security.cert.X509Certificate; @@ -78,20 +78,13 @@ private static CheckClassResultApi fromCheckClassResult(LauncherTrustManager.Che private static CheckClassResultTypeApi fromType(LauncherTrustManager.CheckClassResultType type) { if (type == null) return null; - switch (type) { - case NOT_SIGNED: - return CheckClassResultTypeApi.NOT_SIGNED; - case SUCCESS: - return CheckClassResultTypeApi.SUCCESS; - case UNTRUSTED: - return CheckClassResultTypeApi.UNTRUSTED; - case UNVERIFED: - return CheckClassResultTypeApi.UNVERIFED; - case UNCOMPAT: - return CheckClassResultTypeApi.UNCOMPAT; - default: - return CheckClassResultTypeApi.UNKNOWN; - } + return switch (type) { + case NOT_SIGNED -> CheckClassResultTypeApi.NOT_SIGNED; + case SUCCESS -> CheckClassResultTypeApi.SUCCESS; + case UNTRUSTED -> CheckClassResultTypeApi.UNTRUSTED; + case UNVERIFED -> CheckClassResultTypeApi.UNVERIFED; + case UNCOMPAT -> CheckClassResultTypeApi.UNCOMPAT; + }; } } } diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/api/DialogService.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/api/DialogService.java similarity index 96% rename from LauncherClient/src/main/java/pro/gravit/launcher/api/DialogService.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/api/DialogService.java index 7180c757..aa26756f 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/api/DialogService.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/api/DialogService.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.api; +package pro.gravit.launcher.client.api; -import pro.gravit.launcher.events.NotificationEvent; +import pro.gravit.launcher.base.events.NotificationEvent; import java.util.function.Consumer; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/api/SystemService.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/api/SystemService.java similarity index 69% rename from LauncherClient/src/main/java/pro/gravit/launcher/api/SystemService.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/api/SystemService.java index 9d8aed49..4b7f2674 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/api/SystemService.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/api/SystemService.java @@ -1,6 +1,6 @@ -package pro.gravit.launcher.api; +package pro.gravit.launcher.client.api; -import pro.gravit.launcher.ClientLauncherMethods; +import pro.gravit.launcher.client.ClientLauncherMethods; public class SystemService { private SystemService() { diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java index 230ea6d8..ddad537c 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientExitPhase.java @@ -1,6 +1,6 @@ package pro.gravit.launcher.client.events; -import pro.gravit.launcher.modules.events.ClosePhase; +import pro.gravit.launcher.base.modules.events.ClosePhase; public class ClientExitPhase extends ClosePhase { public final int code; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessClassLoaderEvent.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessClassLoaderEvent.java similarity index 77% rename from LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessClassLoaderEvent.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessClassLoaderEvent.java index e42c17a9..7ece2912 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessClassLoaderEvent.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessClassLoaderEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events.client; +package pro.gravit.launcher.client.events; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.profiles.ClientProfile; import pro.gravit.utils.launch.ClassLoaderControl; import pro.gravit.utils.launch.Launch; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessInitPhase.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessInitPhase.java similarity index 69% rename from LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessInitPhase.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessInitPhase.java index 613d696f..82a1c556 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessInitPhase.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessInitPhase.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events.client; +package pro.gravit.launcher.client.events; import pro.gravit.launcher.client.ClientParams; -import pro.gravit.launcher.modules.events.InitPhase; +import pro.gravit.launcher.base.modules.events.InitPhase; public class ClientProcessInitPhase extends InitPhase { public final ClientParams params; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessLaunchEvent.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessLaunchEvent.java similarity index 71% rename from LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessLaunchEvent.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessLaunchEvent.java index c43a9c5c..9646c6d5 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessLaunchEvent.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessLaunchEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events.client; +package pro.gravit.launcher.client.events; import pro.gravit.launcher.client.ClientParams; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; public class ClientProcessLaunchEvent extends LauncherModule.Event { public final ClientParams params; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessPreInvokeMainClassEvent.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessPreInvokeMainClassEvent.java similarity index 76% rename from LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessPreInvokeMainClassEvent.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessPreInvokeMainClassEvent.java index 731f2c84..ef32888d 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessPreInvokeMainClassEvent.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessPreInvokeMainClassEvent.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.client.events.client; +package pro.gravit.launcher.client.events; import pro.gravit.launcher.client.ClientParams; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.profiles.ClientProfile; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.profiles.ClientProfile; import java.util.Collection; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessReadyEvent.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessReadyEvent.java similarity index 69% rename from LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessReadyEvent.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessReadyEvent.java index 574814a6..9df4dfad 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessReadyEvent.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientProcessReadyEvent.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.client.events.client; +package pro.gravit.launcher.client.events; import pro.gravit.launcher.client.ClientParams; -import pro.gravit.launcher.modules.events.PostInitPhase; +import pro.gravit.launcher.base.modules.events.PostInitPhase; public class ClientProcessReadyEvent extends PostInitPhase { public final ClientParams params; diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java similarity index 84% rename from Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java index 2bf5ba5b..e73361fe 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/events/ClientUnlockConsoleEvent.java @@ -1,6 +1,6 @@ package pro.gravit.launcher.client.events; -import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launcher.base.modules.LauncherModule; import pro.gravit.utils.command.CommandHandler; public class ClientUnlockConsoleEvent extends LauncherModule.Event { diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/utils/ApiBridgeService.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/utils/ApiBridgeService.java similarity index 81% rename from LauncherClient/src/main/java/pro/gravit/launcher/utils/ApiBridgeService.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/utils/ApiBridgeService.java index 8e0dcab9..f4defa2d 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/utils/ApiBridgeService.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/utils/ApiBridgeService.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.utils; +package pro.gravit.launcher.client.utils; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherTrustManager; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.core.LauncherTrustManager; import java.security.cert.X509Certificate; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/utils/DirWatcher.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/utils/DirWatcher.java similarity index 93% rename from LauncherClient/src/main/java/pro/gravit/launcher/utils/DirWatcher.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/utils/DirWatcher.java index 1ee0949b..5184035a 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/utils/DirWatcher.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/utils/DirWatcher.java @@ -1,10 +1,10 @@ -package pro.gravit.launcher.utils; +package pro.gravit.launcher.client.utils; -import pro.gravit.launcher.ClientLauncherMethods; -import pro.gravit.launcher.hasher.FileNameMatcher; -import pro.gravit.launcher.hasher.HashedDir; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.hasher.HashedFile; +import pro.gravit.launcher.client.ClientLauncherMethods; +import pro.gravit.launcher.core.hasher.FileNameMatcher; +import pro.gravit.launcher.core.hasher.HashedDir; +import pro.gravit.launcher.core.hasher.HashedEntry; +import pro.gravit.launcher.core.hasher.HashedFile; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.JVMHelper.OS; diff --git a/LauncherClient/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java b/LauncherClient/src/main/java/pro/gravit/launcher/client/utils/NativeJVMHalt.java similarity index 95% rename from LauncherClient/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java rename to LauncherClient/src/main/java/pro/gravit/launcher/client/utils/NativeJVMHalt.java index 34eea24c..03fae4f3 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/utils/NativeJVMHalt.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/utils/NativeJVMHalt.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.utils; +package pro.gravit.launcher.client.utils; import pro.gravit.utils.helper.LogHelper; diff --git a/LauncherCore/build.gradle b/LauncherCore/build.gradle index 86420ba1..efd55c0a 100644 --- a/LauncherCore/build.gradle +++ b/LauncherCore/build.gradle @@ -1,5 +1,5 @@ -sourceCompatibility = '1.8' -targetCompatibility = '1.8' +sourceCompatibility = '17' +targetCompatibility = '17' dependencies { compileOnly group: 'org.fusesource.jansi', name: 'jansi', version: rootProject['verJansi'] @@ -21,28 +21,10 @@ events "passed", "skipped", "failed" } } -sourceSets { - java11 { - java { - srcDirs = ['src/main/java11'] - } - dependencies { - java11Implementation group: 'com.google.code.gson', name: 'gson', version: rootProject['verGson'] - java11Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava } - } - } -} jar { - into('META-INF/versions/11') { - from sourceSets.java11.output - } archiveClassifier.set('clean') manifest.attributes("Multi-Release": "true") } -compileJava11Java { - sourceCompatibility = 11 - targetCompatibility = 11 -} tasks.register('sourcesJar', Jar) { from sourceSets.main.allJava diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/CertificatePinningTrustManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/CertificatePinningTrustManager.java similarity index 98% rename from LauncherCore/src/main/java/pro/gravit/launcher/CertificatePinningTrustManager.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/CertificatePinningTrustManager.java index e60311eb..854c9422 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/CertificatePinningTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/CertificatePinningTrustManager.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.core; import pro.gravit.utils.helper.LogHelper; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherInject.java similarity index 89% rename from LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherInject.java index b76203ad..8d9d43ff 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInject.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherInject.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.core; import java.lang.annotation.Retention; import java.lang.annotation.Target; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInjectionConstructor.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherInjectionConstructor.java similarity index 89% rename from LauncherCore/src/main/java/pro/gravit/launcher/LauncherInjectionConstructor.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherInjectionConstructor.java index 9c2359df..27dc6dfe 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherInjectionConstructor.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherInjectionConstructor.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.core; import java.lang.annotation.Retention; import java.lang.annotation.Target; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherNetworkAPI.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherNetworkAPI.java similarity index 94% rename from LauncherCore/src/main/java/pro/gravit/launcher/LauncherNetworkAPI.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherNetworkAPI.java index 9c2fad06..b767adbd 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherNetworkAPI.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherNetworkAPI.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.core; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherTrustManager.java similarity index 99% rename from LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherTrustManager.java index 52a4f894..b5d0a268 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/LauncherTrustManager.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.core; import pro.gravit.utils.helper.LogHelper; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/FileNameMatcher.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/FileNameMatcher.java similarity index 97% rename from LauncherCore/src/main/java/pro/gravit/launcher/hasher/FileNameMatcher.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/FileNameMatcher.java index de19d4a9..c1698d0e 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/FileNameMatcher.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/FileNameMatcher.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.hasher; +package pro.gravit.launcher.core.hasher; import java.util.Collection; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedDir.java similarity index 95% rename from LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedDir.java index 71b28e17..343f7e80 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedDir.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedDir.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.hasher; +package pro.gravit.launcher.core.hasher; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.launcher.serialize.stream.EnumSerializer; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.core.serialize.HOutput; +import pro.gravit.launcher.core.serialize.stream.EnumSerializer; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.VerifyHelper; @@ -30,16 +30,10 @@ public HashedDir(HInput input) throws IOException { // Read entry HashedEntry entry; Type type = Type.read(input); - switch (type) { - case FILE: - entry = new HashedFile(input); - break; - case DIR: - entry = new HashedDir(input); - break; - default: - throw new AssertionError("Unsupported hashed entry type: " + type.name()); - } + entry = switch (type) { + case FILE -> new HashedFile(input); + case DIR -> new HashedDir(input); + }; // Try add entry to map VerifyHelper.putIfAbsent(map, name, entry, String.format("Duplicate dir entry: '%s'", name)); diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedEntry.java similarity index 72% rename from LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedEntry.java index d8e491c9..af21ce9f 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntry.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedEntry.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.hasher; +package pro.gravit.launcher.core.hasher; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.stream.EnumSerializer; -import pro.gravit.launcher.serialize.stream.StreamObject; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.core.serialize.stream.EnumSerializer; +import pro.gravit.launcher.core.serialize.stream.StreamObject; import java.io.IOException; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedEntryAdapter.java similarity index 96% rename from LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedEntryAdapter.java index bc70cd91..1c555492 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedEntryAdapter.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedEntryAdapter.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.hasher; +package pro.gravit.launcher.core.hasher; import com.google.gson.*; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedFile.java similarity index 92% rename from LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedFile.java index cc36bf50..f4712fa1 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/hasher/HashedFile.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/hasher/HashedFile.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.hasher; +package pro.gravit.launcher.core.hasher; -import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.launcher.core.LauncherNetworkAPI; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.core.serialize.HOutput; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.SecurityHelper; import pro.gravit.utils.helper.SecurityHelper.DigestAlgorithm; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GsonManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/managers/GsonManager.java similarity index 86% rename from LauncherCore/src/main/java/pro/gravit/launcher/managers/GsonManager.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/managers/GsonManager.java index 5b06d10b..76466a63 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/managers/GsonManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/managers/GsonManager.java @@ -1,9 +1,9 @@ -package pro.gravit.launcher.managers; +package pro.gravit.launcher.core.managers; import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import pro.gravit.launcher.hasher.HashedEntry; -import pro.gravit.launcher.hasher.HashedEntryAdapter; +import pro.gravit.launcher.core.hasher.HashedEntry; +import pro.gravit.launcher.core.hasher.HashedEntryAdapter; import pro.gravit.utils.helper.CommonHelper; public class GsonManager { diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HInput.java similarity index 92% rename from LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HInput.java index 8e456425..5b8161a7 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HInput.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HInput.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.serialize; +package pro.gravit.launcher.core.serialize; import pro.gravit.utils.helper.IOHelper; @@ -42,14 +42,11 @@ public BigInteger readBigInteger(int maxBytes) throws IOException { public boolean readBoolean() throws IOException { int b = readUnsignedByte(); - switch (b) { - case 0b0: - return false; - case 0b1: - return true; - default: - throw new IOException("Invalid boolean state: " + b); - } + return switch (b) { + case 0b0 -> false; + case 0b1 -> true; + default -> throw new IOException("Invalid boolean state: " + b); + }; } diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HOutput.java similarity index 98% rename from LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HOutput.java index 37ee3dc7..aa9f136e 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/HOutput.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/HOutput.java @@ -1,4 +1,4 @@ -package pro.gravit.launcher.serialize; +package pro.gravit.launcher.core.serialize; import pro.gravit.utils.helper.IOHelper; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/signed/DigestBytesHolder.java similarity index 86% rename from LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/signed/DigestBytesHolder.java index 34ae728f..b311ae29 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/signed/DigestBytesHolder.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/signed/DigestBytesHolder.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.serialize.signed; +package pro.gravit.launcher.core.serialize.signed; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.launcher.serialize.stream.StreamObject; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.core.serialize.HOutput; +import pro.gravit.launcher.core.serialize.stream.StreamObject; import pro.gravit.utils.helper.SecurityHelper; import java.io.IOException; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/stream/EnumSerializer.java similarity index 79% rename from LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/stream/EnumSerializer.java index e0bdf871..7c5a113d 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/EnumSerializer.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/stream/EnumSerializer.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher.serialize.stream; +package pro.gravit.launcher.core.serialize.stream; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; -import pro.gravit.launcher.serialize.stream.EnumSerializer.Itf; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.core.serialize.HOutput; +import pro.gravit.launcher.core.serialize.stream.EnumSerializer.Itf; import pro.gravit.utils.helper.VerifyHelper; import java.io.IOException; diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/stream/StreamObject.java similarity index 81% rename from LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java rename to LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/stream/StreamObject.java index c66c0741..d30bb14d 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/serialize/stream/StreamObject.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/core/serialize/stream/StreamObject.java @@ -1,7 +1,7 @@ -package pro.gravit.launcher.serialize.stream; +package pro.gravit.launcher.core.serialize.stream; -import pro.gravit.launcher.serialize.HInput; -import pro.gravit.launcher.serialize.HOutput; +import pro.gravit.launcher.core.serialize.HInput; +import pro.gravit.launcher.core.serialize.HOutput; import pro.gravit.utils.helper.IOHelper; import java.io.ByteArrayOutputStream; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java b/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java deleted file mode 100644 index 90b73309..00000000 --- a/LauncherCore/src/main/java/pro/gravit/utils/PublicURLClassLoader.java +++ /dev/null @@ -1,59 +0,0 @@ -package pro.gravit.utils; - -import java.net.URL; -import java.net.URLClassLoader; - -public class PublicURLClassLoader extends URLClassLoader { - - /** - * Constructs a new URLClassLoader for the specified URLs using the - * default delegation parent {@code ClassLoader}. The URLs will - * be searched in the order specified for classes and resources after - * first searching in the parent class loader. Any URL that ends with - * a '/' is assumed to refer to a directory. Otherwise, the URL is - * assumed to refer to a JAR file which will be downloaded and opened - * as needed. - * - *

If there is a security manager, this method first - * calls the security manager's {@code checkCreateClassLoader} method - * to ensure creation of a class loader is allowed. - * - * @param urls the URLs from which to load classes and resources - * @throws SecurityException if a security manager exists and its - * {@code checkCreateClassLoader} method doesn't allow - * creation of a class loader. - * @throws NullPointerException if {@code urls} is {@code null}. - */ - public PublicURLClassLoader(URL[] urls) { - super(urls); - } - - /** - * Constructs a new URLClassLoader for the given URLs. The URLs will be - * searched in the order specified for classes and resources after first - * searching in the specified parent class loader. Any {@code jar:} - * scheme URL is assumed to refer to a JAR file. Any {@code file:} scheme - * URL that ends with a '/' is assumed to refer to a directory. Otherwise, - * the URL is assumed to refer to a JAR file which will be downloaded and - * opened as needed. - * - *

If there is a security manager, this method first - * calls the security manager's {@code checkCreateClassLoader} method - * to ensure creation of a class loader is allowed. - * - * @param urls the URLs from which to load classes and resources - * @param parent the parent class loader for delegation - * @throws SecurityException if a security manager exists and its - * {@code checkCreateClassLoader} method doesn't allow - * creation of a class loader. - * @throws NullPointerException if {@code urls} is {@code null}. - */ - public PublicURLClassLoader(URL[] urls, ClassLoader parent) { - super(urls, parent); - } - - @Override - public void addURL(URL url) { - super.addURL(url); - } -} diff --git a/LauncherCore/src/main/java/pro/gravit/utils/Version.java b/LauncherCore/src/main/java/pro/gravit/utils/Version.java index 801c763c..5da954a4 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/Version.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/Version.java @@ -5,8 +5,8 @@ public final class Version implements Comparable { public static final int MAJOR = 5; - public static final int MINOR = 5; - public static final int PATCH = 4; + public static final int MINOR = 6; + public static final int PATCH = 0; public static final int BUILD = 1; public static final Version.Type RELEASE = Type.STABLE; public final int major; diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java index ccaeb8ea..a286c248 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/CommonHelper.java @@ -2,13 +2,11 @@ import com.google.gson.*; import pro.gravit.utils.command.CommandException; +import pro.gravit.utils.launch.LaunchOptions; import javax.script.ScriptEngine; import java.lang.reflect.Type; -import java.util.Base64; -import java.util.Collection; -import java.util.LinkedList; -import java.util.Locale; +import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -56,6 +54,21 @@ public static String replace(String source, String... params) { return source; } + public static String replace(Map replaceMap, String arg) { + for(var e : replaceMap.entrySet()) { + arg = arg.replace(e.getKey(), e.getValue()); + } + return arg; + } + + public static List replace(Map replaceMap, List args) { + List updatedList = new ArrayList<>(args.size()); + for(var e : args) { + updatedList.add(replace(replaceMap, e)); + } + return updatedList; + } + public static String[] parseCommand(CharSequence line) throws CommandException { boolean quoted = false; boolean wasQuoted = false; @@ -73,7 +86,7 @@ public static String[] parseCommand(CharSequence line) throws CommandException { throw new CommandException("Quotes wasn't closed"); // Empty args are ignored (except if was quoted) - if (wasQuoted || builder.length() > 0) + if (wasQuoted || !builder.isEmpty()) result.add(builder.toString()); // Reset file builder @@ -111,6 +124,148 @@ public static GsonBuilder newBuilder() { ByteArrayToBase64TypeAdapter.INSTANCE); } + + public static ArgsParseResult parseJavaArgs(List args) { + List classpath = new ArrayList<>(); + List jvmArgs = new ArrayList<>(); + List runArgs = new ArrayList<>(); + String jarFile = null; + String mainClass = null; + String mainModule = null; + LaunchOptions.ModuleConf conf = new LaunchOptions.ModuleConf(); + var prevArgType = PrevArgType.NONE; + boolean runArgsBoolean = false; + boolean first = false; + for(var arg : args) { + if(runArgsBoolean) { + runArgs.add(arg); + continue; + } + if(!first) { + if(!arg.startsWith("-")) { + continue; + } + first = true; + } + switch (prevArgType) { + case NONE -> { + + } + case MODULE_PATH -> { + char c = ':'; + int i = arg.indexOf(c); + if(i<0) { + c = ';'; + } + String[] l = arg.split(Character.toString(c)); + conf.modulePath.addAll(Arrays.asList(l)); + prevArgType = PrevArgType.NONE; + continue; + } + case CLASSPATH -> { + char c = ':'; + int i = arg.indexOf(c); + if(i<0) { + c = ';'; + } + String[] l = arg.split(Character.toString(c)); + classpath.addAll(Arrays.asList(l)); + prevArgType = PrevArgType.POST_CLASSPATH; + continue; + } + case ADD_MODULES -> { + String[] l = arg.split(","); + conf.modules.addAll(Arrays.asList(l)); + prevArgType = PrevArgType.NONE; + continue; + } + case ADD_OPENS -> { + String[] l = arg.split("="); + conf.opens.put(l[0], l[1]); + prevArgType = PrevArgType.NONE; + continue; + } + case ADD_EXPORTS -> { + String[] l = arg.split("="); + conf.exports.put(l[0], l[1]); + prevArgType = PrevArgType.NONE; + continue; + } + case ADD_READS -> { + String[] l = arg.split("="); + if(l.length != 2) { + continue; + } + conf.reads.put(l[0], l[1]); + prevArgType = PrevArgType.NONE; + continue; + } + case MODULE -> { + String[] l = arg.split("/"); + mainModule = l[0]; + mainClass = l[1]; + runArgsBoolean = true; + prevArgType = PrevArgType.NONE; + continue; + } + case POST_CLASSPATH -> { + mainClass = arg; + runArgsBoolean = true; + prevArgType = PrevArgType.NONE; + continue; + } + case JAR -> { + jarFile = arg; + runArgsBoolean = true; + prevArgType = PrevArgType.NONE; + continue; + } + } + if(arg.equals("--module-path") || arg.equals("-p")) { + prevArgType = PrevArgType.MODULE_PATH; + continue; + } + if(arg.equals("--classpath") || arg.equals("-cp")) { + prevArgType = PrevArgType.CLASSPATH; + continue; + } + if(arg.equals("--add-modules")) { + prevArgType = PrevArgType.ADD_MODULES; + continue; + } + if(arg.equals("--add-opens")) { + prevArgType = PrevArgType.ADD_OPENS; + continue; + } + if(arg.equals("--add-exports")) { + prevArgType = PrevArgType.ADD_EXPORTS; + continue; + } + if(arg.equals("--add-reads")) { + prevArgType = PrevArgType.ADD_READS; + continue; + } + if(arg.equals("--module") || arg.equals("-m")) { + prevArgType = PrevArgType.MODULE; + continue; + } + if(arg.equals("-jar")) { + prevArgType = PrevArgType.JAR; + continue; + } + jvmArgs.add(arg); + } + return new ArgsParseResult(conf, classpath, jvmArgs, mainClass, mainModule, jarFile, args); + } + + public record ArgsParseResult(LaunchOptions.ModuleConf conf, List classpath, List jvmArgs, String mainClass, String mainModule, String jarFile, List args) { + + } + + private enum PrevArgType { + NONE, MODULE_PATH, ADD_MODULES, ADD_OPENS, ADD_EXPORTS, ADD_READS, CLASSPATH, POST_CLASSPATH, JAR, MAINCLASS, MODULE; + } + private static class ByteArrayToBase64TypeAdapter implements JsonSerializer, JsonDeserializer { private static final ByteArrayToBase64TypeAdapter INSTANCE = new ByteArrayToBase64TypeAdapter(); private final Base64.Decoder decoder = Base64.getUrlDecoder(); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java index 9043f27d..a69e0f73 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java @@ -14,17 +14,12 @@ public class FormatHelper { public static Ansi rawAnsiFormat(LogHelper.Level level, String dateTime, boolean sub) { Ansi.Color levelColor; boolean bright = level != LogHelper.Level.DEBUG; - switch (level) { - case WARNING: - levelColor = Ansi.Color.YELLOW; - break; - case ERROR: - levelColor = Ansi.Color.RED; - break; - default: // INFO, DEBUG, Unknown - levelColor = Ansi.Color.WHITE; - break; - } + levelColor = switch (level) { + case WARNING -> Ansi.Color.YELLOW; + case ERROR -> Ansi.Color.RED; + default -> // INFO, DEBUG, Unknown + Ansi.Color.WHITE; + }; // Date-time Ansi ansi = new Ansi(); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java index 8be8d890..21acd3d4 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/HackHelper.java @@ -3,8 +3,6 @@ import java.lang.invoke.MethodHandles; import java.lang.reflect.Constructor; import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.function.Consumer; public class HackHelper { private static native MethodHandles.Lookup createHackLookupNative(Class lookupClass); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java index 4151dc98..1b9d17b0 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/IOHelper.java @@ -5,13 +5,18 @@ import java.awt.image.BufferedImage; import java.io.*; import java.net.*; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.nio.file.*; import java.nio.file.attribute.BasicFileAttributes; import java.util.Collections; +import java.util.HexFormat; import java.util.Set; +import java.util.jar.JarFile; +import java.util.jar.Manifest; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.zip.Deflater; @@ -82,10 +87,19 @@ public static void close(OutputStream out) { } } + public static Manifest getManifest(Class clazz) { + Path path = getCodeSource(clazz); + try(JarFile jar = new JarFile(path.toFile())) { + return jar.getManifest(); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + } + public static URL convertToURL(String url) { try { - return new URL(url); - } catch (MalformedURLException e) { + return new URI(url).toURL(); + } catch (MalformedURLException | URISyntaxException e) { throw new IllegalArgumentException("Invalid URL", e); } } @@ -138,17 +152,13 @@ public static String getIP(SocketAddress address) { } public static Path getRoot() { - switch (JVMHelper.OS_TYPE) { - case MUSTDIE: { + return switch (JVMHelper.OS_TYPE) { + case MUSTDIE -> { String drive = System.getenv("SystemDrive").concat("\\"); - return Paths.get(drive); + yield Paths.get(drive); } - case LINUX: - case MACOSX: { - return Paths.get("/"); - } - } - throw new UnsupportedOperationException(); + case LINUX, MACOSX -> Paths.get("/"); + }; } public static byte[] getResourceBytes(String name) throws IOException { @@ -545,19 +555,39 @@ public static void transfer(Path file, OutputStream output) throws IOException { } public static String urlDecode(String s) { - try { - return URLDecoder.decode(s, UNICODE_CHARSET.name()); - } catch (UnsupportedEncodingException e) { - throw new InternalError(e); - } + return URLDecoder.decode(s, UNICODE_CHARSET); } public static String urlEncode(String s) { - try { - return URLEncoder.encode(s, UNICODE_CHARSET.name()); - } catch (UnsupportedEncodingException e) { - throw new InternalError(e); + return URLEncoder.encode(s, UNICODE_CHARSET); + } + + public static String urlDecodeStrict(String s) { + var builder = new StringBuilder(); + char[] charArray = s.toCharArray(); + for (int i = 0; i < charArray.length; i++) { + char c = charArray[i]; + if (c != '%') { + builder.append(c); + continue; + } + + if (i + 2 >= charArray.length) { + return null; + } + + var buffer = UNICODE_CHARSET.decode(ByteBuffer.wrap(HexFormat.of().parseHex(CharBuffer.wrap(charArray, i + 1, 2)))); + + builder.append(buffer); + + i += 2; } + + return builder.toString(); + } + + public static String getPathFromUrlFragment(String urlFragment) { + return urlFragment.indexOf('?') < 0 ? urlFragment : urlFragment.substring(0, urlFragment.indexOf('?')); } public static String verifyFileName(String fileName) { @@ -577,9 +607,9 @@ public static BufferedImage verifyTexture(BufferedImage skin, boolean cloak) { public static String verifyURL(String url) { try { - new URL(url).toURI(); + new URI(url); return url; - } catch (MalformedURLException | URISyntaxException e) { + } catch (URISyntaxException e) { throw new IllegalArgumentException("Invalid URL", e); } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java index bc029287..bf5ecbdf 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JVMHelper.java @@ -1,17 +1,12 @@ package pro.gravit.utils.helper; -import java.io.File; import java.lang.invoke.MethodHandles; import java.lang.management.ManagementFactory; import java.lang.management.OperatingSystemMXBean; import java.lang.management.RuntimeMXBean; -import java.net.MalformedURLException; -import java.net.URL; import java.security.cert.X509Certificate; import java.util.Arrays; -import java.util.Collection; import java.util.Locale; -import java.util.Map; public final class JVMHelper { @@ -53,72 +48,27 @@ public static ARCH getArch(String arch) { } public static int getVersion() { - String version = System.getProperty("java.version"); - if (version.startsWith("1.")) { - version = version.substring(2, 3); - } else { - int dot = version.indexOf("."); - if (dot != -1) { - version = version.substring(0, dot); - } - } - return Integer.parseInt(version); + //System.out.println("[DEBUG] JVMHelper 11 version"); + return Runtime.version().feature(); } public static int getBuild() { - String version = System.getProperty("java.version"); - int dot; - if (version.startsWith("1.")) { - dot = version.indexOf("_"); - } else { - dot = version.lastIndexOf("."); - } - if (dot != -1) { - version = version.substring(dot + 1); - } - try { - return Integer.parseInt(version); - } catch (NumberFormatException exception) { - return 0; - } - + return Runtime.version().update(); } public static String getNativeExtension(JVMHelper.OS OS_TYPE) { - switch (OS_TYPE) { - case MUSTDIE: - return ".dll"; - case LINUX: - return ".so"; - case MACOSX: - return ".dylib"; - default: - throw new InternalError(String.format("Unsupported OS TYPE '%s'", OS_TYPE)); - } + return switch (OS_TYPE) { + case MUSTDIE -> ".dll"; + case LINUX -> ".so"; + case MACOSX -> ".dylib"; + }; } public static String getNativePrefix(JVMHelper.OS OS_TYPE) { - switch (OS_TYPE) { - case LINUX: - case MACOSX: - return "lib"; - default: - return ""; - } - } - - public static void appendVars(ProcessBuilder builder, Map vars) { - builder.environment().putAll(vars); - } - - public static Class firstClass(String... names) throws ClassNotFoundException { - for (String name : names) - try { - return Class.forName(name, false, LOADER); - } catch (ClassNotFoundException ignored) { - // Expected - } - throw new ClassNotFoundException(Arrays.toString(names)); + return switch (OS_TYPE) { + case LINUX, MACOSX -> "lib"; + default -> ""; + }; } public static void fullGC() { @@ -126,26 +76,6 @@ public static void fullGC() { LogHelper.debug("Used heap: %d MiB", RUNTIME.totalMemory() - RUNTIME.freeMemory() >> 20); } - public static String[] getClassPath() { - return System.getProperty("java.class.path").split(File.pathSeparator); - } - - public static URL[] getClassPathURL() { - String[] cp = System.getProperty("java.class.path").split(File.pathSeparator); - URL[] list = new URL[cp.length]; - - for (int i = 0; i < cp.length; i++) { - URL url = null; - try { - url = new URL(cp[i]); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - list[i] = url; - } - return list; - } - public static X509Certificate[] getCertificates(Class clazz) { Object[] signers = clazz.getSigners(); if (signers == null) return null; @@ -170,10 +100,6 @@ private static int getCorrectOSArch() { return System.getProperty("os.arch").contains("64") ? 64 : 32; } - public static String getEnvPropertyCaseSensitive(String name) { - return System.getenv().get(name); - } - public static boolean isJVMMatchesSystemArch() { return JVM_BITS == OS_BITS; } @@ -182,16 +108,6 @@ public static String jvmProperty(String name, String value) { return String.format("-D%s=%s", name, value); } - public static String systemToJvmProperty(String name) { - return String.format("-D%s=%s", name, System.getProperties().getProperty(name)); - } - - public static void addSystemPropertyToArgs(Collection args, String name) { - String property = System.getProperty(name); - if (property != null) - args.add(String.format("-D%s=%s", name, property)); - } - public static void verifySystemProperties(Class mainClass, boolean requireSystem) { Locale.setDefault(Locale.US); // Verify class loader diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java index 96c54a79..e73cec59 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/JavaHelper.java @@ -13,15 +13,7 @@ public class JavaHelper { public static final List javaFxModules; static { - List modules = new ArrayList<>(); - modules.add("javafx.base"); - modules.add("javafx.graphics"); - modules.add("javafx.fxml"); - modules.add("javafx.controls"); - modules.add("javafx.swing"); - modules.add("javafx.media"); - modules.add("javafx.web"); - javaFxModules = Collections.unmodifiableList(modules); + javaFxModules = List.of("javafx.base", "javafx.graphics", "javafx.fxml", "javafx.controls", "javafx.swing", "javafx.media", "javafx.web"); } public static Path tryGetOpenJFXPath(Path jvmDir) { @@ -60,7 +52,7 @@ public static boolean tryAddModule(List paths, String moduleName, StringBu if (path == null) continue; Path result = tryFindModule(path, moduleName); if (result != null) { - if (args.length() != 0) args.append(File.pathSeparatorChar); + if (!args.isEmpty()) args.append(File.pathSeparatorChar); args.append(result.toAbsolutePath()); return true; } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java index d63fa7f6..92e9b182 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/LogHelper.java @@ -1,6 +1,6 @@ package pro.gravit.utils.helper; -import pro.gravit.launcher.LauncherNetworkAPI; +import pro.gravit.launcher.core.LauncherNetworkAPI; import pro.gravit.utils.logging.LogHelperAppender; import pro.gravit.utils.logging.SimpleLogHelperImpl; import pro.gravit.utils.logging.Slf4jLogHelperImpl; @@ -23,7 +23,7 @@ public final class LogHelper { public static final String DEV_PROPERTY = "launcher.dev"; public static final String STACKTRACE_PROPERTY = "launcher.stacktrace"; public static final String NO_JANSI_PROPERTY = "launcher.noJAnsi"; - public static final String NO_SLF4J_PROPERTY = "launcher.noSlf4j"; + public static final String SLF4J_PROPERTY = "launcher.useSlf4j"; private static final Set> EXCEPTIONS_CALLBACKS = Collections.newSetFromMap(new ConcurrentHashMap<>(2)); private static final LogHelperAppender impl; @@ -31,8 +31,7 @@ public final class LogHelper { boolean useSlf4j = false; try { Class.forName("org.slf4j.Logger", false, LogHelper.class.getClassLoader()); - Class.forName("org.slf4j.impl.StaticLoggerBinder", false, LogHelper.class.getClassLoader()); - useSlf4j = !Boolean.getBoolean(NO_SLF4J_PROPERTY); + useSlf4j = Boolean.getBoolean(SLF4J_PROPERTY); } catch (ClassNotFoundException ignored) { } if (useSlf4j) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java index f21eb4fc..9a959230 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/SecurityHelper.java @@ -33,20 +33,15 @@ public final class SecurityHelper { public static final String RSA_ALGO = "RSA"; public static final String RSA_SIGN_ALGO = "SHA256withRSA"; public static final String RSA_CIPHER_ALGO = "RSA/ECB/PKCS1Padding"; + public static final String AES_CIPHER_ALGO = "AES/ECB/PKCS5Padding"; // Algorithm size constants - public static final int AES_KEY_LENGTH = 8; + public static final int AES_KEY_LENGTH = 16; public static final int TOKEN_STRING_LENGTH = TOKEN_LENGTH << 1; public static final int RSA_KEY_LENGTH_BITS = 2048; public static final int RSA_KEY_LENGTH = RSA_KEY_LENGTH_BITS / Byte.SIZE; public static final int CRYPTO_MAX_LENGTH = 2048; public static final String HEX = "0123456789abcdef"; - // Certificate constants - public static final byte[] NUMBERS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; - public static final SecureRandom secureRandom = new SecureRandom(); - // Random generator constants - private static final char[] VOWELS = {'e', 'u', 'i', 'o', 'a'}; - private static final char[] CONS = {'r', 't', 'p', 's', 'd', 'f', 'g', 'h', 'k', 'l', 'c', 'v', 'b', 'n', 'm'}; private SecurityHelper() { } @@ -189,6 +184,16 @@ private static Cipher newRSACipher(int mode, RSAKey key) { return cipher; } + private static Cipher newAESCipher(int mode, byte[] key) { + Cipher cipher = newCipher(AES_CIPHER_ALGO); + try { + cipher.init(mode, new SecretKeySpec(key, "AES")); + } catch (InvalidKeyException e) { + throw new InternalError(e); + } + return cipher; + } + private static KeyFactory newECDSAKeyFactory() { try { return KeyFactory.getInstance(EC_ALGO); @@ -313,70 +318,6 @@ public static byte[] randomAESKey(Random random) { return randomBytes(random, AES_KEY_LENGTH); } - - public static String randomUsername() { - return randomUsername(newRandom()); - } - - - public static String randomUsername(Random random) { - int usernameLength = 3 + random.nextInt(7); // 3-9 - - // Choose prefix - String prefix; - int prefixType = random.nextInt(7); - if (usernameLength >= 5 && prefixType == 6) { // (6) 2-char - prefix = random.nextBoolean() ? "Mr" : "Dr"; - usernameLength -= 2; - } else if (usernameLength >= 6 && prefixType == 5) { // (5) 3-char - prefix = "Mrs"; - usernameLength -= 3; - } else - prefix = ""; - - // Choose suffix - String suffix; - int suffixType = random.nextInt(7); // 0-6, 7 values - if (usernameLength >= 5 && suffixType == 6) { // (6) 10-99 - suffix = String.valueOf(10 + random.nextInt(90)); - usernameLength -= 2; - } else if (usernameLength >= 7 && suffixType == 5) { // (5) 1990-2015 - suffix = String.valueOf(1990 + random.nextInt(26)); - usernameLength -= 4; - } else - suffix = ""; - - // Choose name - int consRepeat = 0; - boolean consPrev = random.nextBoolean(); - char[] chars = new char[usernameLength]; - for (int i = 0; i < chars.length; i++) { - if (i > 1 && consPrev && random.nextInt(10) == 0) { // Doubled - chars[i] = chars[i - 1]; - continue; - } - - // Choose next char - if (consRepeat < 1 && random.nextInt() == 5) - consRepeat++; - else { - consRepeat = 0; - consPrev ^= true; - } - - // Choose char - char[] alphabet = consPrev ? CONS : VOWELS; - chars[i] = alphabet[random.nextInt(alphabet.length)]; - } - - // Make first letter uppercase - if (!prefix.isEmpty() || random.nextBoolean()) - chars[0] = Character.toUpperCase(chars[0]); - - // Return chosen name (and verify for sure) - return VerifyHelper.verifyUsername(prefix + new String(chars) + suffix); - } - public static byte[] sign(byte[] bytes, ECPrivateKey privateKey) { Signature signature = newECSignSignature(privateKey); try { @@ -484,6 +425,22 @@ public static Cipher newRSAEncryptCipher(RSAPublicKey publicKey) { } } + public static Cipher newAESDecryptCipher(byte[] key) { + try { + return newAESCipher(Cipher.DECRYPT_MODE, key); + } catch (SecurityException e) { + throw new InternalError(e); + } + } + + public static Cipher newAESEncryptCipher(byte[] key) { + try { + return newAESCipher(Cipher.ENCRYPT_MODE, key); + } catch (SecurityException e) { + throw new InternalError(e); + } + } + //AES public static byte[] encrypt(String seed, byte[] cleartext) throws Exception { byte[] rawKey = getAESKey(IOHelper.encode(seed)); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/helper/UnpackHelper.java b/LauncherCore/src/main/java/pro/gravit/utils/helper/UnpackHelper.java index b967fb03..5ba58433 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/UnpackHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/UnpackHelper.java @@ -61,7 +61,7 @@ public static void unpackZipNoCheck(String resource, Path target) throws IOExcep IOHelper.transfer(input, target.resolve(IOHelper.toPath(entry.getName()))); } } - } catch (NoSuchFileException e) { + } catch (NoSuchFileException ignored) { } } } diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/BasicLaunch.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/BasicLaunch.java index 1cb326a4..b4865b8d 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/BasicLaunch.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/BasicLaunch.java @@ -56,6 +56,11 @@ public void addLauncherPackage(String prefix) { throw new UnsupportedOperationException(); } + @Override + public void clearLauncherPackages() { + throw new UnsupportedOperationException(); + } + @Override public void addTransformer(ClassTransformer transformer) { if (instrumentation == null) { diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/ClassLoaderControl.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/ClassLoaderControl.java index 08e44065..8d2cfd98 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/ClassLoaderControl.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/ClassLoaderControl.java @@ -7,6 +7,7 @@ public interface ClassLoaderControl { void addLauncherPackage(String prefix); + void clearLauncherPackages(); void addTransformer(ClassTransformer transformer); void addURL(URL url); void addJar(Path path); diff --git a/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java index fa95d0d8..ddabd56c 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/LaunchOptions.java @@ -1,9 +1,6 @@ package pro.gravit.utils.launch; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; public class LaunchOptions { public boolean enableHacks; 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 08f65795..1a155fe4 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/LegacyLaunch.java @@ -126,6 +126,10 @@ public void addAllowedPackage(String pkg) { packages.add(pkg); } + public void clearAllowedPackages() { + packages.clear(); + } + private LegacyClassLoaderControl makeControl() { return new LegacyClassLoaderControl(); } @@ -137,6 +141,11 @@ public void addLauncherPackage(String prefix) { addAllowedPackage(prefix); } + @Override + public void clearLauncherPackages() { + clearAllowedPackages(); + } + @Override public void addTransformer(ClassTransformer transformer) { transformers.add(transformer); diff --git a/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleHacks.java b/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleHacks.java similarity index 100% rename from LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleHacks.java rename to LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleHacks.java 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 0301ad02..5a414ea8 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/launch/ModuleLaunch.java @@ -1,17 +1,332 @@ package pro.gravit.utils.launch; +import pro.gravit.utils.helper.HackHelper; +import pro.gravit.utils.helper.IOHelper; +import pro.gravit.utils.helper.JVMHelper; +import pro.gravit.utils.helper.LogHelper; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.module.Configuration; +import java.lang.module.ModuleFinder; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.Path; -import java.util.Collection; -import java.util.List; +import java.nio.file.Paths; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; public class ModuleLaunch implements Launch { + private ModuleClassLoader moduleClassLoader; + private Configuration configuration; + private ModuleLayer.Controller controller; + private ModuleFinder moduleFinder; + private ModuleLayer layer; + private MethodHandles.Lookup hackLookup; + private boolean disablePackageDelegateSupport; @Override public ClassLoaderControl init(List files, String nativePath, LaunchOptions options) { - throw new UnsupportedOperationException("Please use Multi-Release JAR"); + this.disablePackageDelegateSupport = options.disablePackageDelegateSupport; + moduleClassLoader = new ModuleClassLoader(files.stream().map((e) -> { + try { + return e.toUri().toURL(); + } catch (MalformedURLException ex) { + throw new RuntimeException(ex); + } + }).toArray(URL[]::new), ClassLoader.getPlatformClassLoader()); + moduleClassLoader.nativePath = nativePath; + { + if(options.enableHacks) { + hackLookup = HackHelper.createHackLookup(ModuleLaunch.class); + } + if(options.moduleConf != null) { + // Create Module Layer + moduleFinder = ModuleFinder.of(options.moduleConf.modulePath.stream().map(Paths::get).map(Path::toAbsolutePath).toArray(Path[]::new)); + ModuleLayer bootLayer = ModuleLayer.boot(); + if(options.moduleConf.modules.contains("ALL-MODULE-PATH")) { + var set = moduleFinder.findAll(); + if(LogHelper.isDevEnabled()) { + for(var m : set) { + LogHelper.dev("Found module %s in %s", m.descriptor().name(), m.location().map(URI::toString).orElse("unknown")); + } + LogHelper.dev("Found %d modules", set.size()); + } + for(var m : set) { + options.moduleConf.modules.add(m.descriptor().name()); + } + options.moduleConf.modules.remove("ALL-MODULE-PATH"); + } + configuration = bootLayer.configuration() + .resolveAndBind(moduleFinder, ModuleFinder.of(), options.moduleConf.modules); + controller = ModuleLayer.defineModulesWithOneLoader(configuration, List.of(bootLayer), moduleClassLoader); + layer = controller.layer(); + // Configure exports / opens + for(var e : options.moduleConf.exports.entrySet()) { + String[] split = e.getKey().split("/"); + String moduleName = split[0]; + String pkg = split[1]; + LogHelper.dev("Export module: %s package: %s to %s", moduleName, pkg, e.getValue()); + Module source = layer.findModule(split[0]).orElse(null); + if(source == null) { + throw new RuntimeException(String.format("Module %s not found", moduleName)); + } + Module target = layer.findModule(e.getValue()).orElse(null); + if(target == null) { + throw new RuntimeException(String.format("Module %s not found", e.getValue())); + } + if(options.enableHacks && source.getLayer() != layer) { + ModuleHacks.createController(hackLookup, source.getLayer()).addExports(source, pkg, target); + } else { + controller.addExports(source, pkg, target); + } + } + for(var e : options.moduleConf.opens.entrySet()) { + String[] split = e.getKey().split("/"); + String moduleName = split[0]; + String pkg = split[1]; + LogHelper.dev("Open module: %s package: %s to %s", moduleName, pkg, e.getValue()); + Module source = layer.findModule(split[0]).orElse(null); + if(source == null) { + throw new RuntimeException(String.format("Module %s not found", moduleName)); + } + Module target = layer.findModule(e.getValue()).orElse(null); + if(target == null) { + throw new RuntimeException(String.format("Module %s not found", e.getValue())); + } + if(options.enableHacks && source.getLayer() != layer) { + ModuleHacks.createController(hackLookup, source.getLayer()).addOpens(source, pkg, target); + } else { + controller.addOpens(source, pkg, target); + } + } + for(var e : options.moduleConf.reads.entrySet()) { + LogHelper.dev("Read module %s to %s", e.getKey(), e.getValue()); + Module source = layer.findModule(e.getKey()).orElse(null); + if(source == null) { + throw new RuntimeException(String.format("Module %s not found", e.getKey())); + } + Module target = layer.findModule(e.getValue()).orElse(null); + if(target == null) { + throw new RuntimeException(String.format("Module %s not found", e.getValue())); + } + if(options.enableHacks && source.getLayer() != layer) { + ModuleHacks.createController(hackLookup, source.getLayer()).addReads(source, target); + } else { + controller.addReads(source, target); + } + } + moduleClassLoader.initializeWithLayer(layer); + } + } + return moduleClassLoader.makeControl(); } @Override - public void launch(String mainClass, String mainModule, Collection args) throws Throwable { - throw new UnsupportedOperationException("Please use Multi-Release JAR"); + public void launch(String mainClass, String mainModuleName, Collection args) throws Throwable { + Thread.currentThread().setContextClassLoader(moduleClassLoader); + if(mainModuleName == null) { + Class mainClazz = Class.forName(mainClass, true, moduleClassLoader); + MethodHandle mainMethod = MethodHandles.lookup().findStatic(mainClazz, "main", MethodType.methodType(void.class, String[].class)).asFixedArity(); + JVMHelper.fullGC(); + mainMethod.asFixedArity().invokeWithArguments((Object) args.toArray(new String[0])); + return; + } + Module mainModule = layer.findModule(mainModuleName).orElseThrow(); + Module unnamed = ModuleLaunch.class.getClassLoader().getUnnamedModule(); + if(unnamed != null) { + controller.addOpens(mainModule, getPackageFromClass(mainClass), unnamed); + } + // Start main class + ClassLoader loader = mainModule.getClassLoader(); + Class mainClazz = Class.forName(mainClass, true, loader); + MethodHandle mainMethod = MethodHandles.lookup().findStatic(mainClazz, "main", MethodType.methodType(void.class, String[].class)); + mainMethod.asFixedArity().invokeWithArguments((Object) args.toArray(new String[0])); + } + + private static String getPackageFromClass(String clazz) { + int index = clazz.lastIndexOf("."); + if(index >= 0) { + return clazz.substring(0, index); + } + return clazz; + } + + private class ModuleClassLoader extends URLClassLoader { + private final ClassLoader SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader(); + private final List transformers = new ArrayList<>(); + private final Map> classMap = new ConcurrentHashMap<>(); + private final Map packageToModule = new HashMap<>(); + private String nativePath; + + private final List packages = new ArrayList<>(); + public ModuleClassLoader(URL[] urls, ClassLoader parent) { + super("LAUNCHER", urls, parent); + packages.add("pro.gravit.launcher."); + packages.add("pro.gravit.utils."); + } + + private void initializeWithLayer(ModuleLayer layer) { + for(var m : layer.modules()) { + for(var p : m.getPackages()) { + packageToModule.put(p, m); + } + } + } + + @Override + protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { + if(name != null && !disablePackageDelegateSupport) { + for(String pkg : packages) { + if(name.startsWith(pkg)) { + return SYSTEM_CLASS_LOADER.loadClass(name); + } + } + } + return super.loadClass(name, resolve); + } + + @Override + protected Class findClass(String name) throws ClassNotFoundException { + var clazz = findClass(null, name); + if(clazz == null) { + throw new ClassNotFoundException(name); + } + return clazz; + } + + @Override + protected Class findClass(String moduleName, String name) { + Class clazz; + { + clazz = classMap.get(name); + if(clazz != null) { + return clazz; + } + } + if(name != null && !transformers.isEmpty()) { + boolean needTransform = false; + for(ClassLoaderControl.ClassTransformer t : transformers) { + if(t.filter(moduleName, name)) { + needTransform = true; + break; + } + } + if(needTransform) { + String rawClassName = name.replace(".", "/").concat(".class"); + try(InputStream input = getResourceAsStream(rawClassName)) { + byte[] bytes = IOHelper.read(input); + for(ClassLoaderControl.ClassTransformer t : transformers) { + bytes = t.transform(moduleName, name, null, bytes); + } + clazz = defineClass(name, bytes, 0, bytes.length); + } catch (IOException e) { + return null; + } + } + } + if(clazz == null && layer != null && name != null) { + var pkg = getPackageFromClass(name); + var module = packageToModule.get(pkg); + if(module != null) { + try { + clazz = module.getClassLoader().loadClass(name); + } catch (ClassNotFoundException e) { + return null; + } + } + } + if(clazz == null) { + try { + clazz = super.findClass(name); + } catch (ClassNotFoundException e) { + return null; + } + } + if(clazz != null) { + classMap.put(name, clazz); + return clazz; + } else { + return null; + } + } + + @Override + public String findLibrary(String name) { + return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(JVMHelper.NATIVE_PREFIX).concat(name).concat(JVMHelper.NATIVE_EXTENSION); + } + + public void addAllowedPackage(String pkg) { + packages.add(pkg); + } + + public void clearAllowedPackages() { + packages.clear(); + } + + private ModuleClassLoaderControl makeControl() { + return new ModuleClassLoaderControl(); + } + + private class ModuleClassLoaderControl implements ClassLoaderControl { + + @Override + public void addLauncherPackage(String prefix) { + addAllowedPackage(prefix); + } + + @Override + public void clearLauncherPackages() { + clearAllowedPackages(); + } + + @Override + public void addTransformer(ClassTransformer transformer) { + transformers.add(transformer); + } + + @Override + public void addURL(URL url) { + ModuleClassLoader.this.addURL(url); + } + + @Override + public void addJar(Path path) { + try { + ModuleClassLoader.this.addURL(path.toUri().toURL()); + } catch (MalformedURLException e) { + throw new RuntimeException(e); + } + } + + @Override + public URL[] getURLs() { + return ModuleClassLoader.this.getURLs(); + } + + @Override + public Class getClass(String name) throws ClassNotFoundException { + return Class.forName(name, false, ModuleClassLoader.this); + } + + @Override + public ClassLoader getClassLoader() { + return ModuleClassLoader.this; + } + + @Override + public Object getJava9ModuleController() { + return controller; + } + + @Override + public MethodHandles.Lookup getHackLookup() { + return hackLookup; + } + } } } diff --git a/LauncherCore/src/main/java11/pro/gravit/utils/helper/JVMHelper.java b/LauncherCore/src/main/java11/pro/gravit/utils/helper/JVMHelper.java deleted file mode 100644 index d2779207..00000000 --- a/LauncherCore/src/main/java11/pro/gravit/utils/helper/JVMHelper.java +++ /dev/null @@ -1,213 +0,0 @@ -package pro.gravit.utils.helper; - -import java.io.File; -import java.lang.invoke.MethodHandles; -import java.lang.management.ManagementFactory; -import java.lang.management.OperatingSystemMXBean; -import java.lang.management.RuntimeMXBean; -import java.net.MalformedURLException; -import java.net.URL; -import java.security.cert.X509Certificate; -import java.util.Arrays; -import java.util.Collection; -import java.util.Locale; -import java.util.Map; - -public final class JVMHelper { - - // MXBeans exports - public static final RuntimeMXBean RUNTIME_MXBEAN = ManagementFactory.getRuntimeMXBean(); - public static final OperatingSystemMXBean OPERATING_SYSTEM_MXBEAN = - ManagementFactory.getOperatingSystemMXBean(); - public static final OS OS_TYPE = OS.byName(OPERATING_SYSTEM_MXBEAN.getName()); - public static final int OS_BITS = getCorrectOSArch(); - // System properties - public static final String OS_VERSION = OPERATING_SYSTEM_MXBEAN.getVersion(); - public static final ARCH ARCH_TYPE = getArch(System.getProperty("os.arch")); - public static final String NATIVE_EXTENSION = getNativeExtension(OS_TYPE); - public static final String NATIVE_PREFIX = getNativePrefix(OS_TYPE); - public static final int JVM_BITS = Integer.parseInt(System.getProperty("sun.arch.data.model")); - // Public static fields - public static final Runtime RUNTIME = Runtime.getRuntime(); - public static final ClassLoader LOADER = ClassLoader.getSystemClassLoader(); - public static final int JVM_VERSION = getVersion(); - public static final int JVM_BUILD = getBuild(); - - static { - try { - MethodHandles.publicLookup(); // Just to initialize class - } catch (Throwable exc) { - throw new InternalError(exc); - } - } - - private JVMHelper() { - } - - public static ARCH getArch(String arch) { - if (arch.equals("amd64") || arch.equals("x86-64") || arch.equals("x86_64")) return ARCH.X86_64; - if (arch.equals("i386") || arch.equals("i686") || arch.equals("x86")) return ARCH.X86; - if (arch.startsWith("armv8") || arch.startsWith("aarch64")) return ARCH.ARM64; - if (arch.startsWith("arm") || arch.startsWith("aarch32")) return ARCH.ARM32; - throw new InternalError(String.format("Unsupported arch '%s'", arch)); - } - - public static int getVersion() { - //System.out.println("[DEBUG] JVMHelper 11 version"); - return Runtime.version().feature(); - } - - public static int getBuild() { - return Runtime.version().update(); - } - - public static String getNativeExtension(JVMHelper.OS OS_TYPE) { - switch (OS_TYPE) { - case MUSTDIE: - return ".dll"; - case LINUX: - return ".so"; - case MACOSX: - return ".dylib"; - default: - throw new InternalError(String.format("Unsupported OS TYPE '%s'", OS_TYPE)); - } - } - - public static String getNativePrefix(JVMHelper.OS OS_TYPE) { - switch (OS_TYPE) { - case LINUX: - case MACOSX: - return "lib"; - default: - return ""; - } - } - - public static void appendVars(ProcessBuilder builder, Map vars) { - builder.environment().putAll(vars); - } - - public static Class firstClass(String... names) throws ClassNotFoundException { - for (String name : names) - try { - return Class.forName(name, false, LOADER); - } catch (ClassNotFoundException ignored) { - // Expected - } - throw new ClassNotFoundException(Arrays.toString(names)); - } - - public static void fullGC() { - RUNTIME.gc(); - LogHelper.debug("Used heap: %d MiB", RUNTIME.totalMemory() - RUNTIME.freeMemory() >> 20); - } - - public static String[] getClassPath() { - return System.getProperty("java.class.path").split(File.pathSeparator); - } - - public static URL[] getClassPathURL() { - String[] cp = System.getProperty("java.class.path").split(File.pathSeparator); - URL[] list = new URL[cp.length]; - - for (int i = 0; i < cp.length; i++) { - URL url = null; - try { - url = new URL(cp[i]); - } catch (MalformedURLException e) { - e.printStackTrace(); - } - list[i] = url; - } - return list; - } - - public static X509Certificate[] getCertificates(Class clazz) { - Object[] signers = clazz.getSigners(); - if (signers == null) return null; - return Arrays.stream(signers).filter((c) -> c instanceof X509Certificate).map((c) -> (X509Certificate) c).toArray(X509Certificate[]::new); - } - - public static void checkStackTrace(Class mainClass) { - LogHelper.debug("Testing stacktrace"); - Exception e = new Exception("Testing stacktrace"); - StackTraceElement[] list = e.getStackTrace(); - if (!list[list.length - 1].getClassName().equals(mainClass.getName())) { - throw new SecurityException(String.format("Invalid StackTraceElement: %s", list[list.length - 1].getClassName())); - } - } - - private static int getCorrectOSArch() { - // As always, mustdie must die - if (OS_TYPE == OS.MUSTDIE) - return System.getenv("ProgramFiles(x86)") == null ? 32 : 64; - - // Or trust system property (maybe incorrect) - return System.getProperty("os.arch").contains("64") ? 64 : 32; - } - - public static String getEnvPropertyCaseSensitive(String name) { - return System.getenv().get(name); - } - - public static boolean isJVMMatchesSystemArch() { - return JVM_BITS == OS_BITS; - } - - public static String jvmProperty(String name, String value) { - return String.format("-D%s=%s", name, value); - } - - public static String systemToJvmProperty(String name) { - return String.format("-D%s=%s", name, System.getProperties().getProperty(name)); - } - - public static void addSystemPropertyToArgs(Collection args, String name) { - String property = System.getProperty(name); - if (property != null) - args.add(String.format("-D%s=%s", name, property)); - } - - public static void verifySystemProperties(Class mainClass, boolean requireSystem) { - Locale.setDefault(Locale.US); - // Verify class loader - LogHelper.debug("Verifying class loader"); - if (requireSystem && !mainClass.getClassLoader().equals(LOADER)) - throw new SecurityException("ClassLoader should be system"); - - // Verify system and java architecture - LogHelper.debug("Verifying JVM architecture"); - } - - public enum ARCH { - X86("x86"), X86_64("x86-64"), ARM64("arm64"), ARM32("arm32"); - - public final String name; - - ARCH(String name) { - this.name = name; - } - } - - public enum OS { - MUSTDIE("mustdie"), LINUX("linux"), MACOSX("macosx"); - - public final String name; - - OS(String name) { - this.name = name; - } - - public static OS byName(String name) { - if (name.startsWith("Windows")) - return MUSTDIE; - if (name.startsWith("Linux")) - return LINUX; - if (name.startsWith("Mac OS X")) - return MACOSX; - throw new RuntimeException(String.format("This shit is not yet supported: '%s'", name)); - } - } - -} diff --git a/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java b/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java deleted file mode 100644 index ab4d829d..00000000 --- a/LauncherCore/src/main/java11/pro/gravit/utils/launch/ModuleLaunch.java +++ /dev/null @@ -1,323 +0,0 @@ -package pro.gravit.utils.launch; - -import pro.gravit.utils.helper.HackHelper; -import pro.gravit.utils.helper.IOHelper; -import pro.gravit.utils.helper.JVMHelper; -import pro.gravit.utils.helper.LogHelper; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.module.Configuration; -import java.lang.module.ModuleFinder; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.net.URLClassLoader; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; - -public class ModuleLaunch implements Launch { - private ModuleClassLoader moduleClassLoader; - private Configuration configuration; - private ModuleLayer.Controller controller; - private ModuleFinder moduleFinder; - private ModuleLayer layer; - private MethodHandles.Lookup hackLookup; - private boolean disablePackageDelegateSupport; - @Override - public ClassLoaderControl init(List files, String nativePath, LaunchOptions options) { - this.disablePackageDelegateSupport = options.disablePackageDelegateSupport; - moduleClassLoader = new ModuleClassLoader(files.stream().map((e) -> { - try { - return e.toUri().toURL(); - } catch (MalformedURLException ex) { - throw new RuntimeException(ex); - } - }).toArray(URL[]::new), ClassLoader.getPlatformClassLoader()); - moduleClassLoader.nativePath = nativePath; - { - if(options.enableHacks) { - hackLookup = HackHelper.createHackLookup(ModuleLaunch.class); - } - if(options.moduleConf != null) { - // Create Module Layer - moduleFinder = ModuleFinder.of(options.moduleConf.modulePath.stream().map(Paths::get).map(Path::toAbsolutePath).toArray(Path[]::new)); - ModuleLayer bootLayer = ModuleLayer.boot(); - if(options.moduleConf.modules.contains("ALL-MODULE-PATH")) { - var set = moduleFinder.findAll(); - if(LogHelper.isDevEnabled()) { - for(var m : set) { - LogHelper.dev("Found module %s in %s", m.descriptor().name(), m.location().map(URI::toString).orElse("unknown")); - } - LogHelper.dev("Found %d modules", set.size()); - } - for(var m : set) { - options.moduleConf.modules.add(m.descriptor().name()); - } - options.moduleConf.modules.remove("ALL-MODULE-PATH"); - } - configuration = bootLayer.configuration() - .resolveAndBind(moduleFinder, ModuleFinder.of(), options.moduleConf.modules); - controller = ModuleLayer.defineModulesWithOneLoader(configuration, List.of(bootLayer), moduleClassLoader); - layer = controller.layer(); - // Configure exports / opens - for(var e : options.moduleConf.exports.entrySet()) { - String[] split = e.getKey().split("/"); - String moduleName = split[0]; - String pkg = split[1]; - LogHelper.dev("Export module: %s package: %s to %s", moduleName, pkg, e.getValue()); - Module source = layer.findModule(split[0]).orElse(null); - if(source == null) { - throw new RuntimeException(String.format("Module %s not found", moduleName)); - } - Module target = layer.findModule(e.getValue()).orElse(null); - if(target == null) { - throw new RuntimeException(String.format("Module %s not found", e.getValue())); - } - if(options.enableHacks && source.getLayer() != layer) { - ModuleHacks.createController(hackLookup, source.getLayer()).addExports(source, pkg, target); - } else { - controller.addExports(source, pkg, target); - } - } - for(var e : options.moduleConf.opens.entrySet()) { - String[] split = e.getKey().split("/"); - String moduleName = split[0]; - String pkg = split[1]; - LogHelper.dev("Open module: %s package: %s to %s", moduleName, pkg, e.getValue()); - Module source = layer.findModule(split[0]).orElse(null); - if(source == null) { - throw new RuntimeException(String.format("Module %s not found", moduleName)); - } - Module target = layer.findModule(e.getValue()).orElse(null); - if(target == null) { - throw new RuntimeException(String.format("Module %s not found", e.getValue())); - } - if(options.enableHacks && source.getLayer() != layer) { - ModuleHacks.createController(hackLookup, source.getLayer()).addOpens(source, pkg, target); - } else { - controller.addOpens(source, pkg, target); - } - } - for(var e : options.moduleConf.reads.entrySet()) { - LogHelper.dev("Read module %s to %s", e.getKey(), e.getValue()); - Module source = layer.findModule(e.getKey()).orElse(null); - if(source == null) { - throw new RuntimeException(String.format("Module %s not found", e.getKey())); - } - Module target = layer.findModule(e.getValue()).orElse(null); - if(target == null) { - throw new RuntimeException(String.format("Module %s not found", e.getValue())); - } - if(options.enableHacks && source.getLayer() != layer) { - ModuleHacks.createController(hackLookup, source.getLayer()).addReads(source, target); - } else { - controller.addReads(source, target); - } - } - moduleClassLoader.initializeWithLayer(layer); - } - } - return moduleClassLoader.makeControl(); - } - - @Override - public void launch(String mainClass, String mainModuleName, Collection args) throws Throwable { - Thread.currentThread().setContextClassLoader(moduleClassLoader); - if(mainModuleName == null) { - Class mainClazz = Class.forName(mainClass, true, moduleClassLoader); - MethodHandle mainMethod = MethodHandles.lookup().findStatic(mainClazz, "main", MethodType.methodType(void.class, String[].class)).asFixedArity(); - JVMHelper.fullGC(); - mainMethod.asFixedArity().invokeWithArguments((Object) args.toArray(new String[0])); - return; - } - Module mainModule = layer.findModule(mainModuleName).orElseThrow(); - Module unnamed = ModuleLaunch.class.getClassLoader().getUnnamedModule(); - if(unnamed != null) { - controller.addOpens(mainModule, getPackageFromClass(mainClass), unnamed); - } - // Start main class - ClassLoader loader = mainModule.getClassLoader(); - Class mainClazz = Class.forName(mainClass, true, loader); - MethodHandle mainMethod = MethodHandles.lookup().findStatic(mainClazz, "main", MethodType.methodType(void.class, String[].class)); - mainMethod.asFixedArity().invokeWithArguments((Object) args.toArray(new String[0])); - } - - private static String getPackageFromClass(String clazz) { - int index = clazz.lastIndexOf("."); - if(index >= 0) { - return clazz.substring(0, index); - } - return clazz; - } - - private class ModuleClassLoader extends URLClassLoader { - private final ClassLoader SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader(); - private final List transformers = new ArrayList<>(); - private final Map> classMap = new ConcurrentHashMap<>(); - private final Map packageToModule = new HashMap<>(); - private String nativePath; - - private final List packages = new ArrayList<>(); - public ModuleClassLoader(URL[] urls, ClassLoader parent) { - super("LAUNCHER", urls, parent); - packages.add("pro.gravit.launcher."); - packages.add("pro.gravit.utils."); - } - - private void initializeWithLayer(ModuleLayer layer) { - for(var m : layer.modules()) { - for(var p : m.getPackages()) { - packageToModule.put(p, m); - } - } - } - - @Override - protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException { - if(name != null && !disablePackageDelegateSupport) { - for(String pkg : packages) { - if(name.startsWith(pkg)) { - return SYSTEM_CLASS_LOADER.loadClass(name); - } - } - } - return super.loadClass(name, resolve); - } - - @Override - protected Class findClass(String name) throws ClassNotFoundException { - var clazz = findClass(null, name); - if(clazz == null) { - throw new ClassNotFoundException(name); - } - return clazz; - } - - @Override - protected Class findClass(String moduleName, String name) { - Class clazz; - { - clazz = classMap.get(name); - if(clazz != null) { - return clazz; - } - } - if(name != null && !transformers.isEmpty()) { - boolean needTransform = false; - for(ClassLoaderControl.ClassTransformer t : transformers) { - if(t.filter(moduleName, name)) { - needTransform = true; - break; - } - } - if(needTransform) { - String rawClassName = name.replace(".", "/").concat(".class"); - try(InputStream input = getResourceAsStream(rawClassName)) { - byte[] bytes = IOHelper.read(input); - for(ClassLoaderControl.ClassTransformer t : transformers) { - bytes = t.transform(moduleName, name, null, bytes); - } - clazz = defineClass(name, bytes, 0, bytes.length); - } catch (IOException e) { - return null; - } - } - } - if(clazz == null && layer != null && name != null) { - var pkg = getPackageFromClass(name); - var module = packageToModule.get(pkg); - if(module != null) { - try { - clazz = module.getClassLoader().loadClass(name); - } catch (ClassNotFoundException e) { - return null; - } - } - } - if(clazz == null) { - try { - clazz = super.findClass(name); - } catch (ClassNotFoundException e) { - return null; - } - } - if(clazz != null) { - classMap.put(name, clazz); - return clazz; - } else { - return null; - } - } - - @Override - public String findLibrary(String name) { - return nativePath.concat(IOHelper.PLATFORM_SEPARATOR).concat(JVMHelper.NATIVE_PREFIX).concat(name).concat(JVMHelper.NATIVE_EXTENSION); - } - - public void addAllowedPackage(String pkg) { - packages.add(pkg); - } - - private ModuleClassLoaderControl makeControl() { - return new ModuleClassLoaderControl(); - } - - private class ModuleClassLoaderControl implements ClassLoaderControl { - - @Override - public void addLauncherPackage(String prefix) { - addAllowedPackage(prefix); - } - - @Override - public void addTransformer(ClassTransformer transformer) { - transformers.add(transformer); - } - - @Override - public void addURL(URL url) { - ModuleClassLoader.this.addURL(url); - } - - @Override - public void addJar(Path path) { - try { - ModuleClassLoader.this.addURL(path.toUri().toURL()); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - } - - @Override - public URL[] getURLs() { - return ModuleClassLoader.this.getURLs(); - } - - @Override - public Class getClass(String name) throws ClassNotFoundException { - return Class.forName(name, false, ModuleClassLoader.this); - } - - @Override - public ClassLoader getClassLoader() { - return ModuleClassLoader.this; - } - - @Override - public Object getJava9ModuleController() { - return controller; - } - - @Override - public MethodHandles.Lookup getHackLookup() { - return hackLookup; - } - } - } -} diff --git a/LauncherCore/src/test/java/pro/gravit/launcher/SecurityHelperTests.java b/LauncherCore/src/test/java/pro/gravit/launcher/SecurityHelperTests.java new file mode 100644 index 00000000..4a78442d --- /dev/null +++ b/LauncherCore/src/test/java/pro/gravit/launcher/SecurityHelperTests.java @@ -0,0 +1,48 @@ +package pro.gravit.launcher; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import pro.gravit.utils.helper.SecurityHelper; + +import javax.crypto.CipherInputStream; +import javax.crypto.CipherOutputStream; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +public class SecurityHelperTests { + @Test + public void aesLegacyTest() throws Exception { + byte[] bytes = SecurityHelper.randomBytes(24); + byte[] seed = SecurityHelper.randomBytes(32); + byte[] encrypted = SecurityHelper.encrypt(seed, bytes); + byte[] decrypted = SecurityHelper.decrypt(seed, encrypted); + Assertions.assertArrayEquals(bytes, decrypted); + } + + + @Test + public void aesStreamTest() throws Exception { + byte[] bytes = SecurityHelper.randomBytes(128); + byte[] seed = SecurityHelper.randomAESKey(); + byte[] encrypted; + ByteArrayOutputStream s = new ByteArrayOutputStream(); + try(OutputStream o = new CipherOutputStream(s, SecurityHelper.newAESEncryptCipher(seed))) { + try(ByteArrayInputStream i = new ByteArrayInputStream(bytes)) { + i.transferTo(o); + } + } + encrypted = s.toByteArray(); + byte[] decrypted; + ; + try(InputStream i = new CipherInputStream(new ByteArrayInputStream(encrypted), SecurityHelper.newAESDecryptCipher(seed))) { + ByteArrayOutputStream s2 = new ByteArrayOutputStream(); + try(s2) { + i.transferTo(s2); + } + decrypted = s2.toByteArray(); + } + Assertions.assertArrayEquals(bytes, decrypted); + } +} diff --git a/LauncherModernCore/build.gradle b/LauncherModernCore/build.gradle deleted file mode 100644 index 879f4a48..00000000 --- a/LauncherModernCore/build.gradle +++ /dev/null @@ -1,72 +0,0 @@ -sourceCompatibility = '17' -targetCompatibility = '17' - -dependencies { - api project(':LauncherCore') -} - -test { - useJUnitPlatform() - testLogging { - events "passed", "skipped", "failed" - } -} -jar { - archiveClassifier.set('clean') - manifest.attributes("Multi-Release": "true") -} - -tasks.register('sourcesJar', Jar) { - from sourceSets.main.allJava - archiveClassifier.set('sources') -} - -tasks.register('javadocJar', Jar) { - from javadoc - archiveClassifier.set('javadoc') -} - -publishing { - publications { - launchermoderncore(MavenPublication) { - artifactId = 'launcher-modern-core' - artifact(jar) { - classifier "" - } - artifact sourcesJar - artifact javadocJar - pom { - name = 'GravitLauncher Core Utils with Java 17+' - description = 'GravitLauncher Core Utils' - url = 'https://gravitlauncher.com' - licenses { - license { - name = 'GNU General Public License, Version 3.0' - url = 'https://www.gnu.org/licenses/gpl-3.0.html' - } - } - developers { - developer { - id = 'gravita' - name = 'Gravita' - email = 'gravita@gravit.pro' - } - developer { - id = 'zaxar163' - name = 'Zaxar163' - email = 'zahar.vcherachny@yandex.ru' - } - } - scm { - connection = 'scm:git:https://github.com/GravitLauncher/Launcher.git' - developerConnection = 'scm:git:ssh://git@github.com:GravitLauncher/Launcher.git' - url = 'https://gravitlauncher.com/' - } - } - } - } -} - -signing { - sign publishing.publications.launchermoderncore -} diff --git a/LauncherStart/build.gradle b/LauncherStart/build.gradle index bdc73a50..225658f7 100644 --- a/LauncherStart/build.gradle +++ b/LauncherStart/build.gradle @@ -8,8 +8,8 @@ url "https://repo.spring.io/plugins-release/" } } -sourceCompatibility = '1.8' -targetCompatibility = '1.8' +sourceCompatibility = '17' +targetCompatibility = '17' jar { archiveClassifier.set('clean') diff --git a/LauncherStart/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java b/LauncherStart/src/main/java/pro/gravit/launcher/start/ClientLauncherWrapper.java similarity index 94% rename from LauncherStart/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java rename to LauncherStart/src/main/java/pro/gravit/launcher/start/ClientLauncherWrapper.java index 30e4301b..82791f3f 100644 --- a/LauncherStart/src/main/java/pro/gravit/launcher/ClientLauncherWrapper.java +++ b/LauncherStart/src/main/java/pro/gravit/launcher/start/ClientLauncherWrapper.java @@ -1,8 +1,8 @@ -package pro.gravit.launcher; +package pro.gravit.launcher.start; -import pro.gravit.launcher.client.RuntimeModuleManager; -import pro.gravit.launcher.client.DirBridge; -import pro.gravit.launcher.utils.DirWatcher; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.LauncherConfig; +import pro.gravit.launcher.core.LauncherInject; import pro.gravit.utils.Version; import pro.gravit.utils.helper.*; @@ -103,16 +103,12 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep context.executePath = IOHelper.resolveJavaBin(context.javaVersion.jvmDir); String pathLauncher = IOHelper.getCodeSource(ClientLauncherWrapper.class).toString(); - context.mainClass = "pro.gravit.launcher.LauncherEngineWrapper"; + context.mainClass = "pro.gravit.launcher.runtime.LauncherEngineWrapper"; context.memoryLimit = launcherMemoryLimit; context.classpath.add(pathLauncher); context.jvmProperties.put(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled())); context.jvmProperties.put(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled())); context.jvmProperties.put(LogHelper.DEV_PROPERTY, Boolean.toString(LogHelper.isDevEnabled())); - context.addSystemProperty(DirBridge.CUSTOMDIR_PROPERTY); - context.addSystemProperty(DirBridge.USE_CUSTOMDIR_PROPERTY); - context.addSystemProperty(DirBridge.USE_OPTDIR_PROPERTY); - context.addSystemProperty(DirWatcher.IGN_OVERFLOW); context.jvmModules.add("javafx.base"); context.jvmModules.add("javafx.graphics"); context.jvmModules.add("javafx.fxml"); diff --git a/LauncherStart/src/main/java/pro/gravit/launcher/ClientWrapperModule.java b/LauncherStart/src/main/java/pro/gravit/launcher/start/ClientWrapperModule.java similarity index 60% rename from LauncherStart/src/main/java/pro/gravit/launcher/ClientWrapperModule.java rename to LauncherStart/src/main/java/pro/gravit/launcher/start/ClientWrapperModule.java index 6c4feafb..af380726 100644 --- a/LauncherStart/src/main/java/pro/gravit/launcher/ClientWrapperModule.java +++ b/LauncherStart/src/main/java/pro/gravit/launcher/start/ClientWrapperModule.java @@ -1,6 +1,4 @@ -package pro.gravit.launcher; - -import pro.gravit.launcher.ClientLauncherWrapper; +package pro.gravit.launcher.start; public interface ClientWrapperModule { void wrapperPhase(ClientLauncherWrapper.ClientLauncherWrapperContext context); diff --git a/LauncherStart/src/main/java/pro/gravit/launcher/client/RuntimeModuleManager.java b/LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java similarity index 71% rename from LauncherStart/src/main/java/pro/gravit/launcher/client/RuntimeModuleManager.java rename to LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java index c3f92075..efbc127f 100644 --- a/LauncherStart/src/main/java/pro/gravit/launcher/client/RuntimeModuleManager.java +++ b/LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java @@ -1,11 +1,9 @@ -package pro.gravit.launcher.client; +package pro.gravit.launcher.start; -import pro.gravit.launcher.ClientLauncherWrapper; -import pro.gravit.launcher.ClientWrapperModule; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherTrustManager; -import pro.gravit.launcher.modules.LauncherModule; -import pro.gravit.launcher.modules.impl.SimpleModuleManager; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.core.LauncherTrustManager; +import pro.gravit.launcher.base.modules.LauncherModule; +import pro.gravit.launcher.base.modules.impl.SimpleModuleManager; import java.nio.file.Path; import java.util.Collections; @@ -36,10 +34,15 @@ public List getModules() { } @Override - public final boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { + public boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { return result.type == LauncherTrustManager.CheckClassResultType.SUCCESS; } + @Override + protected ModulesClassLoader createClassLoader() { + return null; + } + public void callWrapper(ClientLauncherWrapper.ClientLauncherWrapperContext context) { for (LauncherModule module : modules) { if (module instanceof ClientWrapperModule) { diff --git a/ServerWrapper/build.gradle b/ServerWrapper/build.gradle index 66520bef..68a4f2bc 100644 --- a/ServerWrapper/build.gradle +++ b/ServerWrapper/build.gradle @@ -14,30 +14,10 @@ } } -sourceSets { - java11 { - java { - srcDirs = ['src/main/java11'] - } - dependencies { - java11Implementation project(':LauncherAPI') - java11Implementation files(sourceSets.main.output.classesDirs) { builtBy compileJava } - } - } -} - -sourceCompatibility = '1.8' -targetCompatibility = '1.8' - -compileJava11Java { - sourceCompatibility = 11 - targetCompatibility = 11 -} +sourceCompatibility = '17' +targetCompatibility = '17' jar { - into('META-INF/versions/11') { - from sourceSets.java11.output - } archiveClassifier.set('clean') manifest.attributes("Main-Class": mainClassName, "Premain-Class": mainAgentName, @@ -59,13 +39,11 @@ java11Implementation files(sourceSets.main.output.classesDirs) { builtBy compile dependencies { pack project(':LauncherAPI') - pack group: 'io.netty', name: 'netty-codec-http', version: rootProject['verNetty'] } shadowJar { duplicatesStrategy = 'EXCLUDE' archiveClassifier = null - relocate 'io.netty', 'pro.gravit.repackage.io.netty' configurations = [project.configurations.pack] exclude 'module-info.class' } diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java index 42e85eec..a1c7e6d5 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapper.java @@ -1,27 +1,24 @@ package pro.gravit.launcher.server; -import pro.gravit.launcher.ClientPermissions; -import pro.gravit.launcher.Launcher; -import pro.gravit.launcher.LauncherConfig; -import pro.gravit.launcher.api.AuthService; -import pro.gravit.launcher.api.ClientService; -import pro.gravit.launcher.api.ConfigService; -import pro.gravit.launcher.api.KeyService; -import pro.gravit.launcher.config.JsonConfigurable; -import pro.gravit.launcher.events.request.AuthRequestEvent; -import pro.gravit.launcher.events.request.ProfilesRequestEvent; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.PlayerProfile; -import pro.gravit.launcher.profiles.optional.actions.OptionalAction; -import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.auth.AuthRequest; -import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest; -import pro.gravit.launcher.request.update.ProfilesRequest; -import pro.gravit.launcher.request.websockets.StdWebSocketService; +import pro.gravit.launcher.base.Launcher; +import pro.gravit.launcher.base.LauncherConfig; +import pro.gravit.launcher.base.api.AuthService; +import pro.gravit.launcher.base.api.ClientService; +import pro.gravit.launcher.base.api.ConfigService; +import pro.gravit.launcher.base.api.KeyService; +import pro.gravit.launcher.base.config.JsonConfigurable; +import pro.gravit.launcher.base.events.request.AuthRequestEvent; +import pro.gravit.launcher.base.events.request.ProfilesRequestEvent; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.optional.actions.OptionalAction; +import pro.gravit.launcher.base.profiles.optional.triggers.OptionalTrigger; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.auth.AuthRequest; +import pro.gravit.launcher.base.request.auth.GetAvailabilityAuthRequest; +import pro.gravit.launcher.base.request.update.ProfilesRequest; +import pro.gravit.launcher.base.request.websockets.StdWebSocketService; import pro.gravit.launcher.server.authlib.InstallAuthlib; import pro.gravit.launcher.server.setup.ServerWrapperSetup; -import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.LogHelper; import pro.gravit.utils.helper.SecurityHelper; @@ -125,8 +122,7 @@ public void run(String... args) throws Throwable { LogHelper.debug("Read ServerWrapperConfig.json"); loadConfig(); updateLauncherConfig(); - if (config.env != null) Launcher.applyLauncherEnv(config.env); - else Launcher.applyLauncherEnv(LauncherConfig.LauncherEnvironment.STD); + Launcher.applyLauncherEnv(Objects.requireNonNullElse(config.env, LauncherConfig.LauncherEnvironment.STD)); StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get(); service.reconnectCallback = () -> { @@ -156,7 +152,7 @@ public void run(String... args) throws Throwable { KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey); } String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass; - if (classname.length() == 0) { + if (classname.isEmpty()) { LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.json or first commandline argument"); System.exit(-1); } @@ -177,7 +173,7 @@ public void run(String... args) throws Throwable { LogHelper.info("ServerWrapper: LaunchServer address: %s. Title: %s", config.address, Launcher.profile != null ? Launcher.profile.getTitle() : "unknown"); LogHelper.info("Minecraft Version (for profile): %s", wrapper.profile == null ? "unknown" : wrapper.profile.getVersion().toString()); String[] real_args; - if(config.args != null && config.args.size() > 0) { + if(config.args != null && !config.args.isEmpty()) { real_args = config.args.toArray(new String[0]); } else if (args.length > 0) { real_args = new String[args.length - 1]; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperGsonManager.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperGsonManager.java index bb19fc5f..48b5f35d 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperGsonManager.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/ServerWrapperGsonManager.java @@ -1,8 +1,8 @@ package pro.gravit.launcher.server; import com.google.gson.GsonBuilder; -import pro.gravit.launcher.managers.GsonManager; -import pro.gravit.launcher.request.websockets.ClientWebSocketService; +import pro.gravit.launcher.core.managers.GsonManager; +import pro.gravit.launcher.base.request.websockets.ClientWebSocketService; public class ServerWrapperGsonManager extends GsonManager { diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/authlib/InstallAuthlib.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/authlib/InstallAuthlib.java index aa6fdbef..a5ed38cf 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/authlib/InstallAuthlib.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/authlib/InstallAuthlib.java @@ -15,6 +15,7 @@ public class InstallAuthlib { private static final Map modifierMap; + private static final String tempLaunchAuthLibName = "authlib.jar"; static { modifierMap = new HashMap<>(); modifierMap.put("META-INF/libraries.list", new LibrariesLstModifier()); @@ -26,30 +27,30 @@ public void run(String... args) throws Exception { boolean deleteAuthlibAfterInstall = false; InstallAuthlibContext context = new InstallAuthlibContext(); if(args[0].startsWith("http://") || args[0].startsWith("https://")) { - Path tempAuthlib = Paths.get("authlib.jar"); + Path tempAuthlib = Paths.get(tempLaunchAuthLibName); LogHelper.info("Download %s to %s", args[0], tempAuthlib); try(InputStream input = IOHelper.newInput(new URL(args[0]))) { IOHelper.transfer(input, tempAuthlib); } - context.pathToAuthlib = tempAuthlib; + context.pathToAuthlib = tempAuthlib.toAbsolutePath(); deleteAuthlibAfterInstall = true; } else { - context.pathToAuthlib = Paths.get(args[0]); + context.pathToAuthlib = Paths.get(args[0]).toAbsolutePath(); } if(Files.notExists(context.pathToAuthlib)) { throw new FileNotFoundException(context.pathToAuthlib.toString()); } - context.workdir = IOHelper.WORKING_DIR; LogHelper.info("Search .jar files in %s", context.workdir.toAbsolutePath()); - IOHelper.walk(context.workdir, new SimpleFileVisitor() { + IOHelper.walk(context.workdir, new SimpleFileVisitor<>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) { - if(file.getFileName().toString().endsWith(".jar")) { + if (file.getFileName().toString().endsWith(".jar") && !file.equals(context.pathToAuthlib)) { context.files.add(file); } return FileVisitResult.CONTINUE; } }, true); + context.files.sort(Comparator.comparingInt((Path path) -> - path.getNameCount())); LogHelper.info("Search authlib in %d files", context.files.size()); for(Path path : context.files) { boolean foundAuthlib = false; diff --git a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java index 9f2e24da..b8b8215f 100644 --- a/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java +++ b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java @@ -1,13 +1,12 @@ package pro.gravit.launcher.server.setup; -import pro.gravit.launcher.events.request.GetPublicKeyRequestEvent; -import pro.gravit.launcher.profiles.ClientProfile; -import pro.gravit.launcher.profiles.ClientProfileVersions; -import pro.gravit.launcher.request.Request; -import pro.gravit.launcher.request.auth.GetPublicKeyRequest; -import pro.gravit.launcher.request.websockets.StdWebSocketService; +import pro.gravit.launcher.base.events.request.GetPublicKeyRequestEvent; +import pro.gravit.launcher.base.profiles.ClientProfile; +import pro.gravit.launcher.base.profiles.ClientProfileVersions; +import pro.gravit.launcher.base.request.Request; +import pro.gravit.launcher.base.request.auth.GetPublicKeyRequest; +import pro.gravit.launcher.base.request.websockets.StdWebSocketService; import pro.gravit.launcher.server.ServerWrapper; -import pro.gravit.utils.PublicURLClassLoader; import pro.gravit.utils.helper.IOHelper; import pro.gravit.utils.helper.JVMHelper; import pro.gravit.utils.helper.LogHelper; @@ -15,6 +14,7 @@ import java.io.IOException; import java.io.Writer; import java.net.URL; +import java.net.URLClassLoader; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -22,7 +22,7 @@ public class ServerWrapperSetup { public ServerWrapperCommands commands; - public PublicURLClassLoader urlClassLoader; + public URLClassLoader urlClassLoader; public ServerWrapperSetup() throws IOException { commands = new ServerWrapperCommands(); @@ -37,7 +37,7 @@ public void run() throws Exception { String agentClassName; try (JarFile file = new JarFile(jarPath.toFile())) { URL jarURL = jarPath.toUri().toURL(); - urlClassLoader = new PublicURLClassLoader(new URL[]{jarURL}); + urlClassLoader = new URLClassLoader(new URL[]{jarURL}); LogHelper.info("Check server jar MainClass"); mainClassName = file.getManifest().getMainAttributes().getValue("Main-Class"); agentClassName = file.getManifest().getMainAttributes().getValue("Premain-Class"); diff --git a/build.gradle b/build.gradle index 6c18cc21..b4b18f09 100644 --- a/build.gradle +++ b/build.gradle @@ -2,10 +2,10 @@ id 'com.github.johnrengelman.shadow' version '7.1.2' apply false id 'maven-publish' id 'signing' - id 'org.openjfx.javafxplugin' version '0.0.10' apply false + id 'org.openjfx.javafxplugin' version '0.1.0' apply false } group = 'pro.gravit.launcher' -version = '5.5.4' +version = '5.6.0' apply from: 'props.gradle' diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7f93135c..d64cd491 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8838ba97..2ea3535d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-all.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/gradlew.bat b/gradlew.bat index 93e3f59f..25da30db 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -43,11 +43,11 @@ set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -57,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail diff --git a/modules b/modules index 7581b6c0..e93620f1 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit 7581b6c01470a5ec32ac67170635d10f6f589b0a +Subproject commit e93620f10963b951c8874dfef17dce91cf8c8da9 diff --git a/props.gradle b/props.gradle index 30ea7931..6ac97aee 100644 --- a/props.gradle +++ b/props.gradle @@ -6,11 +6,11 @@ verGuavaC = '30.1.1-jre' verJansi = '2.4.1' verJline = '3.25.0' - verJwt = '0.11.5' + verJwt = '0.12.5' verBcprov = '1.70' verGson = '2.10.1' verBcpkix = '1.70' - verSlf4j = '1.7.36' + verSlf4j = '2.0.9' verLog4j = '2.20.0' verMySQLConn = '8.3.0' verPostgreSQLConn = '42.7.1' diff --git a/settings.gradle b/settings.gradle index 9566cd8d..dfdf4434 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,7 +1,6 @@ rootProject.name = 'GravitLauncher' include 'Launcher' -include 'LauncherModernCore' include 'LauncherCore' include 'LauncherAPI' include 'LauncherClient'