feat: replaced logging with l4j
Some checks are pending
Build and test / build-and-test (push) Waiting to run

This commit is contained in:
Yui 2024-12-01 17:47:16 -03:00
parent f5ad43ce0f
commit 04dcfb5870
Signed by: yui
GPG Key ID: F368D23A0ABA04B4
2 changed files with 19 additions and 7 deletions

View File

@ -1,5 +1,7 @@
package moe.yuyui.mcstreamerbot.common; package moe.yuyui.mcstreamerbot.common;
import moe.yuyui.mcstreamerbot.MCStreamerBot;
public class EventListener extends Thread { public class EventListener extends Thread {
private final WSServer _websocketServer; private final WSServer _websocketServer;
@ -12,10 +14,10 @@ public class EventListener extends Thread {
@Override @Override
public void run() { public void run() {
try { try {
MCStreamerBot.LOG.info("Event Listener starting...");
this._websocketServer.run(); this._websocketServer.run();
System.out.println("Event Listener started");
} catch (NullPointerException e) { } catch (NullPointerException e) {
System.out.println("Event Listener stopped. Websocket has failed."); MCStreamerBot.LOG.error("Event Listener has failed. Websocket issue.", e);
} }
} }

View File

@ -21,6 +21,7 @@ import org.java_websocket.server.WebSocketServer;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import moe.yuyui.mcstreamerbot.MCStreamerBot;
import moe.yuyui.mcstreamerbot.common.beans.MessagePayloadBean; import moe.yuyui.mcstreamerbot.common.beans.MessagePayloadBean;
import moe.yuyui.mcstreamerbot.common.enums.MessageType; import moe.yuyui.mcstreamerbot.common.enums.MessageType;
import moe.yuyui.mcstreamerbot.events.custom.OnChatMessage; import moe.yuyui.mcstreamerbot.events.custom.OnChatMessage;
@ -45,17 +46,18 @@ public class WSServer extends WebSocketServer {
@Override @Override
public void onOpen(WebSocket conn, ClientHandshake handshake) { public void onOpen(WebSocket conn, ClientHandshake handshake) {
if (_authToken != null) { if (_authToken != null) {
MCStreamerBot.LOG.warn("Connection failed authentication.");
conn.send("bad girl"); conn.send("bad girl");
return; return;
} }
_authClients.add(conn); _authClients.add(conn);
System.out.println("New connection"); MCStreamerBot.LOG.info("New client connection established.");
} }
@Override @Override
public void onClose(WebSocket conn, int code, String reason, boolean remote) { public void onClose(WebSocket conn, int code, String reason, boolean remote) {
_authClients.remove(conn); _authClients.remove(conn);
System.out.println("Connection closed"); MCStreamerBot.LOG.info("Client disconnected.");
} }
@Override @Override
@ -90,7 +92,7 @@ public class WSServer extends WebSocketServer {
} }
return builder.toString(); return builder.toString();
} catch (ZipException e) { } catch (ZipException e) {
System.out.println("Message is not valid"); MCStreamerBot.LOG.warn("Last message received was not valid.");
} catch (IOException ignored) {} } catch (IOException ignored) {}
return null; return null;
@ -116,12 +118,15 @@ public class WSServer extends WebSocketServer {
break; break;
} }
case COMMAND: { case COMMAND: {
MCStreamerBot.LOG.debug("Message COMMAND received");
break; break;
} }
case LISTEN: { case LISTEN: {
MCStreamerBot.LOG.debug("Message LISTEN received");
break; break;
} }
case IGNORE: { case IGNORE: {
MCStreamerBot.LOG.debug("Message IGNORE received");
break; break;
} }
} }
@ -129,12 +134,17 @@ public class WSServer extends WebSocketServer {
@Override @Override
public void onError(WebSocket conn, Exception ex) { public void onError(WebSocket conn, Exception ex) {
ex.printStackTrace(); MCStreamerBot.LOG.fatal("Websocket fatal error.", ex);
conn.close(); conn.close();
} }
@Override @Override
public void onStart() { public void onStart() {
System.out.println("Server started"); MCStreamerBot.LOG.info(
"Server started at ws://{}:{}",
this.getAddress()
.getHostString(),
this.getAddress()
.getPort());
} }
} }