292b539
Branches > main > 292b539 > files
Update names
Commit: 292b5394aa5c1a72abd3fef8dadc92105848c741
Parent: b68825f
3 changed files:
src/net/bowmap/message_application.clj view file
@@ -24,7 +24,7 @@ ; TODO rename :p ; Just return effects instead? ; Handle them at the client level-(defmulti apply-message+(defmulti handle-message "'Applies' a message to a client state. Returns the new client state, as well as the effects that should occur from this message (see the spec)." (fn [msg client]@@ -32,13 +32,13 @@ (s/fdef apply-message :args (s/cat ::msg/message ::client/client) :ret ::response) -(defmethod apply-message :default [msg client]+(defmethod handle-message :default [msg client] {::client/client client}) -(defmethod apply-message ::serverbound/handshaking [msg client]+(defmethod handle-message ::serverbound/handshaking [msg client] {::client/client (assoc client ::state/connection-state (:intent msg))}) -(defmethod apply-message ::serverbound/status-request [_ client]+(defmethod handle-message ::serverbound/status-request [_ client] {::client/client client ::messages [{::msg/id ::clientbound/status-response@@ -51,13 +51,13 @@ :description {:text "Bowmap!"} :enforcesSecureChat false}}]}) -(defmethod apply-message ::serverbound/ping-request [msg client]+(defmethod handle-message ::serverbound/ping-request [msg client] {::client/client client ::messages [{::msg/id ::clientbound/pong-response :timestamp (:timestamp msg)}]}) -(defmethod apply-message ::serverbound/login-start [msg client]+(defmethod handle-message ::serverbound/login-start [msg client] {::client/client client ::messages [{::msg/id ::clientbound/login-success@@ -65,7 +65,7 @@ :username (:username msg) :properties []}]}) -(defmethod apply-message ::serverbound/login-acknowledged [_ client]+(defmethod handle-message ::serverbound/login-acknowledged [_ client] {::client/client (assoc client ::state/connection-state ::state/config) ::messages [{::msg/id ::clientbound/known-packs@@ -74,7 +74,7 @@ :id "core" :version "1.12.11"}]}]}) -(defmethod apply-message ::serverbound/known-packs [_ client]+(defmethod handle-message ::serverbound/known-packs [_ client] {::client/client client ::messages (conj (vec (registry/registry-messages))@@ -101,7 +101,7 @@ :chunk-x x :chunk-z z)))) -(defmethod apply-message ::serverbound/finish-config [_ client]+(defmethod handle-message ::serverbound/finish-config [_ client] {::client/client (assoc client ::state/connection-state ::state/play) ::messages (-> [{::msg/id ::clientbound/loginsrc/net/bowmap/network/minecraft_server.clj view file
@@ -9,27 +9,29 @@ [net.bowmap.network.protocol.state :as state] [net.bowmap.network.server :as server])) -;;;-+; TODO so now, keepalive...+; Idk. (defn handle-incoming-packet [client packet outgoing-messages] (let [message (serverbound/packet->message packet (::state/connection-state client))- {:keys [::client/client ::a/messages]} (a/apply-message message client)]+ {:keys [::client/client ::a/messages]} (a/handle-message message client)] (doseq [message messages] (put! outgoing-messages message)) client)) (defn handle-packets!! [client outgoing-messages]- (let [{::server/keys! [packets-in packets-out]} client]+ (let [{::server/keys! [incoming-frames outgoing-frames]} client] (alt!!- packets-in ([packet]- (if (some? packet)- (handle-incoming-packet client packet outgoing-messages)- (raise "client incoming packet channel closed!")))- outgoing-messages ([message]- (if (some? message)- (do (>!! packets-out (clientbound/message->packet message (::state/connection-state client)))- client)- (raise "client outgoing message channel closed!"))))))+ incoming-frames+ ([frame]+ (if (some? frame)+ (handle-incoming-packet client frame outgoing-messages)+ (raise "client incoming frame channel closed!")))+ outgoing-messages+ ([message]+ (if (some? message)+ (do (>!! outgoing-frames (clientbound/message->packet message (::state/connection-state client)))+ client)+ (raise "client outgoing message channel closed!")))))) (defn connect! [client] (let [outgoing-messages (chan 1024)]src/net/bowmap/network/server.clj view file
@@ -23,8 +23,8 @@ (let [frame (<!! packets-out)] (stream/write-frame!! frame (Socket/.getOutputStream socket))) (recur)))- {::packets-in packets-in- ::packets-out packets-out}))+ {::incoming-frames packets-in+ ::outgoing-frames packets-out})) (defn start-tcp-server! "Starts a TCP server at the given port. Returns a channel of clients as they connect.