Some basic sanity tests for replay files
authorunc0rr
Fri, 24 Jan 2014 00:05:19 +0400
changeset 10065 35bd559c1973
parent 10064 bf1a5ef4ef14
child 10066 1a6e1aad58d6
Some basic sanity tests for replay files
gameServer/CoreTypes.hs
gameServer/EngineInteraction.hs
--- a/gameServer/CoreTypes.hs	Thu Jan 23 23:28:16 2014 +0400
+++ b/gameServer/CoreTypes.hs	Fri Jan 24 00:05:19 2014 +0400
@@ -214,8 +214,8 @@
         )
         (
             Map.fromList $ Prelude.zip
-                ["SCHEME", "SCRIPT", "THEME", "MAZE_SIZE", "DRAWNMAP"]
-                [["Default"], ["Normal"], ["Theme"], ["0"], ["-"]]
+                ["SCRIPT", "THEME", "MAZE_SIZE", "DRAWNMAP"]
+                [["Normal"], ["Theme"], ["0"], ["-"]]
         )
 
 
--- a/gameServer/EngineInteraction.hs	Thu Jan 23 23:28:16 2014 +0400
+++ b/gameServer/EngineInteraction.hs	Fri Jan 24 00:05:19 2014 +0400
@@ -28,7 +28,7 @@
 decompressWithoutExceptions = finalise
                             . Z.foldDecompressStream cons nil err
                             . Z.decompressWithErrors Z.zlibFormat Z.defaultDecompressParams
-  where err errorCode msg = Left msg
+  where err _ msg = Left msg
         nil = Right []
         cons chunk = right (chunk :)
         finalise = right BL.fromChunks
@@ -76,7 +76,7 @@
         -> Map.Map B.ByteString [B.ByteString]
         -> [B.ByteString]
         -> [B.ByteString]
-replayToDemo ti mParams prms msgs = concat [
+replayToDemo ti mParams prms msgs = if not sane then [] else concat [
         [em "TD"]
         , maybeScript
         , maybeMap
@@ -92,6 +92,13 @@
         , [em "!"]
         ]
     where
+        keys1, keys2 :: Set.Set B.ByteString
+        keys1 = Set.fromList ["MAP", "MAPGEN", "MAZE_SIZE", "SEED", "TEMPLATE"]
+        keys2 = Set.fromList ["AMMO", "SCHEME", "SCRIPT", "THEME", "MAZE_SIZE", "DRAWNMAP"]
+        sane = Set.null (Map.keysSet mParams Set.\\ keys1)
+            && Set.null (Map.keysSet prms Set.\\ keys2)
+            && (not . null . drop 27 $ scheme)
+            && (not . null . tail $ prms Map.! "AMMO")
         mapGenTypes = ["+rnd+", "+maze+", "+drawn+"]
         maybeScript = let s = head . fromMaybe ["Normal"] $ Map.lookup "SCRIPT" prms in if s == "Normal" then [] else [eml ["escript Scripts/Multiplayer/", s, ".lua"]]
         maybeMap = let m = mParams Map.! "MAP" in if m `elem` mapGenTypes then [] else [eml ["emap ", m]]