496b7c4
Branches > facts > 496b7c4 > files
Add primitive keepalive
Commit: 496b7c47c394a755350ffbf23162e307a1bfef5c
Parent: a15ac93
2 changed files:
src/net/bowmap/network/client.clj view file
@@ -18,6 +18,7 @@ frame (streams/read-frame!! (Socket/.getInputStream socket))] (decode-packet! frame connection-state))) +; TODO handle errors here as well to disconnect client? (defn send-packet! [client-ref packet] (let [{:keys! [::socket ::state/connection-state]} @client-ref] #_(println "sending packet out: " packet)src/net/bowmap/network/handle.clj view file
@@ -1,7 +1,9 @@ (ns net.bowmap.network.handle (:require+ [clojure.core.async :refer [io-thread]] [net.bowmap.network.chunk :as chunk] [net.bowmap.network.client :refer [send-packet!]]+ [net.bowmap.network.client :as client] [net.bowmap.network.packet :as pk] [net.bowmap.network.packets.clientbound :as clientbound] [net.bowmap.network.packets.registry :as registry]@@ -169,14 +171,20 @@ :velocity-z 0 :yaw 0 :pitch 0- :flags #{}}))}))--; TODO keepalive+ :flags #{}}))+ :keepalive? true})) (defn handle!! [client-ref packet]- (let [{:keys! [client packets]} (handle-packet @client-ref packet)]+ (let [{:keys! [client packets] :keys [keepalive?]} (handle-packet @client-ref packet)] (dosync (ref-set client-ref client)) (doseq [pk packets] (send-packet! client-ref pk))+ (when keepalive?+ (io-thread+ (loop []+ (Thread/sleep 20000)+ (client/send-packet! client-ref {::pk/id ::clientbound/keep-alive+ :id (long (* (rand) Long/MAX_VALUE))})+ (recur)))) client))