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