gameServer/HWProtoInRoomState.hs
changeset 8401 87410ae372f6
parent 8369 31033e521653
child 8403 fbc6e7602e05
equal deleted inserted replaced
8400:33ab77c0b486 8401:87410ae372f6
    25 handleCmd_inRoom ["PART"] = return [MoveToLobby "part"]
    25 handleCmd_inRoom ["PART"] = return [MoveToLobby "part"]
    26 handleCmd_inRoom ["PART", msg] = return [MoveToLobby $ "part: " `B.append` msg]
    26 handleCmd_inRoom ["PART", msg] = return [MoveToLobby $ "part: " `B.append` msg]
    27 
    27 
    28 
    28 
    29 handleCmd_inRoom ("CFG" : paramName : paramStrs)
    29 handleCmd_inRoom ("CFG" : paramName : paramStrs)
    30     | null paramStrs = return [ProtocolError "Empty config entry"]
    30     | null paramStrs = return [ProtocolError $ loc "Empty config entry"]
    31     | otherwise = do
    31     | otherwise = do
    32         chans <- roomOthersChans
    32         chans <- roomOthersChans
    33         cl <- thisClient
    33         cl <- thisClient
    34         if isMaster cl then
    34         if isMaster cl then
    35            return [
    35            return [
    36                 ModifyRoom f,
    36                 ModifyRoom f,
    37                 AnswerClients chans ("CFG" : paramName : paramStrs)]
    37                 AnswerClients chans ("CFG" : paramName : paramStrs)]
    38             else
    38             else
    39             return [ProtocolError "Not room master"]
    39             return [ProtocolError $ loc "Not room master"]
    40     where
    40     where
    41         f r = if paramName `Map.member` (mapParams r) then
    41         f r = if paramName `Map.member` (mapParams r) then
    42                 r{mapParams = Map.insert paramName (head paramStrs) (mapParams r)}
    42                 r{mapParams = Map.insert paramName (head paramStrs) (mapParams r)}
    43                 else
    43                 else
    44                 r{params = Map.insert paramName paramStrs (params r)}
    44                 r{params = Map.insert paramName paramStrs (params r)}
    45 
    45 
    46 handleCmd_inRoom ("ADD_TEAM" : tName : color : grave : fort : voicepack : flag : difStr : hhsInfo)
    46 handleCmd_inRoom ("ADD_TEAM" : tName : color : grave : fort : voicepack : flag : difStr : hhsInfo)
    47     | length hhsInfo /= 16 = return [ProtocolError "Corrupted hedgehogs info"]
    47     | length hhsInfo /= 16 = return [ProtocolError $ loc "Corrupted hedgehogs info"]
    48     | otherwise = do
    48     | otherwise = do
    49         (ci, _) <- ask
    49         (ci, _) <- ask
    50         rm <- thisRoom
    50         rm <- thisRoom
    51         clNick <- clientNick
    51         clNick <- clientNick
    52         clChan <- thisClientChans
    52         clChan <- thisClientChans
    59                 else
    59                 else
    60                 liftM (head . (L.\\) (map B.singleton ['0'..]) . map teamcolor . teams) thisRoom
    60                 liftM (head . (L.\\) (map B.singleton ['0'..]) . map teamcolor . teams) thisRoom
    61         let newTeam = clNick `seq` TeamInfo ci clNick tName teamColor grave fort voicepack flag dif (newTeamHHNum rm) (hhsList hhsInfo)
    61         let newTeam = clNick `seq` TeamInfo ci clNick tName teamColor grave fort voicepack flag dif (newTeamHHNum rm) (hhsList hhsInfo)
    62         return $
    62         return $
    63             if not . null . drop (maxTeams rm - 1) $ teams rm then
    63             if not . null . drop (maxTeams rm - 1) $ teams rm then
    64                 [Warning "too many teams"]
    64                 [Warning $ loc "too many teams"]
    65             else if canAddNumber rm <= 0 then
    65             else if canAddNumber rm <= 0 then
    66                 [Warning "too many hedgehogs"]
    66                 [Warning $ loc "too many hedgehogs"]
    67             else if isJust $ findTeam rm then
    67             else if isJust $ findTeam rm then
    68                 [Warning "There's already a team with same name in the list"]
    68                 [Warning $ loc "There's already a team with same name in the list"]
    69             else if isJust $ gameInfo rm then
    69             else if isJust $ gameInfo rm then
    70                 [Warning "round in progress"]
    70                 [Warning $ loc "round in progress"]
    71             else if isRestrictedTeams rm then
    71             else if isRestrictedTeams rm then
    72                 [Warning "restricted"]
    72                 [Warning $ loc "restricted"]
    73             else
    73             else
    74                 [ModifyRoom (\r -> r{teams = teams r ++ [newTeam]}),
    74                 [ModifyRoom (\r -> r{teams = teams r ++ [newTeam]}),
    75                 SendUpdateOnThisRoom,
    75                 SendUpdateOnThisRoom,
    76                 ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = Just teamColor}),
    76                 ModifyClient (\c -> c{teamsInGame = teamsInGame c + 1, clientClan = Just teamColor}),
    77                 AnswerClients clChan ["TEAM_ACCEPTED", tName],
    77                 AnswerClients clChan ["TEAM_ACCEPTED", tName],
    99         let maybeTeam = findTeam r
    99         let maybeTeam = findTeam r
   100         let team = fromJust maybeTeam
   100         let team = fromJust maybeTeam
   101 
   101 
   102         return $
   102         return $
   103             if isNothing $ findTeam r then
   103             if isNothing $ findTeam r then
   104                 [Warning "REMOVE_TEAM: no such team"]
   104                 [Warning $ loc "REMOVE_TEAM: no such team"]
   105             else if clNick /= teamowner team then
   105             else if clNick /= teamowner team then
   106                 [ProtocolError "Not team owner!"]
   106                 [ProtocolError $ loc "Not team owner!"]
   107             else
   107             else
   108                 [RemoveTeam tName,
   108                 [RemoveTeam tName,
   109                 ModifyClient
   109                 ModifyClient
   110                     (\c -> c{
   110                     (\c -> c{
   111                         teamsInGame = teamsInGame c - 1,
   111                         teamsInGame = teamsInGame c - 1,
   125     let maybeTeam = findTeam r
   125     let maybeTeam = findTeam r
   126     let team = fromJust maybeTeam
   126     let team = fromJust maybeTeam
   127 
   127 
   128     return $
   128     return $
   129         if not $ isMaster cl then
   129         if not $ isMaster cl then
   130             [ProtocolError "Not room master"]
   130             [ProtocolError $ loc "Not room master"]
   131         else if hhNumber < 1 || hhNumber > 8 || isNothing maybeTeam || hhNumber > canAddNumber r + hhnum team then
   131         else if hhNumber < 1 || hhNumber > 8 || isNothing maybeTeam || hhNumber > canAddNumber r + hhnum team then
   132             []
   132             []
   133         else
   133         else
   134             [ModifyRoom $ modifyTeam team{hhnum = hhNumber},
   134             [ModifyRoom $ modifyTeam team{hhnum = hhNumber},
   135             AnswerClients others ["HH_NUM", teamName, showB hhNumber]]
   135             AnswerClients others ["HH_NUM", teamName, showB hhNumber]]
   148     let maybeTeam = findTeam r
   148     let maybeTeam = findTeam r
   149     let team = fromJust maybeTeam
   149     let team = fromJust maybeTeam
   150 
   150 
   151     return $
   151     return $
   152         if not $ isMaster cl then
   152         if not $ isMaster cl then
   153             [ProtocolError "Not room master"]
   153             [ProtocolError $ loc "Not room master"]
   154         else if isNothing maybeTeam then
   154         else if isNothing maybeTeam then
   155             []
   155             []
   156         else
   156         else
   157             [ModifyRoom $ modifyTeam team{teamcolor = newColor},
   157             [ModifyRoom $ modifyTeam team{teamcolor = newColor},
   158             AnswerClients others ["TEAM_COLOR", teamName, newColor],
   158             AnswerClients others ["TEAM_COLOR", teamName, newColor],
   197                 , SendUpdateOnThisRoom
   197                 , SendUpdateOnThisRoom
   198                 , AnswerClients chans $ "CLIENT_FLAGS" : "+g" : nicks
   198                 , AnswerClients chans $ "CLIENT_FLAGS" : "+g" : nicks
   199                 , ModifyRoomClients (\c -> c{isInGame = True})
   199                 , ModifyRoomClients (\c -> c{isInGame = True})
   200                 ]
   200                 ]
   201             else
   201             else
   202             return [Warning "Less than two clans!"]
   202             return [Warning $ loc "Less than two clans!"]
   203         else
   203         else
   204         return []
   204         return []
   205     where
   205     where
   206         enoughClans = not . null . drop 1 . group . map teamcolor . teams
   206         enoughClans = not . null . drop 1 . group . map teamcolor . teams
   207 
   207 
   247 
   247 
   248 handleCmd_inRoom ["TOGGLE_RESTRICT_JOINS"] = do
   248 handleCmd_inRoom ["TOGGLE_RESTRICT_JOINS"] = do
   249     cl <- thisClient
   249     cl <- thisClient
   250     return $
   250     return $
   251         if not $ isMaster cl then
   251         if not $ isMaster cl then
   252             [ProtocolError "Not room master"]
   252             [ProtocolError $ loc "Not room master"]
   253         else
   253         else
   254             [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r})]
   254             [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r})]
   255 
   255 
   256 
   256 
   257 handleCmd_inRoom ["TOGGLE_RESTRICT_TEAMS"] = do
   257 handleCmd_inRoom ["TOGGLE_RESTRICT_TEAMS"] = do
   258     cl <- thisClient
   258     cl <- thisClient
   259     return $
   259     return $
   260         if not $ isMaster cl then
   260         if not $ isMaster cl then
   261             [ProtocolError "Not room master"]
   261             [ProtocolError $ loc "Not room master"]
   262         else
   262         else
   263             [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})]
   263             [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})]
   264 
   264 
   265 
   265 
   266 handleCmd_inRoom ["TOGGLE_REGISTERED_ONLY"] = do
   266 handleCmd_inRoom ["TOGGLE_REGISTERED_ONLY"] = do
   267     cl <- thisClient
   267     cl <- thisClient
   268     return $
   268     return $
   269         if not $ isMaster cl then
   269         if not $ isMaster cl then
   270             [ProtocolError "Not room master"]
   270             [ProtocolError $ loc "Not room master"]
   271         else
   271         else
   272             [ModifyRoom (\r -> r{isRegisteredOnly = not $ isRegisteredOnly r})]
   272             [ModifyRoom (\r -> r{isRegisteredOnly = not $ isRegisteredOnly r})]
   273 
   273 
   274 handleCmd_inRoom ["ROOM_NAME", newName] = do
   274 handleCmd_inRoom ["ROOM_NAME", newName] = do
   275     cl <- thisClient
   275     cl <- thisClient
   277     rm <- thisRoom
   277     rm <- thisRoom
   278     chans <- sameProtoChans
   278     chans <- sameProtoChans
   279 
   279 
   280     return $
   280     return $
   281         if not $ isMaster cl then
   281         if not $ isMaster cl then
   282             [ProtocolError "Not room master"]
   282             [ProtocolError $ loc "Not room master"]
   283         else
   283         else
   284         if isJust $ find (\r -> newName == name r) rs then
   284         if isJust $ find (\r -> newName == name r) rs then
   285             [Warning "Room with such name already exists"]
   285             [Warning $ loc "Room with such name already exists"]
   286         else
   286         else
   287             [ModifyRoom roomUpdate,
   287             [ModifyRoom roomUpdate,
   288             AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (nick cl) (roomUpdate rm))]
   288             AnswerClients chans ("ROOM" : "UPD" : name rm : roomInfo (nick cl) (roomUpdate rm))]
   289     where
   289     where
   290         roomUpdate r = r{name = newName}
   290         roomUpdate r = r{name = newName}