Fix official server build
authorunc0rr
Fri, 23 Dec 2016 23:12:00 +0300 (2016-12-23)
changeset 12113 72f5d670bbee
parent 12112 2c21bca6cbfa
child 12114 cdadc1d487f1
Fix official server build
cmake_modules/CheckHaskellModuleExists.cmake
gameServer/EngineInteraction.hs
--- a/cmake_modules/CheckHaskellModuleExists.cmake	Mon Dec 19 12:34:09 2016 -0500
+++ b/cmake_modules/CheckHaskellModuleExists.cmake	Fri Dec 23 23:12:00 2016 +0300
@@ -22,7 +22,7 @@
         endforeach()
     endif()
 
-    set(PARAMETERS "")
+    #set(PARAMETERS "")
 
     execute_process(COMMAND ${GHC_EXECUTABLE}
                     "-DMODULE=${MODULE}"
--- a/gameServer/EngineInteraction.hs	Mon Dec 19 12:34:09 2016 -0500
+++ b/gameServer/EngineInteraction.hs	Fri Dec 23 23:12:00 2016 +0300
@@ -44,22 +44,16 @@
 import Utils
 
 #if defined(OFFICIAL_SERVER)
-{-
-    this is snippet from http://stackoverflow.com/questions/10043102/how-to-catch-the-decompress-ioerror
-    because standard 'catch' doesn't seem to catch decompression errors for some reason
--}
 import qualified Codec.Compression.Zlib.Internal as ZI
 import qualified Codec.Compression.Zlib as Z
 
-decompressWithoutExceptions :: BL.ByteString -> Either String BL.ByteString
-decompressWithoutExceptions = finalise
-                            . ZI.foldDecompressStream cons nil err
-                            . ZI.decompressWithErrors ZI.zlibFormat ZI.defaultDecompressParams
-  where err _ msg = Left msg
-        nil = Right []
-        cons chunk = right (chunk :)
-        finalise = right BL.fromChunks
-{- end snippet  -}
+decompressWithoutExceptions :: BL.ByteString -> BL.ByteString
+decompressWithoutExceptions = BL.fromChunks . ZI.foldDecompressStreamWithInput chunk end err decomp
+    where
+        decomp = ZI.decompressST ZI.zlibFormat ZI.defaultDecompressParams
+        chunk = (:)
+        end _ = []
+        err = const $ [BW.empty]
 #endif
 
 toEngineMsg :: B.ByteString -> B.ByteString
@@ -187,13 +181,10 @@
         by200 m = Just $ L.splitAt 200 m
 
 unpackDrawnMap :: B.ByteString -> BL.ByteString
-unpackDrawnMap = either (const BL.empty) id
-        . decompressWithoutExceptions
-        . BL.pack
-        . L.drop 4
-        . fromMaybe []
+unpackDrawnMap = either
+        (const BL.empty) 
+        (decompressWithoutExceptions . BL.pack . drop 4 . BW.unpack)
         . Base64.decode
-        . B.unpack
 
 compressWithLength :: BL.ByteString -> BL.ByteString
 compressWithLength b = BL.drop 8 . encode . runPut $ do
@@ -201,9 +192,8 @@
     mapM_ putWord8 $ BW.unpack $ BL.toStrict $ Z.compress b
 
 packDrawnMap :: BL.ByteString -> B.ByteString
-packDrawnMap = B.pack
-    . Base64.encode
-    . BW.unpack
+packDrawnMap =
+      Base64.encode
     . BL.toStrict
     . compressWithLength