Adds no such user response for private messaging.
This commit is contained in:
parent
01454a644f
commit
5dc9a2cf14
@ -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
|
||||
|
@ -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
|
||||
|
@ -26,4 +26,5 @@ data Message = NameInUse UserName
|
||||
| Ping
|
||||
| Pong
|
||||
| PrivMsg User String
|
||||
| NoSuchUser UserName
|
||||
deriving (Show, Eq)
|
||||
|
Loading…
Reference in New Issue
Block a user