mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-07-09 09:12:50 +03:00
Compare commits
1 commit
7cf02eb095
...
28b05aa5cd
Author | SHA1 | Date | |
---|---|---|---|
|
28b05aa5cd |
8 changed files with 15 additions and 76 deletions
|
@ -154,7 +154,7 @@ public static String getRefreshToken() {
|
||||||
|
|
||||||
public static void reconnect() throws Exception {
|
public static void reconnect() throws Exception {
|
||||||
|
|
||||||
getRequestService().connect();
|
getRequestService().open();
|
||||||
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 connect() throws Exception;
|
void open();
|
||||||
|
|
||||||
void registerEventHandler(EventHandler handler);
|
void registerEventHandler(EventHandler handler);
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,6 @@
|
||||||
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;
|
||||||
|
@ -64,7 +63,7 @@ public ClientJSONPoint(URI uri) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect() throws Exception {
|
public void open() throws Exception {
|
||||||
webSocket = webSocketBuilder.buildAsync(uri, this).get();
|
webSocket = webSocketBuilder.buildAsync(uri, this).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,17 +97,6 @@ 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 connect() {
|
public void open() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,12 +11,9 @@
|
||||||
|
|
||||||
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 connect() {
|
public void open() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@
|
||||||
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> {
|
||||||
|
@ -122,7 +121,6 @@ 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();
|
||||||
|
@ -306,38 +304,5 @@ 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,11 +30,8 @@ public ServerWrapperSetup() throws IOException {
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
ServerWrapper wrapper = ServerWrapper.wrapper;
|
ServerWrapper wrapper = ServerWrapper.wrapper;
|
||||||
String jarName = System.getenv("SERVERWRAPPER_JAR_NAME");
|
System.out.println("Print server jar filename:");
|
||||||
if(jarName == null) {
|
String jarName = commands.commandHandler.readLine();
|
||||||
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;
|
||||||
|
@ -59,18 +56,14 @@ public void run() throws Exception {
|
||||||
if (agentClassName != null) {
|
if (agentClassName != null) {
|
||||||
LogHelper.info("Found PremainClass %s", agentClassName);
|
LogHelper.info("Found PremainClass %s", agentClassName);
|
||||||
}
|
}
|
||||||
if(wrapper.config.serverName == null || wrapper.config.serverName.isEmpty()) {
|
System.out.println("Print your server name:");
|
||||||
System.out.println("Print your server name:");
|
wrapper.config.serverName = commands.commandHandler.readLine();
|
||||||
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()) {
|
||||||
if(wrapper.config.address == null || wrapper.config.address.isEmpty()) {
|
System.out.println("Print launchserver websocket host( ws://host:port/api ):");
|
||||||
System.out.println("Print launchserver websocket host( ws://host:port/api ):");
|
wrapper.config.address = commands.commandHandler.readLine();
|
||||||
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();
|
||||||
|
@ -80,11 +73,9 @@ public void run() throws Exception {
|
||||||
}
|
}
|
||||||
Request.setRequestService(service);
|
Request.setRequestService(service);
|
||||||
}
|
}
|
||||||
if(wrapper.config.extendedTokens == null || wrapper.config.extendedTokens.get("checkServer") == null) {
|
System.out.println("Print server token:");
|
||||||
System.out.println("Print server token:");
|
String checkServerToken = commands.commandHandler.readLine();
|
||||||
String checkServerToken = commands.commandHandler.readLine();
|
wrapper.config.extendedTokens.put("checkServer", new Request.ExtendedToken(checkServerToken, 0));
|
||||||
wrapper.config.extendedTokens.put("checkServer", new Request.ExtendedToken(checkServerToken, 0));
|
|
||||||
}
|
|
||||||
wrapper.updateLauncherConfig();
|
wrapper.updateLauncherConfig();
|
||||||
try {
|
try {
|
||||||
wrapper.restore();
|
wrapper.restore();
|
||||||
|
@ -102,9 +93,7 @@ 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)");
|
||||||
if(!wrapper.config.classpath.contains(jarName)) {
|
wrapper.config.classpath.add(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