diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 559103ca..d4de79c9 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -3,6 +3,8 @@ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; +import java.lang.ProcessBuilder.Redirect; +import java.lang.management.ManagementFactory; import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.SocketAddress; @@ -10,6 +12,7 @@ import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.security.KeyPair; @@ -18,6 +21,7 @@ import java.security.spec.InvalidKeySpecException; import java.time.Duration; import java.time.Instant; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -71,6 +75,7 @@ import ru.gravit.launchserver.texture.RequestTextureProvider; import ru.gravit.launchserver.texture.TextureProvider; import ru.gravit.utils.helper.CommonHelper; +import ru.gravit.utils.helper.EnvHelper; import ru.gravit.utils.helper.IOHelper; import ru.gravit.utils.helper.JVMHelper; import ru.gravit.utils.helper.LogHelper; @@ -240,7 +245,7 @@ public static void main(String... args) throws Throwable { // Start LaunchServer Instant start = Instant.now(); try { - new LaunchServer(IOHelper.WORKING_DIR).run(); + new LaunchServer(IOHelper.WORKING_DIR, args).run(); } catch (Throwable exc) { LogHelper.error(exc); return; @@ -253,7 +258,8 @@ public static void main(String... args) throws Throwable { public final Path dir; - + public final List args; + public final Path configFile; public final Path publicKeyFile; @@ -317,9 +323,9 @@ public static void main(String... args) throws Throwable { public static Gson gson; public static GsonBuilder gsonBuilder; - public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { - // Setup config locations + public LaunchServer(Path dir, String[] args) throws IOException, InvalidKeySpecException { this.dir = dir; + this.args = Arrays.asList(args); configFile = dir.resolve("LaunchServer.conf"); publicKeyFile = dir.resolve("public.key"); privateKeyFile = dir.resolve("private.key"); @@ -679,4 +685,27 @@ public void syncUpdatesDir(Collection dirs) throws IOException { } updatesDirMap = Collections.unmodifiableMap(newUpdatesDirMap); } + + public void restart() { + ProcessBuilder builder = new ProcessBuilder(); + List args = new ArrayList<>(); + args.add(IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))).toString()); + args.addAll(ManagementFactory.getRuntimeMXBean().getInputArguments()); + args.addAll(args); + EnvHelper.addEnv(builder); + builder.directory(this.dir.toFile()); + builder.inheritIO(); + builder.redirectErrorStream(true); + builder.redirectOutput(Redirect.PIPE); + try { + builder.start(); + } catch (IOException e) { + LogHelper.error(e); + } + } + + public void fullyRestart() { + server.restart(); + JVMHelper.RUNTIME.exit(0); + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/UpdateManager.java b/LaunchServer/src/main/java/ru/gravit/launchserver/UpdateManager.java index 2a3ba4d3..15537653 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/UpdateManager.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/UpdateManager.java @@ -3,7 +3,6 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.Socket; -import java.net.URL; import java.util.Timer; import java.util.TimerTask; diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RestartCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RestartCommand.java new file mode 100644 index 00000000..fa54bbaa --- /dev/null +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/RestartCommand.java @@ -0,0 +1,26 @@ +package ru.gravit.launchserver.command.basic; + +import ru.gravit.launchserver.LaunchServer; +import ru.gravit.launchserver.command.Command; + +public final class RestartCommand extends Command { + public RestartCommand(LaunchServer server) { + super(server); + } + + @Override + public String getArgsDescription() { + return null; + } + + @Override + public String getUsageDescription() { + return "Stop LaunchServer"; + } + + @Override + @SuppressWarnings("CallToSystemExit") + public void invoke(String... args) { + server.fullyRestart(); + } +} \ No newline at end of file diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java index ada44e61..885fcdc3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/handler/CommandHandler.java @@ -29,6 +29,7 @@ import ru.gravit.launchserver.command.basic.RebindCommand; import ru.gravit.launchserver.command.basic.RegenProguardDictCommand; import ru.gravit.launchserver.command.basic.RemoveMappingsProguardCommand; +import ru.gravit.launchserver.command.basic.RestartCommand; import ru.gravit.launchserver.command.basic.StopCommand; import ru.gravit.launchserver.command.basic.TestCommand; import ru.gravit.launchserver.command.basic.VersionCommand; @@ -105,6 +106,7 @@ protected CommandHandler(LaunchServer server) { registerCommand("version", new VersionCommand(server)); registerCommand("build", new BuildCommand(server)); registerCommand("stop", new StopCommand(server)); + registerCommand("restart", new RestartCommand(server)); registerCommand("rebind", new RebindCommand(server)); registerCommand("debug", new DebugCommand(server)); registerCommand("clear", new ClearCommand(server)); diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/NodeTransformer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/NodeTransformer.java index f90f0a1d..5deb8d00 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/NodeTransformer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/manangers/NodeTransformer.java @@ -7,6 +7,7 @@ import org.objectweb.asm.ClassWriter; import org.objectweb.asm.tree.ClassNode; +import ru.gravit.launcher.LauncherConfig; import ru.gravit.launchserver.asm.SafeClassWriter; import ru.gravit.launchserver.binary.JARLauncherBinary; import ru.gravit.launchserver.manangers.hook.BuildHookManager.Transformer; @@ -31,7 +32,7 @@ public NodeTransformer() { public byte[] transform(byte[] input, String classname, JARLauncherBinary data) { ClassReader cr = new ClassReader(input); ClassNode cn = new ClassNode(); - cr.accept(cn, ClassReader.SKIP_DEBUG); + cr.accept(cn, data.server.config.env.equals(LauncherConfig.LauncherEnvironment.PROD) || data.server.config.env.equals(LauncherConfig.LauncherEnvironment.STD) ? ClassReader.SKIP_DEBUG : 0); for (ClassNodeTransformer tr : transLst) tr.transform(cn, classname, data); ClassWriter cw = new SafeClassWriter(data.reader, ClassWriter.COMPUTE_MAXS); cn.accept(cw); 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 ed888a74..da2f81ad 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java +++ b/Launcher/src/main/java/ru/gravit/launcher/client/ClientLauncher.java @@ -2,8 +2,6 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; import ru.gravit.launcher.*; import ru.gravit.launcher.hasher.DirWatcher; import ru.gravit.launcher.hasher.FileNameMatcher;