gameServer/HWProtoLobbyState.hs
changeset 10351 0eff41e9f63f
parent 10349 a51de45dcc42
child 10460 8dcea9087d75
equal deleted inserted replaced
10350:4e919f7b9d92 10351:0eff41e9f63f
    61     let nicks = map nick jRoomClients
    61     let nicks = map nick jRoomClients
    62     let owner = find isMaster jRoomClients
    62     let owner = find isMaster jRoomClients
    63     let chans = map sendChan (cl : jRoomClients)
    63     let chans = map sendChan (cl : jRoomClients)
    64     let isBanned = host cl `elem` roomBansList jRoom
    64     let isBanned = host cl `elem` roomBansList jRoom
    65     let clTeams =
    65     let clTeams =
    66             if (isJust $ gameInfo jRoom) then
    66             if (clientProto cl >= 48) && (isJust $ gameInfo jRoom) then
    67                 map teamname . filter (\t -> teamowner t == nick cl) . teamsAtStart . fromJust $ gameInfo jRoom 
    67                 map teamname . filter (\t -> teamowner t == nick cl) . teamsAtStart . fromJust $ gameInfo jRoom 
    68                 else
    68                 else
    69                 []
    69                 []
    70     return $
    70     return $
    71         if isNothing maybeRI then
    71         if isNothing maybeRI then
    85                 MoveToRoom jRI
    85                 MoveToRoom jRI
    86                 : ModifyClient (\c -> c{isJoinedMidGame = isJust $ gameInfo jRoom, teamsInGame = fromIntegral $ length clTeams})
    86                 : ModifyClient (\c -> c{isJoinedMidGame = isJust $ gameInfo jRoom, teamsInGame = fromIntegral $ length clTeams})
    87                 : AnswerClients chans ["CLIENT_FLAGS", "-r", nick cl]
    87                 : AnswerClients chans ["CLIENT_FLAGS", "-r", nick cl]
    88                 : [(AnswerClients [sendChan cl] $ "JOINED" : nicks) | not $ null nicks]
    88                 : [(AnswerClients [sendChan cl] $ "JOINED" : nicks) | not $ null nicks]
    89             )
    89             )
       
    90                 ++ [ModifyRoom (\r -> let (t', g') = moveTeams clTeams . fromJust $ gameInfo r in r{gameInfo = Just g', teams = t'}) | not $ null clTeams]
    90             ++ [AnswerClients [sendChan cl] ["CLIENT_FLAGS", "+h", nick $ fromJust owner] | isJust owner]
    91             ++ [AnswerClients [sendChan cl] ["CLIENT_FLAGS", "+h", nick $ fromJust owner] | isJust owner]
    91             ++ [sendStateFlags cl jRoomClients | not $ null jRoomClients]
    92             ++ [sendStateFlags cl jRoomClients | not $ null jRoomClients]
    92             ++ answerFullConfig cl jRoom
    93             ++ answerFullConfig cl jRoom
    93             ++ answerTeams cl jRoom
    94             ++ answerTeams cl jRoom
    94             ++ watchRound cl jRoom chans
    95             ++ watchRound cl jRoom chans
    95             ++ [AnswerClients [sendChan cl] ["CHAT", "[greeting]", greeting jRoom] | greeting jRoom /= ""]
    96             ++ [AnswerClients [sendChan cl] ["CHAT", "[greeting]", greeting jRoom] | greeting jRoom /= ""]
    96             ++ map (\t -> AnswerClients chans ["EM", toEngineMsg $ 'G' `B.cons` t]) clTeams
    97             ++ map (\t -> AnswerClients chans ["EM", toEngineMsg $ 'G' `B.cons` t]) clTeams
    97 
    98 
    98         where
    99         where
       
   100         moveTeams :: [B.ByteString] -> GameInfo -> ([TeamInfo], GameInfo)
       
   101         moveTeams cts g = (deleteFirstsBy2 (\a b -> teamname a == b) (teamsAtStart g) (leftTeams g \\ cts)
       
   102             , g{leftTeams = leftTeams g \\ cts, teamsInGameNumber = teamsInGameNumber g + length cts})
    99         sendStateFlags cl clients = AnswerClients [sendChan cl] . concat . intersperse [""] . filter (not . null) . concat $
   103         sendStateFlags cl clients = AnswerClients [sendChan cl] . concat . intersperse [""] . filter (not . null) . concat $
   100                 [f "+r" ready, f "-r" unready, f "+g" ingame, f "-g" inroomlobby]
   104                 [f "+r" ready, f "-r" unready, f "+g" ingame, f "-g" inroomlobby]
   101             where
   105             where
   102             (ready, unready) = partition isReady clients
   106             (ready, unready) = partition isReady clients
   103             (ingame, inroomlobby) = partition isInGame clients
   107             (ingame, inroomlobby) = partition isInGame clients