File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 88(defn serve-client
99 [nick client]
1010 (doseq [line (socket/read-lines client)]
11+ (println " got message from user:" line)
1112 (let [other-clients (vals (dissoc @clients nick))]
12- (case (first (clojure.string/split line #" " ))
13+ (case
14+ (first (clojure.string/split line #" " ))
1315 ; ; Instructor Note: explain why a doall is needed here
1416 " MSG" (doall (map #(socket/write-line % (str nick " : " (subs line 4 ))) other-clients))
1517
16- ; ;TODO: Process other kinds of command here
17-
18+ ; ;TODO: Process other kinds of command here
19+
1820 ; ; else
1921 (socket/write-line client " ERROR: I don't understand" )))))
2022
2123(defn new-client
2224 [client]
2325 (let [command (socket/read-line client)]
26+ (println " got message:" command)
2427 (if-let [[_ nick] (re-matches #"USER (.*)" command)]
2528 ; ; Instructor note: explain why we have to use a transaction here to make sure checking if user exists and adding them happens atomically
2629 (if (dosync
2730 (when-not (get @clients nick)
2831 (alter clients assoc nick client)))
29-
32+
3033 (serve-client nick client)
31-
34+
3235 (do
3336 (socket/write-line client " ERROR: Nick already taken" )
3437 (socket/close-socket client))))))
You can’t perform that action at this time.
0 commit comments