diff options
author | Ibrahim Mkusa <ibrahimmkusa@gmail.com> | 2017-04-16 17:07:19 -0400 |
---|---|---|
committer | Ibrahim Mkusa <ibrahimmkusa@gmail.com> | 2017-04-16 17:09:57 -0400 |
commit | 9e1f8c33d17189c6bdf4c4db9481c0c08ee12218 (patch) | |
tree | 14b6aa18694c338ccebe3994baad3660de17248a | |
parent | ec7b9a644a62aed32b772b4af701e9280f589e41 (diff) |
clients can type /list users to get usernames logged in
-rw-r--r-- | Hermes/Makefile | 4 | ||||
-rw-r--r-- | Hermes/server.rkt | 12 |
2 files changed, 13 insertions, 3 deletions
diff --git a/Hermes/Makefile b/Hermes/Makefile index eda5bbb..940b2a5 100644 --- a/Hermes/Makefile +++ b/Hermes/Makefile @@ -1,3 +1,3 @@ -# Remove idiotic save files +# Remove temporary files clean: - rm -rf *~ + rm -rf *~ *.out diff --git a/Hermes/server.rkt b/Hermes/server.rkt index 3092770..6314f3b 100644 --- a/Hermes/server.rkt +++ b/Hermes/server.rkt @@ -179,7 +179,7 @@ ; use regexes to evaluate received input from client (define whisper (regexp-match #px"(.*)/whisper\\s+(\\w+)\\s+(.*)" evt-t0)) ; is client trying to whisper to someone (define list-count (regexp-match #px"(.*)/list\\s+count\\s*" evt-t0)) ;; is client asking for number of logged in users - (define list-users (regexp-match #px"(.*)/list\\s+users\\s+(.*)" evt-t0)) ;; user names + (define list-users (regexp-match #px"(.*)/list\\s+users\\s*" evt-t0)) ;; user names ; do something whether it was a message, a whisper, request for number of users and so on (cond [whisper (semaphore-wait connections-s) @@ -212,6 +212,16 @@ (semaphore-post connections-s) (semaphore-post c-count-s) ] + [list-users + (semaphore-wait connections-s) + ; map over connections sending the username to the client + (displayln "Here is a list of users in chat." out) + (map + (lambda (ports) + (displayln (get-username ports) out)) + ((c-connections 'cons-list))) + (flush-output out) + (semaphore-post connections-s)] [else (displayln-safe evt-t0) (semaphore-wait messages-s) |