client.clj
Branches > main > 6934025 > files / src / net / bowmap / network / client.clj
(ns net.bowmap.network.client
(:require
[clojure.spec.alpha :as s]
[net.bowmap.network.connection :as connection]
[net.bowmap.network.state :as state]
[net.bowmap.server.entity :as entity]
[net.bowmap.server.server :as server]))
(s/def ::client (s/keys :opt [::state/connection-state ::connection/connection]))
(defn client [socket]
(ref {::state/connection-state ::state/handshaking
::connection/connection (connection/connection socket)}))
(defn leave! [client-ref]
(dosync
(let [{:keys! [::connection/connection] :keys [::playing? ::entity/uuid]} @client-ref]
(try
(when playing?
; What should really happen if this fails?
; Probably should come up with a better solution
(commute server/players dissoc uuid))
(finally
(send connection connection/close!))))))