diff --git a/src/Link/Client.hs b/src/Link/Client.hs index a00f08f..a5f7d0f 100644 --- a/src/Link/Client.hs +++ b/src/Link/Client.hs @@ -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 diff --git a/src/Link/Protocol.hs b/src/Link/Protocol.hs index b9df26b..720cda8 100644 --- a/src/Link/Protocol.hs +++ b/src/Link/Protocol.hs @@ -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 diff --git a/src/Link/Types.hs b/src/Link/Types.hs index d31012f..16a666b 100644 --- a/src/Link/Types.hs +++ b/src/Link/Types.hs @@ -26,4 +26,5 @@ data Message = NameInUse UserName | Ping | Pong | PrivMsg User String + | NoSuchUser UserName deriving (Show, Eq)