02e7024

Branches > client-handling-rewrite > 02e7024 > files / src

Move protocol-related namespaces into net.bowmap.network.protocol.*

Grahp, 2026-07-08

Commit: 02e70248001ce66722ab23bc09e71d2b1785a24f
Parent: 6f2bf2a

14 changed files:

src/net/bowmap/message_application.clj modified (view file)

@@ -2,13 +2,13 @@   (:require    [clojure.alpha.spec :as s]    [dev.grahp.spec :as S]-   [net.bowmap.network.chunk :as chunk]    [net.bowmap.network.client :as client]-   [net.bowmap.network.message :as msg]-   [net.bowmap.network.message.client :as cl]-   [net.bowmap.network.message.registry :as registry]-   [net.bowmap.network.message.server :as srv]-   [net.bowmap.network.state :as state]+   [net.bowmap.network.protocol.chunk :as chunk]+   [net.bowmap.network.protocol.message :as msg]+   [net.bowmap.network.protocol.message.clientbound :as clientbound]+   [net.bowmap.network.protocol.message.registry :as registry]+   [net.bowmap.network.protocol.message.serverbound :as serverbound]+   [net.bowmap.network.protocol.state :as state]    [net.bowmap.server.gamemode :as gamemode]))  (S/def ::messages (s/coll-of ::msg/message :type vector?))@@ -37,13 +37,13 @@ (defmethod apply-message :default [msg client]   {::client/client client}) -(defmethod apply-message ::srv/handshaking [msg client]+(defmethod apply-message ::serverbound/handshaking [msg client]   {::client/client (assoc client ::state/connection-state (:intent msg))}) -(defmethod apply-message ::srv/status-request [_ client]+(defmethod apply-message ::serverbound/status-request [_ client]   {::client/client client    ::messages-   [{::msg/id ::cl/status-response+   [{::msg/id ::clientbound/status-response      ;; Should be un-bundled yeah.      :response {:version {:name "1.21.11"                           :protocol 774}@@ -53,37 +53,37 @@                 :description {:text "Bowmap!"}                 :enforcesSecureChat false}}]}) -(defmethod apply-message ::srv/ping-request [msg client]+(defmethod apply-message ::serverbound/ping-request [msg client]   {::client/client client    ::messages-   [{::msg/id ::cl/pong-response+   [{::msg/id ::clientbound/pong-response      :timestamp (:timestamp msg)}]}) -(defmethod apply-message ::srv/login-start [msg client]+(defmethod apply-message ::serverbound/login-start [msg client]   {::client/client client    ::messages-   [{::msg/id ::cl/login-success+   [{::msg/id ::clientbound/login-success      :uuid (:uuid msg)      :username (:username msg)      :properties []}]}) -(defmethod apply-message ::srv/login-acknowledged [_ client]+(defmethod apply-message ::serverbound/login-acknowledged [_ client]   {::client/client (assoc client ::state/connection-state ::state/config)    ::messages-   [{::msg/id ::cl/known-packs+   [{::msg/id ::clientbound/known-packs      ;; TODO also probably good to unbundle this      :known-packs [{:namespace "minecraft"                     :id "core"                     :version "1.12.11"}]}]}) -(defmethod apply-message ::srv/known-packs [_ client]+(defmethod apply-message ::serverbound/known-packs [_ client]   {::client/client client    ::messages    (conj (vec (registry/registry-messages))-         {::msg/id ::cl/finish-config})})+         {::msg/id ::clientbound/finish-config})})  (defn- build-chunk-messages []-  (let [pk {::msg/id ::cl/chunk-data-and-update-light+  (let [pk {::msg/id ::clientbound/chunk-data-and-update-light             :chunk-data             (let [stone {:block-count (* 16 16 16)                          :block-states {:bpe 0@@ -103,10 +103,10 @@              :chunk-x x              :chunk-z z)))) -(defmethod apply-message ::srv/finish-config [_ client]+(defmethod apply-message ::serverbound/finish-config [_ client]   {::client/client (assoc client ::state/connection-state ::state/play)    ::messages-   (-> [{::msg/id ::cl/login+   (-> [{::msg/id ::clientbound/login          ;; TODO magic zero :p          ;; I think you can keep a registry of entity ids and stick this on the client          :entity-id 0@@ -129,10 +129,10 @@          :sea-level 60          :enforce-secure-chat? true}

Show all 117 lines

src/net/bowmap/minecraft_server.clj modified (view file)

@@ -3,10 +3,10 @@    [clojure.core.async :refer [<!! >!! alt!! chan io-thread put! timeout]]    [net.bowmap.message-application :as a]    [net.bowmap.network.client :as client]-   [net.bowmap.network.message.client :as cl]-   [net.bowmap.network.message.server :as srv]-   [net.bowmap.network.server :as server]-   [net.bowmap.network.state :as state]))+   [net.bowmap.network.protocol.message.clientbound :as clientbound]+   [net.bowmap.network.protocol.message.serverbound :as serverbound]+   [net.bowmap.network.protocol.state :as state]+   [net.bowmap.network.server :as server]))  ; The logical server, holds a set of clients connected @@ -25,7 +25,7 @@    Because packet reading is dependent on the state of the client, and handling a packet can update the state of the client,    Reading and handling must be synchronized!"   [pk client messages-out process-chan]-  (when-some [msg (srv/packet->message pk (::state/connection-state client))]+  (when-some [msg (serverbound/packet->message pk (::state/connection-state client))]     (run-effects! messages-out process-chan (a/apply-message msg client))))  (defn handle-process! [process client messages-out process-chan]@@ -38,7 +38,7 @@                   (handle-process! process client messages-out process-chan))     messages-out ([msg]                   (when msg-                    (assert (>!! packets-out (cl/message->packet msg (::state/connection-state client))))+                    (assert (>!! packets-out (clientbound/message->packet msg (::state/connection-state client))))                     client))     packets-in ([pk]                 (when pk

src/net/bowmap/network/protocol/chunk.clj renamed from src/net/bowmap/network/chunk.clj (view file)

@@ -1,4 +1,4 @@-(ns net.bowmap.network.chunk+(ns net.bowmap.network.protocol.chunk   (:require [clojure.alpha.spec :as s]))  (s/def ::coordinate (s/schema [::x ::y ::z]))

src/net/bowmap/network/protocol/message.clj renamed from src/net/bowmap/network/message.clj (view file)

@@ -1,4 +1,4 @@-(ns net.bowmap.network.message+(ns net.bowmap.network.protocol.message   (:require    [clojure.alpha.spec :as s]    [dev.grahp.spec :as S]))

src/net/bowmap/network/protocol/message/clientbound.clj renamed from src/net/bowmap/network/message/client.clj (view file)

@@ -1,17 +1,17 @@-(ns net.bowmap.network.message.client+(ns net.bowmap.network.protocol.message.clientbound   (:require    [clojure.alpha.spec :as s]    [dev.grahp.build :refer [build]]-   [net.bowmap.network.message :as msg]-   [net.bowmap.network.packet :as pk]-   [net.bowmap.network.packet.types :as t]-   [net.bowmap.network.packet.write :as write+   [net.bowmap.network.protocol.message :as msg]+   [net.bowmap.network.protocol.packet :as pk]+   [net.bowmap.network.protocol.types :as t]+   [net.bowmap.network.protocol.writers :as write     :refer [bit-mask-> boolean-> byte-> chunk-data-> coerce context-optional->             double-> enum-> float-> identifier-> int-> json-> length-prefixed             light-data-> list-> long-> nbt-> optional-> or-> position->             string-> ubyte-> uuid-> varint->]]-   [net.bowmap.network.registry :as reg]-   [net.bowmap.network.state :as state]+   [net.bowmap.network.protocol.registry :as reg]+   [net.bowmap.network.protocol.state :as state]    [net.bowmap.server.gamemode :as gamemode])   (:import    [io.netty.buffer Unpooled]))

src/net/bowmap/network/protocol/message/registry.clj renamed from src/net/bowmap/network/message/registry.clj (view file)

@@ -1,8 +1,8 @@-(ns net.bowmap.network.message.registry+(ns net.bowmap.network.protocol.message.registry   (:require-   [net.bowmap.network.message :as msg]-   [net.bowmap.network.message.client :as client]-   [net.bowmap.network.registry :as reg]))+   [net.bowmap.network.protocol.message :as msg]+   [net.bowmap.network.protocol.message.clientbound :as client]+   [net.bowmap.network.protocol.registry :as reg]))  (defn registry-messages []   (for [[id m] (partition 2 reg/registries)]

src/net/bowmap/network/protocol/message/serverbound.clj renamed from src/net/bowmap/network/message/server.clj (view file)

@@ -1,15 +1,15 @@-(ns net.bowmap.network.message.server+(ns net.bowmap.network.protocol.message.serverbound   (:require    [clojure.alpha.spec :as s]    [dev.grahp.build :refer [build]]    [dev.grahp.error :refer [adorn raise]]-   [net.bowmap.network.message :as msg]-   [net.bowmap.network.packet :as pk]-   [net.bowmap.network.packet.read+   [net.bowmap.network.protocol.message :as msg]+   [net.bowmap.network.protocol.packet :as pk]+   [net.bowmap.network.protocol.readers     :refer [->bit-mask ->byte ->double ->enum ->float ->identifier ->int             ->list ->long ->optional ->position ->short ->string ->ubyte             ->uuid ->varint coerce]]-   [net.bowmap.network.state :as state])+   [net.bowmap.network.protocol.state :as state])   (:import    [io.netty.buffer ByteBuf])) 

src/net/bowmap/network/protocol/packet.clj renamed from src/net/bowmap/network/packet.clj (view file)

@@ -1,7 +1,7 @@-(ns net.bowmap.network.packet+(ns net.bowmap.network.protocol.packet   (:require    [dev.grahp.spec :as S]-   [net.bowmap.network.packet.read :as read]) +   [net.bowmap.network.protocol.readers :as read])   (:import    [io.netty.buffer ByteBuf Unpooled])) 

src/net/bowmap/network/protocol/readers.clj renamed from src/net/bowmap/network/packet/read.clj (view file)

@@ -1,11 +1,11 @@-(ns net.bowmap.network.packet.read+(ns net.bowmap.network.protocol.readers   "Functions for reading data from serialized packet ByteBufs.    When given bad data, read functions will throw.    See https://minecraft.wiki/w/Java_Edition_protocol/Packets#Data_types"   (:require    [dev.grahp.error :refer [adorn ensure-not! raise]]    [dev.grahp.spec :as S]-   [net.bowmap.network.packet.types :as t])+   [net.bowmap.network.protocol.types :as t])   (:import    [io.netty.buffer ByteBuf]    [java.nio.charset Charset]

src/net/bowmap/network/protocol/registry.clj renamed from src/net/bowmap/network/registry.clj (view file)

@@ -1,6 +1,6 @@-(ns net.bowmap.network.registry+(ns net.bowmap.network.protocol.registry   (:require-   [net.bowmap.network.chunk :as chunk]))+   [net.bowmap.network.protocol.chunk :as chunk]))  ;; Some way to keep track of order of these things and make that clear... ;; Probably a map of id -> order?

src/net/bowmap/network/protocol/state.clj renamed from src/net/bowmap/network/state.clj (view file)

@@ -1,4 +1,4 @@-(ns net.bowmap.network.state+(ns net.bowmap.network.protocol.state   (:require    [dev.grahp.spec :as S])) 

src/net/bowmap/network/protocol/types.clj renamed from src/net/bowmap/network/packet/types.clj (view file)

@@ -1,4 +1,4 @@-(ns net.bowmap.network.packet.types+(ns net.bowmap.network.protocol.types   (:require    [clojure.alpha.spec :as s])) 

src/net/bowmap/network/protocol/writers.clj renamed from src/net/bowmap/network/packet/write.clj (view file)

@@ -1,4 +1,4 @@-(ns net.bowmap.network.packet.write+(ns net.bowmap.network.protocol.writers   "Functions to write Minecraft protocol types.    When given bad data, write functions will throw.    See https://minecraft.wiki/w/Java_Edition_protocol/Packets#Data_types"@@ -8,8 +8,8 @@    [clojure.set :as set]    [dev.grahp.error :refer [adorn raise]]    [dev.grahp.spec :as S]-   [net.bowmap.network.message :as msg]-   [net.bowmap.network.packet.types :as t])+   [net.bowmap.network.protocol.message :as msg]+   [net.bowmap.network.protocol.types :as t])   (:import    [io.netty.buffer ByteBuf CompositeByteBuf Unpooled]    [java.nio.charset Charset]

src/net/bowmap/network/server.clj modified (view file)

@@ -3,7 +3,7 @@    [aleph.tcp :as tcp]    [clojure.core.async :refer [chan put!]]    [manifold.stream :as s]-   [net.bowmap.network.packet :as pk])+   [net.bowmap.network.protocol.packet :as pk])   (:import    [io.netty.bootstrap ServerBootstrap]    [io.netty.channel ChannelOption]))