From 6d39f514cae70475ca009f0ddb6ecc78decd6372 Mon Sep 17 00:00:00 2001 From: Gravit Date: Tue, 22 Jan 2019 11:38:41 +0700 Subject: [PATCH] =?UTF-8?q?[FEATURE]=20=D0=9F=D0=B5=D1=80=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=B9=D0=BA=D0=B0=20optionalClientArgs/optio?= =?UTF-8?q?nalJVMArgs/optionalClassPath?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/gravit/launchserver/LaunchServer.java | 4 +- .../binary/tasks/PrepareBuildTask.java | 2 +- .../launcher/client/ClientLauncher.java | 99 +++---------------- .../request/update/UpdateRequest.java | 4 +- .../launcher/profiles/ClientProfile.java | 50 ++++++++-- .../profiles/optional/OptionalFile.java | 2 +- 6 files changed, 61 insertions(+), 100 deletions(-) diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index a1f3d3ce..0f2b0b45 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -343,8 +343,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE publicKey = (RSAPublicKey) pair.getPublic(); privateKey = (RSAPrivateKey) pair.getPrivate(); - // Write key pair files - LogHelper.info("Writing RSA keypair files"); + // Write key pair list + LogHelper.info("Writing RSA keypair list"); IOHelper.write(publicKeyFile, publicKey.getEncoded()); IOHelper.write(privateKeyFile, privateKey.getEncoded()); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java index 1e2ae3df..dc08fe0b 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/binary/tasks/PrepareBuildTask.java @@ -42,7 +42,7 @@ public boolean allowDelete() { } public void tryUnpack() throws IOException { - LogHelper.info("Unpacking launcher native guard files and runtime"); + LogHelper.info("Unpacking launcher native guard list and runtime"); UnpackHelper.unpackZipNoCheck("guard.zip", server.launcherBinary.guardDir); UnpackHelper.unpackZipNoCheck("runtime.zip", server.launcherBinary.runtimeDir); } 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 78e706a2..84fe9162 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -10,8 +10,6 @@ import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.PlayerProfile; -import ru.gravit.launcher.profiles.optional.OptionalArgs; -import ru.gravit.launcher.profiles.optional.OptionalFile; import ru.gravit.launcher.request.Request; import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.serialize.HInput; @@ -69,12 +67,6 @@ public static final class Params extends StreamObject { @LauncherAPI public final PlayerProfile pp; @LauncherAPI - public final Set updateOptional; - @LauncherAPI - public final Set optionalClientArgs; - @LauncherAPI - public final Set optionalClassPath; - @LauncherAPI public final String accessToken; @LauncherAPI public final boolean autoEnter; @@ -94,18 +86,6 @@ public static final class Params extends StreamObject { public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfile pp, String accessToken, boolean autoEnter, boolean fullScreen, int ram, int width, int height) { this.launcherDigest = launcherDigest.clone(); - this.updateOptional = new HashSet<>(); - this.optionalClientArgs = new HashSet<>(); - this.optionalClassPath = new HashSet<>(); - for (OptionalFile s : Launcher.profile.getOptional()) { - if (s.mark) updateOptional.add(s); - } - for (OptionalArgs s : Launcher.profile.getOptionalClientArgs()) { - if (s.mark) optionalClientArgs.add(s); - } - for (OptionalArgs s : Launcher.profile.getOptionalClassPath()) { - if (s.mark) optionalClassPath.add(s); - } // Client paths this.assetDir = assetDir; this.clientDir = clientDir; @@ -127,31 +107,6 @@ public Params(HInput input) throws Exception { // Client paths assetDir = IOHelper.toPath(input.readString(0)); clientDir = IOHelper.toPath(input.readString(0)); - updateOptional = new HashSet<>(); - optionalClientArgs = new HashSet<>(); - optionalClassPath = new HashSet<>(); - int len = input.readLength(128); - for (int i = 0; i < len; ++i) { - String file = input.readString(512); - boolean mark = input.readBoolean(); - updateOptional.add(new OptionalFile(file, mark)); - } - len = input.readLength(256); - for (int i = 0; i < len; ++i) { - int len2 = input.readLength(16); - boolean mark = input.readBoolean(); - String[] optArgs = new String[len]; - for (int j = 0; j < len2; ++j) optArgs[j] = input.readString(512); - optionalClientArgs.add(new OptionalArgs(optArgs, mark)); - } - len = input.readLength(256); - for (int i = 0; i < len; ++i) { - int len2 = input.readLength(16); - boolean mark = input.readBoolean(); - String[] optArgs = new String[len]; - for (int j = 0; j < len2; ++j) optArgs[j] = input.readString(512); - optionalClassPath.add(new OptionalArgs(optArgs, mark)); - } // Client params pp = new PlayerProfile(input); byte[] encryptedAccessToken = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH); @@ -171,24 +126,6 @@ public void write(HOutput output) throws IOException { // Client paths output.writeString(assetDir.toString(), 0); output.writeString(clientDir.toString(), 0); - output.writeLength(updateOptional.size(), 128); - for (OptionalFile s : updateOptional) { - output.writeString(s.file, 512); - output.writeBoolean(s.mark); - } - output.writeLength(optionalClientArgs.size(), 256); - for (OptionalArgs s : optionalClientArgs) { - output.writeLength(s.args.length, 16); - output.writeBoolean(s.mark); - for (String f : s.args) output.writeString(f, 512); - } - output.writeLength(optionalClassPath.size(), 256); - for (OptionalArgs s : optionalClassPath) { - output.writeLength(s.args.length, 16); - output.writeBoolean(s.mark); - for (String f : s.args) output.writeString(f, 512); - } - // Client params pp.write(output); try { output.writeByteArray(SecurityHelper.encrypt(Launcher.getConfig().secretKeyClient.getBytes(), accessToken.getBytes()), SecurityHelper.CRYPTO_MAX_LENGTH); @@ -285,9 +222,7 @@ private static void addClientArgs(Collection args, ClientProfile profile Collections.addAll(args, "--server", profile.getServerAddress()); Collections.addAll(args, "--port", Integer.toString(profile.getServerPort())); } - for (OptionalArgs optionalArgs : params.optionalClientArgs) { - if (optionalArgs.mark) Collections.addAll(args, optionalArgs.args); - } + profile.pushOptionalClientArgs(args); // Add window size args if (params.fullScreen) Collections.addAll(args, "--fullscreen", Boolean.toString(true)); @@ -426,11 +361,7 @@ public static Process launch( // Add classpath and main class String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); Collections.addAll(args, profile.getJvmArgs()); - if (profile.getOptionalJVMArgs() != null) { - for (OptionalArgs addArgs : profile.getOptionalJVMArgs()) { - if (addArgs.mark) Collections.addAll(args, addArgs.args); - } - } + profile.pushOptionalJvmArgs(args); Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path Collections.addAll(args, "-javaagent:".concat(pathLauncher)); if (wrapper) @@ -513,14 +444,12 @@ public static void main(String... args) throws Throwable { for (Path classpathURL : classPath) { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); } - for (OptionalArgs optionalArgs : params.optionalClassPath) { - if (!optionalArgs.mark) continue; - LinkedList optionalClassPath = resolveClassPathList(params.clientDir, optionalArgs.args); + profile.pushOptionalClassPath(cp -> { + LinkedList optionalClassPath = resolveClassPathList(params.clientDir, cp); for (Path classpathURL : optionalClassPath) { LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); } - } - + }); URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); Thread.currentThread().setContextClassLoader(classLoader); @@ -536,10 +465,11 @@ public static void main(String... args) throws Throwable { // Verify current state of all dirs //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); HashedDir hdir = clientHDir.object; - for (OptionalFile s : Launcher.profile.getOptional()) { - if (params.updateOptional.contains(s)) s.mark = true; - else hdir.removeR(s.file); - } + //for (OptionalFile s : Launcher.profile.getOptional()) { + // if (params.updateOptional.contains(s)) s.mark = true; + // else hdir.removeR(s.file); + //} + Launcher.profile.pushOptionalFile(hdir,false); verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest); verifyHDir(params.clientDir, hdir, clientMatcher, digest); Launcher.modulesManager.postInitModules(); @@ -575,10 +505,11 @@ public void launchLocal(SignedObjectHolder assetHDir, SignedObjectHol // Verify current state of all dirs //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); HashedDir hdir = clientHDir.object; - for (OptionalFile s : Launcher.profile.getOptional()) { - if (params.updateOptional.contains(s)) s.mark = true; - else hdir.removeR(s.file); - } + //for (OptionalFile s : Launcher.profile.getOptional()) { + // if (params.updateOptional.contains(s)) s.mark = true; + // else hdir.removeR(s.file); + //} + Launcher.profile.pushOptionalFile(hdir,false); verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest); verifyHDir(params.clientDir, hdir, clientMatcher, digest); Launcher.modulesManager.postInitModules(); diff --git a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java index 57d72295..5d065966 100644 --- a/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java +++ b/LauncherAPI/src/main/java/ru/gravit/launcher/request/update/UpdateRequest.java @@ -224,7 +224,7 @@ private void deleteExtraDir(Path subDir, HashedDir subHDir, boolean flag) throws String name = mapEntry.getKey(); Path path = subDir.resolve(name); - // Delete files and dirs based on type + // Delete list and dirs based on type HashedEntry entry = mapEntry.getValue(); HashedEntry.Type entryType = entry.getType(); switch (entryType) { @@ -308,7 +308,7 @@ protected SignedObjectHolder requestDo(HInput input, HOutput output) // Get diff between local and remote dir SignedObjectHolder remoteHDirHolder = new SignedObjectHolder<>(input, config.publicKey, HashedDir::new); HashedDir hackHackedDir = remoteHDirHolder.object; - Launcher.profile.pushOptional(hackHackedDir, !Launcher.profile.isUpdateFastCheck()); + Launcher.profile.pushOptionalFile(hackHackedDir, !Launcher.profile.isUpdateFastCheck()); HashedDir.Diff diff = hackHackedDir.diff(localDir, matcher); totalSize = diff.mismatch.size(); boolean compress = input.readBoolean(); diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java index 5c78c576..9210ff1b 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/ClientProfile.java @@ -1,5 +1,6 @@ package ru.gravit.launcher.profiles; +import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils; import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.HashedDir; @@ -8,7 +9,9 @@ import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.VerifyHelper; +import java.io.IOException; import java.net.InetSocketAddress; +import java.nio.file.Path; import java.util.*; public final class ClientProfile implements Comparable { @@ -216,9 +219,8 @@ public Collection getShared() { @LauncherAPI public void markOptional(String name, OptionalType type) { - OptionalFile file = getOptionalFile(name,type); - if(file == null) - { + OptionalFile file = getOptionalFile(name, type); + if (file == null) { throw new SecurityException(String.format("Optional %s not found in optionalList", name)); } markOptional(file); @@ -245,9 +247,8 @@ public void markOptional(OptionalFile file) { @LauncherAPI public void unmarkOptional(String name, OptionalType type) { - OptionalFile file = getOptionalFile(name,type); - if(file == null) - { + OptionalFile file = getOptionalFile(name, type); + if (file == null) { throw new SecurityException(String.format("Optional %s not found in optionalList", name)); } unmarkOptional(file); @@ -278,16 +279,45 @@ public void unmarkOptional(OptionalFile file) { } } - public void pushOptional(HashedDir dir, boolean digest) { + public void pushOptionalFile(HashedDir dir, boolean digest) { for (OptionalFile opt : updateOptional) { - if (opt.type.equals(OptionalType.FILE) && !opt.mark) - { - for(String file : opt.files) + if (opt.type.equals(OptionalType.FILE) && !opt.mark) { + for (String file : opt.list) dir.removeR(file); } } } + public void pushOptionalJvmArgs(Collection jvmArgs1) + { + for (OptionalFile opt : updateOptional) { + if (opt.type.equals(OptionalType.JVMARGS) && opt.mark) { + jvmArgs1.addAll(Arrays.asList(opt.list)); + } + } + } + public void pushOptionalClientArgs(Collection clientArgs1) + { + for (OptionalFile opt : updateOptional) { + if (opt.type.equals(OptionalType.CLIENTARGS) && opt.mark) { + clientArgs1.addAll(Arrays.asList(opt.list)); + } + } + } + public void pushOptionalClassPath(pushOptionalClassPathCallback callback) throws IOException + { + for (OptionalFile opt : updateOptional) { + if (opt.type.equals(OptionalType.CLASSPATH) && opt.mark) { + callback.run(opt.list); + } + } + } + @FunctionalInterface + public interface pushOptionalClassPathCallback + { + void run(String[] opt) throws IOException; + } + @LauncherAPI public int getServerPort() { return serverPort; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalFile.java b/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalFile.java index 4f82ece4..e87a3f91 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalFile.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/profiles/optional/OptionalFile.java @@ -7,7 +7,7 @@ public class OptionalFile { @LauncherAPI - public String[] files; + public String[] list; @LauncherAPI public OptionalType type; @LauncherAPI