equal
deleted
inserted
replaced
5 import System.IO |
5 import System.IO |
6 import Control.Concurrent |
6 import Control.Concurrent |
7 import Control.Concurrent.STM |
7 import Control.Concurrent.STM |
8 import Control.Exception (setUncaughtExceptionHandler, handle, finally) |
8 import Control.Exception (setUncaughtExceptionHandler, handle, finally) |
9 import Control.Monad (forM, forM_, filterM, liftM) |
9 import Control.Monad (forM, forM_, filterM, liftM) |
|
10 import Maybe (fromMaybe) |
10 import Data.List |
11 import Data.List |
11 import Miscutils |
12 import Miscutils |
12 import HWProto |
13 import HWProto |
13 |
14 |
14 acceptLoop :: Socket -> TChan ClientInfo -> IO () |
15 acceptLoop :: Socket -> TChan ClientInfo -> IO () |
67 Right (cmd, client) -> do |
68 Right (cmd, client) -> do |
68 putStrLn ("> " ++ show cmd) |
69 putStrLn ("> " ++ show cmd) |
69 |
70 |
70 let (clientsFunc, roomsFunc, answers) = handleCmd client clients rooms $ cmd |
71 let (clientsFunc, roomsFunc, answers) = handleCmd client clients rooms $ cmd |
71 let mrooms = roomsFunc rooms |
72 let mrooms = roomsFunc rooms |
|
73 let mclients = (clientsFunc clients) |
|
74 let mclient = fromMaybe client $ find (== client) mclients |
72 |
75 |
73 clientsIn <- sendAnswers answers client (clientsFunc clients) mrooms |
76 clientsIn <- sendAnswers answers mclient mclients mrooms |
74 |
77 |
75 mainLoop servSock acceptChan clientsIn mrooms |
78 mainLoop servSock acceptChan clientsIn mrooms |
76 |
79 |
77 |
80 |
78 startServer serverSocket = do |
81 startServer serverSocket = do |