1abc195

Branches > main > 1abc195 > files / src / net / bowmap / server

Add keep-alive

Grahp, 2026-08-22

Commit: 1abc195a0584907ce5ff6e65b161d30e19ab7d98
Parent: c314e19

2 changed files:

src/net/bowmap/protocol/handle.clj modified (view file)

@@ -164,7 +164,7 @@                          :yaw 0                          :pitch 0                          :flags #{}}))-     :keepalive? true}))+     :keep-alive? true}))  (defn handle-player-update-movement-packet [client {:keys [x feet-y z yaw pitch flags]}]   {:facts [{::fact/id ::fact/updated-player-movement

src/net/bowmap/protocol/server.clj modified (view file)

@@ -1,9 +1,10 @@ (ns net.bowmap.protocol.server   (:require-   [clojure.core.async :refer [<!! >!! alt!! io-thread put!]]+   [clojure.core.async :refer [<!! >!! alt!! chan io-thread put! timeout]]    [net.bowmap.protocol.client :as client]    [net.bowmap.protocol.handle :as handle]-   [net.bowmap.protocol.packet.clientbound :refer [encode-packet!]]+   [net.bowmap.protocol.packet :as pk]+   [net.bowmap.protocol.packet.clientbound :as clientbound :refer [encode-packet!]]    [net.bowmap.protocol.packet.serverbound :refer [decode-packet!]]    [net.bowmap.protocol.state :as state]    [net.bowmap.server.logic :as logic]@@ -15,6 +16,7 @@   (io-thread     (let [client (client/client connection)           clientbound-packets (req! client ::client/clientbound-packets)+          keep-alive (chan)           {::connection/keys! [serverbound-frames clientbound-frames close-fn]} connection]       (try         (loop [client client]@@ -22,18 +24,28 @@             serverbound-frames ([frame]                                 (when (some? frame)                                   (let [packet (decode-packet! frame (::state/connection-state client))-                                        {:keys [client packets facts] :or {:client client}} (handle/handle-packet client packet)]+                                        {:keys [client packets facts keep-alive?] :or {:client client}} (handle/handle-packet client packet)]                                     ; TODO probably want to clean up this side effecting stuff                                     (doseq [pk packets]                                       (put! clientbound-packets pk))                                     (doseq [fact facts]                                       (execute-effects! (map #(assoc % ::client/client client) (logic/handle-fact fact))))+                                    (when keep-alive?+                                      (put! keep-alive true))                                     (recur client))))             clientbound-packets ([packet]                                  (if (some? packet)                                    (do (>!! clientbound-frames (encode-packet! packet (::state/connection-state client)))                                        (recur client))-                                   (throw (Exception. "Clientbound packets was closed idk why"))))))+                                   (throw (Exception. "Clientbound packets was closed idk why"))))+            keep-alive ([x]+                        (when x+                          (put! clientbound-packets {::pk/id ::clientbound/keep-alive+                                                     :id (rand-int Integer/MAX_VALUE)})+                          (io-thread+                            (<!! (timeout 20000))+                            (put! keep-alive true)))+                        (recur client))))         (finally           ; TODO Send player disconnected fact, and update the player list from that           (close-fn))))))