packets.clj

Bowmap · bowmap.git · Tickets

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

(ns net.bowmap.server.runtime.packets
  (:require
   [net.bowmap.server.protocol.packet :as packet]
   [net.bowmap.server.protocol.phase :as phase]
   [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]
      ::serverbound/login-acknowledged [(assoc client ::phase/phase ::phase/config)]
      ::serverbound/finish-config [(assoc client ::phase/phase ::phase/play)]
      [client])))