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