packets.clj

Bowmap · bowmap.git · Tickets

Branches > main > 9879d7f > files / src / net / bowmap / server / runtime / packets.clj

(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])))