Skip to content

Commit

Permalink
Merge pull request #7941 from NBKelly/prevent-lockup-when-server-fails
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahTheDuke authored Feb 22, 2025
2 parents 86aa967 + a847d75 commit 138103e
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions src/clj/web/game.clj
Original file line number Diff line number Diff line change
Expand Up @@ -258,37 +258,37 @@
{:keys [gameid command args]} :?data
id :id
timestamp :timestamp}]
(try
(let [{:keys [state] :as lobby} (app-state/get-lobby gameid)
player (lobby/player? uid lobby)
spectator (lobby/spectator? uid lobby)]
(lobby/game-thread
lobby
(cond
(and state player)
(let [old-state @state
side (side-from-str (:side player))]
(try
(swap! app-state/app-state
update :lobbies lobby/handle-set-last-update gameid uid)
(update-and-send-diffs! main/handle-action lobby side command args)
(catch Exception e
(reset! state old-state)
(throw e))))
(and (not spectator) (not= command "toast"))
(throw (ex-info "handle-game-action unknown state or side"
{:gameid gameid
:uid uid
:players (map #(select-keys % [:uid :side]) (:players lobby))
:spectators (map #(select-keys % [:uid]) (:spectators lobby))
:command command
:args args})))
(lobby/log-delay! timestamp id)))
(catch Exception e
(ws/chsk-send! uid [:game/error])
(println (str "Caught exception"
"\nException Data: " (or (ex-data e) (.getMessage e))
"\nStacktrace: " (with-out-str (stacktrace/print-stack-trace e 100)))))))
(let [{:keys [state] :as lobby} (app-state/get-lobby gameid)]
(lobby/game-thread
lobby
(try
(let [player (lobby/player? uid lobby)
spectator (lobby/spectator? uid lobby)]
(cond
(and state player)
(let [old-state @state
side (side-from-str (:side player))]
(try
(swap! app-state/app-state
update :lobbies lobby/handle-set-last-update gameid uid)
(update-and-send-diffs! main/handle-action lobby side command args)
(catch Exception e
(reset! state old-state)
(throw e))))
(and (not spectator) (not= command "toast"))
(throw (ex-info "handle-game-action unknown state or side"
{:gameid gameid
:uid uid
:players (map #(select-keys % [:uid :side]) (:players lobby))
:spectators (map #(select-keys % [:uid]) (:spectators lobby))
:command command
:args args})))
(lobby/log-delay! timestamp id))
(catch Exception e
(ws/chsk-send! uid [:game/error])
(println (str "Caught exception"
"\nException Data: " (or (ex-data e) (.getMessage e))
"\nStacktrace: " (with-out-str (stacktrace/print-stack-trace e 100)))))))))

(defmethod ws/-msg-handler :game/resync
game--resync
Expand Down

0 comments on commit 138103e

Please sign in to comment.