Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spectator server-side fix. #1048

Merged
merged 1 commit into from
Dec 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/clj/game/main.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
(def last-states (atom {}))
(def ctx (ZMQ/context 1))

(def spectator-commands
{"say" core/say})

(def commands
{"say" core/say
"concede" core/concede
Expand Down Expand Up @@ -56,15 +59,26 @@
(defn strip [state]
(dissoc state :events :turn-events :per-turn :prevent :damage))

(defn not-spectator? [state user]
"Returns true if the specified user in the specified state is not a spectator"
(#{(get-in @state [:corp :user]) (get-in @state [:runner :user])} user))

(defn handle-do [user command state side args]
"Ensures the user is allowed to do command they are trying to do"
(if (not-spectator? state user)
((commands command) state (keyword side) args)
(when-let [cmd (spectator-commands command)]
(cmd state (keyword side) args))))

(defn run [socket]
(while true
(let [{:keys [gameid action command side args text] :as msg} (convert (.recv socket))
(let [{:keys [gameid action command side user args text] :as msg} (convert (.recv socket))
state (@game-states gameid)]
(try
(case action
"start" (core/init-game msg)
"remove" (swap! game-states dissoc gameid)
"do" ((commands command) state (keyword side) args)
"do" (handle-do user command state side args)
"notification" (when state
(swap! state update-in [:log] #(conj % {:user "__system__" :text text}))))
(if-let [new-state (@game-states gameid)]
Expand Down
1 change: 1 addition & 0 deletions src/cljs/netrunner/gameboard.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
(try (js/ga "send" "event" "game" command) (catch js/Error e))
(reset! lock true)
(send {:action "do" :gameid (:gameid @game-state) :side (:side @game-state)
:user (:user @app-state)
:command command :args args}))))

(defn send-msg [event owner]
Expand Down