aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-13 15:57:58 -0400
committerIbrahim Mkusa <ibrahimmkusa@gmail.com>2017-04-13 15:57:58 -0400
commit8d9765ca8c154f1a30695f2de3c26166d0451ae4 (patch)
tree254aa5fc0bca7de8a7ec691a02bfb6af3d80e966
parentf6687e7d62ea9139f403c3c8d7c3ffa797aa3583 (diff)
Clients now default to leaving sign out messages
-rw-r--r--Hermes/TODO6
-rw-r--r--Hermes/client.rkt14
-rw-r--r--Hermes/server.rkt5
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)