gameServer/EngineInteraction.hs
changeset 10065 35bd559c1973
parent 10060 bcf2e1ca2971
child 10066 1a6e1aad58d6
equal deleted inserted replaced
10064:bf1a5ef4ef14 10065:35bd559c1973
    26 
    26 
    27 decompressWithoutExceptions :: BL.ByteString -> Either String BL.ByteString
    27 decompressWithoutExceptions :: BL.ByteString -> Either String BL.ByteString
    28 decompressWithoutExceptions = finalise
    28 decompressWithoutExceptions = finalise
    29                             . Z.foldDecompressStream cons nil err
    29                             . Z.foldDecompressStream cons nil err
    30                             . Z.decompressWithErrors Z.zlibFormat Z.defaultDecompressParams
    30                             . Z.decompressWithErrors Z.zlibFormat Z.defaultDecompressParams
    31   where err errorCode msg = Left msg
    31   where err _ msg = Left msg
    32         nil = Right []
    32         nil = Right []
    33         cons chunk = right (chunk :)
    33         cons chunk = right (chunk :)
    34         finalise = right BL.fromChunks
    34         finalise = right BL.fromChunks
    35 {- end snippet  -}
    35 {- end snippet  -}
    36 
    36 
    74 replayToDemo :: [TeamInfo]
    74 replayToDemo :: [TeamInfo]
    75         -> Map.Map B.ByteString B.ByteString
    75         -> Map.Map B.ByteString B.ByteString
    76         -> Map.Map B.ByteString [B.ByteString]
    76         -> Map.Map B.ByteString [B.ByteString]
    77         -> [B.ByteString]
    77         -> [B.ByteString]
    78         -> [B.ByteString]
    78         -> [B.ByteString]
    79 replayToDemo ti mParams prms msgs = concat [
    79 replayToDemo ti mParams prms msgs = if not sane then [] else concat [
    80         [em "TD"]
    80         [em "TD"]
    81         , maybeScript
    81         , maybeScript
    82         , maybeMap
    82         , maybeMap
    83         , [eml ["etheme ", head $ prms Map.! "THEME"]]
    83         , [eml ["etheme ", head $ prms Map.! "THEME"]]
    84         , [eml ["eseed ", mParams Map.! "SEED"]]
    84         , [eml ["eseed ", mParams Map.! "SEED"]]
    90         , concatMap teamSetup ti
    90         , concatMap teamSetup ti
    91         , msgs
    91         , msgs
    92         , [em "!"]
    92         , [em "!"]
    93         ]
    93         ]
    94     where
    94     where
       
    95         keys1, keys2 :: Set.Set B.ByteString
       
    96         keys1 = Set.fromList ["MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"]
       
    97         keys2 = Set.fromList ["AMMO", "SCHEME", "SCRIPT", "THEME", "MAZE_SIZE", "DRAWNMAP"]
       
    98         sane = Set.null (Map.keysSet mParams Set.\\ keys1)
       
    99             && Set.null (Map.keysSet prms Set.\\ keys2)
       
   100             && (not . null . drop 27 $ scheme)
       
   101             && (not . null . tail $ prms Map.! "AMMO")
    95         mapGenTypes = ["+rnd+", "+maze+", "+drawn+"]
   102         mapGenTypes = ["+rnd+", "+maze+", "+drawn+"]
    96         maybeScript = let s = head . fromMaybe ["Normal"] $ Map.lookup "SCRIPT" prms in if s == "Normal" then [] else [eml ["escript Scripts/Multiplayer/", s, ".lua"]]
   103         maybeScript = let s = head . fromMaybe ["Normal"] $ Map.lookup "SCRIPT" prms in if s == "Normal" then [] else [eml ["escript Scripts/Multiplayer/", s, ".lua"]]
    97         maybeMap = let m = mParams Map.! "MAP" in if m `elem` mapGenTypes then [] else [eml ["emap ", m]]
   104         maybeMap = let m = mParams Map.! "MAP" in if m `elem` mapGenTypes then [] else [eml ["emap ", m]]
    98         scheme = tail $ prms Map.! "SCHEME"
   105         scheme = tail $ prms Map.! "SCHEME"
    99         mapgen = mParams Map.! "MAPGEN"
   106         mapgen = mParams Map.! "MAPGEN"