Build neccessary structures in memory on ADDTEAM message, but don't send answer yet (need to review team id concept)
authorunc0rr
Wed, 08 Oct 2008 18:38:54 +0000
changeset 1323 d166f9069c2b
parent 1322 c624b04699fb
child 1324 4b48ae1f0f53
Build neccessary structures in memory on ADDTEAM message, but don't send answer yet (need to review team id concept)
doc/Protocol.odt
netserver/HWProto.hs
Binary file doc/Protocol.odt has changed
--- 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)