141ae58

Branches > refactor/use-spec-1 > 141ae58 > files / src / dev / grahp / error.clj

Update core.clj

Grahp, 2026-05-30

Commit: 141ae58c5352af93f54075e888df6b7a8c0dc15a
Parent: 0e9cbc8

1 changed file:

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

@@ -8,6 +8,12 @@    [net.bowmap.packet.server :as sp]    [net.bowmap.server :as server])) +; Glossary to probably use++; Packet: a serialized byte form, may be framed or unframed+; Framed packet: a byte representation that holds exactly one serialized message+; Message: a map that represents a message being sent between the client and the server, a.k.a. a deserialized packet+ (defn handle-packet   "Handles one ByteBuf of a framed serialized serverbound packet, and returns a    map of :client and :packets."@@ -15,12 +21,37 @@   (let [pk (sp/decode-packet packet-buf (::state/state client))]     (handle/response client pk))) +; could return a map of side-effects as data and be pure.+(defmulti handle-message+  (fn [client msg]+    (:msg/id msg)))++(defn handle-message!+  "Handles one serverbound message from 'client', and performs the side effects of that message.+   Returns the new client state."+  [client msg]+  (let [res (handle-message client msg)]+    (or (:client res) client)))++; TODO why is this not qualified?+(defmethod handle-message :server/handshaking [client msg]+  (assoc client ::state/state (:intent msg)))++; Does it make more sense to use a channel here?+(defn handle-messages+  "Handles all the messages in the client, which may involve sending some messages out, and+   sending some async events to the server.+   And also starting a keepalive loop?"+  [client msg])+ (defn handle-something-or-other [client in packets-out out]   (alt!!+    ; These could be agents around clients with vectors as well instead of immutable maps holding channels     in ([buf]         (when buf           (let [response (handle-packet client buf)]             (when (:keepalive response)+              ; TODO this should probably be a global scheduler               (io-thread                 (loop []                   (<!! (timeout 5000))@@ -41,7 +72,8 @@     (try (loop [client client]            (when-some [client (handle-something-or-other client in packets-out out)]              (recur client)))-         (catch Throwable e (println "In client handler: " e)))))+         (catch Throwable e+           (println "In client handler: " e)))))  (defn start-server []   (server/start-server2! {:handler #'client-handler