Adds no such user response for private messaging.
parent
01454a644f
commit
5dc9a2cf14
|
@ -38,7 +38,7 @@ runClient Server {..} client@Client {..} = do
|
||||||
pingThread <- forkIO $ ping clientAlive
|
pingThread <- forkIO $ ping clientAlive
|
||||||
run clientAlive `finally` killThread pingThread
|
run clientAlive `finally` killThread pingThread
|
||||||
where
|
where
|
||||||
pingDelay = 5
|
pingDelay = 120
|
||||||
pingDelayMicros = pingDelay * 1000 * 1000
|
pingDelayMicros = pingDelay * 1000 * 1000
|
||||||
|
|
||||||
ping clientAlive = do
|
ping clientAlive = do
|
||||||
|
@ -65,7 +65,7 @@ runClient Server {..} client@Client {..} = do
|
||||||
Left mcommand -> case mcommand of
|
Left mcommand -> case mcommand of
|
||||||
Nothing -> printf "Could not parse command\n"
|
Nothing -> printf "Could not parse command\n"
|
||||||
Just command -> handleCommand command
|
Just command -> handleCommand command
|
||||||
Right message -> handleMessage message
|
Right message -> sendResponse message
|
||||||
run clientAlive
|
run clientAlive
|
||||||
|
|
||||||
readCommand = do
|
readCommand = do
|
||||||
|
@ -78,10 +78,10 @@ runClient Server {..} client@Client {..} = do
|
||||||
handleCommand (PrivMsg user msg) =
|
handleCommand (PrivMsg user msg) =
|
||||||
withMVar serverUsers $ \clientMap ->
|
withMVar serverUsers $ \clientMap ->
|
||||||
case Map.lookup user clientMap of
|
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'
|
Just client' -> sendMessage (PrivMsg clientUser msg) client'
|
||||||
handleCommand Pong = do
|
handleCommand Pong = do
|
||||||
now <- getCurrentTime
|
now <- getCurrentTime
|
||||||
void $ swapMVar clientPongTime now
|
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 (NameInUse name) = printf "NAMEINUSE %s" name
|
||||||
formatMessage (Connected name) = printf "CONNECTED %s" name
|
formatMessage (Connected name) = printf "CONNECTED %s" name
|
||||||
formatMessage Ping = "PING"
|
formatMessage Ping = "PING"
|
||||||
|
formatMessage (NoSuchUser name) = printf "NOSUCHUSER %s" name
|
||||||
|
|
|
@ -26,4 +26,5 @@ data Message = NameInUse UserName
|
||||||
| Ping
|
| Ping
|
||||||
| Pong
|
| Pong
|
||||||
| PrivMsg User String
|
| PrivMsg User String
|
||||||
|
| NoSuchUser UserName
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
Loading…
Reference in New Issue