mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-01-09 09:09:46 +03:00
[FEATURE] ParamsWriter
This commit is contained in:
parent
a06014837d
commit
c3fccc141f
3 changed files with 54 additions and 17 deletions
|
@ -4,6 +4,8 @@
|
||||||
import pro.gravit.launcher.api.AuthService;
|
import pro.gravit.launcher.api.AuthService;
|
||||||
import pro.gravit.launcher.api.ClientService;
|
import pro.gravit.launcher.api.ClientService;
|
||||||
import pro.gravit.launcher.client.events.client.*;
|
import pro.gravit.launcher.client.events.client.*;
|
||||||
|
import pro.gravit.launcher.client.params.ParamsWriter;
|
||||||
|
import pro.gravit.launcher.client.params.SocketParamsWriter;
|
||||||
import pro.gravit.launcher.events.request.ProfileByUUIDRequestEvent;
|
import pro.gravit.launcher.events.request.ProfileByUUIDRequestEvent;
|
||||||
import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
|
import pro.gravit.launcher.events.request.ProfileByUsernameRequestEvent;
|
||||||
import pro.gravit.launcher.guard.LauncherGuardManager;
|
import pro.gravit.launcher.guard.LauncherGuardManager;
|
||||||
|
@ -55,22 +57,6 @@
|
||||||
public class ClientLauncherEntryPoint {
|
public class ClientLauncherEntryPoint {
|
||||||
private static ClassLoader classLoader;
|
private static ClassLoader classLoader;
|
||||||
|
|
||||||
private static ClientLauncherProcess.ClientParams readParams(SocketAddress address) throws IOException {
|
|
||||||
try (Socket socket = IOHelper.newSocket()) {
|
|
||||||
socket.connect(address);
|
|
||||||
try (HInput input = new HInput(socket.getInputStream())) {
|
|
||||||
byte[] serialized = input.readByteArray(0);
|
|
||||||
ClientLauncherProcess.ClientParams params = Launcher.gsonManager.gson.fromJson(IOHelper.decode(serialized), ClientLauncherProcess.ClientParams.class);
|
|
||||||
params.clientHDir = new HashedDir(input);
|
|
||||||
params.assetHDir = new HashedDir(input);
|
|
||||||
boolean isNeedReadJavaDir = input.readBoolean();
|
|
||||||
if (isNeedReadJavaDir)
|
|
||||||
params.javaHDir = new HashedDir(input);
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Throwable {
|
public static void main(String[] args) throws Throwable {
|
||||||
LauncherEngine engine = LauncherEngine.clientInstance();
|
LauncherEngine engine = LauncherEngine.clientInstance();
|
||||||
JVMHelper.verifySystemProperties(ClientLauncherEntryPoint.class, true);
|
JVMHelper.verifySystemProperties(ClientLauncherEntryPoint.class, true);
|
||||||
|
@ -90,7 +76,8 @@ public static void main(String[] args) throws Throwable {
|
||||||
engine.readKeys();
|
engine.readKeys();
|
||||||
LauncherGuardManager.initGuard(true);
|
LauncherGuardManager.initGuard(true);
|
||||||
LogHelper.debug("Reading ClientLauncher params");
|
LogHelper.debug("Reading ClientLauncher params");
|
||||||
ClientLauncherProcess.ClientParams params = readParams(new InetSocketAddress("127.0.0.1", Launcher.getConfig().clientPort));
|
ParamsWriter paramsWriter = new SocketParamsWriter(new InetSocketAddress("127.0.0.1", Launcher.getConfig().clientPort));
|
||||||
|
ClientLauncherProcess.ClientParams params = paramsWriter.read();
|
||||||
if (params.profile.getClassLoaderConfig() != ClientProfile.ClassLoaderConfig.AGENT) {
|
if (params.profile.getClassLoaderConfig() != ClientProfile.ClassLoaderConfig.AGENT) {
|
||||||
LauncherEngine.verifyNoAgent();
|
LauncherEngine.verifyNoAgent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package pro.gravit.launcher.client.params;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.client.ClientLauncherProcess;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public interface ParamsWriter {
|
||||||
|
void write(ClientLauncherProcess.ClientParams params) throws IOException;
|
||||||
|
ClientLauncherProcess.ClientParams read() throws IOException;
|
||||||
|
}
|
|
@ -0,0 +1,40 @@
|
||||||
|
package pro.gravit.launcher.client.params;
|
||||||
|
|
||||||
|
import pro.gravit.launcher.client.ClientLauncherProcess;
|
||||||
|
import pro.gravit.utils.helper.IOHelper;
|
||||||
|
|
||||||
|
import java.io.DataInputStream;
|
||||||
|
import java.io.DataOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.ServerSocket;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.net.SocketAddress;
|
||||||
|
|
||||||
|
public class SocketParamsWriter implements ParamsWriter {
|
||||||
|
private final SocketAddress address;
|
||||||
|
|
||||||
|
public SocketParamsWriter(SocketAddress address) {
|
||||||
|
this.address = address;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(ClientLauncherProcess.ClientParams params) throws IOException {
|
||||||
|
try(ServerSocket socket = new ServerSocket()) {
|
||||||
|
socket.bind(address);
|
||||||
|
Socket client = socket.accept();
|
||||||
|
try(DataOutputStream stream = new DataOutputStream(client.getOutputStream())) {
|
||||||
|
params.write(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ClientLauncherProcess.ClientParams read() throws IOException {
|
||||||
|
try(Socket socket = IOHelper.newSocket()) {
|
||||||
|
socket.connect(address, 30*1000);
|
||||||
|
try(DataInputStream stream = new DataInputStream(socket.getInputStream())) {
|
||||||
|
return ClientLauncherProcess.ClientParams.read(stream);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue