a118f54
Branches > refactor/use-spec-1 > a118f54 > files / src / net / bowmap
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 TODOsrc/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)