From 4b72d77ad490323308e28caa0d0d3e5c87c0bf5a Mon Sep 17 00:00:00 2001
From: UnfamiliarLegacy <74633542+UnfamiliarLegacy@users.noreply.github.com>
Date: Wed, 7 Dec 2022 03:26:02 +0100
Subject: [PATCH] Added start of basic logging using logback
---
G-Earth/pom.xml | 37 ++++++++++++++-----
G-Earth/src/main/java/gearth/GEarth.java | 8 +++-
.../proxy/nitro/NitroProxyProvider.java | 28 +++++++++++---
.../nitro/websocket/NitroWebsocketClient.java | 9 +++--
.../nitro/websocket/NitroWebsocketServer.java | 9 ++++-
G-Earth/src/main/resources/logback.xml | 16 ++++++++
6 files changed, 87 insertions(+), 20 deletions(-)
create mode 100644 G-Earth/src/main/resources/logback.xml
diff --git a/G-Earth/pom.xml b/G-Earth/pom.xml
index c30a5ce..0a0cbde 100644
--- a/G-Earth/pom.xml
+++ b/G-Earth/pom.xml
@@ -11,6 +11,7 @@
1.8
9.4.48.v20220622
+ 1.3.5
@@ -224,11 +225,12 @@
com.github.tulskiy
jkeymaster
1.3
-
-
- org.slf4j
- slf4j-jdk14
- 2.0.0-alpha0
+
+
+ org.slf4j
+ slf4j-api
+
+
@@ -274,17 +276,32 @@
com.github.ganskef
littleproxy-mitm
1.1.0
+
+
+ org.slf4j
+ slf4j-api
+
+
+ org.slf4j
+ slf4j-log4j12
+
+
-
-
-
-
G-Earth
G-Wasm-Minimal
1.0.3
-
+
+ ch.qos.logback
+ logback-core
+ ${logback.version}
+
+
+ ch.qos.logback
+ logback-classic
+ ${logback.version}
+
diff --git a/G-Earth/src/main/java/gearth/GEarth.java b/G-Earth/src/main/java/gearth/GEarth.java
index 7982f9a..d5e859d 100644
--- a/G-Earth/src/main/java/gearth/GEarth.java
+++ b/G-Earth/src/main/java/gearth/GEarth.java
@@ -48,7 +48,13 @@ public class GEarth extends Application {
stage = primaryStage;
FXMLLoader loader = new FXMLLoader(getClass().getResource("/gearth/ui/G-Earth.fxml"));
- Parent root = loader.load();
+ Parent root;
+ try {
+ root = loader.load();
+ } catch (Exception e) {
+ e.printStackTrace();
+ return;
+ }
controller = loader.getController();
controller.setStage(primaryStage);
stage.initStyle(StageStyle.TRANSPARENT);
diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/NitroProxyProvider.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/NitroProxyProvider.java
index 4ca7e38..b86a4fc 100644
--- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/NitroProxyProvider.java
+++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/NitroProxyProvider.java
@@ -9,14 +9,17 @@ import gearth.protocol.connection.proxy.ProxyProvider;
import gearth.protocol.connection.proxy.nitro.http.NitroHttpProxy;
import gearth.protocol.connection.proxy.nitro.http.NitroHttpProxyServerCallback;
import gearth.protocol.connection.proxy.nitro.websocket.NitroWebsocketProxy;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
+import java.net.ServerSocket;
import java.util.concurrent.atomic.AtomicBoolean;
public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCallback, StateChangeListener {
+ private static final Logger logger = LoggerFactory.getLogger(NitroProxyProvider.class);
+
private final HProxySetter proxySetter;
private final HStateSetter stateSetter;
private final HConnection connection;
@@ -52,20 +55,27 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
connection.getStateObservable().addListener(this);
+ logger.info("Starting http proxy");
+
if (!nitroHttpProxy.start()) {
- System.out.println("Failed to start nitro proxy");
+ logger.error("Failed to start nitro proxy");
abort();
return;
}
+ logger.info("Starting websocket proxy");
+
if (!nitroWebsocketProxy.start()) {
- System.out.println("Failed to start nitro websocket proxy");
+ logger.error("Failed to start nitro websocket proxy");
abort();
return;
}
websocketPort = nitroWebsocketProxy.getPort();
+ logger.info("Websocket proxy is listening on port {}", websocketPort);
+ logger.info("Nitro proxy started");
+
stateSetter.setState(HState.WAITING_FOR_CLIENT);
}
@@ -75,19 +85,25 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
return;
}
- if (abortLock.compareAndSet(true, true)) {
+ if (!abortLock.compareAndSet(false, true)) {
return;
}
+ logger.info("Aborting nitro proxy");
+
stateSetter.setState(HState.ABORTING);
new Thread(() -> {
+ logger.info("Stopping nitro http proxy");
+
try {
nitroHttpProxy.stop();
} catch (Exception e) {
e.printStackTrace();
}
+ logger.info("Stopping nitro websocket proxy");
+
try {
nitroWebsocketProxy.stop();
} catch (Exception e) {
@@ -97,6 +113,8 @@ public class NitroProxyProvider implements ProxyProvider, NitroHttpProxyServerCa
stateSetter.setState(HState.NOT_CONNECTED);
connection.getStateObservable().removeListener(this);
+
+ logger.info("Nitro proxy stopped");
}).start();
}
diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroWebsocketClient.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroWebsocketClient.java
index 0c06f62..d003c31 100644
--- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroWebsocketClient.java
+++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroWebsocketClient.java
@@ -6,14 +6,13 @@ import gearth.protocol.connection.*;
import gearth.protocol.connection.proxy.nitro.NitroConstants;
import gearth.protocol.connection.proxy.nitro.NitroProxyProvider;
import gearth.protocol.packethandler.nitro.NitroPacketHandler;
-import org.eclipse.jetty.websocket.common.WebSocketSession;
import org.eclipse.jetty.websocket.jsr356.JsrSession;
-import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.websocket.*;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
-import java.lang.reflect.Field;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
@@ -23,6 +22,8 @@ import java.util.concurrent.atomic.AtomicBoolean;
@ServerEndpoint(value = "/")
public class NitroWebsocketClient implements NitroSession {
+ private static final Logger logger = LoggerFactory.getLogger(NitroWebsocketClient.class);
+
private final HProxySetter proxySetter;
private final HStateSetter stateSetter;
private final HConnection connection;
@@ -45,6 +46,8 @@ public class NitroWebsocketClient implements NitroSession {
@OnOpen
public void onOpen(Session session) throws Exception {
+ logger.info("WebSocket connection accepted");
+
activeSession = (JsrSession) session;
activeSession.setMaxBinaryMessageBufferSize(NitroConstants.WEBSOCKET_BUFFER_SIZE);
diff --git a/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroWebsocketServer.java b/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroWebsocketServer.java
index d1017d7..3df6cb7 100644
--- a/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroWebsocketServer.java
+++ b/G-Earth/src/main/java/gearth/protocol/connection/proxy/nitro/websocket/NitroWebsocketServer.java
@@ -6,8 +6,9 @@ import gearth.protocol.connection.proxy.nitro.NitroConstants;
import gearth.protocol.packethandler.PacketHandler;
import gearth.protocol.packethandler.nitro.NitroPacketHandler;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
-import org.eclipse.jetty.websocket.common.extensions.compress.PerMessageDeflateExtension;
import org.eclipse.jetty.websocket.jsr356.JsrExtension;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.websocket.*;
import java.io.IOException;
@@ -16,6 +17,8 @@ import java.util.*;
public class NitroWebsocketServer extends Endpoint implements NitroSession {
+ private static final Logger logger = LoggerFactory.getLogger(NitroWebsocketServer.class);
+
private static final HashSet SKIP_HEADERS = new HashSet<>(Arrays.asList(
"Sec-WebSocket-Extensions",
"Sec-WebSocket-Key",
@@ -36,6 +39,8 @@ public class NitroWebsocketServer extends Endpoint implements NitroSession {
public void connect(String websocketUrl, Map> clientHeaders) throws IOException {
try {
+ logger.info("Connecting to origin websocket at {}", websocketUrl);
+
ClientEndpointConfig.Builder builder = ClientEndpointConfig.Builder.create();
builder.extensions(Collections.singletonList(new JsrExtension(new ExtensionConfig("permessage-deflate;client_max_window_bits"))));
@@ -57,6 +62,8 @@ public class NitroWebsocketServer extends Endpoint implements NitroSession {
ClientEndpointConfig config = builder.build();
ContainerProvider.getWebSocketContainer().connectToServer(this, config, URI.create(websocketUrl));
+
+ logger.info("Connected to origin websocket");
} catch (DeploymentException e) {
throw new IOException("Failed to deploy websocket client", e);
}
diff --git a/G-Earth/src/main/resources/logback.xml b/G-Earth/src/main/resources/logback.xml
new file mode 100644
index 0000000..616ab2c
--- /dev/null
+++ b/G-Earth/src/main/resources/logback.xml
@@ -0,0 +1,16 @@
+
+
+
+ %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file