gameServer/EngineInteraction.hs
changeset 10984 c828cabe33af
parent 10983 6aba07ea908b
child 11031 4ad0252470dd
equal deleted inserted replaced
10983:6aba07ea908b 10984:c828cabe33af
    19 {-# LANGUAGE CPP, OverloadedStrings #-}
    19 {-# LANGUAGE CPP, OverloadedStrings #-}
    20 
    20 
    21 #if defined(OFFICIAL_SERVER)
    21 #if defined(OFFICIAL_SERVER)
    22 module EngineInteraction(replayToDemo, checkNetCmd, toEngineMsg, drawnMapData) where
    22 module EngineInteraction(replayToDemo, checkNetCmd, toEngineMsg, drawnMapData) where
    23 #else
    23 #else
    24 module EngineInteraction(checkNetCmd, toEngineMsg, drawnMapData) where
    24 module EngineInteraction(checkNetCmd, toEngineMsg) where
    25 #endif
    25 #endif
    26 
    26 
    27 import qualified Data.Set as Set
    27 import qualified Data.Set as Set
    28 import Control.Monad
    28 import Control.Monad
    29 import qualified Codec.Binary.Base64 as Base64
    29 import qualified Codec.Binary.Base64 as Base64
    38 import Data.Maybe
    38 import Data.Maybe
    39 -------------
    39 -------------
    40 import CoreTypes
    40 import CoreTypes
    41 import Utils
    41 import Utils
    42 
    42 
       
    43 #if defined(OFFICIAL_SERVER)
    43 {-
    44 {-
    44     this is snippet from http://stackoverflow.com/questions/10043102/how-to-catch-the-decompress-ioerror
    45     this is snippet from http://stackoverflow.com/questions/10043102/how-to-catch-the-decompress-ioerror
    45     because standard 'catch' doesn't seem to catch decompression errors for some reason
    46     because standard 'catch' doesn't seem to catch decompression errors for some reason
    46 -}
    47 -}
    47 import qualified Codec.Compression.Zlib.Internal as Z
    48 import qualified Codec.Compression.Zlib.Internal as Z
    53   where err _ msg = Left msg
    54   where err _ msg = Left msg
    54         nil = Right []
    55         nil = Right []
    55         cons chunk = right (chunk :)
    56         cons chunk = right (chunk :)
    56         finalise = right BL.fromChunks
    57         finalise = right BL.fromChunks
    57 {- end snippet  -}
    58 {- end snippet  -}
       
    59 #endif
    58 
    60 
    59 toEngineMsg :: B.ByteString -> B.ByteString
    61 toEngineMsg :: B.ByteString -> B.ByteString
    60 toEngineMsg msg = B.pack $ Base64.encode (fromIntegral (BW.length msg) : BW.unpack msg)
    62 toEngineMsg msg = B.pack $ Base64.encode (fromIntegral (BW.length msg) : BW.unpack msg)
    61 
    63 
    62 
    64 
   155                             eml ["eaddhh ", showB $ difficulty t, " ", initHealth, " ", hname]
   157                             eml ["eaddhh ", showB $ difficulty t, " ", initHealth, " ", hname]
   156                             , eml ["ehat ", hhat]
   158                             , eml ["ehat ", hhat]
   157                             ])
   159                             ])
   158                         $ hedgehogs t
   160                         $ hedgehogs t
   159                         )
   161                         )
   160 #endif
       
   161 
   162 
   162 drawnMapData :: B.ByteString -> [B.ByteString]
   163 drawnMapData :: B.ByteString -> [B.ByteString]
   163 drawnMapData =
   164 drawnMapData =
   164           L.map (\m -> eml ["edraw ", BW.pack m])
   165           L.map (\m -> eml ["edraw ", BW.pack m])
   165         . L.unfoldr by200
   166         . L.unfoldr by200
   223         , 0x00800000
   224         , 0x00800000
   224         , 0x01000000
   225         , 0x01000000
   225         , 0x02000000
   226         , 0x02000000
   226         , 0x04000000
   227         , 0x04000000
   227         ]
   228         ]
   228 
   229 #endif
   229 
       
   230