mirror of
https://github.com/MewoLab/AquaDX.git
synced 2026-02-07 02:37:26 +08:00
[general] Make AutoChecker to display version info
This commit is contained in:
@@ -15,7 +15,7 @@ public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
private final boolean AQUAVIEWER_ENABLED;
|
||||
|
||||
public WebConfig(@Value("${aquaviewer.server.enable:true}") boolean AQUAVIEWER_ENABLED) {
|
||||
public WebConfig(@Value("${aquaviewer.server.enable}") boolean AQUAVIEWER_ENABLED) {
|
||||
this.AQUAVIEWER_ENABLED = AQUAVIEWER_ENABLED;
|
||||
}
|
||||
|
||||
|
||||
@@ -5,11 +5,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@@ -30,9 +26,11 @@ public class AutoChecker {
|
||||
private final boolean BILLING_ENABLED;
|
||||
private final int BILLING_PORT;
|
||||
private final boolean AQUAVIEWER_ENABLED;
|
||||
private final String VERSION_TAG;
|
||||
private final String BUILD_TIMESTAMP;
|
||||
|
||||
public AutoChecker(
|
||||
@Value("${server.host:}") String SERVER_PORT,
|
||||
@Value("${server.port:}") String SERVER_PORT,
|
||||
@Value("${allnet.server.host:}") String ALLNET_HOST,
|
||||
@Value("${allnet.server.port:}") String ALLNET_PORT,
|
||||
@Value("${aimedb.server.address}") String AIMEDB_BIND,
|
||||
@@ -40,7 +38,9 @@ public class AutoChecker {
|
||||
@Value("${aimedb.server.enable}") boolean AIMEDB_ENABLED,
|
||||
@Value("${billing.server.port}") int BILLING_PORT,
|
||||
@Value("${billing.server.enable}") boolean BILLING_ENABLED,
|
||||
@Value("${aquaviewer.server.enable:true}") boolean AQUAVIEWER_ENABLED) {
|
||||
@Value("${aquaviewer.server.enable}") boolean AQUAVIEWER_ENABLED,
|
||||
@Value("${build.version:N/A}") String VERSION_TAG,
|
||||
@Value("${build.timestamp:N/A}") String BUILD_TIMESTAMP) {
|
||||
this.SERVER_PORT = SERVER_PORT;
|
||||
this.ALLNET_HOST_OVERRIDE = ALLNET_HOST;
|
||||
this.ALLNET_PORT_OVERRIDE = ALLNET_PORT;
|
||||
@@ -50,27 +50,44 @@ public class AutoChecker {
|
||||
this.BILLING_PORT = BILLING_PORT;
|
||||
this.BILLING_ENABLED = BILLING_ENABLED;
|
||||
this.AQUAVIEWER_ENABLED = AQUAVIEWER_ENABLED;
|
||||
this.VERSION_TAG = VERSION_TAG;
|
||||
this.BUILD_TIMESTAMP = BUILD_TIMESTAMP;
|
||||
}
|
||||
|
||||
public void check() {
|
||||
String host = ALLNET_HOST_OVERRIDE.equals("") ? "127.0.0.1" : ALLNET_HOST_OVERRIDE;
|
||||
String port = ALLNET_PORT_OVERRIDE.equals("") ? SERVER_PORT : ALLNET_PORT_OVERRIDE;
|
||||
|
||||
// Boot message
|
||||
System.out.println(" █████╗ ██████╗ ██╗ ██╗ █████╗ \n" +
|
||||
"██╔══██╗██╔═══██╗██║ ██║██╔══██╗\n" +
|
||||
"███████║██║ ██║██║ ██║███████║\n" +
|
||||
"██╔══██║██║▄▄ ██║██║ ██║██╔══██║\n" +
|
||||
"██║ ██║╚██████╔╝╚██████╔╝██║ ██║\n" +
|
||||
"╚═╝ ╚═╝ ╚══▀▀═╝ ╚═════╝ ╚═╝ ╚═╝\n" +
|
||||
" ");
|
||||
System.out.println(
|
||||
" _____ _____ _____ _____ " + LINEBREAK +
|
||||
"| _ | | | | _ |" + LINEBREAK +
|
||||
"| | | | | | |" + LINEBREAK +
|
||||
"|__|__|__ _|_____|__|__|" + LINEBREAK +
|
||||
" |__| " + LINEBREAK);
|
||||
|
||||
System.out.println("Aqua local server");
|
||||
System.out.println("Version: " + VERSION_TAG + " (Built on " + BUILD_TIMESTAMP + ")\n");
|
||||
|
||||
System.out.println("This is a free open-source software. If you paid for it, you were scammed.\n");
|
||||
|
||||
System.out.println("[Web Interface]");
|
||||
if (AQUAVIEWER_ENABLED) {
|
||||
System.out.println("Aqua viewer at http://localhost/web/\n");
|
||||
}
|
||||
System.out.println("Enabled : http://" + host + ":" + port + "/web/" + LINEBREAK);
|
||||
} else {
|
||||
System.out.println("Disabled" + LINEBREAK);
|
||||
}
|
||||
|
||||
System.out.println("======= Self test running =======");
|
||||
// Check aimedb
|
||||
System.out.print(" AimeDB : ");
|
||||
System.out.println("[Self testing]");
|
||||
StringBuilder failDetail = new StringBuilder();
|
||||
|
||||
/*
|
||||
* Aime DB: try open socket to Aime DB port (default 22345)
|
||||
* TODO: Sending hello request would be more reliable than testing if port is open
|
||||
*/
|
||||
System.out.print("Aime DB : ");
|
||||
if(!AIMEDB_ENABLED) {
|
||||
System.out.println("DISABLED, SKIP");
|
||||
System.out.println("SKIP (DISABLED)");
|
||||
} else {
|
||||
String address = "127.0.0.1";
|
||||
if(!AIMEDB_BIND.equals("0.0.0.0")) {
|
||||
@@ -79,55 +96,57 @@ public class AutoChecker {
|
||||
try (Socket test = new Socket(address, AIMEDB_PORT)){
|
||||
System.out.println("OK");
|
||||
} catch (Exception e) {
|
||||
System.out.println("ERROR!!");
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println("ERROR");
|
||||
failDetail.append("Aime DB self-test raised an exception during testing").append(LINEBREAK);
|
||||
failDetail.append("Exception: ").append(e.getCause().getMessage()).append(LINEBREAK);
|
||||
}
|
||||
}
|
||||
|
||||
// Check billing
|
||||
System.out.print(" Billing : ");
|
||||
/*
|
||||
* Billing: try open socket to Billing port (default 8443)
|
||||
* TODO: Try access /sys/test endpoint for more reliable testing (without cert verification)
|
||||
*/
|
||||
System.out.print("Billing : ");
|
||||
if(!BILLING_ENABLED) {
|
||||
System.out.println("DISABLED, SKIP");
|
||||
System.out.println("SKIP (DISABLED)");
|
||||
} else {
|
||||
String host = ALLNET_HOST_OVERRIDE.equals("") ? "127.0.0.1" : ALLNET_HOST_OVERRIDE;
|
||||
try (Socket test = new Socket(host, BILLING_PORT)){
|
||||
System.out.println("OK");
|
||||
} catch (Exception e) {
|
||||
System.out.println("ERROR!!");
|
||||
System.out.println(e.getMessage());
|
||||
System.out.println("ERROR");
|
||||
failDetail.append("Billing self-test raised an exception during testing").append(LINEBREAK);
|
||||
failDetail.append("Exception: ").append(e.getCause().getMessage()).append(LINEBREAK);
|
||||
}
|
||||
}
|
||||
|
||||
// Check http part
|
||||
System.out.print(" AllNet : ");
|
||||
StringBuilder allNetSb = new StringBuilder();
|
||||
if(ALLNET_HOST_OVERRIDE.equals("localhost")||ALLNET_HOST_OVERRIDE.startsWith("127.0.0.")) {
|
||||
System.out.print("WARNING!! ");
|
||||
allNetSb.append("You are using loopback address.").append(LINEBREAK);
|
||||
allNetSb.append("Some game won't connect with loopback address,").append(LINEBREAK);
|
||||
allNetSb.append("please change setting in `application.properties`.").append(LINEBREAK);
|
||||
// ALL.Net: try access /sys/test endpoint (default 80)
|
||||
System.out.print("ALL.Net : ");
|
||||
|
||||
if(ALLNET_HOST_OVERRIDE.equals("localhost")||ALLNET_HOST_OVERRIDE.startsWith("127.")) {
|
||||
System.out.print("WARN, ");
|
||||
failDetail.append("ALL.Net host is currently using loopback address.").append(LINEBREAK);
|
||||
failDetail.append("Game might not connect to server with this. If it was not intentional, please edit configuration file.").append(LINEBREAK);
|
||||
}
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String host = ALLNET_HOST_OVERRIDE.equals("") ? "127.0.0.1" : ALLNET_HOST_OVERRIDE;
|
||||
String port = ALLNET_PORT_OVERRIDE.equals("") ? SERVER_PORT : ALLNET_PORT_OVERRIDE;
|
||||
String url = "http://" + host + ":" + port + "/sys/test";
|
||||
try{
|
||||
ResponseEntity<String> resp = restTemplate.getForEntity(url, String.class);
|
||||
if(resp.getStatusCode().is2xxSuccessful() && Objects.equals(resp.getBody(), "Server running")) {
|
||||
System.out.println("OK");
|
||||
} else {
|
||||
System.out.println("FAIL!");
|
||||
allNetSb.append("Could not connect to ").append(url).append(LINEBREAK);
|
||||
allNetSb.append("Status code: ").append(resp.getStatusCodeValue()).append(LINEBREAK);
|
||||
System.out.println("ERROR");
|
||||
failDetail.append("ALL.Net self-test could not connect to ").append(url).append(LINEBREAK);
|
||||
failDetail.append("Status code: ").append(resp.getStatusCodeValue()).append(LINEBREAK);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("ERROR!");
|
||||
System.out.println(e.getCause().getMessage());
|
||||
System.out.println("ERROR");
|
||||
failDetail.append("ALL.Net self-test raised an exception during testing").append(url).append(LINEBREAK);
|
||||
failDetail.append("Exception: ").append(e.getCause().getMessage()).append(LINEBREAK);
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println(allNetSb.toString());
|
||||
System.out.println(failDetail.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user