a118f54
Branches > main > a118f54 > files / src / dev / grahp
Sync
Commit: a118f541335656d8cc8ab3185eb6f53130050a11
Parent: a52d65f
4 changed files:
src/net/bowmap/message_application.clj view file
@@ -35,7 +35,6 @@ (s/fdef apply-message :args (s/cat ::msg/message ::client/client) :ret ::response) (defmethod apply-message :default [msg client]- (prn "Unhandled message:" msg) {::client/client client}) (defmethod apply-message ::srv/handshaking [msg client]src/net/bowmap/network/message/registry.clj view file
@@ -9,5 +9,5 @@ {::msg/id ::client/registry-data ::reg/id id ::reg/entries (for [[entry-id data] m]- {::reg/entry-id entry-id- ::reg/entry-data data})}))+ {::reg/entry-id entry-id+ ::reg/entry-data data})}))src/net/bowmap/network/message/server.clj view file
@@ -2,13 +2,14 @@ (:require [clojure.alpha.spec :as s] [dev.grahp.build :refer [build]]- [dev.grahp.error :refer [adorn defn! get!]]+ [dev.grahp.error :refer [adorn defn! get! raise]] [net.bowmap.network.message :as msg] [net.bowmap.network.packet :as pk] [net.bowmap.network.packet.read :refer [->bit-mask ->byte ->double ->enum- ->float ->long ->position ->short- ->string ->table ->ubyte ->uuid- ->varint]]+ ->float ->identifier ->int ->list+ ->long ->optional ->position+ ->short ->string ->table ->ubyte+ ->uuid ->varint]] [net.bowmap.network.state :as state]) (:import [io.netty.buffer ByteBuf]))@@ -126,38 +127,108 @@ ::use-item ::custom-click-action]})) +(def idfc [])+(def TODO [])+ (def ^{:spec (s/map-of ::msg/id (s/fspec :args (s/cat :buf #(instance? ByteBuf %)) :ret ::msg/message))} packets (build-message-readers+ ; Handshaking {::handshaking [:protocol ->varint :address ->string :port ->short :intent (->enum ->varint {1 ::state/status 2 ::state/login 3 ::state/transfer})]++ ; Status ::status-request [] ::ping-request [:timestamp ->long]++ ; Login ::login-start [:username ->string :uuid ->uuid]+ ::encryption-response [:shared-secret (->list ->byte)]+ ::login-plugin-response [:message ->varint+ :data (fn [buf] (raise "Fuck you"))] ::login-acknowledged []- ;; This packet has more fields I just don't care about them :p- ::plugin-message []- ;; This packet also has a bunch of fields that I probably do care about!- ::client-information []- ::known-packs []+ ::cookie-response [:key ->identifier+ :payload (->optional (->list ->byte))]++ ; Config++ ::client-information idfc+ ::plugin-message idfc ::finish-config []+ ::pong [:id ->int]+ ::resource-pack-response [:uuid ->uuid+ :result (->enum ->varint {0 :sucessfully-downloaded+ 1 :declined+ 2 :failed-to-download+ 3 :accepted+ 4 :downloaded+ 5 :invalid-url+ 6 :failed-to-reload+ 7 :discarded})]+ ; The wiki is too damn confusing+ ::known-packs idfc+ ::custom-click-action TODO+ ::accept-code-of-conduct TODO++ ;; This packet has more fields I just don't care about them :p+ ;; This packet also has a bunch of fields that I probably do care about!++ ; Play+ ::confirm-teleportation [:teleport-id ->varint]- ::keep-alive [:id ->long]+ ::query-block-entity-tag TODO+ ::bundle-item-selected TODO+ ::change-difficulty TODO+ ::change-game-mode TODO+ ::acknowledge-message TODO+ ::chat-command TODO+ ::signed-chat-command TODO+ ::chat-message TODO+ ::player-session TODO+ ::chunk-batch-received TODO+ ::client-status TODO ::client-tick-end []- ::player-loaded []- ::player-input [:flags (->bit-mask ->ubyte [:forward :backward :left :right :jump :sneak :sprint])]+ ::command-suggestions-request TODO+ ::acknowledge-configuration TODO+ ::click-container-button TODO+ ::click-container TODO+ ::close-container TODO+ ::change-container-slot-state TODO+ ::debug-subscription-request TODO+ ::edit-book TODO+ ::query-entity-tag TODO+ ::interact TODO+ ::jigsaw-generate TODO+ ::keep-alive [:id ->long]+ ::lock-difficulty TODO+ ::set-player-rotation [:yaw ->float :pitch ->float :flags ->byte]+ ::set-player-position-and-rotation [:x ->double+ :feet-y ->double+ :z ->double+ :yaw ->float+ :pitch ->float+ :flags ->byte] ::set-player-position [:x ->double :feet-y ->double :z ->double :flags ->byte]+ ::set-player-movement-flags [:flags (->bit-mask ->byte [:on-ground :pushing-against-wall])]+ ::move-vehicle TODO+ ::paddle-boat TODO+ ::pick-item-from-block TODO+ ::pick-item-from-entity TODO+ ;; TODO is this different?+ #_[::ping-request TODO]+ ::place-recipe TODO+ ::player-abilities [:flags (->bit-mask ->byte {1 :flying?})] ; TODO is this right? ::player-action [:status (->enum ->varint [:started-digging :canceled-digging :finished-digging :drop-item-stack :drop-item :update-item-state :swap-item-in-hand]) ; TODO aren't positions and locations different things?@@ -169,13 +240,36 @@ :action-id (->enum ->varint [:leave-bed :start-sprinting :stop-sprinting :start-jumping-with-horse :stop-jumping-with-horse :open-vehicle-inventory :start-flying-with-elytra]) :jump-boost ->varint]- ::player-abilities [:flags (->bit-mask ->byte {1 :flying?})] ; TODO is this right?- ::set-player-position-and-rotation [:x ->double- :feet-y ->double- :z ->double- :yaw ->float- :pitch ->float- :flags ->byte]}))+ ::player-input [:flags (->bit-mask ->ubyte [:forward :backward :left :right :jump :sneak :sprint])]+ ::player-loaded []+ ::change-recipe-book-settings TODO+ ::set-seen-recipe TODO+ ::rename-item TODO+ ::seen-advancements TODO+ ::select-trade TODO+ ::set-beacon-effect TODO+ ::set-held-item TODO+ ::program-command-block TODO+ ::program-command-block-minecart TODO+ ::set-creative-mode-slot TODO+ ::program-jigsaw-block TODO+ ::program-structure-block TODO+ ::set-test-block TODO+ ::update-sign TODO+ ::swing-arm TODO+ ::teleport-to-entity TODO+ ::test-instance-block-action TODO+ ::use-item-on TODO+ ::use-item TODO}))++(assert (= (set (vals packet-ids))+ (set (keys packets))))++(comment+ (require '[clojure.set :as set])+ (let [all-ids (set (vals packet-ids))+ present-ids (set (keys packets))]+ (set/difference all-ids present-ids))) (defn! packet->message "Deserializes one (framed, serialized) packet into a message.src/net/bowmap/network/packet/read.clj view file
@@ -96,3 +96,37 @@ y (bit-shift-right (bit-shift-left v 52) 52) z (bit-shift-right (bit-shift-left v 26) 38)] {:x x :y y :z z}))++;; TODO untested!+(defn- read-array [reader buf length]+ (loop [i 0+ acc []]+ (if (< i length)+ (recur (inc i)+ (conj acc (reader buf)))+ acc)))++(defn ->array [reader length]+ (fn [buf]+ (read-array reader buf length)))++(defn ->list [reader]+ (fn [buf]+ (let [length (->varint buf)]+ (read-array reader buf length))))++(defn ->context-optional [writer]+ (fn [buf x]+ (if x+ (writer buf x)+ buf)))++(defn ->boolean [buf]+ (= 1 (->varint buf)))++(defn ->optional [reader]+ (fn [buf]+ (when (->boolean buf)+ (reader buf))))++(def ->identifier ->string)