849
|
1 |
module Miscutils where
|
|
2 |
|
|
3 |
import IO
|
|
4 |
import System.IO
|
|
5 |
import Control.Concurrent
|
|
6 |
import Control.Concurrent.STM
|
|
7 |
import Control.Exception (finally)
|
894
|
8 |
import Data.Word
|
|
9 |
import Data.Char
|
849
|
10 |
|
851
|
11 |
data ClientInfo =
|
|
12 |
ClientInfo
|
|
13 |
{
|
889
|
14 |
chan :: TChan String,
|
851
|
15 |
handle :: Handle,
|
|
16 |
nick :: String,
|
894
|
17 |
protocol :: Word16,
|
851
|
18 |
room :: String,
|
|
19 |
isMaster :: Bool
|
|
20 |
}
|
|
21 |
|
|
22 |
data RoomInfo =
|
|
23 |
RoomInfo
|
|
24 |
{
|
|
25 |
name :: String,
|
|
26 |
password :: String
|
|
27 |
}
|
|
28 |
|
890
|
29 |
tselect :: [ClientInfo] -> STM (String, ClientInfo)
|
|
30 |
tselect = foldl orElse retry . map (\ci -> (flip (,) ci) `fmap` readTChan (chan ci))
|
889
|
31 |
|
894
|
32 |
maybeRead :: Read a => String -> Maybe a
|
|
33 |
maybeRead s = case reads s of
|
|
34 |
[(x, rest)] | all isSpace rest -> Just x
|
|
35 |
_ -> Nothing
|