author | Rowan D |
Mon, 03 Dec 2012 17:51:57 +0100 | |
changeset 8204 | 9a6030d96273 |
parent 7766 | 98edc0724a28 |
child 8479 | 8d71109b04d2 |
permissions | -rw-r--r-- |
6068 | 1 |
module EngineInteraction where |
2 |
||
3 |
import qualified Data.Set as Set |
|
4 |
import Control.Monad |
|
5 |
import qualified Codec.Binary.Base64 as Base64 |
|
6 |
import qualified Data.ByteString.Char8 as B |
|
7 |
import qualified Data.ByteString as BW |
|
6069 | 8 |
------------- |
9 |
import CoreTypes |
|
6068 | 10 |
|
11 |
||
12 |
toEngineMsg :: B.ByteString -> B.ByteString |
|
13 |
toEngineMsg msg = B.pack $ Base64.encode (fromIntegral (BW.length msg) : BW.unpack msg) |
|
14 |
||
15 |
||
16 |
fromEngineMsg :: B.ByteString -> Maybe B.ByteString |
|
17 |
fromEngineMsg msg = liftM BW.pack (Base64.decode (B.unpack msg) >>= removeLength) |
|
18 |
where |
|
19 |
removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing |
|
20 |
removeLength _ = Nothing |
|
21 |
||
22 |
||
23 |
checkNetCmd :: B.ByteString -> (Bool, Bool) |
|
24 |
checkNetCmd msg = check decoded |
|
25 |
where |
|
26 |
decoded = fromEngineMsg msg |
|
27 |
check Nothing = (False, False) |
|
28 |
check (Just ms) | B.length ms > 0 = let m = B.head ms in (m `Set.member` legalMessages, m == '+') |
|
29 |
| otherwise = (False, False) |
|
6206
75e0d8169ba2
As sheepluva pointed out, allowing this message to be legal allows naughtiness. The server usage of this message does not seem to use this check.
nemo
parents:
6070
diff
changeset
|
30 |
legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sNpPwtghbc12345" ++ slotMessages |
6068 | 31 |
slotMessages = "\128\129\130\131\132\133\134\135\136\137\138" |
32 |
||
7766 | 33 |
|
6069 | 34 |
gameInfo2Replay :: GameInfo -> B.ByteString |
35 |
gameInfo2Replay GameInfo{roundMsgs = rm, |
|
36 |
teamsAtStart = teams, |
|
6070 | 37 |
giMapParams = params1, |
38 |
giParams = params2} = undefined |