Handles disconnected users gracefully when you /whisper
This commit is contained in:
parent
e68c65c36a
commit
28d78a8a97
@ -1,7 +1,6 @@
|
||||
FEATURES
|
||||
need to pass color settings between users
|
||||
16. plain tcp -> ssl based
|
||||
***17. fix breaks for improper disconnects from clients
|
||||
18. Add topics after project completion
|
||||
** regexes to parse strings for different formats -related to 5
|
||||
** align code better for readability
|
||||
|
@ -129,7 +129,8 @@
|
||||
|
||||
(cond [(eof-object? evt)
|
||||
(displayln-safe "Server connection closed." error-out-s error-out)
|
||||
(custodian-shutdown-all main-client-cust)
|
||||
(exit)
|
||||
;(custodian-shutdown-all main-client-cust)
|
||||
;(exit)
|
||||
]
|
||||
[(string? evt)
|
||||
|
@ -188,26 +188,29 @@
|
||||
(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
|
||||
|
||||
; TODO if user doesn't exist handle it********
|
||||
(cond [whisper
|
||||
(semaphore-wait connections-s)
|
||||
; get output port for user
|
||||
; this might be null
|
||||
(define that-user-ports
|
||||
(first (filter
|
||||
(filter
|
||||
(lambda (ports)
|
||||
(if (string=? (whisper-to whisper) (get-username ports))
|
||||
#t
|
||||
#f))
|
||||
((c-connections 'cons-list)))))
|
||||
((c-connections 'cons-list))))
|
||||
; try to send that user the whisper
|
||||
(if (port-closed? (get-output-port that-user-ports))
|
||||
(if (and (null? that-user-ports)
|
||||
#t) ; #t is placeholder for further checks
|
||||
(begin
|
||||
(displayln "User is unavailable" out)
|
||||
(displayln "User is unavailable. /color black" 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))))
|
||||
(get-output-port (car that-user-ports)))
|
||||
(flush-output (get-output-port (car that-user-ports)))))
|
||||
(semaphore-post connections-s)]
|
||||
[list-count
|
||||
;;should put a semaphore on connections
|
||||
|
Loading…
Reference in New Issue
Block a user