aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-16 16:48:51 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-16 16:48:51 -0400
commitec7b9a644a62aed32b772b4af701e9280f589e41 (patch)
tree64beb92b9dbcdc3d48a64ce05a23b207175605b9
parent61e6c973179aa2392c13a7472fb66b4975ad6478 (diff)
clients can type in /list count to ask for number of logged in users
-rw-r--r--Hermes/TODO4
-rw-r--r--Hermes/server.rkt16
2 files changed, 17 insertions, 3 deletions
diff --git a/Hermes/TODO b/Hermes/TODO
index 416162e..a1a92df 100644
--- a/Hermes/TODO
+++ b/Hermes/TODO
@@ -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
diff --git a/Hermes/server.rkt b/Hermes/server.rkt
index 3685de0..3092770 100644
--- a/Hermes/server.rkt
+++ b/Hermes/server.rkt
@@ -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)