100 ] |
100 ] |
101 where |
101 where |
102 anotherTeamClan ci = teamcolor . fromJust . find (\t -> teamownerId t == ci) . teams |
102 anotherTeamClan ci = teamcolor . fromJust . find (\t -> teamownerId t == ci) . teams |
103 findTeam = find (\t -> name == teamname t) . teams |
103 findTeam = find (\t -> name == teamname t) . teams |
104 |
104 |
105 {- |
105 |
106 |
106 handleCmd_inRoom ["HH_NUM", teamName, numberStr] = do |
107 handleCmd_inRoom clID clients rooms ["HH_NUM", teamName, numberStr] |
107 cl <- thisClient |
108 | not $ isMaster client = [ProtocolError "Not room master"] |
108 others <- roomOthersChans |
109 | hhNumber < 1 || hhNumber > 8 || noSuchTeam || hhNumber > (canAddNumber + (hhnum team)) = [] |
109 r <- thisRoom |
110 | otherwise = |
110 |
111 [ModifyRoom $ modifyTeam team{hhnum = hhNumber}, |
111 let maybeTeam = findTeam r |
112 AnswerOthersInRoom ["HH_NUM", teamName, show hhNumber]] |
112 let team = fromJust maybeTeam |
113 where |
113 |
114 client = clients IntMap.! clID |
114 return $ |
115 room = rooms IntMap.! (roomID client) |
115 if not $ isMaster cl then |
116 hhNumber = fromMaybe 0 (maybeRead numberStr :: Maybe Int) |
116 [ProtocolError "Not room master"] |
117 noSuchTeam = isNothing findTeam |
117 else if hhNumber < 1 || hhNumber > 8 || isNothing maybeTeam || hhNumber > (canAddNumber r) + (hhnum team) then |
118 team = fromJust findTeam |
118 [] |
119 findTeam = find (\t -> teamName == teamname t) $ teams room |
119 else |
120 canAddNumber = 48 - (sum . map hhnum $ teams room) |
120 [ModifyRoom $ modifyTeam team{hhnum = hhNumber}, |
121 |
121 AnswerClients others ["HH_NUM", teamName, B.pack $ show hhNumber]] |
122 |
122 where |
123 handleCmd_inRoom clID clients rooms ["TEAM_COLOR", teamName, newColor] |
123 hhNumber = case B.readInt numberStr of |
124 | not $ isMaster client = [ProtocolError "Not room master"] |
124 Just (i, t) | B.null t -> fromIntegral i |
125 | noSuchTeam = [] |
125 otherwise -> 0 |
126 | otherwise = [ModifyRoom $ modifyTeam team{teamcolor = newColor}, |
126 findTeam = find (\t -> teamName == teamname t) . teams |
127 AnswerOthersInRoom ["TEAM_COLOR", teamName, newColor], |
127 canAddNumber = (-) 48 . sum . map hhnum . teams |
|
128 |
|
129 |
|
130 |
|
131 handleCmd_inRoom ["TEAM_COLOR", teamName, newColor] = do |
|
132 cl <- thisClient |
|
133 others <- roomOthersChans |
|
134 r <- thisRoom |
|
135 |
|
136 let maybeTeam = findTeam r |
|
137 let team = fromJust maybeTeam |
|
138 |
|
139 return $ |
|
140 if not $ isMaster cl then |
|
141 [ProtocolError "Not room master"] |
|
142 else if isNothing maybeTeam then |
|
143 [] |
|
144 else |
|
145 [ModifyRoom $ modifyTeam team{teamcolor = newColor}, |
|
146 AnswerClients others ["TEAM_COLOR", teamName, newColor], |
128 ModifyClient2 (teamownerId team) (\c -> c{clientClan = newColor})] |
147 ModifyClient2 (teamownerId team) (\c -> c{clientClan = newColor})] |
129 where |
148 where |
130 noSuchTeam = isNothing findTeam |
149 findTeam = find (\t -> teamName == teamname t) . teams |
131 team = fromJust findTeam |
150 |
132 findTeam = find (\t -> teamName == teamname t) $ teams room |
|
133 client = clients IntMap.! clID |
|
134 room = rooms IntMap.! (roomID client) |
|
135 -} |
|
136 |
151 |
137 handleCmd_inRoom ["TOGGLE_READY"] = do |
152 handleCmd_inRoom ["TOGGLE_READY"] = do |
138 cl <- thisClient |
153 cl <- thisClient |
139 chans <- roomClientsChans |
154 chans <- roomClientsChans |
140 return [ |
155 return [ |
190 [] |
205 [] |
191 where |
206 where |
192 client = clients IntMap.! clID |
207 client = clients IntMap.! clID |
193 room = rooms IntMap.! (roomID client) |
208 room = rooms IntMap.! (roomID client) |
194 answerRemovedTeams = map (\t -> AnswerThisRoom ["REMOVE_TEAM", t]) $ leftTeams room |
209 answerRemovedTeams = map (\t -> AnswerThisRoom ["REMOVE_TEAM", t]) $ leftTeams room |
195 |
210 -} |
196 |
211 |
197 handleCmd_inRoom clID clients _ ["TOGGLE_RESTRICT_JOINS"] |
212 handleCmd_inRoom ["TOGGLE_RESTRICT_JOINS"] = do |
198 | isMaster client = [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r})] |
213 cl <- thisClient |
199 | otherwise = [ProtocolError "Not room master"] |
214 return $ |
200 where |
215 if not $ isMaster cl then |
201 client = clients IntMap.! clID |
216 [ProtocolError "Not room master"] |
202 |
217 else |
203 |
218 [ModifyRoom (\r -> r{isRestrictedJoins = not $ isRestrictedJoins r})] |
204 handleCmd_inRoom clID clients _ ["TOGGLE_RESTRICT_TEAMS"] |
219 |
205 | isMaster client = [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})] |
220 |
206 | otherwise = [ProtocolError "Not room master"] |
221 handleCmd_inRoom ["TOGGLE_RESTRICT_TEAMS"] = do |
207 where |
222 cl <- thisClient |
208 client = clients IntMap.! clID |
223 return $ |
209 |
224 if not $ isMaster cl then |
|
225 [ProtocolError "Not room master"] |
|
226 else |
|
227 [ModifyRoom (\r -> r{isRestrictedTeams = not $ isRestrictedTeams r})] |
|
228 |
|
229 {- |
210 handleCmd_inRoom clID clients rooms ["KICK", kickNick] = |
230 handleCmd_inRoom clID clients rooms ["KICK", kickNick] = |
211 [KickRoomClient kickID | isMaster client && not noSuchClient && (kickID /= clID) && (roomID client == roomID kickClient)] |
231 [KickRoomClient kickID | isMaster client && not noSuchClient && (kickID /= clID) && (roomID client == roomID kickClient)] |
212 where |
232 where |
213 client = clients IntMap.! clID |
233 client = clients IntMap.! clID |
214 maybeClient = Foldable.find (\cl -> kickNick == nick cl) clients |
234 maybeClient = Foldable.find (\cl -> kickNick == nick cl) clients |