From f321b8bd2764e90e5167530605b2643c0d2e4fd4 Mon Sep 17 00:00:00 2001 From: Gravita <12893402+gravit0@users.noreply.github.com> Date: Fri, 29 Dec 2023 16:37:14 +0700 Subject: [PATCH] [FIX] ExitResponse, update SimpleModuleManager --- .../socket/response/auth/ExitResponse.java | 5 +- .../launcher/base/modules/LauncherModule.java | 4 ++ .../base/modules/LauncherModulesContext.java | 4 ++ .../modules/impl/SimpleModuleContext.java | 11 +++ .../modules/impl/SimpleModuleManager.java | 23 +++++- .../request/websockets/ClientJSONPoint.java | 2 + .../launcher/client/ClientModuleManager.java | 6 ++ LauncherModernCore/build.gradle | 72 ------------------- .../launcher/start/RuntimeModuleManager.java | 5 ++ .../server/setup/ServerWrapperSetup.java | 5 +- 10 files changed, 61 insertions(+), 76 deletions(-) delete mode 100644 LauncherModernCore/build.gradle 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 6cd1647c..37394753 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 @@ -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(); diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModule.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModule.java index 6e1d2f68..86d032b8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModule.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModule.java @@ -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/base/modules/LauncherModulesContext.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModulesContext.java index 5710af91..b648faa8 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModulesContext.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/LauncherModulesContext.java @@ -1,7 +1,11 @@ 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/base/modules/impl/SimpleModuleContext.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleContext.java index 2547f594..2d1bc257 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleContext.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleContext.java @@ -4,6 +4,8 @@ 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; public final ModulesConfigManager configManager; @@ -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/base/modules/impl/SimpleModuleManager.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java index 97bf724f..db3668a4 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/base/modules/impl/SimpleModuleManager.java @@ -11,6 +11,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; @@ -32,9 +33,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[]{}, SimpleModuleManager.class.getClassLoader()); + 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); @@ -268,6 +273,10 @@ public ModulesConfigManager getConfigManager() { return modulesConfigManager; } + void addUrlToClassLoader(URL url) { + classLoader.addURL(url); + } + protected final class ModulesVisitor extends SimpleFileVisitor { private ModulesVisitor() { } @@ -279,4 +288,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/base/request/websockets/ClientJSONPoint.java b/LauncherAPI/src/main/java/pro/gravit/launcher/base/request/websockets/ClientJSONPoint.java index 7f65dadf..73f1d9dc 100644 --- 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 @@ -14,6 +14,7 @@ import java.security.cert.CertificateException; import java.time.Duration; import java.util.concurrent.CompletionStage; +import java.util.concurrent.ExecutionException; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; @@ -27,6 +28,7 @@ public abstract class ClientJSONPoint implements WebSocket.Listener { 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 { 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 03a6f14e..b516523f 100644 --- a/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java +++ b/LauncherClient/src/main/java/pro/gravit/launcher/client/ClientModuleManager.java @@ -5,6 +5,7 @@ import pro.gravit.launcher.base.modules.LauncherModule; import pro.gravit.launcher.base.modules.impl.SimpleModuleManager; +import java.net.URL; import java.nio.file.Path; import java.util.Collections; import java.util.List; @@ -33,6 +34,11 @@ public List getModules() { return Collections.unmodifiableList(modules); } + @Override + protected ModulesClassLoader createClassLoader() { + return null; + } + @Override public boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult result) { return result.type == LauncherTrustManager.CheckClassResultType.SUCCESS; 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/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java b/LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java index ab9640cf..efbc127f 100644 --- a/LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java +++ b/LauncherStart/src/main/java/pro/gravit/launcher/start/RuntimeModuleManager.java @@ -38,6 +38,11 @@ public boolean verifyClassCheckResult(LauncherTrustManager.CheckClassResult resu 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/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java b/ServerWrapper/src/main/java/pro/gravit/launcher/server/setup/ServerWrapperSetup.java index 336f4889..79f655a7 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 @@ -15,6 +15,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 +23,7 @@ public class ServerWrapperSetup { public ServerWrapperCommands commands; - public PublicURLClassLoader urlClassLoader; + public URLClassLoader urlClassLoader; public ServerWrapperSetup() throws IOException { commands = new ServerWrapperCommands(); @@ -37,7 +38,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");