equal
deleted
inserted
replaced
5 import Data.Char |
5 import Data.Char |
6 import Data.Word |
6 import Data.Word |
7 import qualified Data.Map as Map |
7 import qualified Data.Map as Map |
8 import qualified Data.IntMap as IntMap |
8 import qualified Data.IntMap as IntMap |
9 import qualified Data.Set as Set |
9 import qualified Data.Set as Set |
|
10 import Data.ByteString.Internal (w2c) |
10 import Numeric |
11 import Numeric |
11 import Network.Socket |
12 import Network.Socket |
12 import System.IO |
13 import System.IO |
13 import qualified Data.List as List |
14 import qualified Data.List as List |
14 import Maybe |
15 import Maybe |
27 |
28 |
28 toEngineMsg :: String -> String |
29 toEngineMsg :: String -> String |
29 toEngineMsg msg = Base64.encode (fromIntegral (length msg) : (UTF8.encode msg)) |
30 toEngineMsg msg = Base64.encode (fromIntegral (length msg) : (UTF8.encode msg)) |
30 |
31 |
31 fromEngineMsg :: String -> Maybe String |
32 fromEngineMsg :: String -> Maybe String |
32 fromEngineMsg msg = Base64.decode msg >>= return . UTF8.decode >>= removeLength |
33 fromEngineMsg msg = Base64.decode msg >>= removeLength >>= return . (map w2c) |
33 where |
34 where |
34 removeLength (x:xs) = if length xs == ord x then Just xs else Nothing |
35 removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing |
35 removeLength _ = Nothing |
36 removeLength _ = Nothing |
36 |
37 |
37 isLegalNetCommand :: String -> Bool |
38 isLegalNetCommand :: String -> Bool |
38 isLegalNetCommand msg = test decoded |
39 isLegalNetCommand msg = test decoded |
39 where |
40 where |