diff --git a/src/main/java/moe/yuyui/mcstreamerbot/common/EventListener.java b/src/main/java/moe/yuyui/mcstreamerbot/common/EventListener.java index 021cdaf..e14a838 100644 --- a/src/main/java/moe/yuyui/mcstreamerbot/common/EventListener.java +++ b/src/main/java/moe/yuyui/mcstreamerbot/common/EventListener.java @@ -1,5 +1,7 @@ package moe.yuyui.mcstreamerbot.common; +import moe.yuyui.mcstreamerbot.MCStreamerBot; + public class EventListener extends Thread { private final WSServer _websocketServer; @@ -12,10 +14,10 @@ public class EventListener extends Thread { @Override public void run() { try { + MCStreamerBot.LOG.info("Event Listener starting..."); this._websocketServer.run(); - System.out.println("Event Listener started"); } catch (NullPointerException e) { - System.out.println("Event Listener stopped. Websocket has failed."); + MCStreamerBot.LOG.error("Event Listener has failed. Websocket issue.", e); } } diff --git a/src/main/java/moe/yuyui/mcstreamerbot/common/WSServer.java b/src/main/java/moe/yuyui/mcstreamerbot/common/WSServer.java index c80b12c..9dab13e 100644 --- a/src/main/java/moe/yuyui/mcstreamerbot/common/WSServer.java +++ b/src/main/java/moe/yuyui/mcstreamerbot/common/WSServer.java @@ -21,6 +21,7 @@ import org.java_websocket.server.WebSocketServer; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import moe.yuyui.mcstreamerbot.MCStreamerBot; import moe.yuyui.mcstreamerbot.common.beans.MessagePayloadBean; import moe.yuyui.mcstreamerbot.common.enums.MessageType; import moe.yuyui.mcstreamerbot.events.custom.OnChatMessage; @@ -45,17 +46,18 @@ public class WSServer extends WebSocketServer { @Override public void onOpen(WebSocket conn, ClientHandshake handshake) { if (_authToken != null) { + MCStreamerBot.LOG.warn("Connection failed authentication."); conn.send("bad girl"); return; } _authClients.add(conn); - System.out.println("New connection"); + MCStreamerBot.LOG.info("New client connection established."); } @Override public void onClose(WebSocket conn, int code, String reason, boolean remote) { _authClients.remove(conn); - System.out.println("Connection closed"); + MCStreamerBot.LOG.info("Client disconnected."); } @Override @@ -90,7 +92,7 @@ public class WSServer extends WebSocketServer { } return builder.toString(); } catch (ZipException e) { - System.out.println("Message is not valid"); + MCStreamerBot.LOG.warn("Last message received was not valid."); } catch (IOException ignored) {} return null; @@ -116,12 +118,15 @@ public class WSServer extends WebSocketServer { break; } case COMMAND: { + MCStreamerBot.LOG.debug("Message COMMAND received"); break; } case LISTEN: { + MCStreamerBot.LOG.debug("Message LISTEN received"); break; } case IGNORE: { + MCStreamerBot.LOG.debug("Message IGNORE received"); break; } } @@ -129,12 +134,17 @@ public class WSServer extends WebSocketServer { @Override public void onError(WebSocket conn, Exception ex) { - ex.printStackTrace(); + MCStreamerBot.LOG.fatal("Websocket fatal error.", ex); conn.close(); } @Override public void onStart() { - System.out.println("Server started"); + MCStreamerBot.LOG.info( + "Server started at ws://{}:{}", + this.getAddress() + .getHostString(), + this.getAddress() + .getPort()); } }