54c3189
Branches > main > 54c3189 > files / src / net / bowmap / server
Use unique entity ids for clients
Commit: 54c3189b4b4084365ba8495b715a2b66afae50df
Parent: 242aed7
2 changed files:
src/net/bowmap/network/handle.clj view file
@@ -7,6 +7,7 @@ [net.bowmap.network.packets.registry :as registry] [net.bowmap.network.packets.serverbound :as serverbound :refer [decode-packet!]] [net.bowmap.network.state :as state]+ [net.bowmap.server.entity :as entity] [net.bowmap.server.gamemode :as gamemode])) ; Handles incoming packets from clients@@ -123,12 +124,15 @@ :chunk-z z)))) (defmethod handler ::serverbound/finish-config [client _]- (let [client (assoc client ::state/connection-state ::state/play)]+ (let [entity-id (entity/next-entity-id!)+ client (assoc client+ ::state/connection-state ::state/play+ ::entity/id entity-id)] (client/send-clientbound-packet client {::pk/id ::clientbound/login ;; TODO magic one :p ;; I think you can keep a registry of entity ids and stick this on the client- :entity-id 1+ :entity-id entity-id :hardcore? false :dimension-names ["world"] :max-players 1000 ; TODO extract :psrc/net/bowmap/server/entity.clj view file
@@ -0,0 +1,10 @@+(ns net.bowmap.server.entity+ (:require+ [clojure.spec.alpha :as s]))++; A unique ephemeral ID for this entity, used in the protocol+(s/def ::id pos-int?)+(defonce highest-entity-id (ref 0))++(defn next-entity-id! []+ (dosync (commute highest-entity-id inc)))