netserver/HWProto.hs
changeset 1323 d166f9069c2b
parent 1322 c624b04699fb
child 1325 c8994d47f41d
--- a/netserver/HWProto.hs	Wed Oct 08 18:29:16 2008 +0000
+++ b/netserver/HWProto.hs	Wed Oct 08 18:38:54 2008 +0000
@@ -29,6 +29,7 @@
 	where
 		toAnswer (paramName, paramStrs) =
 			(clientOnly, "CONFIG_PARAM" : paramName : paramStrs)
+answerCantAdd = [(clientOnly, ["WARNING", "Too many teams"])]
 
 -- Main state-independent cmd handler
 handleCmd :: CmdHandler
@@ -123,7 +124,17 @@
 	where
 		clRoom = roomByName (room client) rooms
 
-handleCmd_inRoom client _ _ ("ADDTEAM" : name : color : grave : fort : difStr : hhsInfo)
-	| length hhsInfo == 16 = (noChangeClients, noChangeRooms, answerBadCmd)
+handleCmd_inRoom client _ rooms ("ADDTEAM" : name : color : grave : fort : difStr : hhsInfo)
+	| length hhsInfo == 16 =
+	if length (teams clRoom) == 6 then
+		(noChangeClients, noChangeRooms, answerCantAdd)
+	else
+		(noChangeClients, modifyRoom clRoom{teams = newTeam : teams clRoom}, [])
+	where
+		clRoom = roomByName (room client) rooms
+		newTeam = (TeamInfo name color grave fort difficulty (hhsList hhsInfo))
+		difficulty = fromMaybe 0 (maybeRead difStr :: Maybe Int)
+		hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs
+
 
 handleCmd_inRoom _ _ _ _ = (noChangeClients, noChangeRooms, answerBadCmd)