diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java b/LaunchServer/src/main/java/ru/gravit/launchserver/LaunchServer.java index 58237d2b..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"); @@ -374,7 +379,6 @@ public LaunchServer(Path dir) throws IOException, InvalidKeySpecException { modulesManager.autoload(dir.resolve("modules")); modulesManager.preInitModules(); initGson(); - LogHelper.setStacktraceEnabled(true); // Read LaunchServer config generateConfigIfNotExists(); @@ -399,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) @@ -553,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(); @@ -673,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/asm/ClassMetadataReader.java b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java index 53cf3e89..c1f07859 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/asm/ClassMetadataReader.java @@ -23,7 +23,7 @@ private class CheckSuperClassVisitor extends ClassVisitor { String superClassName; public CheckSuperClassVisitor() { - super(Opcodes.ASM5); + super(Opcodes.ASM7); } @Override @@ -57,10 +57,13 @@ public void acceptVisitor(String className, ClassVisitor visitor) throws IOExcep public byte[] getClassData(String className) throws IOException { for (JarFile f : cp) { - if (f.getEntry(className + ".class") != null) + if (f.getEntry(className + ".class") != null) { + byte[] bytes = null; try (InputStream in = f.getInputStream(f.getEntry(className + ".class"))) { - return IOHelper.read(in); + bytes = IOHelper.read(in); } + return bytes; + } } return IOHelper.read(IOHelper.getResourceURL(className + ".class")); } 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/DebugCommand.java b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java index 19adc8b6..89c6a12a 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/command/basic/DebugCommand.java @@ -11,22 +11,29 @@ public DebugCommand(LaunchServer server) { @Override public String getArgsDescription() { - return "[true/false]"; + return "[true/false] (true/false)"; } @Override public String getUsageDescription() { - return "Enable or disable debug logging at runtime"; + return "Enable or disable debug and stacktrace logging at runtime"; } @Override public void invoke(String... args) { - boolean newValue; + boolean newValue, newTraceValue; if (args.length >= 1) { newValue = Boolean.parseBoolean(args[0]); + if(args.length >= 2) newTraceValue = Boolean.parseBoolean(args[1]); + else newTraceValue = newValue; LogHelper.setDebugEnabled(newValue); + LogHelper.setStacktraceEnabled(newTraceValue); } else + { newValue = LogHelper.isDebugEnabled(); + newTraceValue = LogHelper.isStacktraceEnabled(); + } LogHelper.subInfo("Debug enabled: " + newValue); + LogHelper.subInfo("Stacktrace enabled: " + newTraceValue); } } 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 59dbd2b4..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,9 +32,9 @@ 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_FRAMES); + ClassWriter cw = new SafeClassWriter(data.reader, ClassWriter.COMPUTE_MAXS); cn.accept(cw); return cw.toByteArray(); } diff --git a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java index f80075e6..93fb1ce3 100644 --- a/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java +++ b/LaunchServer/src/main/java/ru/gravit/launchserver/socket/ServerSocketHandler.java @@ -27,7 +27,7 @@ public interface Listener { void onDisconnect(Exception e); - boolean onHandshake(long session, Integer type); + boolean onHandshake(long session, int type); } private static final ThreadFactory THREAD_FACTORY = r -> CommonHelper.newThread("Network Thread", true, r); @@ -76,7 +76,7 @@ public void close() { listener.onDisconnect(e); } - /*package*/ boolean onHandshake(long session, Integer type) { + /*package*/ boolean onHandshake(long session, int type) { return listener == null || listener.onHandshake(session, type); } 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/ClientLauncherWrapper.java b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java index 932dc823..c8b4c21f 100644 --- a/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java +++ b/Launcher/src/main/java/ru/gravit/launcher/ClientLauncherWrapper.java @@ -30,6 +30,7 @@ public static void main(String[] arguments) throws IOException, InterruptedExcep args.add(javaBin.toString()); String pathLauncher = IOHelper.getCodeSource(ClientLauncher.class).toString(); args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); + args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); Collections.addAll(args, "-javaagent:".concat(pathLauncher)); Collections.addAll(args, "-cp"); Collections.addAll(args, pathLauncher); 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..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; @@ -358,6 +356,7 @@ public static Process launch( args.add("-Xmx" + params.ram + 'M'); } args.add(JVMHelper.jvmProperty(LogHelper.DEBUG_PROPERTY, Boolean.toString(LogHelper.isDebugEnabled()))); + args.add(JVMHelper.jvmProperty(LogHelper.STACKTRACE_PROPERTY, Boolean.toString(LogHelper.isStacktraceEnabled()))); if (LauncherConfig.ADDRESS_OVERRIDE != null) args.add(JVMHelper.jvmProperty(LauncherConfig.ADDRESS_OVERRIDE_PROPERTY, LauncherConfig.ADDRESS_OVERRIDE)); if (JVMHelper.OS_TYPE == OS.MUSTDIE) { diff --git a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java index e42b62a7..8fcdeada 100644 --- a/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java +++ b/ServerWrapper/src/main/java/ru/gravit/launcher/server/ServerWrapper.java @@ -87,6 +87,7 @@ public static void main(String[] args) throws Throwable { modulesManager.preInitModules(); LogHelper.debug("Read ServerWrapperConfig.json"); gsonBuiler = new GsonBuilder(); + gsonBuiler.setPrettyPrinting(); gson = gsonBuiler.create(); generateConfigIfNotExists(); try(Reader reader = IOHelper.newReader(configFile)) @@ -99,7 +100,7 @@ public static void main(String[] args) throws Throwable { else CommonHelper.newThread("Server Auth Thread", true, () -> ServerWrapper.loopAuth(wrapper, config.reconnectCount, config.reconnectSleep)); modulesManager.initModules(); - String classname = config.mainclass.isEmpty() ? args[0] : config.mainclass; + String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass; if (classname.length() == 0) { LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.cfg or first commandline argument"); } @@ -152,6 +153,7 @@ private static void generateConfigIfNotExists() throws IOException { newConfig.port = 7240; newConfig.login = "login"; newConfig.password = "password"; + newConfig.mainclass = ""; //try(Reader reader = IOHelper.newReader(IOHelper.getResourceURL("ru/gravit/launcher/server/ServerWrapper.cfg"))) //{ // newConfig = gson.fromJson(reader,Config.class); 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; diff --git a/modules b/modules index eec958f2..ec143160 160000 --- a/modules +++ b/modules @@ -1 +1 @@ -Subproject commit eec958f2c5edbc7c053686ab7cebaab8dbca2778 +Subproject commit ec1431605c4951ace5cbd2ab392b67cea25bddd5