e990856

Bowmap · bowmap.git · Tickets

Branches > main > e990856 > files / src / net / bowmap / server / protocol

Separate client state update and packet handling and move to better namespaces

Grahp, 2026-09-25

Commit: e9908564af509f4482c812c4f88382a3afbac9dd
Parent: 88faa97

3 changed files:

src/net/bowmap/server/game/handle.clj added (view file)

@@ -0,0 +1,24 @@+(ns net.bowmap.server.game.handle+  (:require+   [net.bowmap.server.protocol.clientbound-packets :as clientbound]+   [net.bowmap.server.protocol.component :as component]+   [net.bowmap.server.protocol.packet :as packet]+   [net.bowmap.server.protocol.schema :as p]+   [net.bowmap.server.protocol.serverbound-packets :as serverbound]))++(defmulti handle-packet+  "Handles a packet from a player, returning [player' [packets*]?]."+  (fn [player packet]+    (::packet/id packet)))++(defmethod handle-packet :default [player _] [player])++(defmethod handle-packet ::serverbound/status-request [player _]+  [player+   [{::packet/id ::clientbound/status-response+     ::p/version-name "26.2"+     ::p/protocol 776+     ::p/motd {::component/text "Bowmap!"+               ::component/color "#9f9f9f"}+     ::p/online-player-count 0+     ::p/max-player-count 1000}]])

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

@@ -1,10 +1,22 @@ (ns net.bowmap.server.runtime.connections   (:require+   [net.bowmap.server.game.handle :as handle]    [net.bowmap.server.network.connection :as connection]    [net.bowmap.server.network.server :as server]+   [net.bowmap.server.protocol.packet :as packet]    [net.bowmap.server.protocol.packet-serialization :as serialize]    [net.bowmap.server.protocol.phase :as phase]-   [net.bowmap.server.runtime.packets :as packets]))+   [net.bowmap.server.protocol.serverbound-packets :as serverbound]))++(defn apply-packet+  "Returns the value a client should take on when handling 'packet'."+  [client packet]+  (let [{::packet/keys! [id]} packet]+    (case id+      ::serverbound/handshaking (assoc client ::phase/phase (req! packet ::phase/phase))+      ::serverbound/login-acknowledged (assoc client ::phase/phase ::phase/config)+      ::serverbound/finish-config (assoc client ::phase/phase ::phase/play)+      client)))  (defn handle-connection! [connection]   (let [client (atom {::phase/phase ::phase/handshaking})@@ -15,12 +27,12 @@       (when-some [frame (connection/receive-frame!! connection)]         (let [c @client               packet (serialize/decode-frame c frame)-              [client' packets] (packets/apply-packet c packet)]+              client' (apply-packet c packet)]           (assert (compare-and-set! client c client'))-          (let [[player' packets] (packets/handle-packet @player packet)]+          (let [[player' packets] (handle/handle-packet @player packet)]             (reset! player player')-            (run! send-packet! packets))-          (recur))))))+            (run! send-packet! packets)))+        (recur)))))  (defn handle-connections!   [server]

src/net/bowmap/server/runtime/packets.clj deleted (view file)

@@ -1,26 +0,0 @@-(ns net.bowmap.server.runtime.packets-  (:require-   [net.bowmap.server.protocol.clientbound-packets :as clientbound]-   [net.bowmap.server.protocol.component :as component]-   [net.bowmap.server.protocol.packet :as packet]-   [net.bowmap.server.protocol.phase :as phase]-   [net.bowmap.server.protocol.schema :as p]-   [net.bowmap.server.protocol.serverbound-packets :as serverbound]))--(defn apply-packet-  "'Applies' a serverbound packet to a client.-   Returns [client' [packet*]?]"-  [client packet]-  (let [{::packet/keys! [id]} packet]-    (case id-      ::serverbound/handshaking [(assoc client ::phase/phase (req! packet ::phase/phase))]-      ::serverbound/status-request [client [{::packet/id ::clientbound/status-response-                                             ::p/version-name "26.2"-                                             ::p/protocol 776-                                             ::p/motd {::component/text "Bowmap!"-                                                       ::component/color "#9f9f9f"}-                                             ::p/online-player-count 0-                                             ::p/max-player-count 1000}]]-      ::serverbound/login-acknowledged [(assoc client ::phase/phase ::phase/config)]-      ::serverbound/finish-config [(assoc client ::phase/phase ::phase/play)]-      [client])))