Fixed scoring exploit on Control and removed user branding from the map
Changed hog positioning code on CTF_Blizzard so that each side is positioned in the same manner, and gets to move in the same order
Fixed version control fail in CTF_Blizzard
{-# LANGUAGE OverloadedStrings #-}module Utils whereimport Data.Charimport Data.Wordimport qualified Data.Map as Mapimport qualified Data.Set as Setimport Numericimport Network.Socketimport System.IOimport qualified Data.List as Listimport Control.Monad-------------------------------------------------import qualified Codec.Binary.Base64 as Base64import qualified Data.ByteString.Char8 as Bimport qualified Data.ByteString as BWimport CoreTypessockAddr2String :: SockAddr -> IO B.ByteStringsockAddr2String (SockAddrInet _ hostAddr) = liftM B.pack $ inet_ntoa hostAddrsockAddr2String (SockAddrInet6 _ _ (a, b, c, d) _) = return $ B.pack $ (foldr1 (.) $ List.intersperse (':':) $ concatMap (\n -> (\(a0, a1) -> [showHex a0, showHex a1]) $ divMod n 65536) [a, b, c, d]) []toEngineMsg :: B.ByteString -> B.ByteStringtoEngineMsg msg = B.pack $ Base64.encode (fromIntegral (BW.length msg) : BW.unpack msg)fromEngineMsg :: B.ByteString -> Maybe B.ByteStringfromEngineMsg 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 _ = NothingcheckNetCmd :: B.ByteString -> (Bool, Bool)checkNetCmd = check . liftM B.unpack . fromEngineMsg where check Nothing = (False, False) check (Just (m:_)) = (m `Set.member` legalMessages, m == '+') check _ = (False, False) legalMessages = Set.fromList $ "M#+LlRrUuDdZzAaSjJ,sFNpPwtghb12345" ++ slotMessages slotMessages = "\128\129\130\131\132\133\134\135\136\137\138"maybeRead :: Read a => String -> Maybe amaybeRead s = case reads s of [(x, rest)] | all isSpace rest -> Just x _ -> NothingteamToNet :: TeamInfo -> [B.ByteString]teamToNet team = "ADD_TEAM" : teamname team : teamgrave team : teamfort team : teamvoicepack team : teamflag team : teamowner team : (B.pack . show $ difficulty team) : hhsInfo where hhsInfo = concatMap (\(HedgehogInfo n hat) -> [n, hat]) $ hedgehogs teammodifyTeam :: TeamInfo -> RoomInfo -> RoomInfomodifyTeam team room = room{teams = replaceTeam team $ teams room} where replaceTeam _ [] = error "modifyTeam: no such team" replaceTeam tm (t:ts) = if teamname tm == teamname t then tm : ts else t : replaceTeam tm tsillegalName :: B.ByteString -> BoolillegalName b = null s || all isSpace s || isSpace (head s) || isSpace (last s) where s = B.unpack bprotoNumber2ver :: Word16 -> B.ByteStringprotoNumber2ver v = Map.findWithDefault "Unknown" v vermap where vermap = Map.fromList [ (17, "0.9.7-dev") , (19, "0.9.7") , (20, "0.9.8-dev") , (21, "0.9.8") , (22, "0.9.9-dev") , (23, "0.9.9") , (24, "0.9.10-dev") , (25, "0.9.10") , (26, "0.9.11-dev") , (27, "0.9.11") , (28, "0.9.12-dev") , (29, "0.9.12") , (30, "0.9.13-dev") , (31, "0.9.13") , (32, "0.9.14-dev") , (33, "0.9.14") , (34, "0.9.15-dev") , (35, "0.9.14.1") , (37, "0.9.15") , (38, "0.9.16-dev") ]askFromConsole :: B.ByteString -> IO B.ByteStringaskFromConsole msg = do B.putStr msg hFlush stdout B.getLineunfoldrE :: (b -> Either b (a, b)) -> b -> ([a], b)unfoldrE f b = case f b of Right (a, new_b) -> let (a', b') = unfoldrE f new_b in (a : a', b') Left new_b -> ([], new_b)showB :: Show a => a -> B.ByteStringshowB = B.pack .show