author | sheepluva |
Wed, 16 Jun 2010 21:14:23 +0200 | |
changeset 3508 | a7ca07614a2d |
parent 3501 | a3159a410e5c |
child 3542 | f216b24aeb7f |
permissions | -rw-r--r-- |
3435 | 1 |
module HandlerUtils where |
2 |
||
3 |
import Control.Monad.Reader |
|
3500
af8390d807d6
Use sockets instead of handles, use bytestrings instead of strings
unc0rr
parents:
3435
diff
changeset
|
4 |
import qualified Data.ByteString.Char8 as B |
3435 | 5 |
|
6 |
import RoomsAndClients |
|
7 |
import CoreTypes |
|
8 |
import Actions |
|
9 |
||
10 |
thisClient :: Reader (ClientIndex, IRnC) ClientInfo |
|
11 |
thisClient = do |
|
12 |
(ci, rnc) <- ask |
|
13 |
return $ rnc `client` ci |
|
14 |
||
3500
af8390d807d6
Use sockets instead of handles, use bytestrings instead of strings
unc0rr
parents:
3435
diff
changeset
|
15 |
clientNick :: Reader (ClientIndex, IRnC) B.ByteString |
3435 | 16 |
clientNick = liftM nick thisClient |
17 |
||
18 |
roomOthersChans :: Reader (ClientIndex, IRnC) [ClientChan] |
|
19 |
roomOthersChans = do |
|
20 |
(ci, rnc) <- ask |
|
21 |
let ri = clientRoom rnc ci |
|
22 |
return $ map (sendChan . client rnc) (roomClients rnc ri) |
|
23 |
||
24 |
thisClientChans :: Reader (ClientIndex, IRnC) [ClientChan] |
|
25 |
thisClientChans = do |
|
26 |
(ci, rnc) <- ask |
|
27 |
return $ [sendChan (rnc `client` ci)] |
|
28 |
||
3500
af8390d807d6
Use sockets instead of handles, use bytestrings instead of strings
unc0rr
parents:
3435
diff
changeset
|
29 |
answerClient :: [B.ByteString] -> Reader (ClientIndex, IRnC) [Action] |
3435 | 30 |
answerClient msg = thisClientChans >>= return . (: []) . flip AnswerClients msg |
3501 | 31 |
|
32 |
allRoomInfos :: Reader (a, IRnC) [RoomInfo] |
|
33 |
allRoomInfos = liftM ((\irnc -> map (room irnc) $ allRooms irnc) . snd) ask |