From 5c0beb61c73bf38ad3403942827afb4fddec2083 Mon Sep 17 00:00:00 2001 From: amy Date: Mon, 25 Nov 2024 17:00:55 +0330 Subject: [PATCH] stupid dum amy --- src/main/java/dev/exhq/Main.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/exhq/Main.java b/src/main/java/dev/exhq/Main.java index ce57f16..6ea3c57 100644 --- a/src/main/java/dev/exhq/Main.java +++ b/src/main/java/dev/exhq/Main.java @@ -18,7 +18,7 @@ public class Main { AtomicReference client = new AtomicReference<>(); Javalin app = Javalin.create(); app.post("/send", ctx -> { - if (client.get() == null){ + if (client.get() == null) { ctx.status(400).result("echo was not found"); return; } @@ -29,7 +29,7 @@ public class Main { app.ws("/ws", ws -> { ws.onConnect(wsConnectContext -> { wsConnectContext.session.setIdleTimeout(Duration.ofDays(-1)); - if ((wsConnectContext.queryParam("meow") == null) || !Objects.equals(wsConnectContext.queryParam("meow"), pass)){ + if ((wsConnectContext.queryParam("meow") == null) || !Objects.equals(wsConnectContext.queryParam("meow"), pass)) { wsConnectContext.send("who tf are you"); wsConnectContext.closeSession(); return; @@ -37,6 +37,11 @@ public class Main { client.set(wsConnectContext); wsConnectContext.send("connected"); }); + ws.onClose(wsCloseContext -> { + if (client.get() != null && client.get().session.equals(wsCloseContext.session)) { + client.set(null); + } + }); });