c649fcf

Branches > facts > c649fcf > files / src / net / bowmap / stormbow

Better use new connection interface

Grahp, 2026-08-22

Commit: c649fcfe1e1bbdf1870245949c46e630b47d717c
Parent: bf7e6f7

2 changed files:

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

@@ -1,9 +1,8 @@ (ns net.bowmap.network.client   (:require-   [clojure.core.async :refer [>!! chan]]+   [clojure.core.async :refer [chan]]    [clojure.spec.alpha :as s]    [net.bowmap.network.connection :as connection]-   [net.bowmap.network.packets.clientbound :refer [encode-packet!]]    [net.bowmap.network.state :as state]))  (s/def ::client (s/keys :opt [::state/connection-state ::connection/connection]))@@ -13,9 +12,3 @@    ::connection/connection connection    ; Not the best place but I can move later    ::clientbound-packets (chan 1024)})--(defn send-packet!! [client packet]-  (let [{:keys! [::connection/connection ::state/connection-state]} client-        {:keys! [::connection/clientbound-frames]} connection-        frame (encode-packet! packet connection-state)]-    (>!! clientbound-frames frame)))

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

@@ -1,22 +1,21 @@ (ns net.bowmap.network.server   (:require-   [clojure.core.async :refer [<!! alt!! io-thread put!]]-   [net.bowmap.network.client :as client :refer [send-packet!!]]+   [clojure.core.async :refer [<!! >!! alt!! io-thread put!]]+   [net.bowmap.network.client :as client]    [net.bowmap.network.connection :as connection]    [net.bowmap.network.handle :as handle]    [net.bowmap.network.minecraft-server :as mc]+   [net.bowmap.network.packets.clientbound :refer [encode-packet!]]    [net.bowmap.network.packets.serverbound :refer [decode-packet!]]    [net.bowmap.network.state :as state]-   [net.bowmap.server.entity :as entity]    [net.bowmap.server.logic :as logic]-   [net.bowmap.stormbow.fact :as fact]    [net.bowmap.stormbow.responses :refer [handle-responses!]]))  (defn handle-connection [connection]   (io-thread     (let [client (client/client connection)           clientbound-packets (req! client ::client/clientbound-packets)-          serverbound-frames (req! connection ::connection/serverbound-frames)]+          {::connection/keys! [serverbound-frames clientbound-frames close-fn]} connection]       (try         (loop [client client]           (alt!!@@ -29,17 +28,14 @@                                     (doseq [fact facts]                                       (handle-responses! (logic/handle-fact fact)))                                     (recur client))))-            clientbound-packets ([pk]-                                 (if (some? pk)-                                   ; Would be nice to enqueue frames so there is symmetry-                                   (do (send-packet!! client pk)+            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"))))))         (finally           ; TODO Send player disconnected fact, and update the player list from that-          #_(handle-responses! (logic/handle-fact {::fact/id ::fact/player-left-                                                   ::entity/uuid (::entity/uuid client)}))-          ((::close-fn connection)))))))+          (close-fn))))))  (defn start-server! [port]   (let [connections (mc/start-server! port)]