packet_handling.clj

Branches > main > e6445b6 > files / src / net / bowmap / packet_handling.clj

(ns net.bowmap.packet-handling
  (:require
   [net.bowmap.client.state :as state]
   [net.bowmap.packet :as pk]
   [net.bowmap.packets.client :as cp]
   [net.bowmap.packets.server :as sp]))

(defmulti handle-packet
  (fn [pk client]
    (::pk/id pk)))

(defmethod handle-packet :default [pk client]
  (prn "Unhandled packet:" pk))

;; TODO I think this stateyness could absolutely be encoded in the packet itself...
(defmethod handle-packet ::sp/handshaking [pk client]
  {::state/state (:intent pk)})

(defmethod handle-packet ::sp/status-request [pk client]
  {:response {::pk/id ::cp/status-response
              :response {:to :do}}})