From 8d9765ca8c154f1a30695f2de3c26166d0451ae4 Mon Sep 17 00:00:00 2001 From: Ibrahim Mkusa Date: Thu, 13 Apr 2017 15:57:58 -0400 Subject: Clients now default to leaving sign out messages --- Hermes/TODO | 6 ++---- Hermes/client.rkt | 14 ++++++++++---- Hermes/server.rkt | 5 +++++ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Hermes/TODO b/Hermes/TODO index 5a357fc..bff56e6 100644 --- a/Hermes/TODO +++ b/Hermes/TODO @@ -5,12 +5,10 @@ 6. keep count of connected clients using object orientation 7. maybe fiddle around with irc library 8. separate main running code from definitions -**9. closure connections, messages, threads. Avoid using set! without an object - like make-account -make own count to deal with closures 10. authentication for databases 11. user can ask for no of logged in users. Server has to pars e 12. Hide user's own input in command line -13. Need to gracefully handle disconnected clients by removing from list +** 13. Need to gracefully handle disconnected clients by removing from list of connections +14. bye message prompt for clients diff --git a/Hermes/client.rkt b/Hermes/client.rkt index 86813ac..9b7d4a0 100644 --- a/Hermes/client.rkt +++ b/Hermes/client.rkt @@ -43,16 +43,22 @@ ;; sends a message to the server (define (send-messages username out) - ;; intelligent read, quits when user types in "quit" - (define input (read-line)) - (cond ((string=? input "quit") (exit))) ; get current time (define date-today (seconds->date (current-seconds) #t)) ;TODO pad the second if its only 1 character (define date-print (string-append (number->string (date-hour date-today)) + ":" + (number->string (date-minute date-today)) ":" (number->string (date-second date-today)) - "| ")) + " | ")) + ;; intelligent read, quits when user types in "quit" + (define input (read-line)) + (cond ((string=? input "quit") + (displayln (string-append date-print username " signing out. See ya!") out) + (flush-output out) + (exit))) + (displayln (string-append date-print username ": " input) out) (flush-output out)) diff --git a/Hermes/server.rkt b/Hermes/server.rkt index 20a83bb..5b599a7 100644 --- a/Hermes/server.rkt +++ b/Hermes/server.rkt @@ -105,6 +105,11 @@ "Sending client a welcome message.") stdout) (displayln welcome-message out) + ;; print to server log and client + (define print-no-users (string-append "Number of users in chat: " + (number->string ((c-count 'current-count))))) + (displayln print-no-users out) + (displayln-safe print-no-users stdout) (flush-output out) (semaphore-wait connections-s) ((c-connections 'add) in out) -- cgit v1.2.3