0e9cbc8

Branches > client-handling-rewrite > 0e9cbc8 > files

Add server packets & docstrings/comments

Grahp, 2026-05-30

Commit: 0e9cbc80a0ec7172d5d8cde3c05a779471d6e092
Parent: ba47432

6 changed files:

src/dev/grahp/build.clj modified (view file)

@@ -1,7 +1,8 @@ (ns dev.grahp.build)  (defmacro build-  "Builds a map using pairs returned by the body of 'for'."+  "'Buidls' a map using the pairs returned by the body of 'for'.+   Same as (into {} (for ...))."   {:clj-kondo/lint-as 'clojure.core/for}   [bindings & body]   `(into {}

src/dev/grahp/error.clj modified (view file)

@@ -20,8 +20,9 @@      `(throw (~msg ~m ~cause))      `(throw (ex-info ~msg ~m ~cause))))) +; TODO of the same type? (defmacro adorn-  "Catches any throwables 'body' throws and throws an exception caused by the+  "Catches any throwables 'body' throws and throws an exception (not of the same type as the throwable) caused by the    throwable with an additional message and data map."   [body msg m]   `(try ~body

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

@@ -33,6 +33,7 @@      [::status-response       ::pong-response]      ::state/login+     ;; TODO just because the serialized form is different doesn't mean they have to be different message ids...      [::login-disconnect ;; Uses JSON instead of a text component :p       ::encryption-request       ::login-success@@ -273,6 +274,8 @@                          (write/write-varint! (numeric-id pk state))                          (encode-body pk))))) +; TODO also update, see sp/decode-packet+; message->packet (defn encode-packet   "Encodes packet 'pk' into a ByteBuf of the packet bytes.    Like decoding, encoding a packet also requires the connection state, as

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

@@ -9,6 +9,7 @@   (:import    [io.netty.buffer ByteBuf])) +; TODO docstring (defn build-packets [registry]   (reduce (fn [acc [packet-id table]]             (assoc acc packet-id@@ -18,6 +19,7 @@                               ::pk/id packet-id)))))           {} registry)) +; TODO docstring (defn build-packet-ids [registry]   (build [[state packet-ids] registry           [i id] (map-indexed vector packet-ids)]@@ -25,6 +27,7 @@       ::pk/numeric-id i}      id])) +; TODO document why ids are enumerated like this? (def ^{:spec (s/map-of (s/schema [::state/state ::pk/numeric-id]) ::pk/id)}   packet-ids   (build-packet-ids@@ -140,8 +143,22 @@      ::keep-alive [:id :long]      ::client-tick-end []      ::player-loaded []-     ::player-input [:flags [:bit-mask :ubyte [:forward :backward :left :right :jump :sneak :sprint]]]}))+     ::player-input [:flags [:bit-mask :ubyte [:forward :backward :left :right :jump :sneak :sprint]]]+     ::set-player-rotation [:yaw :float+                            :pitch :float+                            :flags :byte]+     ::set-player-position [:x :double+                            :feet-y :double+                            :z :double+                            :flags :byte]+     ::set-player-position-and-rotation [:x :double+                                         :feet-y :double+                                         :z :double+                                         :yaw :float+                                         :pitch :float+                                         :flags :byte]})) +; TODO update to reflect packet/message distinction (defn decode-packet   "Decodes/deserializes one packet (::net.bowmap.packet) from framed ByteBuf 'buf'.    The initial length field of the packet should be stripped from the buffer.

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

@@ -6,10 +6,16 @@    [net.bowmap.packet.registry :as registry]    [net.bowmap.packet.server :as sp])) +; "packet handling" is inherently about the low-level protocol level, so either handle stuff at a low level or turn+; packets into high level game events to be sent somewhere else+ (defmulti handle-packet   (fn [pk client]     (::pk/id pk))) +; Should return just a client...+; Should be a much better interface as well+; Basically sending a packet into the server? (defn response   "Returns a map of a client, and any other keys a packet handler may use.    Client may be unchanged, or adorned with any information, such as a new state."@@ -27,10 +33,12 @@  (defmethod handle-packet ::sp/status-request [pk client]   {:response [{::pk/id ::cp/status-response+               ;; Should be un-bundled yeah.                :response {:version {:name "1.21.11"                                     :protocol 774}-                          :players {:max 1000-                                    :online 0}+                          :players {:online 0+                                    :max 1000}+                          ; Is this a text component? Could make that interface                           :description {:text "Bowmap!"}                           :enforcesSecureChat false}}]}) @@ -47,6 +55,7 @@ (defmethod handle-packet ::sp/login-acknowledged [pk client]   {:client (assoc client ::state/state ::state/config)    :response [{::pk/id ::cp/known-packs+               ;; TODO also probably good to unbundle this                :known-packs [{:namespace "minecraft" :id "core" :version "1.12.11"}]}]})  (defmethod handle-packet ::sp/known-packs [pk client]

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

@@ -36,6 +36,7 @@  ; Could return a channel of clients? (defn start-server2!+  "Starts a server at the port, calling 'handler' with an 'in' and 'out' channel of packets."   [& {:keys [handler port]}]   (tcp/start-server (fn [stream info]                       (handle-client handler stream info))