mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-07-09 09:12:50 +03:00
Compare commits
4 commits
28b05aa5cd
...
7cf02eb095
Author | SHA1 | Date | |
---|---|---|---|
|
7cf02eb095 | ||
|
9e29053afa | ||
|
2e93102106 | ||
|
d4b69195b3 |
8 changed files with 76 additions and 15 deletions
|
@ -154,7 +154,7 @@ public static String getRefreshToken() {
|
||||||
|
|
||||||
public static void reconnect() throws Exception {
|
public static void reconnect() throws Exception {
|
||||||
|
|
||||||
getRequestService().open();
|
getRequestService().connect();
|
||||||
restore();
|
restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
public interface RequestService {
|
public interface RequestService {
|
||||||
<T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException;
|
<T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException;
|
||||||
void open();
|
void connect() throws Exception;
|
||||||
|
|
||||||
void registerEventHandler(EventHandler handler);
|
void registerEventHandler(EventHandler handler);
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
import java.net.http.WebSocket;
|
import java.net.http.WebSocket;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.security.KeyManagementException;
|
import java.security.KeyManagementException;
|
||||||
import java.security.KeyStoreException;
|
import java.security.KeyStoreException;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
@ -63,7 +64,7 @@ public ClientJSONPoint(URI uri) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void open() throws Exception {
|
public void connect() throws Exception {
|
||||||
webSocket = webSocketBuilder.buildAsync(uri, this).get();
|
webSocket = webSocketBuilder.buildAsync(uri, this).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +98,17 @@ public CompletionStage<?> onClose(WebSocket webSocket, int statusCode, String re
|
||||||
return WebSocket.Listener.super.onClose(webSocket, statusCode, reason);
|
return WebSocket.Listener.super.onClose(webSocket, statusCode, reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onOpen(WebSocket webSocket) {
|
||||||
|
onOpen();
|
||||||
|
WebSocket.Listener.super.onOpen(webSocket);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompletionStage<?> onBinary(WebSocket webSocket, ByteBuffer data, boolean last) {
|
||||||
|
return WebSocket.Listener.super.onBinary(webSocket, data, last);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(WebSocket webSocket, Throwable error) {
|
public void onError(WebSocket webSocket, Throwable error) {
|
||||||
LogHelper.error(error);
|
LogHelper.error(error);
|
||||||
|
|
|
@ -45,7 +45,7 @@ public <T extends WebSocketEvent> CompletableFuture<T> request(Request<T> reques
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open() {
|
public void connect() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,12 @@
|
||||||
|
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.http.WebSocket;
|
||||||
|
import java.nio.ByteBuffer;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.CompletionStage;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public <T extends WebSocketEvent> CompletableFuture<T> request(Request<T> reques
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void open() {
|
public void connect() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class ServerWrapper extends JsonConfigurable<ServerWrapper.Config> {
|
public class ServerWrapper extends JsonConfigurable<ServerWrapper.Config> {
|
||||||
|
@ -121,6 +122,7 @@ public void run(String... args) throws Throwable {
|
||||||
}
|
}
|
||||||
LogHelper.debug("Read ServerWrapperConfig.json");
|
LogHelper.debug("Read ServerWrapperConfig.json");
|
||||||
loadConfig();
|
loadConfig();
|
||||||
|
config.applyEnv();
|
||||||
updateLauncherConfig();
|
updateLauncherConfig();
|
||||||
Launcher.applyLauncherEnv(Objects.requireNonNullElse(config.env, LauncherConfig.LauncherEnvironment.STD));
|
Launcher.applyLauncherEnv(Objects.requireNonNullElse(config.env, LauncherConfig.LauncherEnvironment.STD));
|
||||||
StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get();
|
StdWebSocketService service = StdWebSocketService.initWebSockets(config.address).get();
|
||||||
|
@ -304,5 +306,38 @@ public void apply() {
|
||||||
ConfigService.checkServerConfig.needProperties = checkServerNeedProperties;
|
ConfigService.checkServerConfig.needProperties = checkServerNeedProperties;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void applyEnv() {
|
||||||
|
this.authId = applyEnvOrDefault("SERVERWRAPPER_AUTH_ID", this.authId);
|
||||||
|
this.address = applyEnvOrDefault("SERVERWRAPPER_ADDRESS", this.address);
|
||||||
|
this.serverName = applyEnvOrDefault("SERVERWRAPPER_SERVER_NAME", this.serverName);
|
||||||
|
this.encodedServerEcPublicKey = applyEnvOrDefault("SERVERWRAPPER_EC_PUBLIC_KEY", Base64.getUrlDecoder()::decode, null);
|
||||||
|
this.encodedServerRsaPublicKey = applyEnvOrDefault("SERVERWRAPPER_RSA_PUBLIC_KEY", Base64.getUrlDecoder()::decode, null);
|
||||||
|
{
|
||||||
|
String token = System.getenv("SERVERWRAPPER_CHECK_SERVER_TOKEN");
|
||||||
|
if(token != null) {
|
||||||
|
if(extendedTokens == null) {
|
||||||
|
extendedTokens = new HashMap<>();
|
||||||
|
}
|
||||||
|
extendedTokens.put("checkServer", new Request.ExtendedToken(token, 0L));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String applyEnvOrDefault(String envName, String def) {
|
||||||
|
String value = System.getenv(envName);
|
||||||
|
if(value == null) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static<T> T applyEnvOrDefault(String envName, Function<String, T> mappingFunction, T def) {
|
||||||
|
String value = System.getenv(envName);
|
||||||
|
if(value == null) {
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
return mappingFunction.apply(value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,8 +30,11 @@ public ServerWrapperSetup() throws IOException {
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ServerWrapper wrapper = ServerWrapper.wrapper;
|
ServerWrapper wrapper = ServerWrapper.wrapper;
|
||||||
System.out.println("Print server jar filename:");
|
String jarName = System.getenv("SERVERWRAPPER_JAR_NAME");
|
||||||
String jarName = commands.commandHandler.readLine();
|
if(jarName == null) {
|
||||||
|
System.out.println("Print server jar filename:");
|
||||||
|
jarName = commands.commandHandler.readLine();
|
||||||
|
}
|
||||||
Path jarPath = Paths.get(jarName);
|
Path jarPath = Paths.get(jarName);
|
||||||
String mainClassName;
|
String mainClassName;
|
||||||
String agentClassName;
|
String agentClassName;
|
||||||
|
@ -56,14 +59,18 @@ public void run() throws Exception {
|
||||||
if (agentClassName != null) {
|
if (agentClassName != null) {
|
||||||
LogHelper.info("Found PremainClass %s", agentClassName);
|
LogHelper.info("Found PremainClass %s", agentClassName);
|
||||||
}
|
}
|
||||||
System.out.println("Print your server name:");
|
if(wrapper.config.serverName == null || wrapper.config.serverName.isEmpty()) {
|
||||||
wrapper.config.serverName = commands.commandHandler.readLine();
|
System.out.println("Print your server name:");
|
||||||
|
wrapper.config.serverName = commands.commandHandler.readLine();
|
||||||
|
}
|
||||||
wrapper.config.mainclass = mainClassName;
|
wrapper.config.mainclass = mainClassName;
|
||||||
boolean altMode = false;
|
boolean altMode = false;
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
if(!Request.isAvailable() || Request.getRequestService().isClosed()) {
|
if(!Request.isAvailable() || Request.getRequestService().isClosed()) {
|
||||||
System.out.println("Print launchserver websocket host( ws://host:port/api ):");
|
if(wrapper.config.address == null || wrapper.config.address.isEmpty()) {
|
||||||
wrapper.config.address = commands.commandHandler.readLine();
|
System.out.println("Print launchserver websocket host( ws://host:port/api ):");
|
||||||
|
wrapper.config.address = commands.commandHandler.readLine();
|
||||||
|
}
|
||||||
StdWebSocketService service;
|
StdWebSocketService service;
|
||||||
try {
|
try {
|
||||||
service = StdWebSocketService.initWebSockets(wrapper.config.address).get();
|
service = StdWebSocketService.initWebSockets(wrapper.config.address).get();
|
||||||
|
@ -73,9 +80,11 @@ public void run() throws Exception {
|
||||||
}
|
}
|
||||||
Request.setRequestService(service);
|
Request.setRequestService(service);
|
||||||
}
|
}
|
||||||
System.out.println("Print server token:");
|
if(wrapper.config.extendedTokens == null || wrapper.config.extendedTokens.get("checkServer") == null) {
|
||||||
String checkServerToken = commands.commandHandler.readLine();
|
System.out.println("Print server token:");
|
||||||
wrapper.config.extendedTokens.put("checkServer", new Request.ExtendedToken(checkServerToken, 0));
|
String checkServerToken = commands.commandHandler.readLine();
|
||||||
|
wrapper.config.extendedTokens.put("checkServer", new Request.ExtendedToken(checkServerToken, 0));
|
||||||
|
}
|
||||||
wrapper.updateLauncherConfig();
|
wrapper.updateLauncherConfig();
|
||||||
try {
|
try {
|
||||||
wrapper.restore();
|
wrapper.restore();
|
||||||
|
@ -93,7 +102,9 @@ public void run() throws Exception {
|
||||||
}
|
}
|
||||||
if(wrapper.profile != null && wrapper.profile.getVersion().compareTo(ClientProfileVersions.MINECRAFT_1_18) >= 0) {
|
if(wrapper.profile != null && wrapper.profile.getVersion().compareTo(ClientProfileVersions.MINECRAFT_1_18) >= 0) {
|
||||||
LogHelper.info("Switch to alternative start mode (1.18)");
|
LogHelper.info("Switch to alternative start mode (1.18)");
|
||||||
wrapper.config.classpath.add(jarName);
|
if(!wrapper.config.classpath.contains(jarName)) {
|
||||||
|
wrapper.config.classpath.add(jarName);
|
||||||
|
}
|
||||||
wrapper.config.classLoaderConfig = ClientProfile.ClassLoaderConfig.LAUNCHER;
|
wrapper.config.classLoaderConfig = ClientProfile.ClassLoaderConfig.LAUNCHER;
|
||||||
altMode = true;
|
altMode = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue