responses.clj
Branches > facts > 508beeb > files / src / net / bowmap / stormbow / responses.clj
(ns net.bowmap.stormbow.responses
(:require
[clojure.core.async :refer [put!]]
[net.bowmap.network.client :as client]
[net.bowmap.network.connection :as connection]
[net.bowmap.network.packet :as pk]
[net.bowmap.network.packets.clientbound :as clientbound :refer [encode-packet!]]
[net.bowmap.network.state :as state]
[net.bowmap.stormbow.response :as response]))
(defmulti handle-response!
(fn [response]
(::response/id response)))
::client/client ::state/connection-state
; TODO currently this must always happen within a transaction, but that's no good!
; This is being called _always_ synchronously from the packet handler, which is also no good for even more reasons
; So, figure out how to not do that?
; This method works outside of a transaction, but it's being passed the client _value_
; The client value may well have changed since this method was called
(defmethod handle-response! ::response/send-server-list [response]
(let [{:keys! [::client/client server-list-response]} response
{:keys! [::state/connection-state ::client/clientbound-packets]} client
packet {::pk/id ::clientbound/status-response
:response server-list-response}]
; Probably just want to return these packets
(put! clientbound-packets packet)))
(defn handle-responses! [responses]
(run! handle-response! responses))