9c1aee6
Branches > client-handling-rewrite > 9c1aee6 > files / .gitignore
Initial client handling rewrite
Commit: 9c1aee69304b35cccc90eedeb1c79cbf9a8184ee
Parent: 02e7024
2 changed files:
src/net/bowmap/message_application.clj view file
@@ -26,6 +26,7 @@ (fn [process client] (::process-id process))) +; Rename to somefin else (defmulti apply-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)."src/net/bowmap/minecraft_server.clj view file
@@ -44,21 +44,36 @@ (when pk (read-and-handle-packet! pk client messages-out process-chan))))) -(defn connect! [client packets-in packets-out]- (let [messages-out (chan 1024)- process-chan (chan 64)]- ; TODO error handling and disconnect- (io-thread- (loop [client client]- (when-some [client (handle-packets-and-messages! client packets-in messages-out packets-out process-chan)]- ; Otherwise, stop?- (recur client))))- nil))+#_(defn connect! [client packets-in packets-out]+ (let [messages-out (chan 1024)+ process-chan (chan 64)]+ ; TODO error handling and disconnect+ (io-thread+ (loop [client client]+ (when-some [client (handle-packets-and-messages! client packets-in messages-out packets-out process-chan)]+ ; Otherwise, stop?+ (recur client))))+ nil)) -(defn client- "Returns a new client value"- []- {::state/connection-state ::state/handshaking})+#_(defn client+ "Returns a new client value"+ []+ {::state/connection-state ::state/handshaking})++(defn handle-client+ ([client]+ (assoc client {::state/connection-state ::state/handshaking+ :messages-out (chan 1024)+ :process-chan (chan 64)}))+ ([client direction message]+ (let [{:keys! [messages-out process-chan]} client]+ (case direction+ :serverbound+ :clientbound (run-effects! messages-out process-chan (a/apply-message message client))))))++(defn client-handling-loop [client handler]+ (loop [client (handler client)]+ (handler client))) ; TODO make reloadable, if port is already running, just swap it out? ; TODO this is networking, and so should be in net.bowmap.server.network