gameServer/HWProtoInRoomState.hs
changeset 1811 1b9e33623b7e
parent 1804 4e78ad846fb6
child 1813 cfe1481e0247
equal deleted inserted replaced
1810:4059cafd1da7 1811:1b9e33623b7e
    16 handleCmd_inRoom clID clients _ ["CHAT_STRING", msg] =
    16 handleCmd_inRoom clID clients _ ["CHAT_STRING", msg] =
    17 	[AnswerOthersInRoom ["CHAT_STRING", clientNick, msg]]
    17 	[AnswerOthersInRoom ["CHAT_STRING", clientNick, msg]]
    18 	where
    18 	where
    19 		clientNick = nick $ clients IntMap.! clID
    19 		clientNick = nick $ clients IntMap.! clID
    20 
    20 
       
    21 
    21 handleCmd_inRoom clID clients _ ["PART"] =
    22 handleCmd_inRoom clID clients _ ["PART"] =
    22 	if isMaster client then
    23 	if isMaster client then
    23 		[RemoveRoom]
    24 		[RemoveRoom]
    24 	else
    25 	else
    25 		[RoomRemoveThisClient]
    26 		[RoomRemoveThisClient]
    26 	where
    27 	where
    27 		client = clients IntMap.! clID
    28 		client = clients IntMap.! clID
       
    29 
    28 
    30 
    29 handleCmd_inRoom clID clients rooms ("CFG" : paramName : paramStrs) =
    31 handleCmd_inRoom clID clients rooms ("CFG" : paramName : paramStrs) =
    30 	if isMaster client then
    32 	if isMaster client then
    31 		[ModifyRoom (\r -> r{params = Map.insert paramName paramStrs (params r)})
    33 		[ModifyRoom (\r -> r{params = Map.insert paramName paramStrs (params r)})
    32 		, AnswerOthersInRoom ("CFG" : paramName : paramStrs)]
    34 		, AnswerOthersInRoom ("CFG" : paramName : paramStrs)]
   140 
   142 
   141 
   143 
   142 handleCmd_inRoom clID clients rooms ["START_GAME"] =
   144 handleCmd_inRoom clID clients rooms ["START_GAME"] =
   143 	if isMaster client && (playersIn room == readyPlayers room) && (not $ gameinprogress room) then
   145 	if isMaster client && (playersIn room == readyPlayers room) && (not $ gameinprogress room) then
   144 		if enoughClans then
   146 		if enoughClans then
   145 			[ModifyRoom (\r -> r{gameinprogress = True, roundMsgs = empty, leftTeams = [], teamsAtStart = teams r}),
   147 			[ModifyRoom
       
   148 					(\r -> r{
       
   149 						gameinprogress = True,
       
   150 						roundMsgs = empty,
       
   151 						leftTeams = [],
       
   152 						teamsAtStart = teams r}
       
   153 					),
   146 			AnswerThisRoom ["RUN_GAME"]]
   154 			AnswerThisRoom ["RUN_GAME"]]
   147 		else
   155 		else
   148 			[Warning "Less than two clans!"]
   156 			[Warning "Less than two clans!"]
   149 	else
   157 	else
   150 		[]
   158 		[]
   152 		client = clients IntMap.! clID
   160 		client = clients IntMap.! clID
   153 		room = rooms IntMap.! (roomID client)
   161 		room = rooms IntMap.! (roomID client)
   154 		enoughClans = not $ null $ drop 1 $ group $ map teamcolor $ teams room
   162 		enoughClans = not $ null $ drop 1 $ group $ map teamcolor $ teams room
   155 
   163 
   156 
   164 
   157 handleCmd_inRoom client _ rooms ["GAMEMSG", msg] =
   165 handleCmd_inRoom _ _ rooms ["GAMEMSG", msg] =
   158 	[ModifyRoom (\r -> r{roundMsgs = roundMsgs r |> msg}),
   166 	[ModifyRoom (\r -> r{roundMsgs = roundMsgs r |> msg}),
   159 	AnswerOthersInRoom ["GAMEMSG", msg]]
   167 	AnswerOthersInRoom ["GAMEMSG", msg]]
   160 
   168 
   161 
   169 
       
   170 handleCmd_inRoom clID clients rooms ["ROUNDFINISHED"] =
       
   171 	if isMaster client then
       
   172 		[ModifyRoom
       
   173 				(\r -> r{
       
   174 					gameinprogress = False,
       
   175 					readyPlayers = 0,
       
   176 					roundMsgs = empty,
       
   177 					leftTeams = [],
       
   178 					teamsAtStart = []}
       
   179 				),
       
   180 		UnreadyRoomClients
       
   181 		] ++ answerRemovedTeams
       
   182 	else
       
   183 		[]
       
   184 	where
       
   185 		client = clients IntMap.! clID
       
   186 		room = rooms IntMap.! (roomID client)
       
   187 		answerRemovedTeams = map (\t -> AnswerThisRoom ["REMOVE_TEAM", t]) $ leftTeams room
       
   188 
       
   189 
   162 handleCmd_inRoom clID _ _ _ = [ProtocolError "Incorrect command (state: in room)"]
   190 handleCmd_inRoom clID _ _ _ = [ProtocolError "Incorrect command (state: in room)"]