mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-03-30 21:18:17 +03:00
[FEATURE] ServerWrapperSetup Agent
This commit is contained in:
parent
25d88ba30d
commit
6da27bdf99
3 changed files with 15 additions and 7 deletions
|
@ -17,7 +17,6 @@
|
||||||
|
|
||||||
public class ServerAgent {
|
public class ServerAgent {
|
||||||
public static final Boolean isAutoloadLibraries = Boolean.getBoolean(System.getProperty("serverwrapper,agentlibrariesload", "false"));
|
public static final Boolean isAutoloadLibraries = Boolean.getBoolean(System.getProperty("serverwrapper,agentlibrariesload", "false"));
|
||||||
public static final Boolean isAgentProxy = Boolean.getBoolean(System.getProperty("serverwrapper,agentproxy", "false"));
|
|
||||||
public static Instrumentation inst = null;
|
public static Instrumentation inst = null;
|
||||||
private static boolean isAgentStarted = false;
|
private static boolean isAgentStarted = false;
|
||||||
|
|
||||||
|
@ -47,8 +46,8 @@ public static void premain(String agentArgument, Instrumentation instrumentation
|
||||||
Path libraries = Paths.get("libraries");
|
Path libraries = Paths.get("libraries");
|
||||||
if (IOHelper.exists(libraries)) loadLibraries(libraries);
|
if (IOHelper.exists(libraries)) loadLibraries(libraries);
|
||||||
}
|
}
|
||||||
if (isAgentProxy) {
|
String proxyClassName = System.getProperty("serverwrapper.agentproxy", null);
|
||||||
String proxyClassName = System.getProperty("serverwrapper.agentproxyclass");
|
if (proxyClassName != null) {
|
||||||
Class<?> proxyClass;
|
Class<?> proxyClass;
|
||||||
try {
|
try {
|
||||||
proxyClass = Class.forName(proxyClassName);
|
proxyClass = Class.forName(proxyClassName);
|
||||||
|
|
|
@ -249,7 +249,6 @@ public Config getDefaultConfig() {
|
||||||
newConfig.stopOnError = true;
|
newConfig.stopOnError = true;
|
||||||
newConfig.reconnectCount = 10;
|
newConfig.reconnectCount = 10;
|
||||||
newConfig.reconnectSleep = 1000;
|
newConfig.reconnectSleep = 1000;
|
||||||
newConfig.websocket = new WebSocketConf();
|
|
||||||
newConfig.address = "ws://localhost:9274/api";
|
newConfig.address = "ws://localhost:9274/api";
|
||||||
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
newConfig.env = LauncherConfig.LauncherEnvironment.STD;
|
||||||
return newConfig;
|
return newConfig;
|
||||||
|
@ -261,7 +260,6 @@ public static final class Config {
|
||||||
public String projectname;
|
public String projectname;
|
||||||
public String address;
|
public String address;
|
||||||
public String serverName;
|
public String serverName;
|
||||||
public WebSocketConf websocket;
|
|
||||||
public int reconnectCount;
|
public int reconnectCount;
|
||||||
public int reconnectSleep;
|
public int reconnectSleep;
|
||||||
public boolean customClassPath;
|
public boolean customClassPath;
|
||||||
|
|
|
@ -29,11 +29,13 @@ public void run() throws IOException {
|
||||||
String jarName = commands.commandHandler.readLine();
|
String jarName = commands.commandHandler.readLine();
|
||||||
Path jarPath = Paths.get(jarName);
|
Path jarPath = Paths.get(jarName);
|
||||||
String mainClassName;
|
String mainClassName;
|
||||||
|
String agentClassName;
|
||||||
try (JarFile file = new JarFile(jarPath.toFile())) {
|
try (JarFile file = new JarFile(jarPath.toFile())) {
|
||||||
URL jarURL = jarPath.toUri().toURL();
|
URL jarURL = jarPath.toUri().toURL();
|
||||||
urlClassLoader = new PublicURLClassLoader(new URL[]{jarURL});
|
urlClassLoader = new PublicURLClassLoader(new URL[]{jarURL});
|
||||||
LogHelper.info("Check server jar MainClass");
|
LogHelper.info("Check server jar MainClass");
|
||||||
mainClassName = file.getManifest().getMainAttributes().getValue("Main-Class");
|
mainClassName = file.getManifest().getMainAttributes().getValue("Main-Class");
|
||||||
|
agentClassName = file.getManifest().getMainAttributes().getValue("Premain-Class");
|
||||||
if (mainClassName == null) {
|
if (mainClassName == null) {
|
||||||
LogHelper.error("Main-Class not found in MANIFEST");
|
LogHelper.error("Main-Class not found in MANIFEST");
|
||||||
return;
|
return;
|
||||||
|
@ -46,6 +48,9 @@ public void run() throws IOException {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LogHelper.info("Found MainClass %s", mainClassName);
|
LogHelper.info("Found MainClass %s", mainClassName);
|
||||||
|
if(agentClassName != null) {
|
||||||
|
LogHelper.info("Found PremainClass %s", agentClassName);
|
||||||
|
}
|
||||||
System.out.println("Print your server name:");
|
System.out.println("Print your server name:");
|
||||||
wrapper.config.serverName = commands.commandHandler.readLine();
|
wrapper.config.serverName = commands.commandHandler.readLine();
|
||||||
System.out.println("Print launchserver websocket host( ws://host:port/api ):");
|
System.out.println("Print launchserver websocket host( ws://host:port/api ):");
|
||||||
|
@ -82,14 +87,20 @@ public void run() throws IOException {
|
||||||
ServerWrapper.modulesManager.invokeEvent(new ServerWrapperSetupEvent(this));
|
ServerWrapper.modulesManager.invokeEvent(new ServerWrapperSetupEvent(this));
|
||||||
try (Writer writer = IOHelper.newWriter(startScript)) {
|
try (Writer writer = IOHelper.newWriter(startScript)) {
|
||||||
if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) {
|
if (JVMHelper.OS_TYPE == JVMHelper.OS.LINUX) {
|
||||||
writer.append("#!/bin/sh\n\n");
|
writer.append("#!/bin/bash\n\n");
|
||||||
}
|
}
|
||||||
writer.append("java ");
|
writer.append(IOHelper.resolveJavaBin(Paths.get(System.getProperty("java.home"))).toAbsolutePath().toString());
|
||||||
|
writer.append(" ");
|
||||||
if (mainClassName.contains("bungee")) {
|
if (mainClassName.contains("bungee")) {
|
||||||
LogHelper.info("Found BungeeCord mainclass. Modules dir change to modules_srv");
|
LogHelper.info("Found BungeeCord mainclass. Modules dir change to modules_srv");
|
||||||
writer.append(JVMHelper.jvmProperty("serverwrapper.modulesDir", "modules_srv"));
|
writer.append(JVMHelper.jvmProperty("serverwrapper.modulesDir", "modules_srv"));
|
||||||
writer.append(" ");
|
writer.append(" ");
|
||||||
}
|
}
|
||||||
|
if(agentClassName != null) {
|
||||||
|
writer.append("-javaagent:ServerWrapper.jar ");
|
||||||
|
writer.append("-Dserverwrapper.agentproxy=".concat(agentClassName));
|
||||||
|
writer.append(" ");
|
||||||
|
}
|
||||||
//More args
|
//More args
|
||||||
writer.append("-cp ");
|
writer.append("-cp ");
|
||||||
String pathServerWrapper = IOHelper.getCodeSource(ServerWrapper.class).getFileName().toString();
|
String pathServerWrapper = IOHelper.getCodeSource(ServerWrapper.class).getFileName().toString();
|
||||||
|
|
Loading…
Reference in a new issue