Skip to content

Commit

Permalink
Merge pull request #7572 from NBKelly/prompt-before-game-times-out
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke authored Sep 1, 2024
2 parents bbe90fb + 57d29d5 commit 2abb4de
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions resources/public/sound/attributions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Pulse: pulse 1.wav by cameronmusic -- https://freesound.org/s/138421/ -- License
Wave: deep-bass-wave-130.mp3 by iscence -- https://freesound.org/s/65516/ -- License: Creative Commons 0

Archer: archer by d/0 -- https://github.com/db0/Android-Netrunner-OCTGN -- used with permission from D/0

Time-out: ok9.wav by ZenithInfinitiveStudios -- https://freesound.org/s/343008/ -- License: Creative Commons 0
Binary file added resources/public/sound/time-out.mp3
Binary file not shown.
Binary file added resources/public/sound/time-out.ogg
Binary file not shown.
6 changes: 6 additions & 0 deletions src/clj/web/lobby.clj
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,12 @@
[db time-inactive]
(let [changed? (volatile! false)]
(doseq [{:keys [gameid last-update started] :as lobby} (app-state/get-lobbies)]
(when (and gameid
(inst/is-after (inst/now) (inst/plus-seconds last-update (- time-inactive 30)))
(not (inst/is-after (inst/now) (inst/plus-seconds last-update (- time-inactive 29)))))
(let [uids (keep :uid (get-players-and-spectators lobby))]
(doseq [uid uids]
(when uid (ws/chsk-send! uid [:game/timeout-soon gameid])))))
(when (and gameid (inst/is-after (inst/now) (inst/plus-seconds last-update time-inactive)))
(let [uids (keep :uid (get-players-and-spectators lobby))]
(vreset! changed? true)
Expand Down
10 changes: 10 additions & 0 deletions src/cljs/nr/gameboard/actions.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
parse-state]]
[nr.translations :refer [tr]]
[nr.utils :refer [toastr-options]]
[nr.sounds :refer [play-sfx]]
[nr.ws :as ws]
[reagent.core :as r]
[reagent.ratom :as ratom]))
Expand Down Expand Up @@ -53,6 +54,14 @@
(toast (tr [:game.inactivity "Game closed due to inactivity"]) "error" {:time-out 0 :close-button true})
(leave-game!)))

(defn handle-timeout-soon [gameid]
(when (= gameid (current-gameid app-state))
(play-sfx ["time-out"])
(toast (tr [:game.timeout-soon "Game will time out within 30 seconds for inactivity"])
"error"
{:time-out 29000
:close-button true})))

(defn handle-error []
(toast (tr [:game.error "Internal Server Error. Please type /bug in the chat and follow the instructions."])
"error"
Expand All @@ -66,6 +75,7 @@
(defmethod ws/event-msg-handler :game/resync [{data :?data}] (reset-game! (parse-state data)))
(defmethod ws/event-msg-handler :game/diff [{data :?data}] (handle-diff! (parse-state data)))
(defmethod ws/event-msg-handler :game/timeout [{data :?data}] (handle-timeout data))
(defmethod ws/event-msg-handler :game/timeout-soon [{data :?data}] (handle-timeout-soon data))
(defmethod ws/event-msg-handler :game/error [_] (handle-error))

(defn send-command
Expand Down
1 change: 1 addition & 0 deletions src/cljs/nr/sounds.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"rez-other"
"run-successful"
"run-unsuccessful"
"time-out"
"virus-purge"])

(defn random-sound
Expand Down

0 comments on commit 2abb4de

Please sign in to comment.