0fa6363
Branches > client-handling-rewrite > 0fa6363 > files
Process updates
Commit: 0fa6363581e0bf60502f84e3e370b6c694c96548
Parent: 51010ca
2 changed files:
src/net/bowmap/message_application.clj view file
@@ -10,20 +10,15 @@ [net.bowmap.network.state :as state])) (S/def ::messages (s/coll-of ::msg/message :type vector?))-;; TODO def ::processes+(S/def ::process-id qualified-keyword?)+(S/def ::process-timeout pos-int?)+(S/def ::process (s/schema [::process-id ::process-timeout]))+(S/def ::processes (s/coll-of ::process :type vector?)) (S/def ::response (s/schema [::client/client ::messages ::processes])) ; And eventually game events as well :) (defmulti apply-process- (fn [id client]- id))--(defmethod apply-process ::keep-alive [_ client]- {::client/client client- ::processes [{::process-id ::keep-alive- ::process-timeout 20000}]- ::messages- [{::msg/id ::cl/keep-alive- :id (long (* (rand) Long/MAX_VALUE))}]})+ (fn [process client]+ (::process-id process))) (defmulti apply-message "'Applies' a message to a client state. Returns the new client state, as well@@ -112,3 +107,10 @@ :event :wait-for-chunks}] ::processes [{::process-id ::keep-alive ::process-timeout 20000}]})++(defmethod apply-process ::keep-alive [process client]+ {::client/client client+ ::processes [process]+ ::messages+ [{::msg/id ::cl/keep-alive+ :id (long (* (rand) Long/MAX_VALUE))}]})src/net/bowmap/minecraft_server.clj view file
@@ -14,10 +14,10 @@ ; Schedule processes (let [{:keys [::client/client ::a/processes ::a/messages]} result] ;; Processes to start- (doseq [{::a/keys [process-id process-timeout]} processes]+ (doseq [process processes] (io-thread- (<!! (timeout process-timeout))- (>!! process-chan process-id)))+ (<!! (timeout (::a/process-timeout process)))+ (>!! process-chan process))) (doseq [msg messages] (put! messages-out msg)) client))@@ -30,15 +30,15 @@ (when-some [msg (srv/packet->message pk (::state/connection-state client))] (run-effects! messages-out process-chan (a/apply-message msg client)))) -(defn handle-process! [process-id client messages-out process-chan]- (run-effects! messages-out process-chan (a/apply-process process-id client)))+(defn handle-process! [process client messages-out process-chan]+ (run-effects! messages-out process-chan (a/apply-process process client))) (defn handle-packets-and-messages! [client packets-in messages-out packets-out process-chan] (alt!! ; Timeouts? ; TODO should take the old process map so you can reuse timeouts if you want to!- process-chan ([process-id]- (handle-process! process-id client messages-out process-chan))+ process-chan ([process]+ (handle-process! process client messages-out process-chan)) messages-out ([msg] (when msg (assert (>!! packets-out (cl/message->packet msg (::state/connection-state client))))