From 71a760e0542156d1ee6c9e9b174135f94c3469fc Mon Sep 17 00:00:00 2001 From: nek0 Date: Thu, 31 Oct 2024 21:01:53 +0100 Subject: [PATCH] cleanup --- src-client/Client/Communication.hs | 1 - src-server/Server/Communication/Handler.hs | 7 +++---- src-server/Server/Communication/Receive.hs | 2 +- src-server/Server/Communication/Send.hs | 8 +++----- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src-client/Client/Communication.hs b/src-client/Client/Communication.hs index 3503f2e..01ef064 100644 --- a/src-client/Client/Communication.hs +++ b/src-client/Client/Communication.hs @@ -123,7 +123,6 @@ receiveMessage sock queue st = do maybe (putStrLn $ "received garbled data: " <> B8.unpack (B8.fromStrict rawMsg)) (\jsonMsg -> do - print jsonMsg STM.atomically $ STM.writeTQueue queue jsonMsg ) mJsonMsg diff --git a/src-server/Server/Communication/Handler.hs b/src-server/Server/Communication/Handler.hs index 7df8e03..8ad1ecb 100644 --- a/src-server/Server/Communication/Handler.hs +++ b/src-server/Server/Communication/Handler.hs @@ -120,7 +120,6 @@ handleMessages = do liftIO $ do msgs <- STM.atomically $ STM.flushTQueue queue - do - mapM_ - (handleMessage serverState readerContainer) - msgs + mapM_ + (handleMessage serverState readerContainer) + msgs diff --git a/src-server/Server/Communication/Receive.hs b/src-server/Server/Communication/Receive.hs index 283d7be..e29b41e 100644 --- a/src-server/Server/Communication/Receive.hs +++ b/src-server/Server/Communication/Receive.hs @@ -37,7 +37,7 @@ receiveMessage sockContainer queue clientList = do try $ recvBuf sock ptr maxBufferLength bufferLength <- case eBufferLength of Left (e :: IOException) -> do - putStrLn ("Socket vanished, cleaning up after " <> show e) + -- putStrLn ("Socket vanished, cleaning up after " <> show e) dropClient clientList sock pure 0 Right len -> pure len diff --git a/src-server/Server/Communication/Send.hs b/src-server/Server/Communication/Send.hs index bce6f50..dd5a6fe 100644 --- a/src-server/Server/Communication/Send.hs +++ b/src-server/Server/Communication/Send.hs @@ -62,11 +62,10 @@ sendMessageQueue -> STM.TQueue ServerMessage -> IO () sendMessageQueue sockContainer queue = do - sock <- STM.atomically $ STM.takeTMVar sockContainer + sock <- STM.atomically $ STM.readTMVar sockContainer msgs <- STM.atomically $ STM.flushTQueue queue mapM_ (\msg -> do - print msg let msgJson = A.encode msg msgVector = VS.fromList $ B.unpack $ B.toStrict ('<' `B8.cons` (msgJson `B8.snoc` '>')) VS.unsafeWith @@ -81,7 +80,6 @@ sendMessageQueue sockContainer queue = do ) ) msgs - STM.atomically $ STM.putTMVar sockContainer sock sendPings :: Game () sendPings = do @@ -104,7 +102,7 @@ sendPings = do put stateContainer else do random <- liftIO nextRandom - let newPong = (lastPongTime, random) + let newPong = (now, random) liftIO $ queueMessage ( Ping random ) @@ -133,7 +131,7 @@ dropClient clientList sock = do void $ STM.swapTMVar clientList reducedClients pure mclient maybe - (putStrLn $ "closing unknown socket: " <> show sock) + (pure ()) -- putStrLn $ "closing unknown socket: " <> show sock) (\client -> do putStrLn $ "dropping client: " <> show (fromJust $ ccUUID client) killThread (ccListener client)