This commit is contained in:
nek0 2024-10-31 21:01:53 +01:00
parent 5e4c7ca992
commit 71a760e054
4 changed files with 7 additions and 11 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)