Adds no such user response for private messaging.

pull/1/head
Abhinav Sarkar 2015-09-10 02:43:51 +05:30
parent 01454a644f
commit 5dc9a2cf14
3 changed files with 6 additions and 4 deletions

View File

@ -38,7 +38,7 @@ runClient Server {..} client@Client {..} = do
pingThread <- forkIO $ ping clientAlive
run clientAlive `finally` killThread pingThread
where
pingDelay = 5
pingDelay = 120
pingDelayMicros = pingDelay * 1000 * 1000
ping clientAlive = do
@ -65,7 +65,7 @@ runClient Server {..} client@Client {..} = do
Left mcommand -> case mcommand of
Nothing -> printf "Could not parse command\n"
Just command -> handleCommand command
Right message -> handleMessage message
Right message -> sendResponse message
run clientAlive
readCommand = do
@ -78,10 +78,10 @@ runClient Server {..} client@Client {..} = do
handleCommand (PrivMsg user msg) =
withMVar serverUsers $ \clientMap ->
case Map.lookup user clientMap of
Nothing -> printf "No such user: %s\n" (userName user)
Nothing -> sendResponse $ NoSuchUser (userName user)
Just client' -> sendMessage (PrivMsg clientUser msg) client'
handleCommand Pong = do
now <- getCurrentTime
void $ swapMVar clientPongTime now
handleMessage = printToHandle clientHandle . formatMessage
sendResponse = printToHandle clientHandle . formatMessage

View File

@ -15,3 +15,4 @@ formatMessage (PrivMsg user msg) = printf "PRIVMSG %s %s" (userName user) msg
formatMessage (NameInUse name) = printf "NAMEINUSE %s" name
formatMessage (Connected name) = printf "CONNECTED %s" name
formatMessage Ping = "PING"
formatMessage (NoSuchUser name) = printf "NOSUCHUSER %s" name

View File

@ -26,4 +26,5 @@ data Message = NameInUse UserName
| Ping
| Pong
| PrivMsg User String
| NoSuchUser UserName
deriving (Show, Eq)