--- a/gameServer/CoreTypes.hs Fri Feb 19 00:07:59 2016 +0100
+++ b/gameServer/CoreTypes.hs Sat Feb 20 22:02:13 2016 +0300
@@ -154,6 +154,7 @@
eiEM,
eiJoin :: !EventsInfo,
teamsInGame :: !Word,
+ teamIndexes :: ![Word8],
pendingActions :: ![Action]
}
--- a/gameServer/EngineInteraction.hs Fri Feb 19 00:07:59 2016 +0100
+++ b/gameServer/EngineInteraction.hs Sat Feb 20 22:02:13 2016 +0300
@@ -78,14 +78,14 @@
splitMessages = L.unfoldr (\b -> if B.null b then Nothing else Just $ B.splitAt (1 + fromIntegral (BW.head b)) b)
-checkNetCmd :: B.ByteString -> (B.ByteString, B.ByteString, Maybe (Maybe B.ByteString))
-checkNetCmd msg = check decoded
+checkNetCmd :: [Word8] -> B.ByteString -> (B.ByteString, B.ByteString, Maybe (Maybe B.ByteString))
+checkNetCmd teamsIndexes msg = check decoded
where
decoded = liftM (splitMessages . BW.pack) $ Base64.decode $ B.unpack msg
check Nothing = (B.empty, B.empty, Nothing)
check (Just msgs) = let (a, b) = (filter isLegal msgs, filter isNonEmpty a) in (encode a, encode b, lft a)
encode = B.pack . Base64.encode . BW.unpack . B.concat
- isLegal m = (B.length m > 1) && (flip Set.member legalMessages . B.head . B.tail $ m)
+ isLegal m = (B.length m > 1) && (flip Set.member legalMessages . B.head . B.tail $ m) && not (isMalformed (B.head m) (B.tail m))
lft = foldr l Nothing
l m n = let m' = B.head $ B.tail m; tst = flip Set.member in
if not $ tst timedMessages m' then n
@@ -94,6 +94,9 @@
legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sNpPwtgfhbc12345" ++ slotMessages
slotMessages = "\128\129\130\131\132\133\134\135\136\137\138"
timedMessages = Set.fromList $ "+LlRrUuDdZzAaSjJ,NpPwtgfc12345" ++ slotMessages
+ isMalformed 'h' m | B.length m >= 3 = let hognum = m `B.index` 1; teamnum = m `BW.index` 2 in hognum < '1' || hognum > '8' || teamnum `L.notElem` teamsIndexes
+ | otherwise = True
+ isMalformed _ _ = False
#if defined(OFFICIAL_SERVER)
replayToDemo :: [TeamInfo]
--- a/gameServer/HWProtoInRoomState.hs Fri Feb 19 00:07:59 2016 +0100
+++ b/gameServer/HWProtoInRoomState.hs Sat Feb 20 22:02:13 2016 +0300
@@ -54,7 +54,7 @@
, AnswerClients chans ["RUN_GAME"]
, SendUpdateOnThisRoom
, AnswerClients chans $ "CLIENT_FLAGS" : "+g" : nicks
- , ModifyRoomClients (\c -> c{isInGame = True})
+ , ModifyRoomClients (\c -> c{isInGame = True, teamIndexes = map snd . filter (\(t, _) -> teamowner t == nick cl) $ zip (teams rm) [0..]})
]
else
return [Warning $ loc "Less than two clans!"]
@@ -260,6 +260,8 @@
rm <- thisRoom
chans <- roomOthersChans
+ let (legalMsgs, nonEmptyMsgs, lastFTMsg) = checkNetCmd (teamIndexes cl) msg
+
if teamsInGame cl > 0 && (isJust $ gameInfo rm) && (not $ B.null legalMsgs) then
return $ AnswerClients chans ["EM", legalMsgs]
: [ModifyRoom (\r -> r{gameInfo = liftM
@@ -269,8 +271,6 @@
$ gameInfo r}), RegisterEvent EngineMessage]
else
return []
- where
- (legalMsgs, nonEmptyMsgs, lastFTMsg) = checkNetCmd msg
handleCmd_inRoom ["ROUNDFINISHED", _] = do
--- a/gameServer/NetRoutines.hs Fri Feb 19 00:07:59 2016 +0100
+++ b/gameServer/NetRoutines.hs Sat Feb 20 22:02:13 2016 +0300
@@ -81,6 +81,7 @@
newEventsInfo
0
[]
+ []
)
writeChan chan $ Accept newClient