Fix: NPE in AuthManager, game logs display in UI
This commit is contained in:
@@ -10,6 +10,7 @@ import me.sashegdev.zernmc.launcher.utils.ZAnsi;
|
||||
import me.sashegdev.zernmc.launcher.utils.ZHttpClient;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -252,12 +253,16 @@ public class AuthManager {
|
||||
}
|
||||
|
||||
int statusCode = conn.getResponseCode();
|
||||
var is = (statusCode >= 200 && statusCode < 300) ? conn.getInputStream() : conn.getErrorStream();
|
||||
InputStream is = (statusCode >= 200 && statusCode < 300) ? conn.getInputStream() : conn.getErrorStream();
|
||||
|
||||
String responseBody;
|
||||
if (is != null) {
|
||||
try (var scanner = new java.util.Scanner(is, StandardCharsets.UTF_8.name())) {
|
||||
responseBody = scanner.useDelimiter("\\A").hasNext() ? scanner.next() : "";
|
||||
}
|
||||
} else {
|
||||
responseBody = "No response body (status " + statusCode + ")";
|
||||
}
|
||||
|
||||
return new SimpleHttpResponse(statusCode, responseBody);
|
||||
|
||||
|
||||
@@ -41,7 +41,6 @@ public class JFXLauncher extends Application {
|
||||
private Stage mainStage;
|
||||
|
||||
public static void appendGameLog(String log) {
|
||||
System.out.println("[GAMELOG] " + log);
|
||||
synchronized (gameLogBuffer) {
|
||||
gameLogBuffer.append(log).append("\n");
|
||||
|
||||
@@ -56,6 +55,9 @@ public class JFXLauncher extends Application {
|
||||
}
|
||||
|
||||
public static void initGameLog(Path instanceDir) {
|
||||
synchronized (gameLogBuffer) {
|
||||
gameLogBuffer.setLength(0);
|
||||
}
|
||||
try {
|
||||
Path logsDir = instanceDir.resolve("logs");
|
||||
Files.createDirectories(logsDir);
|
||||
@@ -266,12 +268,7 @@ public class JFXLauncher extends Application {
|
||||
}
|
||||
|
||||
private void handleGameLogs(HttpExchange exchange) {
|
||||
String logs = getGameLogs();
|
||||
log("[GAME-LOGS-API] Request, logs length: " + logs.length());
|
||||
if (!logs.isEmpty()) {
|
||||
log("[GAME-LOGS-API] First 200 chars: " + logs.substring(0, Math.min(200, logs.length())));
|
||||
}
|
||||
sendJson(exchange, Map.of("success", true, "data", logs));
|
||||
sendJson(exchange, Map.of("success", true, "data", getGameLogs()));
|
||||
}
|
||||
|
||||
private void handleExit(HttpExchange exchange) {
|
||||
|
||||
@@ -268,10 +268,8 @@ function startLogPolling() {
|
||||
|
||||
// Game logs
|
||||
const gameResult = await apiCall('/game-logs');
|
||||
console.log('[DEBUG] Game logs request:', gameResult.success, 'length:', gameResult.data ? gameResult.data.length : 0);
|
||||
if (gameResult.success && gameResult.data && gameResult.data.length > lastGameLogLength) {
|
||||
const newLogs = gameResult.data.substring(lastGameLogLength);
|
||||
console.log('[DEBUG] New game logs:', newLogs.substring(0, 200));
|
||||
const lines = newLogs.split('\n').filter(l => l.trim());
|
||||
lines.forEach(line => {
|
||||
log('[GAME] ' + line, 'info');
|
||||
|
||||
Reference in New Issue
Block a user