static analysis fixes
This commit is contained in:
parent
73adfff54c
commit
fbc2c4da3e
8 changed files with 57 additions and 49 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -11,3 +11,4 @@ result
|
||||||
*.local
|
*.local
|
||||||
*.svg
|
*.svg
|
||||||
*~
|
*~
|
||||||
|
.hie/
|
||||||
|
|
|
@ -4,9 +4,9 @@ import qualified Control.Concurrent.STM as STM
|
||||||
|
|
||||||
import Control.Monad.RWS
|
import Control.Monad.RWS
|
||||||
|
|
||||||
import qualified Data.Matrix as M
|
import Data.List (foldl')
|
||||||
|
|
||||||
import Debug.Trace
|
import qualified Data.Matrix as M
|
||||||
|
|
||||||
import Graphics.Vty
|
import Graphics.Vty
|
||||||
|
|
||||||
|
@ -48,7 +48,7 @@ draw = do
|
||||||
(\y ->
|
(\y ->
|
||||||
map
|
map
|
||||||
(\x ->
|
(\x ->
|
||||||
getPixel $ foldl
|
getPixel $ foldl'
|
||||||
(\acc coord@(row, col) ->
|
(\acc coord@(row, col) ->
|
||||||
if mapSlice M.! coord == Just Wall
|
if mapSlice M.! coord == Just Wall
|
||||||
then
|
then
|
||||||
|
@ -67,7 +67,7 @@ draw = do
|
||||||
[1 .. w]
|
[1 .. w]
|
||||||
)
|
)
|
||||||
[1 .. h]
|
[1 .. h]
|
||||||
image = foldl
|
image = foldl'
|
||||||
(\img line ->
|
(\img line ->
|
||||||
img <-> string defAttr line
|
img <-> string defAttr line
|
||||||
)
|
)
|
||||||
|
|
|
@ -18,7 +18,7 @@ import Control.Monad.RWS.Strict
|
||||||
|
|
||||||
import Data.List (find)
|
import Data.List (find)
|
||||||
|
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromMaybe)
|
||||||
|
|
||||||
import Network.Socket as Net
|
import Network.Socket as Net
|
||||||
|
|
||||||
|
@ -91,7 +91,9 @@ disconnectClients curLevel clientSockets queueList = do
|
||||||
threadDelay 1000 -- wait for the message to be actually sent
|
threadDelay 1000 -- wait for the message to be actually sent
|
||||||
sock <- do
|
sock <- do
|
||||||
socketList <- STM.atomically $ STM.readTMVar clientSockets
|
socketList <- STM.atomically $ STM.readTMVar clientSockets
|
||||||
pure $ fromJust $ find (\s -> csUUID s == Just uuid) socketList
|
pure $ fromMaybe
|
||||||
|
(error $ "Socket not present for client: " <> show uuid)
|
||||||
|
(find (\s -> csUUID s == Just uuid) socketList)
|
||||||
dropClient curLevel clientSockets queueList (csSocket sock)
|
dropClient curLevel clientSockets queueList (csSocket sock)
|
||||||
)
|
)
|
||||||
(cqUUID queue)
|
(cqUUID queue)
|
||||||
|
|
|
@ -17,13 +17,16 @@ import Data.Time
|
||||||
|
|
||||||
import Data.UUID.V4
|
import Data.UUID.V4
|
||||||
|
|
||||||
|
import System.Random (randomRIO)
|
||||||
|
|
||||||
|
-- internal imports
|
||||||
|
|
||||||
import Library.Types
|
import Library.Types
|
||||||
|
|
||||||
import Server.Communication.Send
|
import Server.Communication.Send
|
||||||
import Server.Log
|
import Server.Log
|
||||||
import Server.Types
|
import Server.Types
|
||||||
import Server.Util
|
import Server.Util
|
||||||
import System.Random (randomRIO)
|
|
||||||
|
|
||||||
-- | function for translating 'ClientMessage's into server actions
|
-- | function for translating 'ClientMessage's into server actions
|
||||||
handleMessage
|
handleMessage
|
||||||
|
@ -42,9 +45,9 @@ handleMessage stateContainer readerContainer msg = do
|
||||||
IdRequest -> do
|
IdRequest -> do
|
||||||
clientId <- nextRandom
|
clientId <- nextRandom
|
||||||
threadDelay 1000
|
threadDelay 1000
|
||||||
let clientIdx = findIndex (isNothing . csUUID) socks
|
let clientIdx = fromMaybe (error "no socket found of new client") (findIndex (isNothing . csUUID) socks)
|
||||||
sock = socks !! fromJust clientIdx
|
sock = socks !! clientIdx
|
||||||
queue = queues !! fromJust clientIdx
|
queue = queues !! clientIdx
|
||||||
if csUUID sock == cqUUID queue
|
if csUUID sock == cqUUID queue
|
||||||
then do
|
then do
|
||||||
let otherSocks = delete sock socks
|
let otherSocks = delete sock socks
|
||||||
|
@ -118,11 +121,12 @@ handleMessage stateContainer readerContainer msg = do
|
||||||
else do
|
else do
|
||||||
now <- getCurrentTime
|
now <- getCurrentTime
|
||||||
STM.atomically$ do
|
STM.atomically$ do
|
||||||
let otherPlayers = filter (\a -> playerId a /= playerId player) players
|
let !otherPlayers = filter (\a -> playerId a /= playerId player) players
|
||||||
modPlayer = player
|
!modPlayer = player
|
||||||
{ playerLastPong = (now, pongUuid)
|
{ playerLastPong = (now, pongUuid)
|
||||||
}
|
}
|
||||||
void $ STM.swapTMVar (scPlayers stateContainer) (modPlayer : otherPlayers)
|
!newPlayers = modPlayer : otherPlayers
|
||||||
|
void $ STM.swapTMVar (scPlayers stateContainer) newPlayers
|
||||||
sendUpdate curLevel stateContainer (rcMap readerContainer) player
|
sendUpdate curLevel stateContainer (rcMap readerContainer) player
|
||||||
)
|
)
|
||||||
mPlayer
|
mPlayer
|
||||||
|
|
|
@ -151,16 +151,17 @@ dropClient curLevel socketList queueList sock = do
|
||||||
maybe
|
maybe
|
||||||
(logPrintIO curLevel Warning $ "closing unknown socket: " <> show sock)
|
(logPrintIO curLevel Warning $ "closing unknown socket: " <> show sock)
|
||||||
(\client -> do
|
(\client -> do
|
||||||
logPrintIO curLevel Info $ "killing client sender and listener because of socket closing: " <> show (fromJust $ csUUID client)
|
let clientUUID = fromMaybe (error "no UUID for client?!") (csUUID client)
|
||||||
|
logPrintIO curLevel Info $ "killing client sender and listener because of socket closing: " <> show clientUUID
|
||||||
killThread (csSender client)
|
killThread (csSender client)
|
||||||
killThread (csReceiver client)
|
killThread (csReceiver client)
|
||||||
logPrintIO curLevel Info $ "dropping client because of socket closing: " <> show (fromJust $ csUUID client)
|
logPrintIO curLevel Info $ "dropping client because of socket closing: " <> show clientUUID
|
||||||
)
|
)
|
||||||
mClient
|
mClient
|
||||||
STM.atomically $ do
|
STM.atomically $ do
|
||||||
queues <- STM.readTMVar queueList
|
queues <- STM.readTMVar queueList
|
||||||
let reducedClients = filter (\client -> csSocket client /= sock) clients
|
let reducedClients = filter (\client -> csSocket client /= sock) clients
|
||||||
reducedQueues = filter (\queue -> cqUUID queue /= csUUID (fromJust mClient)) queues
|
reducedQueues = filter (\queue -> cqUUID queue /= csUUID (fromMaybe (error "What happened to the client?!") mClient)) queues
|
||||||
void $ STM.swapTMVar socketList reducedClients
|
void $ STM.swapTMVar socketList reducedClients
|
||||||
void $ STM.swapTMVar queueList reducedQueues
|
void $ STM.swapTMVar queueList reducedQueues
|
||||||
close sock
|
close sock
|
||||||
|
|
|
@ -16,8 +16,6 @@ import Data.Time
|
||||||
|
|
||||||
import Data.String (fromString)
|
import Data.String (fromString)
|
||||||
|
|
||||||
import System.IO (stdout)
|
|
||||||
|
|
||||||
-- internal imports
|
-- internal imports
|
||||||
|
|
||||||
import Server.Game.Update
|
import Server.Game.Update
|
||||||
|
@ -37,11 +35,11 @@ runGame = do
|
||||||
handleMessages
|
handleMessages
|
||||||
-- updateSpawners delta
|
-- updateSpawners delta
|
||||||
-- updateWizards delta
|
-- updateWizards delta
|
||||||
-- modify'
|
modify'
|
||||||
-- (\s -> s
|
(\s -> s
|
||||||
-- { scServerLastTick = now
|
{ scServerLastTick = now
|
||||||
-- }
|
}
|
||||||
-- )
|
)
|
||||||
fps <- asks rcFPS
|
fps <- asks rcFPS
|
||||||
sendPings
|
sendPings
|
||||||
let remainingTime = recip (fromIntegral fps) - delta
|
let remainingTime = recip (fromIntegral fps) - delta
|
||||||
|
|
|
@ -25,14 +25,14 @@ import Options.Applicative as O
|
||||||
import Library.Types
|
import Library.Types
|
||||||
|
|
||||||
data Settings = Settings
|
data Settings = Settings
|
||||||
{ setSocketPath :: FilePath
|
{ setSocketPath :: !FilePath
|
||||||
, setMapRows :: Int
|
, setMapRows :: !Int
|
||||||
, setMapColumns :: Int
|
, setMapColumns :: !Int
|
||||||
, setSpawnerProbability :: Float
|
, setSpawnerProbability :: !Float
|
||||||
, setFPS :: Int
|
, setFPS :: !Int
|
||||||
, setClientMaxTimeout :: Float
|
, setClientMaxTimeout :: !Float
|
||||||
, setFramesPerPing :: Int
|
, setFramesPerPing :: !Int
|
||||||
, setLogLevel :: LogLevel
|
, setLogLevel :: !LogLevel
|
||||||
}
|
}
|
||||||
deriving (Show, Generic)
|
deriving (Show, Generic)
|
||||||
|
|
||||||
|
@ -61,12 +61,12 @@ options = Options
|
||||||
)
|
)
|
||||||
|
|
||||||
data ReaderContainer = ReaderContainer
|
data ReaderContainer = ReaderContainer
|
||||||
{ rcMap :: ServerMap
|
{ rcMap :: !ServerMap
|
||||||
, rcFPS :: Int
|
, rcFPS :: !Int
|
||||||
, rcFramesPerPing :: Int
|
, rcFramesPerPing :: !Int
|
||||||
, rcClientMaxTimeout :: Float
|
, rcClientMaxTimeout :: !Float
|
||||||
, rcMainSocket :: Socket
|
, rcMainSocket :: !Socket
|
||||||
, rcLogLevel :: LogLevel
|
, rcLogLevel :: !LogLevel
|
||||||
}
|
}
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
|
@ -81,31 +81,31 @@ data StateContainer = StateContainer
|
||||||
}
|
}
|
||||||
|
|
||||||
data ClientSocket = ClientSocket
|
data ClientSocket = ClientSocket
|
||||||
{ csUUID :: Maybe UUID
|
{ csUUID :: !(Maybe UUID)
|
||||||
, csSocket :: Socket
|
, csSocket :: !Socket
|
||||||
, csSender :: ThreadId
|
, csSender :: !ThreadId
|
||||||
, csReceiver :: ThreadId
|
, csReceiver :: !ThreadId
|
||||||
}
|
}
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
data ClientQueue = ClientQueue
|
data ClientQueue = ClientQueue
|
||||||
{ cqUUID :: Maybe UUID
|
{ cqUUID :: !(Maybe UUID)
|
||||||
, cqQueue :: STM.TQueue ServerMessage
|
, cqQueue :: !(STM.TQueue ServerMessage)
|
||||||
}
|
}
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
data Player = Player
|
data Player = Player
|
||||||
{ playerId :: UUID
|
{ playerId :: !UUID
|
||||||
, playerWizard :: Wizard
|
, playerWizard :: !Wizard
|
||||||
, playerReady :: Bool
|
, playerReady :: !Bool
|
||||||
, playerLastPong :: (UTCTime, UUID)
|
, playerLastPong :: !(UTCTime, UUID)
|
||||||
}
|
}
|
||||||
deriving (Eq, Show)
|
deriving (Eq, Show)
|
||||||
|
|
||||||
-- | Data object for storing the server's state
|
-- | Data object for storing the server's state
|
||||||
data ServerState = ServerState
|
data ServerState = ServerState
|
||||||
{ serverGameOver :: Bool -- ^ global game over state (only one contestant left)
|
{ serverGameOver :: !Bool -- ^ global game over state (only one contestant left)
|
||||||
, serverStop :: Bool -- ^ Server shutdown
|
, serverStop :: !Bool -- ^ Server shutdown
|
||||||
}
|
}
|
||||||
deriving (Show, Eq)
|
deriving (Show, Eq)
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,8 @@ extra-doc-files: CHANGELOG.md
|
||||||
|
|
||||||
common warnings
|
common warnings
|
||||||
ghc-options: -Wall -threaded -rtsopts
|
ghc-options: -Wall -threaded -rtsopts
|
||||||
|
-fwrite-ide-info
|
||||||
|
-hiedir=.hie
|
||||||
|
|
||||||
library
|
library
|
||||||
import: warnings
|
import: warnings
|
||||||
|
|
Loading…
Reference in a new issue