From 30cd1f21f00695fcae00cb1a7771496c25e7c83c Mon Sep 17 00:00:00 2001 From: Gravit Date: Fri, 3 Apr 2020 17:44:25 +0700 Subject: [PATCH] [FEATURE] ClientProcessBuilder events --- .../launcher/client/ClientLauncherProcess.java | 13 ++++++++----- .../ClientProcessBuilderParamsWrittedEvent.java | 12 ++++++++++++ .../request/websockets/StdWebSocketService.java | 4 ++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderParamsWrittedEvent.java diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java index a1211037..a1c7ad02 100644 --- a/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java +++ b/Launcher/src/main/java/pro/gravit/launcher/client/ClientLauncherProcess.java @@ -3,8 +3,10 @@ import pro.gravit.launcher.Launcher; import pro.gravit.launcher.LauncherEngine; import pro.gravit.launcher.LauncherNetworkAPI; -import pro.gravit.launcher.guard.LauncherGuardInterface; -import pro.gravit.launcher.guard.LauncherGuardManager; +import pro.gravit.launcher.client.events.client.ClientProcessBuilderCreateEvent; +import pro.gravit.launcher.client.events.client.ClientProcessBuilderLaunchedEvent; +import pro.gravit.launcher.client.events.client.ClientProcessBuilderParamsWrittedEvent; +import pro.gravit.launcher.client.events.client.ClientProcessBuilderPreLaunchEvent; import pro.gravit.launcher.hasher.HashedDir; import pro.gravit.launcher.profiles.ClientProfile; import pro.gravit.launcher.profiles.PlayerProfile; @@ -13,10 +15,7 @@ import pro.gravit.utils.Version; import pro.gravit.utils.helper.*; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.OutputStream; -import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import java.net.SocketAddress; @@ -87,6 +86,7 @@ private void applyClientProfile() this.jvmArgs.add("-Xmx" + params.ram + 'M'); } this.params.session = Request.getSession(); + LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderCreateEvent(this)); } @@ -215,6 +215,7 @@ private void addModernClientArgs(Collection args) { public void start(boolean pipeOutput) throws IOException, InterruptedException { if(isStarted) throw new IllegalStateException("Process already started"); if(LauncherEngine.guard != null) LauncherEngine.guard.applyGuardParams(this); + LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderPreLaunchEvent(this)); List processArgs = new LinkedList<>(); processArgs.add(executeFile.toString()); processArgs.addAll(jvmArgs); @@ -243,6 +244,7 @@ public void start(boolean pipeOutput) throws IOException, InterruptedException { processBuilder.redirectOutput(ProcessBuilder.Redirect.PIPE); } process = processBuilder.start(); + LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderLaunchedEvent(this)); isStarted = true; } public void runWriteParams(SocketAddress address) throws IOException @@ -265,6 +267,7 @@ public void runWriteParams(SocketAddress address) throws IOException params.javaHDir.write(output); } } + LauncherEngine.modulesManager.invokeEvent(new ClientProcessBuilderParamsWrittedEvent(this)); } public Process getProcess() { diff --git a/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderParamsWrittedEvent.java b/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderParamsWrittedEvent.java new file mode 100644 index 00000000..bb535568 --- /dev/null +++ b/Launcher/src/main/java/pro/gravit/launcher/client/events/client/ClientProcessBuilderParamsWrittedEvent.java @@ -0,0 +1,12 @@ +package pro.gravit.launcher.client.events.client; + +import pro.gravit.launcher.client.ClientLauncherProcess; +import pro.gravit.launcher.modules.LauncherModule; + +public class ClientProcessBuilderParamsWrittedEvent extends LauncherModule.Event { + public final ClientLauncherProcess process; + + public ClientProcessBuilderParamsWrittedEvent(ClientLauncherProcess process) { + this.process = process; + } +} diff --git a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java index dfb5eecf..0987f911 100644 --- a/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java +++ b/LauncherAPI/src/main/java/pro/gravit/launcher/request/websockets/StdWebSocketService.java @@ -25,6 +25,10 @@ public void registerEventHandler(EventHandler handler) { eventHandlers.add(handler); } + public void unregisterEventHandler(EventHandler handler) + { + eventHandlers.remove(handler); + } public void processEventHandlers(T event) { for(EventHandler handler : eventHandlers)