2ba13a7
Branches > main > 2ba13a7 > files / src / net / bowmap
Add login and play packets to new client handling
Commit: 2ba13a700f8a6862b24b82e15ab891abf71c0534
Parent: 083e2e7
1 changed file:
src/net/bowmap/network/handle.clj view file
@@ -1,10 +1,15 @@ (ns net.bowmap.network.handle (:require+ [net.bowmap.network.chunk :as chunk] [net.bowmap.network.client :refer [send-packet!]] [net.bowmap.network.packet :as pk] [net.bowmap.network.packets.clientbound :as clientbound]+ [net.bowmap.network.packets.registry :as registry] [net.bowmap.network.packets.serverbound :as serverbound]+ [net.bowmap.network.registry :as reg] [net.bowmap.network.state :as state]+ [net.bowmap.server.entity :as entity]+ [net.bowmap.server.gamemode :as gamemode] [net.bowmap.server.server :as server])) (defmulti handle-packet@@ -12,13 +17,15 @@ (::pk/id packet))) (defmethod handle-packet :default [client _]- {:client client})+ {:client client+ :packets []}) (defmethod handle-packet ::serverbound/handshaking [client pk] (let [{:keys! [intent protocol]} pk] {:client (assoc client ::state/connection-state intent- :protocol-id protocol)}))+ :protocol-id protocol)+ :packets []})) ; TODO move to a fact and the game logic handler :) (defmethod handle-packet ::serverbound/status-request [client _]@@ -33,8 +40,143 @@ :description {:text "Bowmap!"} :enforcesSecureChat false}}]}) +(defmethod handle-packet ::serverbound/ping-request [client pk]+ {:client client+ :packets [{::pk/id ::clientbound/pong-response+ :timestamp (:timestamp pk)}]})++(defmethod handle-packet ::serverbound/login-start [client pk]+ (let [{:keys! [uuid username]} pk]+ {:client (assoc client ::entity/uuid uuid)+ :packets [{::pk/id ::clientbound/login-success+ :profile {:uuid uuid+ :username username+ :properties []}+ :session-id (random-uuid)}]}))++(defmethod handle-packet ::serverbound/login-acknowledged [client _]+ {:client (assoc client ::state/connection-state ::state/config)+ :packets [{::pk/id ::clientbound/known-packs+ ;; TODO also probably good to unbundle this+ :known-packs [{:namespace "minecraft"+ :id "core"+ :version "26.2"}]}]})++; TODO how to update state here?+; Yield facts from this as well and send 'em in!+; Or well, this can be retried so just use the dosync+(defmethod handle-packet ::serverbound/known-packs [client _]+ {:client client+ :packets (conj (vec (registry/registry-packets))+ {::pk/id ::clientbound/update-tags+ :tagged-registries [{:registry "minecraft:block"+ :tags [{:tag-name "bowmap:infiniburn"+ :entries []}]}]}++ {::pk/id ::clientbound/update-tags+ :tagged-registries [{:registry "minecraft:damage_type"+ :tags [{:tag-name "minecraft:is_fire"+ :entries []}+ {:tag-name "minecraft:is_explosion"+ :entries []}+ {:tag-name "minecraft:bypasses_shield"+ :entries []}]}]}++ {::pk/id ::clientbound/update-tags+ :tagged-registries [{:registry "minecraft:banner_pattern"+ :tags [{:tag-name "minecraft:pattern_item/bordure_indented" :entries []}+ {:tag-name "minecraft:pattern_item/creeper" :entries []}+ {:tag-name "minecraft:pattern_item/field_masoned" :entries []}+ {:tag-name "minecraft:pattern_item/flow" :entries []}+ {:tag-name "minecraft:pattern_item/flower" :entries []}+ {:tag-name "minecraft:pattern_item/globe" :entries []}+ {:tag-name "minecraft:pattern_item/guster" :entries []}+ {:tag-name "minecraft:pattern_item/mojang" :entries []}+ {:tag-name "minecraft:pattern_item/piglin" :entries []}+ {:tag-name "minecraft:pattern_item/skull" :entries []}]}]}++ {::pk/id ::clientbound/finish-config})})+++(defn- build-chunk-packets []+ (let [pk {::pk/id ::clientbound/chunk-data-and-update-light+ :chunk-data+ (let [stone {:block-count (* 16 16 16)