netserver/HWProto.hs
changeset 1325 c8994d47f41d
parent 1323 d166f9069c2b
child 1327 9d43a6e6b9ca
equal deleted inserted replaced
1324:4b48ae1f0f53 1325:c8994d47f41d
    28 answerFullConfig room = map toAnswer (Map.toList $ params room)
    28 answerFullConfig room = map toAnswer (Map.toList $ params room)
    29 	where
    29 	where
    30 		toAnswer (paramName, paramStrs) =
    30 		toAnswer (paramName, paramStrs) =
    31 			(clientOnly, "CONFIG_PARAM" : paramName : paramStrs)
    31 			(clientOnly, "CONFIG_PARAM" : paramName : paramStrs)
    32 answerCantAdd = [(clientOnly, ["WARNING", "Too many teams"])]
    32 answerCantAdd = [(clientOnly, ["WARNING", "Too many teams"])]
       
    33 answerTeamAccepted team = [(clientOnly, ["TEAM_ACCEPTED", teamname team])]
       
    34 answerAddTeam team = [(othersInRoom, ["ADD_TEAM", teamname team, teamgrave team, teamfort team, show $ difficulty team] ++ hhsInfo)]
       
    35 	where
       
    36 		hhsInfo = concatMap (\(HedgehogInfo name hat) -> [name, hat]) $ hedgehogs team
    33 
    37 
    34 -- Main state-independent cmd handler
    38 -- Main state-independent cmd handler
    35 handleCmd :: CmdHandler
    39 handleCmd :: CmdHandler
    36 handleCmd client _ rooms ("QUIT":xs) =
    40 handleCmd client _ rooms ("QUIT":xs) =
    37 	if null (room client) then
    41 	if null (room client) then
   127 handleCmd_inRoom client _ rooms ("ADDTEAM" : name : color : grave : fort : difStr : hhsInfo)
   131 handleCmd_inRoom client _ rooms ("ADDTEAM" : name : color : grave : fort : difStr : hhsInfo)
   128 	| length hhsInfo == 16 =
   132 	| length hhsInfo == 16 =
   129 	if length (teams clRoom) == 6 then
   133 	if length (teams clRoom) == 6 then
   130 		(noChangeClients, noChangeRooms, answerCantAdd)
   134 		(noChangeClients, noChangeRooms, answerCantAdd)
   131 	else
   135 	else
   132 		(noChangeClients, modifyRoom clRoom{teams = newTeam : teams clRoom}, [])
   136 		(noChangeClients, modifyRoom clRoom{teams = newTeam : teams clRoom}, answerTeamAccepted newTeam ++ answerAddTeam newTeam)
   133 	where
   137 	where
   134 		clRoom = roomByName (room client) rooms
   138 		clRoom = roomByName (room client) rooms
   135 		newTeam = (TeamInfo name color grave fort difficulty (hhsList hhsInfo))
   139 		newTeam = (TeamInfo name color grave fort difficulty (hhsList hhsInfo))
   136 		difficulty = fromMaybe 0 (maybeRead difStr :: Maybe Int)
   140 		difficulty = fromMaybe 0 (maybeRead difStr :: Maybe Int)
       
   141 		hhsList [] = []
   137 		hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs
   142 		hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs
   138 
   143 
   139 
   144 
   140 handleCmd_inRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)
   145 handleCmd_inRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)