gameServer/HandlerUtils.hs
changeset 3500 af8390d807d6
parent 3435 4e4f88a7bdf2
child 3501 a3159a410e5c
equal deleted inserted replaced
3499:66eba4e41b91 3500:af8390d807d6
     1 module HandlerUtils where
     1 module HandlerUtils where
     2 
     2 
     3 import Control.Monad.Reader
     3 import Control.Monad.Reader
       
     4 import qualified Data.ByteString.Char8 as B
     4 
     5 
     5 import RoomsAndClients
     6 import RoomsAndClients
     6 import CoreTypes
     7 import CoreTypes
     7 import Actions
     8 import Actions
     8 
     9 
     9 thisClient :: Reader (ClientIndex, IRnC) ClientInfo
    10 thisClient :: Reader (ClientIndex, IRnC) ClientInfo
    10 thisClient = do
    11 thisClient = do
    11     (ci, rnc) <- ask
    12     (ci, rnc) <- ask
    12     return $ rnc `client` ci
    13     return $ rnc `client` ci
    13 
    14 
    14 clientNick :: Reader (ClientIndex, IRnC) String
    15 clientNick :: Reader (ClientIndex, IRnC) B.ByteString
    15 clientNick = liftM nick thisClient
    16 clientNick = liftM nick thisClient
    16 
    17 
    17 roomOthersChans :: Reader (ClientIndex, IRnC) [ClientChan]
    18 roomOthersChans :: Reader (ClientIndex, IRnC) [ClientChan]
    18 roomOthersChans = do
    19 roomOthersChans = do
    19     (ci, rnc) <- ask
    20     (ci, rnc) <- ask
    23 thisClientChans :: Reader (ClientIndex, IRnC) [ClientChan]
    24 thisClientChans :: Reader (ClientIndex, IRnC) [ClientChan]
    24 thisClientChans = do
    25 thisClientChans = do
    25     (ci, rnc) <- ask
    26     (ci, rnc) <- ask
    26     return $ [sendChan (rnc `client` ci)]
    27     return $ [sendChan (rnc `client` ci)]
    27 
    28 
    28 answerClient :: [String] -> Reader (ClientIndex, IRnC) [Action]
    29 answerClient :: [B.ByteString] -> Reader (ClientIndex, IRnC) [Action]
    29 answerClient msg = thisClientChans >>= return . (: []) . flip AnswerClients msg
    30 answerClient msg = thisClientChans >>= return . (: []) . flip AnswerClients msg