From bddf31c94e93cac750ffa94172883340062aa6f2 Mon Sep 17 00:00:00 2001 From: Gravit'a <12893402+gravit0@users.noreply.github.com> Date: Thu, 25 May 2023 15:33:01 +0700 Subject: [PATCH] [FEATURE] LaunchServerLauncherExeInit --- .../pro/gravit/launchserver/LaunchServer.java | 15 ++++----------- .../launchserver/helper/MakeProfileHelper.java | 2 +- .../events/LaunchServerLauncherExeInit.java | 15 +++++++++++++++ .../pro/gravit/launcher/LauncherTrustManager.java | 8 ++++---- .../pro/gravit/utils/helper/FormatHelper.java | 10 +++++----- build.gradle | 4 +++- gradle/wrapper/gradle-wrapper.properties | 2 +- 7 files changed, 33 insertions(+), 23 deletions(-) create mode 100644 LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerLauncherExeInit.java diff --git a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java index e370576a..70b4abca 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/LaunchServer.java @@ -95,8 +95,6 @@ public final class LaunchServer implements Runnable, AutoCloseable, Reconfigurab * Pipeline for building EXE */ public final LauncherBinary launcherEXEBinary; - //public static LaunchServer server = null; - public final Class launcherEXEBinaryClass; // Server config public final AuthHookManager authHookManager; public final LaunchServerModulesManager modulesManager; @@ -148,9 +146,6 @@ public LaunchServer(LaunchServerDirectories directories, LaunchServerEnv env, La // Print keypair fingerprints - // Load class bindings. - launcherEXEBinaryClass = defaultLauncherEXEBinaryClass; - runtime.verify(); config.verify(); @@ -276,12 +271,10 @@ public void invoke(String... args) throws Exception { } private LauncherBinary binary() { - if (launcherEXEBinaryClass != null) { - try { - return (LauncherBinary) MethodHandles.publicLookup().findConstructor(launcherEXEBinaryClass, MethodType.methodType(void.class, LaunchServer.class)).invoke(this); - } catch (Throwable e) { - logger.error(e); - } + LaunchServerLauncherExeInit event = new LaunchServerLauncherExeInit(this, null); + modulesManager.invokeEvent(event); + if(event.binary != null) { + return event.binary; } try { Class.forName("net.sf.launch4j.Builder"); 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 f5fe8bc9..0491160d 100644 --- a/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/helper/MakeProfileHelper.java @@ -25,7 +25,7 @@ public static ClientProfile makeProfile(ClientProfile.Version version, String ti builder.setAssetDir("asset" + version.toCleanString()); } builder.setAssetIndex(version.toString()); - builder.setInfo("Информация о сервере"); + builder.setInfo("Server description"); builder.setTitle(title); builder.setUuid(UUID.randomUUID()); builder.setMainClass(getMainClassByVersion(version, options)); 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 new file mode 100644 index 00000000..48969876 --- /dev/null +++ b/LaunchServer/src/main/java/pro/gravit/launchserver/modules/events/LaunchServerLauncherExeInit.java @@ -0,0 +1,15 @@ +package pro.gravit.launchserver.modules.events; + +import pro.gravit.launcher.modules.LauncherModule; +import pro.gravit.launchserver.LaunchServer; +import pro.gravit.launchserver.binary.LauncherBinary; + +public class LaunchServerLauncherExeInit extends LauncherModule.Event { + public final LaunchServer server; + public LauncherBinary binary; + + public LaunchServerLauncherExeInit(LaunchServer server, LauncherBinary binary) { + this.server = server; + this.binary = binary; + } +} diff --git a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java index 5ba6e684..52a4f894 100644 --- a/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java +++ b/LauncherCore/src/main/java/pro/gravit/launcher/LauncherTrustManager.java @@ -65,13 +65,13 @@ private void injectCertificates() { // добавление стандартных сертификатов в новый KeyStore jdkTrustStore.keySet().forEach(key -> setCertificateEntry(mergedTrustStore, key, jdkTrustStore.get(key))); - // Инициализация контекста. В случае неудачи допустимо прерывание процесса, но сертификаты добавлены не будут + // Context initialization. In case of failure, the process is allowed to be interrupted, but certificates will not be added TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(mergedTrustStore); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(null, trustManagerFactory.getTrustManagers(), null); - // Установка контекста по умолчанию + // Setting the default context HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory()); LogHelper.info("Successfully injected certificates to truststore"); } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException | IOException | CertificateException e) { @@ -99,7 +99,7 @@ private static Map getDefaultKeyStore() { } /** - * Извлечение существующих сертификатов из стандартного KeyStore текущий сессии JVM. Процесс не должен прерываться в случае неудачи + * Retrieve existing certificates from the standard KeyStore of the current JVM session. The process should not be interrupted in case of failure */ private static void extractAllCertsAndPutInMap(KeyStore keyStore, Map placeToExport) { try { @@ -121,7 +121,7 @@ private static void setCertificateEntry(KeyStore keyStore, String name, Certific } /** - * Извлечение существующего сертификата из стандартного KeyStore текущий сессии JVM. Процесс не должен прерываться в случае неудачи + * Retrieve an existing certificate from the standard KeyStore of the current JVM session. The process should not be interrupted in case of failure */ private static void extractCertAndPutInMap(KeyStore keyStoreFromExtract, String key, Map placeToExtract) { try { 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 a0229df0..9043f27d 100644 --- a/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java +++ b/LauncherCore/src/main/java/pro/gravit/utils/helper/FormatHelper.java @@ -4,11 +4,11 @@ import pro.gravit.utils.Version; /* - * Nashorn при инициализации LogHelper пытается инициализировтаь все доступные в нем методы. - * При попытке инициализировать rawAnsiFormat он пытается найти класс org.fusesource.jansi.Ansi - * И есстественно крашится с ClassNotFound - * В итоге любой вызов LogHelper.* приводит к ClassNotFound org.fusesource.jansi.Ansi - * Поэтому rawAnsiFormat вынесен в отдельный Helper + * Nashorn when initializing LogHelper tries to initialize all methods available in it. + * When trying to initialize rawAnsiFormat , it tries to find the org.fusesource.jansi.Ansi class + * And naturally crashes with ClassNotFound + * As a result, any call to LogHelper.* results in ClassNotFound org.fusesource.jansi.Ansi + * Therefore, rawAnsiFormat is moved to a separate Helper */ public class FormatHelper { public static Ansi rawAnsiFormat(LogHelper.Level level, String dateTime, boolean sub) { diff --git a/build.gradle b/build.gradle index 4ec0d34b..c87e3bf6 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ id 'org.openjfx.javafxplugin' version '0.0.10' apply false } group = 'pro.gravit.launcher' -version = '5.4.2' +version = '5.4.3-SNAPSHOT' apply from: 'props.gradle' @@ -48,6 +48,8 @@ options.encoding = "UTF-8" options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation" options.incremental = true // one flag, and things will get MUCH faster + compileJava.options.encoding = 'UTF-8' + compileTestJava.options.encoding = 'UTF-8' } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 761b8f08..8707e8b5 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.0.2-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-all.zip networkTimeout=10000 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists