diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 88af9d57..2d47fa2e 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java @@ -2,7 +2,9 @@ import java.io.BufferedReader; import java.io.BufferedWriter; +import java.io.File; import java.io.IOException; +import java.lang.ProcessBuilder.Redirect; import java.net.InetSocketAddress; import java.net.MalformedURLException; import java.net.SocketAddress; @@ -18,6 +20,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; @@ -88,7 +91,7 @@ public static final class Config { public String projectName; public String[] mirrors; - + public String binaryName; public LauncherConfig.LauncherEnvironment env; @@ -133,6 +136,8 @@ public static final class Config { public boolean isWarningMissArchJava; + public String startScript; + public String getAddress() { return address; @@ -236,7 +241,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; @@ -249,7 +254,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; @@ -300,7 +306,6 @@ public static void main(String... args) throws Throwable { public final CommandHandler commandHandler; - public final ServerSocketHandler serverSocketHandler; private final AtomicBoolean started = new AtomicBoolean(false); @@ -313,9 +318,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"); @@ -398,7 +403,6 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { reconfigurableManager = new ReconfigurableManager(); socketHookManager = new SocketHookManager(); authHookManager = new AuthHookManager(); - GarbageManager.registerNeedGC(sessionManager); GarbageManager.registerNeedGC(limiter); if(config.permissionsHandler instanceof Reloadable) @@ -552,6 +556,7 @@ private void generateConfigIfNotExists() throws IOException { newConfig.launch4j.productVer = newConfig.launch4j.fileVer; newConfig.buildPostTransform = new PostBuildTransformConf(); newConfig.env = LauncherConfig.LauncherEnvironment.STD; + newConfig.startScript = "." + File.separator + "start.sh"; newConfig.authHandler = new MemoryAuthHandler(); newConfig.hwidHandler = new AcceptHWIDHandler(); @@ -672,4 +677,25 @@ public void syncUpdatesDir(Collection dirs) throws IOException { } updatesDirMap = Collections.unmodifiableMap(newUpdatesDirMap); } + + public void restart() { + ProcessBuilder builder = new ProcessBuilder(); + List args = new ArrayList<>(); + if (config.startScript != null) args.add(config.startScript); + else throw new IllegalArgumentException ("Please create start script and link it as startScript in config."); + 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() { + restart(); + JVMHelper.RUNTIME.exit(0); + } } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java index 974f7ddd..362fd2ab 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/auth/handler/AuthHandler.java @@ -6,7 +6,6 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; -import ru.gravit.launchserver.LaunchServer; import ru.gravit.launchserver.auth.AuthException; import ru.gravit.launchserver.auth.provider.AuthProviderResult; import ru.gravit.utils.helper.VerifyHelper; @@ -14,7 +13,6 @@ public abstract class AuthHandler implements AutoCloseable { private static final Map> AUTH_HANDLERS = new ConcurrentHashMap<>(4); private static boolean registredHandl = false; - private transient LaunchServer server = LaunchServer.server; public static UUID authError(String message) throws AuthException { 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..4af32282 --- /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 "Restart 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/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg index 76431adc..dff8f626 100644 --- a/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg +++ b/LaunchServer/src/main/resources/ru/gravit/launchserver/defaults/config.cfg @@ -1,5 +1,5 @@ { - "port": 7420, + "port": 7240, "authHandler": { "type": "memory" }, 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 e61306d3..c795199f 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; diff --git a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java index ae27933b..41cc81d1 100644 --- a/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java +++ b/libLauncher/src/main/java/ru/gravit/launcher/Launcher.java @@ -58,11 +58,11 @@ public final class Launcher { public static final String CONFIG_SCRIPT_FILE = "config.js"; private static final Pattern UUID_PATTERN = Pattern.compile("-", Pattern.LITERAL); - public static int MAJOR = 4; - public static int MINOR = 1; - public static int PATCH = 0; - public static int BUILD = 7; - public static Version.Type RELEASE = Version.Type.BETA; + public static final int MAJOR = 4; + public static final int MINOR = 1; + public static final int PATCH = 0; + public static final int BUILD = 7; + public static final Version.Type RELEASE = Version.Type.BETA; public static GsonBuilder gsonBuilder; public static Gson gson;