From a32434e4461d48bbd77041895f33d620dfb9ca47 Mon Sep 17 00:00:00 2001 From: Gravit Date: Sat, 22 Sep 2018 19:34:30 +0700 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=BA=D0=B5=D1=82=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=D0=B0=D1=87=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5=D1=82=D1=80=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../launcher/client/ClientLauncher.java | 67 ++++++++++++++----- 1 file changed, 52 insertions(+), 15 deletions(-) diff --git a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java index ec198b10..cfd8734e 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -6,7 +6,7 @@ import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; -import java.net.URL; +import java.net.*; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; @@ -303,12 +303,32 @@ public static Process launch( // Write params file (instead of CLI; Mustdie32 API can't handle command line > 32767 chars) LogHelper.debug("Writing ClientLauncher params"); Path paramsFile = Files.createTempFile("ClientLauncherParams", ".bin"); - try (HOutput output = new HOutput(IOHelper.newOutput(paramsFile))) { - params.write(output); - profile.write(output); - assetHDir.write(output); - clientHDir.write(output); - } + CommonHelper.newThread("Client params writter",false,() -> + { + try { + try (ServerSocket socket = new ServerSocket()) { + socket.setReuseAddress(true); + socket.bind(new InetSocketAddress("127.0.0.1", 54983)); + Socket client = socket.accept(); + try (HOutput output = new HOutput(client.getOutputStream())) { + params.write(output); + profile.write(output); + assetHDir.write(output); + clientHDir.write(output); + } + } + } catch (IOException e) { + LogHelper.error(e); + try (HOutput output = new HOutput(IOHelper.newOutput(paramsFile))) { + params.write(output); + profile.write(output); + assetHDir.write(output); + clientHDir.write(output); + } catch (IOException e1) { + LogHelper.error(e1); + } + } + }).start(); // Resolve java bin and set permissions LogHelper.debug("Resolving JVM binary"); //Path javaBin = IOHelper.resolveJavaBin(jvmDir); @@ -394,16 +414,33 @@ public static void main(String... args) throws Throwable { SignedObjectHolder profile; SignedObjectHolder assetHDir, clientHDir; RSAPublicKey publicKey = Launcher.getConfig().publicKey; - try (HInput input = new HInput(IOHelper.newInput(paramsFile))) { - params = new Params(input); - profile = new SignedObjectHolder<>(input, publicKey, ClientProfile.RO_ADAPTER); + try { + try (Socket socket = IOHelper.newSocket()) { + socket.connect(new InetSocketAddress("127.0.0.1", 54983)); + try (HInput input = new HInput(socket.getInputStream())) { + params = new Params(input); + profile = new SignedObjectHolder<>(input, publicKey, ClientProfile.RO_ADAPTER); - // Read hdirs - assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); - clientHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); - } finally { - Files.delete(paramsFile); + // Read hdirs + assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); + clientHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); + } + } + } catch (IOException ex) + { + LogHelper.error(ex); + try (HInput input = new HInput(IOHelper.newInput(paramsFile))) { + params = new Params(input); + profile = new SignedObjectHolder<>(input, publicKey, ClientProfile.RO_ADAPTER); + + // Read hdirs + assetHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); + clientHDir = new SignedObjectHolder<>(input, publicKey, HashedDir::new); + } finally { + Files.delete(paramsFile); + } } + title = params.title; Launcher.modulesManager.initModules(); // Verify ClientLauncher sign and classpath