82d578c

Branches > client-handling-rewrite > 82d578c > files

yeah i'm pretty indecisive about the specs

Grahp, 2026-06-02

Commit: 82d578ce2b3f47c37f6e790ec392aabb156743f2
Parent: da5bbf0

2 changed files:

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

@@ -1,24 +1,18 @@-; TODO (ns net.bowmap.network.message.client-  "Clientbound packets"   (:require    [clojure.alpha.spec :as s]    [dev.grahp.build :refer [build]]    [dev.grahp.error :refer [adorn get!]]-   [dev.grahp.spec :as S]    [net.bowmap.network.message :as msg]    [net.bowmap.network.packet :as pk]    [net.bowmap.network.packet.types :as t]-   [net.bowmap.network.packet.write :refer [boolean-> byte->-                                            context-optional-> enum-> float->-                                            identifier-> int-> json->-                                            length-prefixed list-> long->-                                            nbt-> optional-> or-> position->-                                            string-> table-> ubyte-> uuid->-                                            varint->]]+   [net.bowmap.network.packet.write :as write+    :refer [boolean-> byte-> context-optional-> enum-> float-> identifier->+            int-> json-> length-prefixed list-> long-> nbt-> optional-> or->+            position-> string-> table-> ubyte-> uuid-> varint->]]    [net.bowmap.network.state :as state])   (:import-   [io.netty.buffer ByteBuf Unpooled]))+   [io.netty.buffer Unpooled]))  (defn build-packet-ids [registry]   (build [[state packet-ids] registry@@ -29,7 +23,7 @@  (s/fdef build-packet-ids         :args (s/cat :registry (s/map-of ::state/connection-state (s/coll-of ::msg/id :type vector?)))-        :ret ::message->packet-ids)+        :ret (s/map-of (s/schema [::state/connection-state ::msg/id]) ::pk/id))  (defn build-packets [registry]   (reduce (fn [acc [packet-id table]]@@ -38,13 +32,10 @@  (s/fdef build-packets         :args (s/cat (s/map-of ::msg/id ::t/table))-        :ret ::packets)+        :ret (s/map-of ::msg/id ::write/writer)) -(S/def ::message->packet-ids (s/map-of (s/schema [::state/connection-state ::msg/id]) ::pk/id))-(def message->packet-ids-  ; Packet ids could map directly to numeric-ids and be stateless,-  ; but some packets have duplicates across connection states that you'd want to handle in the same way.-  ; If it turns out that I don't end up handling packets in this way, then packet ids could map directly to numeric ids.+(def ^{:spec ::message->packet-ids}+  message->packet-ids   (build-packet-ids     {::state/status      [::status-response@@ -219,9 +210,6 @@       ::clear-dialog       ::show-dialog-play]})) -(S/def ::packets-  (s/map-of ::msg/id (s/fspec :args (s/cat :buf #(instance? ByteBuf %) :pk ::msg/message)-                              :ret #(instance? ByteBuf %)))) (def packets   (build-packets     {::status-response [:response "Response to serverbound ::status-request" json->]

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

@@ -3,16 +3,22 @@    When given bad data, write functions will throw.    See https://minecraft.wiki/w/Java_Edition_protocol/Packets#Data_types"   (:require+   [clojure.alpha.spec :as s]    [clojure.data.json :as json]    [clojure.set :as set]    [dev.grahp.error :refer [adorn raise]]    [dev.grahp.spec :as S]+   [net.bowmap.network.message :as msg]    [net.bowmap.network.packet.types :as t])   (:import    [io.netty.buffer ByteBuf CompositeByteBuf Unpooled]    [java.nio.charset Charset]    [java.util UUID])) +(S/def ::writer (s/fspec :args (s/cat :buf #(instance? ByteBuf %) :msg ::msg/message)+                         :ret #(instance? ByteBuf %)))++ (defn varint-> [buf n]   (loop [buf buf          n n]