author | unc0rr |
Fri, 28 Sep 2012 00:39:20 +0400 | |
changeset 7715 | 8b653edac2a2 |
parent 6206 | 75e0d8169ba2 |
child 7766 | 98edc0724a28 |
permissions | -rw-r--r-- |
6068 | 1 |
module EngineInteraction where |
2 |
||
3 |
import qualified Data.Set as Set |
|
4 |
import qualified Data.List as List |
|
5 |
import Control.Monad |
|
6 |
import qualified Codec.Binary.Base64 as Base64 |
|
7 |
import qualified Data.ByteString.Char8 as B |
|
8 |
import qualified Data.ByteString as BW |
|
6069 | 9 |
------------- |
10 |
import CoreTypes |
|
6068 | 11 |
|
12 |
||
13 |
toEngineMsg :: B.ByteString -> B.ByteString |
|
14 |
toEngineMsg msg = B.pack $ Base64.encode (fromIntegral (BW.length msg) : BW.unpack msg) |
|
15 |
||
16 |
||
17 |
fromEngineMsg :: B.ByteString -> Maybe B.ByteString |
|
18 |
fromEngineMsg msg = liftM BW.pack (Base64.decode (B.unpack msg) >>= removeLength) |
|
19 |
where |
|
20 |
removeLength (x:xs) = if length xs == fromIntegral x then Just xs else Nothing |
|
21 |
removeLength _ = Nothing |
|
22 |
||
23 |
||
24 |
checkNetCmd :: B.ByteString -> (Bool, Bool) |
|
25 |
checkNetCmd msg = check decoded |
|
26 |
where |
|
27 |
decoded = fromEngineMsg msg |
|
28 |
check Nothing = (False, False) |
|
29 |
check (Just ms) | B.length ms > 0 = let m = B.head ms in (m `Set.member` legalMessages, m == '+') |
|
30 |
| 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
|
31 |
legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sNpPwtghbc12345" ++ slotMessages |
6068 | 32 |
slotMessages = "\128\129\130\131\132\133\134\135\136\137\138" |
33 |
||
6069 | 34 |
gameInfo2Replay :: GameInfo -> B.ByteString |
35 |
gameInfo2Replay GameInfo{roundMsgs = rm, |
|
36 |
teamsAtStart = teams, |
|
6070 | 37 |
giMapParams = params1, |
38 |
giParams = params2} = undefined |