client.clj

Branches > main > 0b339d9 > files / src / net / bowmap / network / client.clj

(ns net.bowmap.network.client
  (:require
   [clojure.core.async :refer [chan]]
   [clojure.spec.alpha :as s]
   [net.bowmap.network.connection :as connection]
   [net.bowmap.network.packets.clientbound :refer [encode-packet!]]
   [net.bowmap.network.state :as state]))

(s/def ::client (s/keys :opt [::state/connection-state ::connection/connection]))

(defn client [socket]
  {::state/connection-state ::state/handshaking
   ::connection/connection (connection/connection socket)
   ; Not the best place but I can move later
   ::clientbound-packets (chan 1024)})

(defn send-packet!! [client packet]
  (let [{:keys! [::connection/connection ::state/connection-state]} client
        frame (encode-packet! packet connection-state)]
    (connection/send-frame!! frame connection)))