--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gameServer/EngineInteraction.hs Tue Sep 27 19:27:19 2011 +0400
@@ -0,0 +1,32 @@
+module EngineInteraction where
+
+import qualified Data.Set as Set
+import qualified Data.List as List
+import Control.Monad
+import qualified Codec.Binary.Base64 as Base64
+import qualified Data.ByteString.Char8 as B
+import qualified Data.ByteString as BW
+
+
+
+toEngineMsg :: B.ByteString -> B.ByteString
+toEngineMsg msg = B.pack $ Base64.encode (fromIntegral (BW.length msg) : BW.unpack msg)
+
+
+fromEngineMsg :: B.ByteString -> Maybe B.ByteString
+fromEngineMsg msg = liftM BW.pack (Base64.decode (B.unpack msg) >>= removeLength)
+ where
+ removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing
+ removeLength _ = Nothing
+
+
+checkNetCmd :: B.ByteString -> (Bool, Bool)
+checkNetCmd msg = check decoded
+ where
+ decoded = fromEngineMsg msg
+ check Nothing = (False, False)
+ check (Just ms) | B.length ms > 0 = let m = B.head ms in (m `Set.member` legalMessages, m == '+')
+ | otherwise = (False, False)
+ legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sFNpPwtghbc12345" ++ slotMessages
+ slotMessages = "\128\129\130\131\132\133\134\135\136\137\138"
+