diff --git a/deps.edn b/deps.edn index af6891c..1f386e1 100644 --- a/deps.edn +++ b/deps.edn @@ -15,6 +15,7 @@ com.github.seancorfield/next.jdbc {:mvn/version "1.3.894"} camel-snake-kebab/camel-snake-kebab {:mvn/version "0.4.3"} metosin/muuntaja {:mvn/version "0.6.8"} + ring/ring-core {:mvn/version "2.0.0-alpha1"} ring/ring-defaults {:mvn/version "0.3.4"} org.clojure/clojure {:mvn/version "1.11.3"} com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"} diff --git a/src/com/score_the_pigs.clj b/src/com/score_the_pigs.clj index 4503487..cfe25ea 100644 --- a/src/com/score_the_pigs.clj +++ b/src/com/score_the_pigs.clj @@ -1,12 +1,10 @@ (ns com.score-the-pigs (:require - [clojure.pprint :as pp] [clojure.test :as test] [com.biffweb :as biff] [com.score-the-pigs.app :as app] [com.score-the-pigs.middleware :as mid] [com.score-the-pigs.ui :as ui] - [migratus.core :as migratus] [next.jdbc :as jdbc] [nrepl.cmdline :as nrepl-cmd] [taoensso.telemere.timbre :as log]) @@ -74,7 +72,6 @@ (defn start [] (let [new-system (reduce (fn [system component] - (pp/pprint system) (log/info "starting:" (str component)) (component system)) initial-system diff --git a/src/com/score_the_pigs/app.clj b/src/com/score_the_pigs/app.clj index db75602..8b3e9c9 100644 --- a/src/com/score_the_pigs/app.clj +++ b/src/com/score_the_pigs/app.clj @@ -120,18 +120,17 @@ (defn connect-ws [{:keys [path-params] :example/keys [chat-clients]}] + (let [code (:code path-params)] - {:status 101 - :headers {"upgrade" "websocket" - "connection" "upgrade"} - :ws {:on-connect (fn [ws] - (swap! chat-clients assoc code ws)) - :on-close (fn [ws _status-code _reason] - (swap! chat-clients - (fn [chat-clients] - (let [chat-clients (update chat-clients code disj ws)] - (cond-> chat-clients - (empty? (get chat-clients code)) (dissoc code))))))}})) + (jetty/ws-upgrade-response + {:on-connect (fn [ws] + (swap! chat-clients assoc code ws)) + :on-close (fn [ws _status-code _reason] + (swap! chat-clients + (fn [chat-clients] + (let [chat-clients (update chat-clients code disj ws)] + (cond-> chat-clients + (empty? (get chat-clients code)) (dissoc code))))))}))) (def pig-position ["jowler" @@ -300,7 +299,13 @@ (jdbc/execute! tx (sql/format {:update :player :set {:game_score :round_score - :round_score 0}})) + :round_score 0} + :where [:and [:= :play_order current-player] + [:= :game_code :game-code]]})) + + (jdbc/execute! tx (sql/format + {:update :player + :set {:round_score 0}})) (jdbc/execute! tx next-player-query)) @update-display-table (now-playing next-player game-code ds))) @@ -310,8 +315,10 @@ (jdbc/with-transaction [tx ds] (jdbc/execute! tx (sql/format {:update :player - :set {:game_score 0 - :round_score 0}})) + :set {:game_score :round_score + :round_score 0} + :where [:and [:= :play_order current-player] + [:= :game_code :game-code]]})) (jdbc/execute! tx next-player-query)) @update-display-table (now-playing next-player game-code ds))