gameServer/HandlerUtils.hs
author unc0rr
Sun, 06 Jun 2010 15:29:33 +0000
changeset 3500 af8390d807d6
parent 3435 4e4f88a7bdf2
child 3501 a3159a410e5c
permissions -rw-r--r--
Use sockets instead of handles, use bytestrings instead of strings

module HandlerUtils where

import Control.Monad.Reader
import qualified Data.ByteString.Char8 as B

import RoomsAndClients
import CoreTypes
import Actions

thisClient :: Reader (ClientIndex, IRnC) ClientInfo
thisClient = do
    (ci, rnc) <- ask
    return $ rnc `client` ci

clientNick :: Reader (ClientIndex, IRnC) B.ByteString
clientNick = liftM nick thisClient

roomOthersChans :: Reader (ClientIndex, IRnC) [ClientChan]
roomOthersChans = do
    (ci, rnc) <- ask
    let ri = clientRoom rnc ci
    return $ map (sendChan . client rnc) (roomClients rnc ri)

thisClientChans :: Reader (ClientIndex, IRnC) [ClientChan]
thisClientChans = do
    (ci, rnc) <- ask
    return $ [sendChan (rnc `client` ci)]

answerClient :: [B.ByteString] -> Reader (ClientIndex, IRnC) [Action]
answerClient msg = thisClientChans >>= return . (: []) . flip AnswerClients msg