92885b7

Branches > client-handling-rewrite > 92885b7 > files

Add login packets

Grahp, 2026-02-27

Commit: 92885b7a1820370214d0144fed1324deb4cce119
Parent: e20a0a8

2 changed files:

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

@@ -20,16 +20,11 @@                         packet-ids)))         registry)) -(defn type->codec [t]-  (if (vector? t)-    (apply write/writer t)-    (write/writer t)))- (defn build-packet [pk-name schema]   (let [fn-name (symbol (str "encode-" (name pk-name) "-packet"))         fields (map :field schema)         types (map :type schema)-        codecs (map type->codec types)+        codecs (map write/writer types)         name-codec-pairs (for [codec codecs]                            [(gensym) codec])         codec-names (map first name-codec-pairs)@@ -43,7 +38,6 @@              `(~codec ~buf (~field ~pk)))          ~buf)))) -;; TODO why does this not use the conform-registry? (defmacro build-packets [registry]   (reduce (fn [acc [packet-id schema]]             (assoc acc packet-id (build-packet packet-id schema)))@@ -58,7 +52,14 @@   (build-packet-ids    {::state/status     [::status-response-     ::pong-response]}))+     ::pong-response]+    ::state/login+    [::login-disconnect+     ::encryption-request+     ::login-success+     ::set-compression+     ::login-plugin-request+     ::login-cookie-request]}))  (defn numeric-id [state id]   (packet-ids {::state/state state ::pk/id id}))@@ -68,7 +69,12 @@   packets   (build-packets    {::status-response [:response "Response to ::sp/status-request" :json]-    ::pong-response [:timestamp "The same timestamp as ::sp/ping-request" :long]}))+    ::pong-response [:timestamp "The same timestamp as ::sp/ping-request" :long]+    ::login-success [:uuid :uuid+                     :username :string+                     :properties [:list [:table [:name :string+                                                 :value :string+                                                 :signature [:optional :string]]]]]}))  (defn packet-encoder [pk]   (packets (::pk/id pk)))

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

@@ -10,6 +10,7 @@    [io.netty.buffer ByteBuf]))  ;; Surely there's a better way to do that lmao+;; TODO turned into 'reader' (defn type->codec   "Takes a type from net.bowmap.codecs.read and returns a form that will evaluate to a function to decode that type from a ByteBuffer"   [t]@@ -38,7 +39,7 @@             (assoc acc packet-id (build-packet packet-id schema)))           {} (reg/conform-registry registry))) -(def ^{:spec (s/map-of ::pk/id (s/fspec :args (s/cat :buf #(instance? % ByteBuf))+(def ^{:spec (s/map-of ::pk/id (s/fspec :args (s/cat :buf #(instance? ByteBuf %))                                         :ret ::pk/packet))}   packets   (build-packets@@ -47,7 +48,9 @@                     :port :short                     :intent [:enum :varint {1 ::state/status 2 ::state/login 3 ::state/transfer}]]      ::status-request []-     ::ping-request [:timestamp :long]}))+     ::ping-request [:timestamp :long]+     ::login-start [:username :string+                    :uuid :uuid]}))  ;; TODO this is unreadable lol (defmacro build-packet-ids [registry]@@ -65,7 +68,13 @@     [::handshaking]     ::state/status     [::status-request-     ::ping-request]}))+     ::ping-request]+    ::state/login+    [::login-start+     ::encryption-response+     ::login-plugin-response+     ::login-acknowledged+     ::login-cookie-response]}))  (defn decode-packet!   "Decodes and returns one packet from ByteBuf 'buf', which should contain at least one readable packet.@@ -84,4 +93,4 @@         dedec (packets packet-id)]     (if dedec       (dedec buf)-      (raise "Failed to decode packet, no such packet with that id." {:id numeric-id :state state}))))+      (raise "Failed to decode packet, no such packet with that id." {:id numeric-id :state state :packet-id packet-id}))))