62d54a1
Branches > main > 62d54a1 > files / src
Unbundle some packet handling things
Commit: 62d54a1576a30409e5650d9b85ff6ec0b51c2243
Parent: 67fc197
4 changed files:
src/net/bowmap/network/handle.clj view file
@@ -6,9 +6,11 @@ [net.bowmap.network.packets.clientbound :as clientbound] [net.bowmap.network.packets.registry :as registry] [net.bowmap.network.packets.serverbound :as serverbound :refer [decode-packet!]]+ [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.gamemode :as gamemode]+ [net.bowmap.server.server :as server])) ; Handles incoming packets from clients @@ -25,14 +27,15 @@ ::state/connection-state (req! pk :intent) :protocol-id (req! pk :protocol))) +; TODO move to a fact and the game logic handler :) (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" :protocol 776}- :players {:online 0- :max 1000}+ :players {:online (count @server/players)+ :max server/max-player-count} ; Is this a text component? Could make that interface :description {:text "Bowmap!"} :enforcesSecureChat false}}))@@ -46,7 +49,7 @@ (defmethod handler ::serverbound/login-start [client pk] (let [{:keys! [uuid username]} pk] (client/send-clientbound-packet- client+ (assoc client ::entity/uuid uuid) {::pk/id ::clientbound/login-success :profile {:uuid uuid :username username@@ -121,22 +124,23 @@ (let [entity-id (entity/next-entity-id!) client (assoc client ::state/connection-state ::state/play- ::entity/id entity-id)]+ ::entity/id entity-id)+ player {::entity/id entity-id+ ::entity/uuid (req! client ::entity/uuid)}] (client/send-clientbound-packet client {::pk/id ::clientbound/login- ;; TODO magic one :p- ;; I think you can keep a registry of entity ids and stick this on the client :entity-id entity-id :hardcore? false- :dimension-names ["world"]- :max-players 1000 ; TODO extract :p+ ; TODO use the registry id, show that connection somehow because this is a reference to that id+ :dimension-names [reg/world-dimension]+ :max-players server/max-player-count :view-distance 32 :simulation-distance 32 :reduced-debug-info? false :enable-respawn-screen? false :do-limited-crafting? false- :dimension-type-id 0- :dimension-name "world"+ :dimension-type-id reg/world-dimension-id+ :dimension-name reg/world-dimension :hashed-seed 203894 :gamemode ::gamemode/adventure :debug-world? false@@ -147,6 +151,9 @@ :online-mode? false :enforce-secure-chat? true}) + (dosync+ (commute server/players conj player))+ (client/send-clientbound-packet client {::pk/id ::clientbound/game-event :event :wait-for-chunks})src/net/bowmap/network/registry.clj view file
@@ -3,9 +3,11 @@ [clojure.set :as set] [net.bowmap.network.chunk :as chunk])) -(def null-sound {:sound_id "bowmap:null"})+(def world-dimension "world") -(let [damage-types ["cactus" "campfire" "cramming" "dragon_breath" "drown" "dry_out" "ender_pearl" "fall" "out_of_world"+(def null-sound {:sound_id "bowmap:null"})+(let [null-sound {:sound_id "bowmap:null"}+ damage-types ["cactus" "campfire" "cramming" "dragon_breath" "drown" "dry_out" "ender_pearl" "fall" "out_of_world" "fly_into_wall" "freeze" "generic" "generic_kill" "hot_floor" "in_fire" "in_wall" "lava" "lightning_bolt" "magic" "on_fire" "outside_border" "stalagmite" "starve" "sweet_berry_bush" "wither" "spear"]]@@ -46,18 +48,18 @@ "resin" {:asset_name "null" :description {:color "#000000" :translate "bowmap.null"}}} - "dimension_type" {"world" {:ambient_light 1.0- :attributes {}- :coordinate_scale 1.0- :has_ceiling false- :has_ender_dragon_fight false- :has_skylight true- :height chunk/world-height- :logical_height chunk/world-height- :infiniburn "#minecraft:infiniburn_overworld"- :min_y 0- :monster_spawn_block_light_limit 0- :monster_spawn_light_level 0}}+ "dimension_type" {world-dimension {:ambient_light 1.0+ :attributes {}+ :coordinate_scale 1.0+ :has_ceiling false+ :has_ender_dragon_fight false+ :has_skylight true+ :height chunk/world-height+ :logical_height chunk/world-height+ :infiniburn "#minecraft:infiniburn_overworld"+ :min_y 0+ :monster_spawn_block_light_limit 0+ :monster_spawn_light_level 0}} "cat_variant" {"cats" {:asset_id "null" :baby_asset_id "null"@@ -195,3 +197,5 @@ (def registry-ids->values (update-vals registries #(zipmap (range) (keys %)))) (def registry-values->ids (update-vals registry-ids->values set/map-invert))++(def world-dimension-id (req! (req! registry-values->ids "worldgen/biome") "plains"))src/net/bowmap/server/entity.clj view file
@@ -4,6 +4,7 @@ ; A unique ephemeral ID for this entity, used in the protocol (s/def ::id pos-int?)+(s/def ::uuid uuid?) (defonce highest-entity-id (ref 0)) (defn next-entity-id! []src/net/bowmap/server/server.clj view file
@@ -0,0 +1,4 @@+(ns net.bowmap.server.server)++(defonce players (ref #{}))+(def max-player-count 1000)