gameServer/HandlerUtils.hs
author mario.liebisch
Wed, 16 Jun 2010 11:50:45 +0200
changeset 3505 ada9f697eb11
parent 3501 a3159a410e5c
child 3542 f216b24aeb7f
permissions -rw-r--r--
Engine: * Bomb clusters now inherit 20 % of their parent's horizontal velocity (makes it a little bit more realistic without completely changing gameplay IMO - needs testing) Mercurial: * Added EOL rules (requires plugin to be activated) and ignore list

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

allRoomInfos :: Reader (a, IRnC) [RoomInfo]
allRoomInfos = liftM ((\irnc -> map (room irnc) $ allRooms irnc) . snd) ask