25 import qualified Data.ByteString.Char8 as B |
25 import qualified Data.ByteString.Char8 as B |
26 import Control.Monad |
26 import Control.Monad |
27 import Control.Monad.Reader |
27 import Control.Monad.Reader |
28 -------------------------------------- |
28 -------------------------------------- |
29 import CoreTypes |
29 import CoreTypes |
|
30 import Consts |
30 import Utils |
31 import Utils |
31 import HandlerUtils |
32 import HandlerUtils |
32 import RoomsAndClients |
33 import RoomsAndClients |
33 import EngineInteraction |
34 import EngineInteraction |
34 import Votes |
35 import Votes |
142 AnswerClients othChans $ teamToNet $ newTeam, |
143 AnswerClients othChans $ teamToNet $ newTeam, |
143 AnswerClients roomChans ["TEAM_COLOR", tName, teamColor], |
144 AnswerClients roomChans ["TEAM_COLOR", tName, teamColor], |
144 AnswerClients roomChans ["HH_NUM", tName, showB $ hhnum newTeam] |
145 AnswerClients roomChans ["HH_NUM", tName, showB $ hhnum newTeam] |
145 ] |
146 ] |
146 where |
147 where |
147 canAddNumber rt = (48::Int) - (sum $ map hhnum rt) |
148 canAddNumber rt = (cMaxHHs) - (sum $ map hhnum rt) |
148 findTeam = find (\t -> tName == teamname t) . teams |
149 findTeam = find (\t -> tName == teamname t) . teams |
149 dif = readInt_ difStr |
150 dif = readInt_ difStr |
150 hhsList [] = [] |
151 hhsList [] = [] |
151 hhsList [_] = error "Hedgehogs list with odd elements number" |
152 hhsList [_] = error "Hedgehogs list with odd elements number" |
152 hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs |
153 hhsList (n:h:hhs) = HedgehogInfo n h : hhsList hhs |
153 newTeamHHNum rt p = min p (canAddNumber rt) |
154 newTeamHHNum rt p = min p (canAddNumber rt) |
154 maxTeams r |
155 maxTeams r |
155 | roomProto r < 38 = 6 |
156 | roomProto r < 38 = 6 |
156 | otherwise = 8 |
157 | otherwise = cMaxTeams |
157 |
158 |
158 |
159 |
159 handleCmd_inRoom ["REMOVE_TEAM", tName] = do |
160 handleCmd_inRoom ["REMOVE_TEAM", tName] = do |
160 (ci, _) <- ask |
161 (ci, _) <- ask |
161 r <- thisRoom |
162 r <- thisRoom |
194 return $ |
195 return $ |
195 if not $ isMaster cl then |
196 if not $ isMaster cl then |
196 [ProtocolError $ loc "You're not the room master!"] |
197 [ProtocolError $ loc "You're not the room master!"] |
197 else if isNothing maybeTeam then |
198 else if isNothing maybeTeam then |
198 [] |
199 [] |
199 else if hhNumber < 1 || hhNumber > 8 || hhNumber > canAddNumber r + hhnum team then |
200 else if hhNumber < 1 || hhNumber > cHogsPerTeam || hhNumber > canAddNumber r + hhnum team then |
200 [AnswerClients clChan ["HH_NUM", teamName, showB $ hhnum team]] |
201 [AnswerClients clChan ["HH_NUM", teamName, showB $ hhnum team]] |
201 else |
202 else |
202 [ModifyRoom $ modifyTeam team{hhnum = hhNumber}, |
203 [ModifyRoom $ modifyTeam team{hhnum = hhNumber}, |
203 AnswerClients others ["HH_NUM", teamName, showB hhNumber]] |
204 AnswerClients others ["HH_NUM", teamName, showB hhNumber]] |
204 where |
205 where |
205 hhNumber = readInt_ numberStr |
206 hhNumber = readInt_ numberStr |
206 findTeam = find (\t -> teamName == teamname t) . teams |
207 findTeam = find (\t -> teamName == teamname t) . teams |
207 canAddNumber = (-) 48 . sum . map hhnum . teams |
208 canAddNumber = (-) cMaxHHs . sum . map hhnum . teams |
208 |
209 |
209 |
210 |
210 |
211 |
211 handleCmd_inRoom ["TEAM_COLOR", teamName, newColor] = do |
212 handleCmd_inRoom ["TEAM_COLOR", teamName, newColor] = do |
212 cl <- thisClient |
213 cl <- thisClient |
391 |
392 |
392 |
393 |
393 handleCmd_inRoom ["MAXTEAMS", n] = roomAdminOnly $ do |
394 handleCmd_inRoom ["MAXTEAMS", n] = roomAdminOnly $ do |
394 cl <- thisClient |
395 cl <- thisClient |
395 let m = readInt_ n |
396 let m = readInt_ n |
396 if m < 2 || m > 8 then |
397 if m < 2 || m > cMaxTeams then |
397 return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/maxteams: specify number from 2 to 8"]] |
398 return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/maxteams: specify number from 2 to 8"]] |
398 else |
399 else |
399 return [ModifyRoom (\r -> r{teamsNumberLimit = m})] |
400 return [ModifyRoom (\r -> r{teamsNumberLimit = m})] |
400 |
401 |
401 handleCmd_inRoom ["FIX"] = serverAdminOnly $ |
402 handleCmd_inRoom ["FIX"] = serverAdminOnly $ |
474 |
475 |
475 handleCmd_inRoom ["CALLVOTE", "HEDGEHOGS", hhs] = do |
476 handleCmd_inRoom ["CALLVOTE", "HEDGEHOGS", hhs] = do |
476 cl <- thisClient |
477 cl <- thisClient |
477 let h = readInt_ hhs |
478 let h = readInt_ hhs |
478 |
479 |
479 if h > 0 && h <= 8 then |
480 if h > 0 && h <= cHogsPerTeam then |
480 startVote $ VoteHedgehogsPerTeam h |
481 startVote $ VoteHedgehogsPerTeam h |
481 else |
482 else |
482 return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote hedgehogs: Specify number from 1 to 8."]] |
483 return [AnswerClients [sendChan cl] ["CHAT", "[server]", loc "/callvote hedgehogs: Specify number from 1 to 8."]] |
483 |
484 |
484 |
485 |