[FEATURE] Перестройка optionalClientArgs/optionalJVMArgs/optionalClassPath

This commit is contained in:
Gravit 2019-01-22 11:38:41 +07:00
parent 1a1c6b6c5a
commit 6d39f514ca
No known key found for this signature in database
GPG key ID: 061981E1E85D3216
6 changed files with 61 additions and 100 deletions

View file

@ -343,8 +343,8 @@ public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecE
publicKey = (RSAPublicKey) pair.getPublic(); publicKey = (RSAPublicKey) pair.getPublic();
privateKey = (RSAPrivateKey) pair.getPrivate(); privateKey = (RSAPrivateKey) pair.getPrivate();
// Write key pair files // Write key pair list
LogHelper.info("Writing RSA keypair files"); LogHelper.info("Writing RSA keypair list");
IOHelper.write(publicKeyFile, publicKey.getEncoded()); IOHelper.write(publicKeyFile, publicKey.getEncoded());
IOHelper.write(privateKeyFile, privateKey.getEncoded()); IOHelper.write(privateKeyFile, privateKey.getEncoded());
} }

View file

@ -42,7 +42,7 @@ public boolean allowDelete() {
} }
public void tryUnpack() throws IOException { 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("guard.zip", server.launcherBinary.guardDir);
UnpackHelper.unpackZipNoCheck("runtime.zip", server.launcherBinary.runtimeDir); UnpackHelper.unpackZipNoCheck("runtime.zip", server.launcherBinary.runtimeDir);
} }

View file

@ -10,8 +10,6 @@
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
import ru.gravit.launcher.profiles.ClientProfile; import ru.gravit.launcher.profiles.ClientProfile;
import ru.gravit.launcher.profiles.PlayerProfile; 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.Request;
import ru.gravit.launcher.request.update.LegacyLauncherRequest; import ru.gravit.launcher.request.update.LegacyLauncherRequest;
import ru.gravit.launcher.serialize.HInput; import ru.gravit.launcher.serialize.HInput;
@ -69,12 +67,6 @@ public static final class Params extends StreamObject {
@LauncherAPI @LauncherAPI
public final PlayerProfile pp; public final PlayerProfile pp;
@LauncherAPI @LauncherAPI
public final Set<OptionalFile> updateOptional;
@LauncherAPI
public final Set<OptionalArgs> optionalClientArgs;
@LauncherAPI
public final Set<OptionalArgs> optionalClassPath;
@LauncherAPI
public final String accessToken; public final String accessToken;
@LauncherAPI @LauncherAPI
public final boolean autoEnter; 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, public Params(byte[] launcherDigest, Path assetDir, Path clientDir, PlayerProfile pp, String accessToken,
boolean autoEnter, boolean fullScreen, int ram, int width, int height) { boolean autoEnter, boolean fullScreen, int ram, int width, int height) {
this.launcherDigest = launcherDigest.clone(); 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 // Client paths
this.assetDir = assetDir; this.assetDir = assetDir;
this.clientDir = clientDir; this.clientDir = clientDir;
@ -127,31 +107,6 @@ public Params(HInput input) throws Exception {
// Client paths // Client paths
assetDir = IOHelper.toPath(input.readString(0)); assetDir = IOHelper.toPath(input.readString(0));
clientDir = 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 // Client params
pp = new PlayerProfile(input); pp = new PlayerProfile(input);
byte[] encryptedAccessToken = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH); byte[] encryptedAccessToken = input.readByteArray(SecurityHelper.CRYPTO_MAX_LENGTH);
@ -171,24 +126,6 @@ public void write(HOutput output) throws IOException {
// Client paths // Client paths
output.writeString(assetDir.toString(), 0); output.writeString(assetDir.toString(), 0);
output.writeString(clientDir.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); pp.write(output);
try { try {
output.writeByteArray(SecurityHelper.encrypt(Launcher.getConfig().secretKeyClient.getBytes(), accessToken.getBytes()), SecurityHelper.CRYPTO_MAX_LENGTH); output.writeByteArray(SecurityHelper.encrypt(Launcher.getConfig().secretKeyClient.getBytes(), accessToken.getBytes()), SecurityHelper.CRYPTO_MAX_LENGTH);
@ -285,9 +222,7 @@ private static void addClientArgs(Collection<String> args, ClientProfile profile
Collections.addAll(args, "--server", profile.getServerAddress()); Collections.addAll(args, "--server", profile.getServerAddress());
Collections.addAll(args, "--port", Integer.toString(profile.getServerPort())); Collections.addAll(args, "--port", Integer.toString(profile.getServerPort()));
} }
for (OptionalArgs optionalArgs : params.optionalClientArgs) { profile.pushOptionalClientArgs(args);
if (optionalArgs.mark) Collections.addAll(args, optionalArgs.args);
}
// Add window size args // Add window size args
if (params.fullScreen) if (params.fullScreen)
Collections.addAll(args, "--fullscreen", Boolean.toString(true)); Collections.addAll(args, "--fullscreen", Boolean.toString(true));
@ -426,11 +361,7 @@ public static Process launch(
// Add classpath and main class // Add classpath and main class
String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString();
Collections.addAll(args, profile.getJvmArgs()); Collections.addAll(args, profile.getJvmArgs());
if (profile.getOptionalJVMArgs() != null) { profile.pushOptionalJvmArgs(args);
for (OptionalArgs addArgs : profile.getOptionalJVMArgs()) {
if (addArgs.mark) Collections.addAll(args, addArgs.args);
}
}
Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path Collections.addAll(args, "-Djava.library.path=".concat(params.clientDir.resolve(NATIVES_DIR).toString())); // Add Native Path
Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, "-javaagent:".concat(pathLauncher));
if (wrapper) if (wrapper)
@ -513,14 +444,12 @@ public static void main(String... args) throws Throwable {
for (Path classpathURL : classPath) { for (Path classpathURL : classPath) {
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());
} }
for (OptionalArgs optionalArgs : params.optionalClassPath) { profile.pushOptionalClassPath(cp -> {
if (!optionalArgs.mark) continue; LinkedList<Path> optionalClassPath = resolveClassPathList(params.clientDir, cp);
LinkedList<Path> optionalClassPath = resolveClassPathList(params.clientDir, optionalArgs.args);
for (Path classpathURL : optionalClassPath) { for (Path classpathURL : optionalClassPath) {
LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString()); LauncherAgent.addJVMClassPath(classpathURL.toAbsolutePath().toString());
} }
} });
URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath()); URL[] classpathurls = resolveClassPath(params.clientDir, profile.getClassPath());
classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader()); classLoader = new PublicURLClassLoader(classpathurls, ClassLoader.getSystemClassLoader());
Thread.currentThread().setContextClassLoader(classLoader); Thread.currentThread().setContextClassLoader(classLoader);
@ -536,10 +465,11 @@ public static void main(String... args) throws Throwable {
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object; HashedDir hdir = clientHDir.object;
for (OptionalFile s : Launcher.profile.getOptional()) { //for (OptionalFile s : Launcher.profile.getOptional()) {
if (params.updateOptional.contains(s)) s.mark = true; // if (params.updateOptional.contains(s)) s.mark = true;
else hdir.removeR(s.file); // else hdir.removeR(s.file);
} //}
Launcher.profile.pushOptionalFile(hdir,false);
verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest); verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest);
verifyHDir(params.clientDir, hdir, clientMatcher, digest); verifyHDir(params.clientDir, hdir, clientMatcher, digest);
Launcher.modulesManager.postInitModules(); Launcher.modulesManager.postInitModules();
@ -575,10 +505,11 @@ public void launchLocal(SignedObjectHolder<HashedDir> assetHDir, SignedObjectHol
// Verify current state of all dirs // Verify current state of all dirs
//verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest); //verifyHDir(IOHelper.JVM_DIR, jvmHDir.object, null, digest);
HashedDir hdir = clientHDir.object; HashedDir hdir = clientHDir.object;
for (OptionalFile s : Launcher.profile.getOptional()) { //for (OptionalFile s : Launcher.profile.getOptional()) {
if (params.updateOptional.contains(s)) s.mark = true; // if (params.updateOptional.contains(s)) s.mark = true;
else hdir.removeR(s.file); // else hdir.removeR(s.file);
} //}
Launcher.profile.pushOptionalFile(hdir,false);
verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest); verifyHDir(params.assetDir, assetHDir.object, assetMatcher, digest);
verifyHDir(params.clientDir, hdir, clientMatcher, digest); verifyHDir(params.clientDir, hdir, clientMatcher, digest);
Launcher.modulesManager.postInitModules(); Launcher.modulesManager.postInitModules();

View file

@ -224,7 +224,7 @@ private void deleteExtraDir(Path subDir, HashedDir subHDir, boolean flag) throws
String name = mapEntry.getKey(); String name = mapEntry.getKey();
Path path = subDir.resolve(name); Path path = subDir.resolve(name);
// Delete files and dirs based on type // Delete list and dirs based on type
HashedEntry entry = mapEntry.getValue(); HashedEntry entry = mapEntry.getValue();
HashedEntry.Type entryType = entry.getType(); HashedEntry.Type entryType = entry.getType();
switch (entryType) { switch (entryType) {
@ -308,7 +308,7 @@ protected SignedObjectHolder<HashedDir> requestDo(HInput input, HOutput output)
// Get diff between local and remote dir // Get diff between local and remote dir
SignedObjectHolder<HashedDir> remoteHDirHolder = new SignedObjectHolder<>(input, config.publicKey, HashedDir::new); SignedObjectHolder<HashedDir> remoteHDirHolder = new SignedObjectHolder<>(input, config.publicKey, HashedDir::new);
HashedDir hackHackedDir = remoteHDirHolder.object; 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); HashedDir.Diff diff = hackHackedDir.diff(localDir, matcher);
totalSize = diff.mismatch.size(); totalSize = diff.mismatch.size();
boolean compress = input.readBoolean(); boolean compress = input.readBoolean();

View file

@ -1,5 +1,6 @@
package ru.gravit.launcher.profiles; package ru.gravit.launcher.profiles;
import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
import ru.gravit.launcher.LauncherAPI; import ru.gravit.launcher.LauncherAPI;
import ru.gravit.launcher.hasher.FileNameMatcher; import ru.gravit.launcher.hasher.FileNameMatcher;
import ru.gravit.launcher.hasher.HashedDir; import ru.gravit.launcher.hasher.HashedDir;
@ -8,7 +9,9 @@
import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.IOHelper;
import ru.gravit.utils.helper.VerifyHelper; import ru.gravit.utils.helper.VerifyHelper;
import java.io.IOException;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.file.Path;
import java.util.*; import java.util.*;
public final class ClientProfile implements Comparable<ClientProfile> { public final class ClientProfile implements Comparable<ClientProfile> {
@ -217,8 +220,7 @@ public Collection<String> getShared() {
@LauncherAPI @LauncherAPI
public void markOptional(String name, OptionalType type) { public void markOptional(String name, OptionalType type) {
OptionalFile file = getOptionalFile(name, type); OptionalFile file = getOptionalFile(name, type);
if(file == null) if (file == null) {
{
throw new SecurityException(String.format("Optional %s not found in optionalList", name)); throw new SecurityException(String.format("Optional %s not found in optionalList", name));
} }
markOptional(file); markOptional(file);
@ -246,8 +248,7 @@ public void markOptional(OptionalFile file) {
@LauncherAPI @LauncherAPI
public void unmarkOptional(String name, OptionalType type) { public void unmarkOptional(String name, OptionalType type) {
OptionalFile file = getOptionalFile(name, type); OptionalFile file = getOptionalFile(name, type);
if(file == null) if (file == null) {
{
throw new SecurityException(String.format("Optional %s not found in optionalList", name)); throw new SecurityException(String.format("Optional %s not found in optionalList", name));
} }
unmarkOptional(file); 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) { for (OptionalFile opt : updateOptional) {
if (opt.type.equals(OptionalType.FILE) && !opt.mark) if (opt.type.equals(OptionalType.FILE) && !opt.mark) {
{ for (String file : opt.list)
for(String file : opt.files)
dir.removeR(file); dir.removeR(file);
} }
} }
} }
public void pushOptionalJvmArgs(Collection<String> jvmArgs1)
{
for (OptionalFile opt : updateOptional) {
if (opt.type.equals(OptionalType.JVMARGS) && opt.mark) {
jvmArgs1.addAll(Arrays.asList(opt.list));
}
}
}
public void pushOptionalClientArgs(Collection<String> 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 @LauncherAPI
public int getServerPort() { public int getServerPort() {
return serverPort; return serverPort;

View file

@ -7,7 +7,7 @@
public class OptionalFile { public class OptionalFile {
@LauncherAPI @LauncherAPI
public String[] files; public String[] list;
@LauncherAPI @LauncherAPI
public OptionalType type; public OptionalType type;
@LauncherAPI @LauncherAPI