mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-04-18 22:13:04 +03:00
[FEATURE] Setup support env configuration in ServerWrapper, fix compile
This commit is contained in:
parent
2e93102106
commit
9e29053afa
8 changed files with 47 additions and 21 deletions
|
@ -154,7 +154,7 @@ public static String getRefreshToken() {
|
|||
|
||||
public static void reconnect() throws Exception {
|
||||
|
||||
getRequestService().open();
|
||||
getRequestService().connect();
|
||||
restore();
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
public interface RequestService {
|
||||
<T extends WebSocketEvent> CompletableFuture<T> request(Request<T> request) throws IOException;
|
||||
void open();
|
||||
void connect() throws Exception;
|
||||
|
||||
void registerEventHandler(EventHandler handler);
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.security.KeyManagementException;
|
||||
import java.security.KeyStoreException;
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -97,6 +98,17 @@ public CompletionStage<?> onClose(WebSocket webSocket, int statusCode, String re
|
|||
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
|
||||
public void onError(WebSocket webSocket, Throwable error) {
|
||||
LogHelper.error(error);
|
||||
|
|
|
@ -45,7 +45,7 @@ public <T extends WebSocketEvent> CompletableFuture<T> request(Request<T> reques
|
|||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
public void connect() {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -11,9 +11,12 @@
|
|||
|
||||
import javax.net.ssl.SSLException;
|
||||
import java.io.IOException;
|
||||
import java.net.http.WebSocket;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.HashSet;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.CompletionStage;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ public <T extends WebSocketEvent> CompletableFuture<T> request(Request<T> reques
|
|||
}
|
||||
|
||||
@Override
|
||||
public void open() {
|
||||
public void connect() {
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -308,13 +308,13 @@ public void apply() {
|
|||
}
|
||||
|
||||
public void applyEnv() {
|
||||
this.authId = applyEnvOrDefault("LAUNCHSERVER_AUTH_ID", this.authId);
|
||||
this.address = applyEnvOrDefault("LAUNCHSERVER_ADDRESS", this.address);
|
||||
this.serverName = applyEnvOrDefault("LAUNCHSERVER_SERVER_NAME", this.serverName);
|
||||
this.encodedServerEcPublicKey = applyEnvOrDefault("LAUNCHSERVER_EC_PUBLIC_KEY", Base64.getUrlDecoder()::decode, null);
|
||||
this.encodedServerRsaPublicKey = applyEnvOrDefault("LAUNCHSERVER_RSA_PUBLIC_KEY", Base64.getUrlDecoder()::decode, null);
|
||||
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("CHECK_SERVER_TOKEN");
|
||||
String token = System.getenv("SERVERWRAPPER_CHECK_SERVER_TOKEN");
|
||||
if(token != null) {
|
||||
if(extendedTokens == null) {
|
||||
extendedTokens = new HashMap<>();
|
||||
|
|
|
@ -30,8 +30,11 @@ public ServerWrapperSetup() throws IOException {
|
|||
|
||||
public void run() throws Exception {
|
||||
ServerWrapper wrapper = ServerWrapper.wrapper;
|
||||
System.out.println("Print server jar filename:");
|
||||
String jarName = commands.commandHandler.readLine();
|
||||
String jarName = System.getenv("SERVERWRAPPER_JAR_NAME");
|
||||
if(jarName == null) {
|
||||
System.out.println("Print server jar filename:");
|
||||
jarName = commands.commandHandler.readLine();
|
||||
}
|
||||
Path jarPath = Paths.get(jarName);
|
||||
String mainClassName;
|
||||
String agentClassName;
|
||||
|
@ -56,14 +59,18 @@ public void run() throws Exception {
|
|||
if (agentClassName != null) {
|
||||
LogHelper.info("Found PremainClass %s", agentClassName);
|
||||
}
|
||||
System.out.println("Print your server name:");
|
||||
wrapper.config.serverName = commands.commandHandler.readLine();
|
||||
if(wrapper.config.serverName == null || wrapper.config.serverName.isEmpty()) {
|
||||
System.out.println("Print your server name:");
|
||||
wrapper.config.serverName = commands.commandHandler.readLine();
|
||||
}
|
||||
wrapper.config.mainclass = mainClassName;
|
||||
boolean altMode = false;
|
||||
for (int i = 0; i < 10; ++i) {
|
||||
if(!Request.isAvailable() || Request.getRequestService().isClosed()) {
|
||||
System.out.println("Print launchserver websocket host( ws://host:port/api ):");
|
||||
wrapper.config.address = commands.commandHandler.readLine();
|
||||
if(wrapper.config.address == null || wrapper.config.address.isEmpty()) {
|
||||
System.out.println("Print launchserver websocket host( ws://host:port/api ):");
|
||||
wrapper.config.address = commands.commandHandler.readLine();
|
||||
}
|
||||
StdWebSocketService service;
|
||||
try {
|
||||
service = StdWebSocketService.initWebSockets(wrapper.config.address).get();
|
||||
|
@ -73,9 +80,11 @@ public void run() throws Exception {
|
|||
}
|
||||
Request.setRequestService(service);
|
||||
}
|
||||
System.out.println("Print server token:");
|
||||
String checkServerToken = commands.commandHandler.readLine();
|
||||
wrapper.config.extendedTokens.put("checkServer", new Request.ExtendedToken(checkServerToken, 0));
|
||||
if(wrapper.config.extendedTokens == null || wrapper.config.extendedTokens.get("checkServer") == null) {
|
||||
System.out.println("Print server token:");
|
||||
String checkServerToken = commands.commandHandler.readLine();
|
||||
wrapper.config.extendedTokens.put("checkServer", new Request.ExtendedToken(checkServerToken, 0));
|
||||
}
|
||||
wrapper.updateLauncherConfig();
|
||||
try {
|
||||
wrapper.restore();
|
||||
|
@ -93,7 +102,9 @@ public void run() throws Exception {
|
|||
}
|
||||
if(wrapper.profile != null && wrapper.profile.getVersion().compareTo(ClientProfileVersions.MINECRAFT_1_18) >= 0) {
|
||||
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;
|
||||
altMode = true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue