[FEATURE] Add ServerWrapperInlineInitializer

This commit is contained in:
Gravita 2025-05-04 19:38:34 +07:00
parent 76570ddbe5
commit b41e8db336
2 changed files with 42 additions and 23 deletions

View file

@ -103,31 +103,20 @@ public void getProfiles() throws Exception {
} }
} }
public void run(String... args) throws Throwable {
public void initialize() throws Exception {
initGson(); initGson();
AuthRequest.registerProviders(); AuthRequest.registerProviders();
GetAvailabilityAuthRequest.registerProviders(); GetAvailabilityAuthRequest.registerProviders();
OptionalAction.registerProviders(); OptionalAction.registerProviders();
OptionalTrigger.registerProviders(); OptionalTrigger.registerProviders();
if (args.length > 0 && args[0].equalsIgnoreCase("setup") && !disableSetup) {
LogHelper.debug("Read ServerWrapperConfig.json"); LogHelper.debug("Read ServerWrapperConfig.json");
loadConfig(); loadConfig();
ServerWrapperSetup setup = new ServerWrapperSetup();
setup.run();
System.exit(0);
} }
if (args.length > 1 && args[0].equalsIgnoreCase("installAuthlib") && !disableSetup) {
LogHelper.debug("Read ServerWrapperConfig.json"); public void connect() throws Exception {
loadConfig();
InstallAuthlib command = new InstallAuthlib();
command. run(args[1]);
System.exit(0);
}
LogHelper.debug("Read ServerWrapperConfig.json");
loadConfig();
config.applyEnv(); config.applyEnv();
updateLauncherConfig(); updateLauncherConfig();
Launcher.applyLauncherEnv(Objects.requireNonNullElse(config.env, LauncherConfig.LauncherEnvironment.STD));
StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get(); StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get();
service.reconnectCallback = () -> service.reconnectCallback = () ->
{ {
@ -139,11 +128,6 @@ public void run(String... args) throws Throwable {
LogHelper.error(e); LogHelper.error(e);
} }
}; };
if(config.properties != null) {
for(Map.Entry<String, String> e : config.properties.entrySet()) {
System.setProperty(e.getKey(), e.getValue());
}
}
Request.setRequestService(service); Request.setRequestService(service);
if (config.logFile != null) LogHelper.addOutput(IOHelper.newWriter(Paths.get(config.logFile), true)); if (config.logFile != null) LogHelper.addOutput(IOHelper.newWriter(Paths.get(config.logFile), true));
{ {
@ -156,6 +140,34 @@ public void run(String... args) throws Throwable {
if(config.encodedServerEcPublicKey != null) { if(config.encodedServerEcPublicKey != null) {
KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey); KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey);
} }
ClientService.nativePath = config.nativesDir;
ConfigService.serverName = config.serverName;
}
public void run(String... args) throws Throwable {
initialize();
if (args.length > 0 && args[0].equalsIgnoreCase("setup") && !disableSetup) {
ServerWrapperSetup setup = new ServerWrapperSetup();
setup.run();
System.exit(0);
}
if (args.length > 1 && args[0].equalsIgnoreCase("installAuthlib") && !disableSetup) {
InstallAuthlib command = new InstallAuthlib();
command. run(args[1]);
System.exit(0);
}
connect();
if(config.properties != null) {
for(Map.Entry<String, String> e : config.properties.entrySet()) {
System.setProperty(e.getKey(), e.getValue());
}
}
if(config.encodedServerRsaPublicKey != null) {
KeyService.serverRsaPublicKey = SecurityHelper.toPublicRSAKey(config.encodedServerRsaPublicKey);
}
if(config.encodedServerEcPublicKey != null) {
KeyService.serverEcPublicKey = SecurityHelper.toPublicECDSAKey(config.encodedServerEcPublicKey);
}
String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass; String classname = (config.mainclass == null || config.mainclass.isEmpty()) ? args[0] : config.mainclass;
if (classname.isEmpty()) { if (classname.isEmpty()) {
LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.json or first commandline argument"); LogHelper.error("MainClass not found. Please set MainClass for ServerWrapper.json or first commandline argument");
@ -185,8 +197,6 @@ public void run(String... args) throws Throwable {
System.arraycopy(args, 1, real_args, 0, args.length - 1); System.arraycopy(args, 1, real_args, 0, args.length - 1);
} else real_args = args; } else real_args = args;
Launch launch; Launch launch;
ClientService.nativePath = config.nativesDir;
ConfigService.serverName = config.serverName;
if(config.loadNatives != null) { if(config.loadNatives != null) {
for(String e : config.loadNatives) { for(String e : config.loadNatives) {
System.load(Paths.get(config.nativesDir).resolve(ClientService.findLibrary(e)).toAbsolutePath().toString()); System.load(Paths.get(config.nativesDir).resolve(ClientService.findLibrary(e)).toAbsolutePath().toString());

View file

@ -0,0 +1,9 @@
package pro.gravit.launcher.server;
public class ServerWrapperInlineInitializer {
public static void initialize() throws Exception {
ServerWrapper.wrapper = new ServerWrapper(ServerWrapper.Config.class, ServerWrapper.configFile);
ServerWrapper.wrapper.initialize();
ServerWrapper.wrapper.connect();
}
}