responses.clj
Branches > main > 0d60f7a > files / src / net / bowmap / stormbow / responses.clj
(ns net.bowmap.stormbow.responses
(:require
[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 ::connection/connection]} client
packet {::pk/id ::clientbound/status-response
:response server-list-response}
frame (encode-packet! packet connection-state)]
(send connection connection/send-frame-action! frame)))
(defn handle-responses! [responses]
(run! handle-response! responses))