gameServer/Utils.hs
changeset 2381 959da8402cac
parent 2349 ba7a0813c532
child 2403 6c5d504af2ba
equal deleted inserted replaced
2380:603965eca22b 2381:959da8402cac
    34 fromEngineMsg msg = liftM (map w2c) (Base64.decode msg >>= removeLength)
    34 fromEngineMsg msg = liftM (map w2c) (Base64.decode msg >>= removeLength)
    35 	where
    35 	where
    36 		removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing
    36 		removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing
    37 		removeLength _ = Nothing
    37 		removeLength _ = Nothing
    38 
    38 
    39 isLegalNetCommand :: String -> Bool
    39 checkNetCmd :: String -> (Bool, Bool)
    40 isLegalNetCommand msg = test decoded
    40 checkNetCmd msg = check decoded
    41 	where
    41 	where
    42 		decoded = fromEngineMsg msg
    42 		decoded = fromEngineMsg msg
    43 		test Nothing = False
    43 		check Nothing = (False, False)
    44 		test (Just (m:ms)) = m `Set.member` legalMessages
    44 		check (Just (m:ms)) = (m `Set.member` legalMessages, m == '+')
    45 		test _ = False
    45 		check _ = (False, False)
    46 		legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sFNpPwtghb12345" ++ slotMessages
    46 		legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sFNpPwtghb12345" ++ slotMessages
    47 		slotMessages = "\128\129\130\131\132\133\134\135\136\137\138"
    47 		slotMessages = "\128\129\130\131\132\133\134\135\136\137\138"
    48 
    48 
    49 maybeRead :: Read a => String -> Maybe a
    49 maybeRead :: Read a => String -> Maybe a
    50 maybeRead s = case reads s of
    50 maybeRead s = case reads s of