239bccb

Branches > main > 239bccb > files

I haven't had caffeine in so long this is crazy

Grahp, 2026-08-23

Commit: 239bccb3259035c596d29d215844d9e7d6671d79
Parent: 70c1f87

3 changed files:

src/net/bowmap/protocol/server.clj modified (view file)

@@ -12,6 +12,9 @@    [net.bowmap.transport.connection :as connection]    [net.bowmap.transport.server :as mc])) +(defn adorn-effects-with-client [client fact-seq]+  (mapv #(assoc % ::client/client client) fact-seq))+ (defn handle-connection [connection]   (io-thread     (let [client (client/client connection)@@ -28,7 +31,7 @@                                     (doseq [pk packets]                                       (put! clientbound-packets pk))                                     (doseq [fact facts]-                                      (execute-effects! (mapv #(assoc % ::client/client client) (logic/handle-fact fact))))+                                      (execute-effects! (update (logic/apply-rules fact) :effects #(adorn-effects-with-client client %))))                                     (when keep-alive?                                       (keepalive/keep-alive! client))                                     (recur client))))

src/net/bowmap/server/logic.clj modified (view file)

@@ -17,6 +17,9 @@     [{::effect/id ::effect/send-server-list       :server-list-response {:version {:name "26.2"                                        :protocol 776}+                             ; Gets the number of players playing, which is what you want+                             ; And there are no side-effects!+                             #_(count (fact ::fact/playing))                              :players {:online (count @server/players)                                        :max server/max-player-count}                              :description {:text "Bowmap!"}@@ -33,6 +36,9 @@  (defmethod handle-fact ::fact/player-left [{:keys! [::player/uuid]}]   (dosync+    {::fact/id ::fact/playing+     ::fact/mode ::fact/retract+     ::player/uuid uuid}     (commute server/players dissoc uuid)     [])) @@ -43,3 +49,22 @@  ; Called when the player actually moves, not just when a position is sent (defmethod handle-fact ::fact/player-moved [_ _])++(defn fact? [x]+  (::fact/id x))++(defn apply-rules+  "Applies rules recursively, returns a map containing :facts and :effects, the seqs of all facts that were asserted/retracted, and the seq of all effects that are implied from that fact."+  ([fact] (apply-rules {:facts [fact] :effects []} fact))+  ([acc fact]+   (let [results (handle-fact fact)]+     (reduce (fn [acc result]+               (if (fact? result)+                 (apply-rules (update acc :facts conj result) result)+                 (update acc :effects conj result)))+             acc results))))++(comment+  (apply-rules {:net.bowmap.stormbow.fact/id :net.bowmap.stormbow.fact/server-list-requested})+  (apply-rules+    {::fact/id ::fact/server-list-requested}))

src/net/bowmap/stormbow/effect_execution.clj modified (view file)

@@ -17,5 +17,7 @@                 :response server-list-response}]     (put! clientbound-packets packet))) +; TODO this now also has :facts [...]+; So you can update state based on that :) (defn execute-effects! [effects]-  (run! execute-effect! effects))+  (run! execute-effect! (:effects effects)))