Clients can now whisper to each other /whisper
This commit is contained in:
parent
5d36ba1d5d
commit
61e6c97317
@ -1,5 +1,5 @@
|
|||||||
FEATURES
|
FEATURES
|
||||||
5. command(whisper, color, quit, count, users), message parsable?
|
5. command(whisper, count, users), message parsable? parse in the client side should do something similar for settings (color, quit)
|
||||||
16. plain tcp -> ssl based
|
16. plain tcp -> ssl based
|
||||||
17. fix breaks for improper disconnects from clients
|
17. fix breaks for improper disconnects from clients
|
||||||
18. Add topics after project completion
|
18. Add topics after project completion
|
||||||
|
@ -150,6 +150,16 @@
|
|||||||
(sleep 1360)
|
(sleep 1360)
|
||||||
(custodian-shutdown-all cust)))))
|
(custodian-shutdown-all cust)))))
|
||||||
|
|
||||||
|
; whisper selector for the username and message
|
||||||
|
(define (whisper-info exp)
|
||||||
|
(cadr exp))
|
||||||
|
|
||||||
|
(define (whisper-to exp)
|
||||||
|
(caddr exp))
|
||||||
|
|
||||||
|
(define (whisper-message exp)
|
||||||
|
(cadddr exp))
|
||||||
|
|
||||||
(define (chat_with_client in out)
|
(define (chat_with_client in out)
|
||||||
; deals with queueing incoming messages for server to broadcast to all clients
|
; deals with queueing incoming messages for server to broadcast to all clients
|
||||||
(define (something-to-say in)
|
(define (something-to-say in)
|
||||||
@ -166,11 +176,36 @@
|
|||||||
;(exit)
|
;(exit)
|
||||||
(kill-thread (current-thread))]
|
(kill-thread (current-thread))]
|
||||||
[(string? evt-t0)
|
[(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
|
||||||
|
(cond [whisper
|
||||||
|
(semaphore-wait connections-s)
|
||||||
|
; get output port for user
|
||||||
|
(define that-user-ports
|
||||||
|
(first (filter
|
||||||
|
(lambda (ports)
|
||||||
|
(if (string=? (whisper-to whisper) (get-username ports))
|
||||||
|
#t
|
||||||
|
#f))
|
||||||
|
((c-connections 'cons-list)))))
|
||||||
|
; try to send that user the whisper
|
||||||
|
(if (port-closed? (get-output-port that-user-ports))
|
||||||
|
(begin
|
||||||
|
(displayln "User is unavailable" out)
|
||||||
|
(flush-output out))
|
||||||
|
(begin
|
||||||
|
(displayln (string-append (whisper-info whisper) (whisper-message whisper))
|
||||||
|
(get-output-port that-user-ports))
|
||||||
|
(flush-output (get-output-port that-user-ports))))
|
||||||
|
(semaphore-post connections-s)]
|
||||||
|
[else
|
||||||
|
(displayln-safe evt-t0)
|
||||||
(semaphore-wait messages-s)
|
(semaphore-wait messages-s)
|
||||||
; append the message to list of messages NO NEED done during broadcast
|
; evaluate it .
|
||||||
; (displayln-safe evt-t0 convs-out-s convs-out)
|
|
||||||
((c-messages 'add) evt-t0)
|
((c-messages 'add) evt-t0)
|
||||||
(semaphore-post messages-s)]
|
(semaphore-post messages-s)])]
|
||||||
[else
|
[else
|
||||||
(displayln-safe "Timeout waiting. Nothing received from client")]))
|
(displayln-safe "Timeout waiting. Nothing received from client")]))
|
||||||
|
|
||||||
@ -189,6 +224,10 @@
|
|||||||
(define (get-input-port ports)
|
(define (get-input-port ports)
|
||||||
(cadr ports))
|
(cadr ports))
|
||||||
|
|
||||||
|
; extract username
|
||||||
|
(define (get-username ports)
|
||||||
|
(car ports))
|
||||||
|
|
||||||
; broadcasts received message from clients periodically
|
; broadcasts received message from clients periodically
|
||||||
; TODO before broadcasting the message make sure the ports is still open
|
; TODO before broadcasting the message make sure the ports is still open
|
||||||
; no EOF if it is remove client from connections
|
; no EOF if it is remove client from connections
|
||||||
|
Loading…
x
Reference in New Issue
Block a user