Skip to content

Commit 138103e

Browse files
authored
Merge pull request #7941 from NBKelly/prevent-lockup-when-server-fails
2 parents 86aa967 + a847d75 commit 138103e

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

src/clj/web/game.clj

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -258,37 +258,37 @@
258258
{:keys [gameid command args]} :?data
259259
id :id
260260
timestamp :timestamp}]
261-
(try
262-
(let [{:keys [state] :as lobby} (app-state/get-lobby gameid)
263-
player (lobby/player? uid lobby)
264-
spectator (lobby/spectator? uid lobby)]
265-
(lobby/game-thread
266-
lobby
267-
(cond
268-
(and state player)
269-
(let [old-state @state
270-
side (side-from-str (:side player))]
271-
(try
272-
(swap! app-state/app-state
273-
update :lobbies lobby/handle-set-last-update gameid uid)
274-
(update-and-send-diffs! main/handle-action lobby side command args)
275-
(catch Exception e
276-
(reset! state old-state)
277-
(throw e))))
278-
(and (not spectator) (not= command "toast"))
279-
(throw (ex-info "handle-game-action unknown state or side"
280-
{:gameid gameid
281-
:uid uid
282-
:players (map #(select-keys % [:uid :side]) (:players lobby))
283-
:spectators (map #(select-keys % [:uid]) (:spectators lobby))
284-
:command command
285-
:args args})))
286-
(lobby/log-delay! timestamp id)))
287-
(catch Exception e
288-
(ws/chsk-send! uid [:game/error])
289-
(println (str "Caught exception"
290-
"\nException Data: " (or (ex-data e) (.getMessage e))
291-
"\nStacktrace: " (with-out-str (stacktrace/print-stack-trace e 100)))))))
261+
(let [{:keys [state] :as lobby} (app-state/get-lobby gameid)]
262+
(lobby/game-thread
263+
lobby
264+
(try
265+
(let [player (lobby/player? uid lobby)
266+
spectator (lobby/spectator? uid lobby)]
267+
(cond
268+
(and state player)
269+
(let [old-state @state
270+
side (side-from-str (:side player))]
271+
(try
272+
(swap! app-state/app-state
273+
update :lobbies lobby/handle-set-last-update gameid uid)
274+
(update-and-send-diffs! main/handle-action lobby side command args)
275+
(catch Exception e
276+
(reset! state old-state)
277+
(throw e))))
278+
(and (not spectator) (not= command "toast"))
279+
(throw (ex-info "handle-game-action unknown state or side"
280+
{:gameid gameid
281+
:uid uid
282+
:players (map #(select-keys % [:uid :side]) (:players lobby))
283+
:spectators (map #(select-keys % [:uid]) (:spectators lobby))
284+
:command command
285+
:args args})))
286+
(lobby/log-delay! timestamp id))
287+
(catch Exception e
288+
(ws/chsk-send! uid [:game/error])
289+
(println (str "Caught exception"
290+
"\nException Data: " (or (ex-data e) (.getMessage e))
291+
"\nStacktrace: " (with-out-str (stacktrace/print-stack-trace e 100)))))))))
292292

293293
(defmethod ws/-msg-handler :game/resync
294294
game--resync

0 commit comments

Comments
 (0)