726 let i = if null items then ["heads", "tails"] else items |
726 let i = if null items then ["heads", "tails"] else items |
727 n <- io $ randomRIO (0, length i - 1) |
727 n <- io $ randomRIO (0, length i - 1) |
728 processAction $ AnswerClients chans ["CHAT", "[random]", i !! n] |
728 processAction $ AnswerClients chans ["CHAT", "[random]", i !! n] |
729 |
729 |
730 |
730 |
|
731 processAction (LoadGhost location) = do |
|
732 ri <- clientRoomA |
|
733 rnc <- gets roomsClients |
|
734 thisRoomChans <- liftM (map sendChan) $ roomClientsS ri |
|
735 #if defined(OFFICIAL_SERVER) |
|
736 rm <- io $ room'sM rnc id ri |
|
737 points <- io $ loadFile (B.unpack $ "ghosts/" `B.append` sanitizeName location) |
|
738 when (roomProto rm > 51) $ do |
|
739 processAction $ ModifyRoom $ \r -> r{params = Map.insert "DRAWNMAP" [prependGhostPoints (toP points) $ head $ (params r) Map.! "DRAWNMAP"] (params r)} |
|
740 #endif |
|
741 cl <- client's id |
|
742 rm <- io $ room'sM rnc id ri |
|
743 mapM_ processAction $ map (replaceChans thisRoomChans) $ answerFullConfigParams cl (mapParams rm) (params rm) |
|
744 where |
|
745 loadFile :: String -> IO [Int] |
|
746 loadFile fileName = E.handle (\(e :: SomeException) -> return []) $ do |
|
747 points <- liftM read $ readFile fileName |
|
748 return (points `deepseq` points) |
|
749 replaceChans chans (AnswerClients _ msg) = AnswerClients chans msg |
|
750 replaceChans _ a = a |
|
751 toP [] = [] |
|
752 toP (p1:p2:ps) = (fromIntegral p1, fromIntegral p2) : toP ps |
|
753 {- |
|
754 let a = map (replaceChans chans) $ answerFullConfigParams cl mp p |
|
755 -} |
731 #if defined(OFFICIAL_SERVER) |
756 #if defined(OFFICIAL_SERVER) |
732 processAction SaveReplay = do |
757 processAction SaveReplay = do |
733 ri <- clientRoomA |
758 ri <- clientRoomA |
734 rnc <- gets roomsClients |
759 rnc <- gets roomsClients |
735 |
760 |