13bd5fb
Branches > main > 13bd5fb > files / src
Update client handling
Commit: 13bd5fb814e09f785d77827347abcc882086683d
Parent: 2190c63
3 changed files:
src/net/bowmap/network/handle.clj view file
@@ -1,6 +1,5 @@ (ns net.bowmap.network.handle (:require- [clojure.core.async :refer [put!]] [net.bowmap.network.chunk :as chunk] [net.bowmap.network.client :as client] [net.bowmap.network.packet :as pk]@@ -11,11 +10,10 @@ [net.bowmap.network.state :as state] [net.bowmap.server.entity :as entity] [net.bowmap.server.gamemode :as gamemode]- [net.bowmap.server.logic :as logic] [net.bowmap.server.player :as player]+ [net.bowmap.server.position :as position] [net.bowmap.server.server :as server]- [net.bowmap.stormbow.fact :as fact]- [net.bowmap.stormbow.responses :refer [handle-responses!]]))+ [net.bowmap.stormbow.fact :as fact])) (defmulti handle-packet (fn [client packet]@@ -166,15 +164,27 @@ :flags #{}})) :keepalive? true})) -; TODO just make this a pure function and put the handling logic elsewhere to make the separation clearer-(defn handle!! [client packet]- ; May want sync-facts vs. async-facts?- ; The facts themselves shouldn't care but the handler might- (let [{:keys [client packets facts keepalive?] :or {client client}} (handle-packet client packet)- {:keys! [::client/clientbound-packets]} client]- (doseq [pk packets]- (put! clientbound-packets pk))- ; TODO re-re-add keepalive- (doseq [fact facts]- (handle-responses! (logic/handle-fact fact)))- client))+(defn handle-player-update-movement-packet [client {:keys [x feet-y z yaw pitch flags]}]+ {:facts [{::fact/id ::fact/updated-player-movement+ ; TODO need the player here!+ ; It's never actually kept track of, I guess because you want to use the UUID+ ::position/x x+ ::position/y feet-y+ ::position/z z+ ::position/yaw yaw+ ::position/pitch pitch+ ; may be ::entity/ characteristics, idk+ :pushing-against-wall? (:pushing-against-wall flags)+ :on-ground? (:on-ground flags)}]})++(defmethod handle-packet ::set-player-rotation [client pk]+ (handle-player-update-movement-packet client pk))++(defmethod handle-packet ::set-player-position-and-rotation [client pk]+ (handle-player-update-movement-packet client pk))++(defmethod handle-packet ::set-player-position [client pk]+ (handle-player-update-movement-packet client pk))++(defmethod handle-packet ::set-player-movement-flags [client pk]+ (handle-player-update-movement-packet client pk))src/net/bowmap/network/server.clj view file
@@ -1,12 +1,16 @@ (ns net.bowmap.network.server (:require- [clojure.core.async :refer [<!! alt!! io-thread]]+ [clojure.core.async :refer [<!! alt!! io-thread put!]] [net.bowmap.network.client :as client :refer [send-packet!!]] [net.bowmap.network.connection :as connection] [net.bowmap.network.handle :as handle] [net.bowmap.network.minecraft-server :as mc] [net.bowmap.network.packets.serverbound :refer [decode-packet!]]- [net.bowmap.network.state :as state]))+ [net.bowmap.network.state :as state]+ [net.bowmap.server.entity :as entity]+ [net.bowmap.server.logic :as logic]+ [net.bowmap.stormbow.fact :as fact]+ [net.bowmap.stormbow.responses :refer [handle-responses!]])) (defn handle-connection [connection] (io-thread@@ -18,7 +22,13 @@ (alt!! serverbound-frames ([frame] (when (some? frame)- (recur (handle/handle!! client (decode-packet! frame (::state/connection-state client))))))+ (let [packet (decode-packet! frame (::state/connection-state client))+ {:keys [client packets facts] :or {:client client}} (handle/handle-packet client packet)]+ (doseq [pk packets]+ (put! clientbound-packets pk))+ (doseq [fact facts]+ (handle-responses! (logic/handle-fact fact)))+ (recur client)))) clientbound-packets ([pk] (if (some? pk) (do (send-packet!! client pk)@@ -26,6 +36,8 @@ (throw (Exception. "Clientbound packets was closed idk why"))))))) (finally ; TODO Send player disconnected fact, and update the player list from that+ (handle-responses! (logic/handle-fact {::fact/id ::fact/player-left+ ::entity/uuid (::entity/uuid client)})) (connection/close! connection))))) (defn start-server! [port]src/net/bowmap/server/position.clj view file
@@ -0,0 +1,9 @@+(ns net.bowmap.server.position+ (:require+ [clojure.spec.alpha :as s]))++(s/def ::x float?)+(s/def ::y float?)+(s/def ::z float?)+(s/def ::yaw float?)+(s/def ::pitch float?)