stupid dum amy

This commit is contained in:
amy 2024-11-25 17:00:55 +03:30
parent 9b5b2cd5b0
commit 5c0beb61c7
No known key found for this signature in database

View file

@ -18,7 +18,7 @@ public class Main {
AtomicReference<WsContext> client = new AtomicReference<>(); AtomicReference<WsContext> client = new AtomicReference<>();
Javalin app = Javalin.create(); Javalin app = Javalin.create();
app.post("/send", ctx -> { app.post("/send", ctx -> {
if (client.get() == null){ if (client.get() == null) {
ctx.status(400).result("echo was not found"); ctx.status(400).result("echo was not found");
return; return;
} }
@ -29,7 +29,7 @@ public class Main {
app.ws("/ws", ws -> { app.ws("/ws", ws -> {
ws.onConnect(wsConnectContext -> { ws.onConnect(wsConnectContext -> {
wsConnectContext.session.setIdleTimeout(Duration.ofDays(-1)); 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.send("who tf are you");
wsConnectContext.closeSession(); wsConnectContext.closeSession();
return; return;
@ -37,6 +37,11 @@ public class Main {
client.set(wsConnectContext); client.set(wsConnectContext);
wsConnectContext.send("connected"); wsConnectContext.send("connected");
}); });
ws.onClose(wsCloseContext -> {
if (client.get() != null && client.get().session.equals(wsCloseContext.session)) {
client.set(null);
}
});
}); });