clients can type in /list count to ask for number of logged in users

This commit is contained in:
Ibrahim Mkusa 2017-04-16 16:48:51 -04:00
parent 61e6c97317
commit ec7b9a644a
2 changed files with 17 additions and 3 deletions

View File

@ -5,6 +5,8 @@ FEATURES
18. Add topics after project completion
** regexes to parse strings for different formats -related to 5
** put into a list if necessary for manipulation
** sync/timeout to plain sync
** align code better for readability
** adjust sleep time on all to be 0.1 for more responsiveness
** better function names
@ -19,4 +21,4 @@ new ones
11. user can ask for no of logged in users. - server already reports
even the list of users connected.
12. on connection server should also display list of users currently logged in
** whispers aren't currently logged

View File

@ -178,8 +178,9 @@
[(string? evt-t0)
; 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).*" evt-t0)) ;; is client asking for number of logged in users
(define list-users (regexp-match #px"(^/list)\\s+(users).*" evt-t0)) ;; user names
(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
; do something whether it was a message, a whisper, request for number of users and so on
(cond [whisper
(semaphore-wait connections-s)
; get output port for user
@ -200,6 +201,17 @@
(get-output-port that-user-ports))
(flush-output (get-output-port that-user-ports))))
(semaphore-post connections-s)]
[list-count
;;should put a semaphore on connections
(semaphore-wait c-count-s)
(semaphore-wait connections-s)
(define no-of-users (string-append "Number of users in chat: "
(number->string ((c-count 'current-count)))))
(displayln no-of-users out)
(flush-output out)
(semaphore-post connections-s)
(semaphore-post c-count-s)
]
[else
(displayln-safe evt-t0)
(semaphore-wait messages-s)