63fb35e
Branches > facts > 63fb35e > files / src / net / bowmap / transport / server.clj
Move entities to a protocol namespace
Commit: 63fb35ee4452530b431046776f2c6b85d87b00c5
Parent: 61fdd79
4 changed files:
src/net/bowmap/protocol/entity.clj src/net/bowmap/server/entity.clj view file
@@ -1,10 +1,9 @@-(ns net.bowmap.server.entity+(ns net.bowmap.protocol.entity (:require [clojure.spec.alpha :as s])) ; A unique ephemeral ID for this entity, used in the protocol (s/def ::id pos-int?)-(s/def ::uuid uuid?) (defonce highest-entity-id (ref 0)) (defn next-entity-id! []src/net/bowmap/protocol/handle.clj view file
@@ -8,7 +8,7 @@ [net.bowmap.protocol.packet.serverbound :as serverbound] [net.bowmap.protocol.registry :as reg] [net.bowmap.protocol.state :as state]- [net.bowmap.server.entity :as entity]+ [net.bowmap.protocol.entity :as entity] [net.bowmap.server.gamemode :as gamemode] [net.bowmap.server.player :as player] [net.bowmap.server.position :as position]@@ -38,7 +38,7 @@ (defmethod handle-packet ::serverbound/login-start [client pk] (let [{:keys! [uuid username]} pk]- {:client (assoc client ::entity/uuid uuid)+ {:client (assoc client ::player/uuid uuid) :packets [{::pk/id ::clientbound/login-success :profile {:uuid uuid :username username@@ -117,13 +117,16 @@ ; TODO shit, this is not a pure function! ; I'm just going to pretend like this is a pure function for now. (let [entity-id (entity/next-entity-id!)- uuid (req! client ::entity/uuid)+ uuid (req! client ::player/uuid) client (assoc client ::state/connection-state ::state/play ::entity/id entity-id ::client/playing? true)+ ; TODO should players have entity ids?+ ; Not sure if that's a player-level concern+ ; Players have associated protocol entities, of course, so this may not be needed player {::entity/id entity-id- ::entity/uuid uuid}]+ ::player/uuid uuid}] {:client client :facts [{::fact/id ::fact/player-joined ::player/player player}]@@ -168,6 +171,7 @@ {: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+ ::player/uuid (req! client ::player/uuid) ::position/x x ::position/y feet-y ::position/z zsrc/net/bowmap/server/logic.clj view file
@@ -3,7 +3,7 @@ ; TODO I'd be skeptical of references to protocol stuff from within server... ; This is really only here so the response handler can know who to send the response to [net.bowmap.protocol.client :as client]- [net.bowmap.server.entity :as entity]+ [net.bowmap.protocol.entity :as entity] [net.bowmap.server.player :as player] [net.bowmap.server.server :as server] [net.bowmap.stormbow.fact :as fact]@@ -25,13 +25,13 @@ ; Want this to be pure, which means you need a way to encode that state change as data? (defmethod handler ::fact/player-joined [{::player/keys! [player]}]- (let [{::entity/keys! [uuid]} player]+ (let [{::player/keys! [uuid]} player] (if (@server/players uuid) (throw (Exception. "Player tried to join with an existing UUID")) (commute server/players assoc uuid player)) [])) -(defmethod handler ::fact/player-left [{:keys! [::entity/uuid]}]+(defmethod handler ::fact/player-left [{:keys! [::player/uuid]}] (commute server/players dissoc uuid) []) src/net/bowmap/server/player.clj view file
@@ -1 +1,5 @@-(ns net.bowmap.server.player)+(ns net.bowmap.server.player+ (:require+ [clojure.spec.alpha :as s]))++(s/def ::uuid uuid?)