clients can type /list users to get usernames logged in

This commit is contained in:
Ibrahim Mkusa 2017-04-16 17:07:19 -04:00
parent ec7b9a644a
commit 9e1f8c33d1
2 changed files with 13 additions and 3 deletions

View File

@ -1,3 +1,3 @@
# Remove idiotic save files
# Remove temporary files
clean:
rm -rf *~
rm -rf *~ *.out

View File

@ -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)