8643329

Branches > main > 8643329 > files

Keepalive + cleanup

Grahp, 2026-07-10

Commit: 86433295e9f6abdeb3f6870274a6cb28ed2ed7d0
Parent: 292b539

2 changed files:

src/net/bowmap/message_application.clj modified (view file)

@@ -142,12 +142,4 @@               :pitch 0               :flags #{}})) -   ::processes [{::process-id ::keep-alive-                 ::process-timeout 20000}]})--#_(defmethod apply-process ::keep-alive [process client]-    {::client/client client-     ::processes [process]-     ::messages-     [{::msg/id ::clientbound/keep-alive-       :id (long (* (rand) Long/MAX_VALUE))}]})+   ::keep-alive? true})

src/net/bowmap/network/minecraft_server.clj modified (view file)

@@ -1,21 +1,28 @@ (ns net.bowmap.network.minecraft-server    (:require-   [clojure.core.async :refer [<!! >!! alt!! chan close! io-thread put!]]+   [clojure.core.async :refer [<!! >!! alt!! chan close! io-thread put!+                               timeout]]    [dev.grahp.error :refer [raise]]    [net.bowmap.message-application :as a]    [net.bowmap.network.client :as client]+   [net.bowmap.network.protocol.message :as msg]    [net.bowmap.network.protocol.message.clientbound :as clientbound]    [net.bowmap.network.protocol.message.serverbound :as serverbound]    [net.bowmap.network.protocol.state :as state]    [net.bowmap.network.server :as server])) -; TODO so now, keepalive...-; Idk. (defn handle-incoming-packet [client packet outgoing-messages]   (let [message (serverbound/packet->message packet (::state/connection-state client))-        {:keys [::client/client ::a/messages]} (a/handle-message message client)]+        {::client/keys! [client] ::a/keys [messages keep-alive?]} (a/handle-message message client)]     (doseq [message messages]       (put! outgoing-messages message))+    (when keep-alive?+      (io-thread+        (loop []+          (when (>!! outgoing-messages {::msg/id ::clientbound/keep-alive+                                        :id (long (* (rand) Long/MAX_VALUE))})+            (<!! (timeout 20000))+            (recur)))))     client))  (defn handle-packets!! [client outgoing-messages]@@ -37,7 +44,7 @@   (let [outgoing-messages (chan 1024)]     (io-thread       (loop [client client]-        (recur (or (handle-packets!! client outgoing-messages) client))))+        (recur (handle-packets!! client outgoing-messages))))     nil))  (defn closing-promise