netserver/HWProto.hs
changeset 1323 d166f9069c2b
parent 1322 c624b04699fb
child 1325 c8994d47f41d
equal deleted inserted replaced
1322:c624b04699fb 1323:d166f9069c2b
    27 answerConfigParam paramName paramStrs = [(othersInRoom, "CONFIG_PARAM" : paramName : paramStrs)]
    27 answerConfigParam paramName paramStrs = [(othersInRoom, "CONFIG_PARAM" : paramName : paramStrs)]
    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 
    33 
    33 -- Main state-independent cmd handler
    34 -- Main state-independent cmd handler
    34 handleCmd :: CmdHandler
    35 handleCmd :: CmdHandler
    35 handleCmd client _ rooms ("QUIT":xs) =
    36 handleCmd client _ rooms ("QUIT":xs) =
    36 	if null (room client) then
    37 	if null (room client) then
   121 	else
   122 	else
   122 		(noChangeClients, noChangeRooms, answerNotMaster)
   123 		(noChangeClients, noChangeRooms, answerNotMaster)
   123 	where
   124 	where
   124 		clRoom = roomByName (room client) rooms
   125 		clRoom = roomByName (room client) rooms
   125 
   126 
   126 handleCmd_inRoom client _ _ ("ADDTEAM" : name : color : grave : fort : difStr : hhsInfo)
   127 handleCmd_inRoom client _ rooms ("ADDTEAM" : name : color : grave : fort : difStr : hhsInfo)
   127 	| length hhsInfo == 16 = (noChangeClients, noChangeRooms, answerBadCmd)
   128 	| length hhsInfo == 16 =
       
   129 	if length (teams clRoom) == 6 then
       
   130 		(noChangeClients, noChangeRooms, answerCantAdd)
       
   131 	else
       
   132 		(noChangeClients, modifyRoom clRoom{teams = newTeam : teams clRoom}, [])
       
   133 	where
       
   134 		clRoom = roomByName (room client) rooms
       
   135 		newTeam = (TeamInfo name color grave fort difficulty (hhsList hhsInfo))
       
   136 		difficulty = fromMaybe 0 (maybeRead difStr :: Maybe Int)
       
   137 		hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs
       
   138 
   128 
   139 
   129 handleCmd_inRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)
   140 handleCmd_inRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)