242aed7
Branches > main > 242aed7 > files / src
Unbundle client agent from packet handling code
Commit: 242aed74e25353ca132a26cb5e11ec08143ed821
Parent: b557414
3 changed files:
src/net/bowmap/network/client.clj view file
@@ -56,8 +56,7 @@ (defn send-clientbound-packet [client packet] (println "sending packet out: " packet) (write-frame!! (encode-packet! packet (req! client ::state/connection-state))- (Socket/.getOutputStream (req! client ::socket)))- client)+ (Socket/.getOutputStream (req! client ::socket)))) (defn client [socket] (agent {::socket socketsrc/net/bowmap/network/handle.clj view file
@@ -12,20 +12,20 @@ ; Handles incoming packets from clients (defmulti handler- (fn [client client-agent packet]+ (fn [client packet] (::pk/id packet))) -(defmethod handler :default [client a pk]+(defmethod handler :default [client pk] (prn "Unhandled packet:" pk) client) -(defmethod handler ::serverbound/handshaking [client _ pk]+(defmethod handler ::serverbound/handshaking [client pk] (assoc client ::state/connection-state (req! pk :intent) :protocol-id (req! pk :protocol))) -(defmethod handler ::serverbound/status-request [client a _]- (send a client/send-clientbound-packet+(defmethod handler ::serverbound/status-request [client _]+ (client/send-clientbound-packet client {::pk/id ::clientbound/status-response ;; Should be un-bundled yeah. :response {:version {:name "26.2"@@ -37,40 +37,44 @@ :enforcesSecureChat false}}) client) -(defmethod handler ::serverbound/ping-request [client a pk]- (send a client/send-clientbound-packet- {::pk/id ::clientbound/pong-response- :timestamp (:timestamp pk)})+(defmethod handler ::serverbound/ping-request [client pk]+ (client/send-clientbound-packet+ client+ {::pk/id ::clientbound/pong-response+ :timestamp (:timestamp pk)}) client) -(defmethod handler ::serverbound/login-start [client a pk]+(defmethod handler ::serverbound/login-start [client pk] (let [{:keys! [uuid username]} pk]- (send a client/send-clientbound-packet- {::pk/id ::clientbound/login-success- :profile {:uuid uuid- :username username- :properties []}- :session-id (random-uuid)}))+ (client/send-clientbound-packet+ client+ {::pk/id ::clientbound/login-success+ :profile {:uuid uuid+ :username username+ :properties []}+ :session-id (random-uuid)})) client) -(defmethod handler ::serverbound/login-acknowledged [client a pk]- (send a client/send-clientbound-packet- {::pk/id ::clientbound/known-packs- ;; TODO also probably good to unbundle this- :known-packs [{:namespace "minecraft"- :id "core"- :version "26.2"}]})- (assoc client ::state/connection-state ::state/config))+(defmethod handler ::serverbound/login-acknowledged [client _]+ (let [client (assoc client ::state/connection-state ::state/config)]+ (client/send-clientbound-packet+ client+ {::pk/id ::clientbound/known-packs+ ;; TODO also probably good to unbundle this+ :known-packs [{:namespace "minecraft"+ :id "core"+ :version "26.2"}]})+ client)) -(defmethod handler ::serverbound/known-packs [client a pk]+(defmethod handler ::serverbound/known-packs [client _] (doseq [pk (registry/registry-packets)]- (send a client/send-clientbound-packet pk))+ (client/send-clientbound-packet client pk)) - (send a client/send-clientbound-packet {::pk/id ::clientbound/update-tags+ (client/send-clientbound-packet client {::pk/id ::clientbound/update-tags :tagged-registries [{:registry "minecraft:block" :tags [{:tag-name "minecraft:infiniburn_overworld" :entries []}]}]})- (send a client/send-clientbound-packet {::pk/id ::clientbound/update-tags+ (client/send-clientbound-packet client {::pk/id ::clientbound/update-tags :tagged-registries [{:registry "minecraft:damage_type" :tags [{:tag-name "minecraft:is_fire" :entries []}@@ -78,7 +82,7 @@ :entries []} {:tag-name "minecraft:bypasses_shield" :entries []}]}]})- (send a client/send-clientbound-packet {::pk/id ::clientbound/update-tags+ (client/send-clientbound-packet client {::pk/id ::clientbound/update-tagssrc/net/bowmap/network/server.clj view file
@@ -17,7 +17,7 @@ (try (loop [] (let [frame (client/read-frame!! input-stream)]- (handle/process-incoming-frame! client-agent frame))+ (send client-agent handle/process-serverbound-frame frame)) (recur)) (catch EOFException _) (catch SocketException _)