gameServer/Actions.hs
changeset 11575 db7743e2fad1
parent 11465 0ae2e4c13bd1
child 11577 bee3a2f8e117
--- a/gameServer/Actions.hs	Wed Feb 24 22:37:03 2016 +0300
+++ b/gameServer/Actions.hs	Thu Feb 25 23:17:52 2016 +0300
@@ -728,6 +728,26 @@
     processAction $ AnswerClients chans ["CHAT", "[random]", i !! n]
 
 
+processAction (LoadGhost location) = do
+    points <- io $ loadFile (B.unpack $ "ghosts/" `B.append` sanitizeName location)
+    ri <- clientRoomA
+    rnc <- gets roomsClients
+    thisRoomChans <- liftM (map sendChan) $ roomClientsS ri
+    -- inject ghost points into map
+    rm <- io $ room'sM rnc id ri
+    cl <- client's id
+    mapM processAction $ map (replaceChans thisRoomChans) $ answerFullConfigParams cl (mapParams rm) (params rm)
+    return ()
+    where
+    loadFile :: String -> IO [Int]
+    loadFile fileName = E.handle (\(e :: SomeException) -> return []) $ do
+        points <- liftM read $ readFile fileName
+        return (points `deepseq` points)
+    replaceChans chans (AnswerClients _ msg) = AnswerClients chans msg
+    replaceChans _ a = a
+{-
+        let a = map (replaceChans chans) $ answerFullConfigParams cl mp p
+-}
 #if defined(OFFICIAL_SERVER)
 processAction SaveReplay = do
     ri <- clientRoomA
@@ -846,4 +866,4 @@
     forM_ (actions `deepseq` actions) processAction
 
 processAction CheckVotes =
-    checkVotes >>= mapM_ processAction
\ No newline at end of file
+    checkVotes >>= mapM_ processAction