logic.clj

Branches > main > ac83dad > files / src / net / bowmap / server / logic.clj

(ns net.bowmap.server.logic
  (:require
    [net.bowmap.network.client :as client]
    [net.bowmap.server.server :as server]
    [net.bowmap.stormbow.fact :as fact]
    [net.bowmap.stormbow.response :as response]))

(defmulti handler
  (fn [fact]
    (::fact/id fact)))

(defmethod handler ::fact/server-list-requested [fact]
  (let [{:keys! [::client/client]} fact]
    [{::response/id ::response/send-server-list
      ::client/client client
      :server-list-response {:version {:name "26.2"
                                       :protocol 776}
                             :players {:online (count @server/players)
                                       :max server/max-player-count}
                             ; Is this a text component? Could make that interface
                             :description {:text "Bowmap!"}
                             :enforcesSecureChat false}}]))

; Returns a seq of responses
; And document that this is not called synchronously (hence the transactions as well)
(defn handle-fact [fact]
  ; TODO I think this is fine because it has to be run within a transaction anyway?
  ; All though I suppose not all fact handling needs to be in a transaction some is trivial so idk.
  (dosync (handler fact)))