gameServer/Utils.hs
changeset 2403 6c5d504af2ba
parent 2381 959da8402cac
child 2448 30b4a7c8e9b2
equal deleted inserted replaced
2402:edd12b259e7c 2403:6c5d504af2ba
    26 	return $ (foldr1 (.)
    26 	return $ (foldr1 (.)
    27 		$ List.intersperse (\a -> ':':a)
    27 		$ List.intersperse (\a -> ':':a)
    28 		$ concatMap (\n -> (\(a, b) -> [showHex a, showHex b]) $ divMod n 65536) [a, b, c, d]) []
    28 		$ concatMap (\n -> (\(a, b) -> [showHex a, showHex b]) $ divMod n 65536) [a, b, c, d]) []
    29 
    29 
    30 toEngineMsg :: String -> String
    30 toEngineMsg :: String -> String
    31 toEngineMsg msg = Base64.encode (fromIntegral (length msg) : (UTF8.encode msg))
    31 toEngineMsg msg = Base64.encode (fromIntegral (length encodedMsg) : encodedMsg)
       
    32 	where
       
    33 	encodedMsg = UTF8.encode msg
    32 
    34 
    33 fromEngineMsg :: String -> Maybe String
    35 fromEngineMsg :: String -> Maybe String
    34 fromEngineMsg msg = liftM (map w2c) (Base64.decode msg >>= removeLength)
    36 fromEngineMsg msg = liftM (map w2c) (Base64.decode msg >>= removeLength)
    35 	where
    37 	where
    36 		removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing
    38 		removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing