From 76aad828834f69e946eb82c7cfdc9022ebea973f Mon Sep 17 00:00:00 2001 From: Jonttuuu <50843099+Jonttuuu@users.noreply.github.com> Date: Sun, 30 Jul 2023 15:15:55 +0300 Subject: [PATCH] Add handler for HELLO websocket message --- src/main/java/fi/flexplex/lib/FlexLibAdapter.java | 5 +++++ src/main/java/fi/flexplex/lib/FlexLibAdapterImpl.java | 5 +++++ src/main/java/fi/flexplex/lib/WebSocketClient.java | 4 ++++ 3 files changed, 14 insertions(+) diff --git a/src/main/java/fi/flexplex/lib/FlexLibAdapter.java b/src/main/java/fi/flexplex/lib/FlexLibAdapter.java index 996a3b1..dbdbe78 100644 --- a/src/main/java/fi/flexplex/lib/FlexLibAdapter.java +++ b/src/main/java/fi/flexplex/lib/FlexLibAdapter.java @@ -2,6 +2,11 @@ package fi.flexplex.lib; public interface FlexLibAdapter { + /** + * Called when WebSocket is connected and server responded HELLO + */ + public default void onWebSocketConnect() {} + /** * Called when player friend list or friend requests are updated * @param player diff --git a/src/main/java/fi/flexplex/lib/FlexLibAdapterImpl.java b/src/main/java/fi/flexplex/lib/FlexLibAdapterImpl.java index abff53e..a3d1766 100644 --- a/src/main/java/fi/flexplex/lib/FlexLibAdapterImpl.java +++ b/src/main/java/fi/flexplex/lib/FlexLibAdapterImpl.java @@ -14,4 +14,9 @@ public final class FlexLibAdapterImpl implements FlexLibAdapter { this.flexLib.updatePlayerFriends(player); } + @Override + public void onWebSocketConnect() { + this.flexLib.getLogger().info("WebSocket connected"); + } + } diff --git a/src/main/java/fi/flexplex/lib/WebSocketClient.java b/src/main/java/fi/flexplex/lib/WebSocketClient.java index 901049d..0d136f8 100644 --- a/src/main/java/fi/flexplex/lib/WebSocketClient.java +++ b/src/main/java/fi/flexplex/lib/WebSocketClient.java @@ -76,6 +76,10 @@ public final class WebSocketClient { } } break; + case "HELLO": + for (final FlexLibAdapter listener : flexLib.getEventListeners()) { + listener.onWebSocketConnect(); + } default: flexLib.getLogger().warning("Received invalid WebSocket message from FlexPlex. Message: " + args[0]); break;