gameServer/Actions.hs
changeset 1929 7e6cc8da1c58
parent 1928 9bf8f4f30d6b
child 1930 e71c24f11483
equal deleted inserted replaced
1928:9bf8f4f30d6b 1929:7e6cc8da1c58
   109 	writeChan (sendChan $ clients ! clID) ["WARNING", msg]
   109 	writeChan (sendChan $ clients ! clID) ["WARNING", msg]
   110 	return (clID, serverInfo, clients, rooms)
   110 	return (clID, serverInfo, clients, rooms)
   111 
   111 
   112 
   112 
   113 processAction (clID, serverInfo, clients, rooms) (ByeClient msg) = do
   113 processAction (clID, serverInfo, clients, rooms) (ByeClient msg) = do
   114 	mapM_ (processAction (clID, serverInfo, clients, rooms)) $ answerOthersQuit ++ answerInformRoom
   114 	(_, _, newClients, newRooms) <-
       
   115 			processAction  (clID, serverInfo, clients, rooms)
       
   116 					(if isMaster client then RemoveRoom else RemoveClientTeams clID)
       
   117 
       
   118 	mapM_ (processAction (clID, serverInfo, newClients, newRooms)) $ answerOthersQuit ++ answerInformRoom
   115 	writeChan (sendChan $ clients ! clID) ["BYE", msg]
   119 	writeChan (sendChan $ clients ! clID) ["BYE", msg]
   116 	return (
   120 	return (
   117 			0,
   121 			0,
   118 			serverInfo,
   122 			serverInfo,
   119 			delete clID clients,
   123 			delete clID newClients,
   120 			adjust (\r -> r{
   124 			adjust (\r -> r{
   121 					playersIDs = IntSet.delete clID (playersIDs r),
   125 					playersIDs = IntSet.delete clID (playersIDs r),
   122 					playersIn = (playersIn r) - 1,
   126 					playersIn = (playersIn r) - 1,
   123 					readyPlayers = if isReady client then readyPlayers r - 1 else readyPlayers r
   127 					readyPlayers = if isReady client then readyPlayers r - 1 else readyPlayers r
   124 					}) rID rooms
   128 					}) rID newRooms
   125 			)
   129 			)
   126 	where
   130 	where
   127 		client = clients ! clID
   131 		client = clients ! clID
   128 		rID = roomID client
   132 		rID = roomID client
   129 		clientNick = nick client
   133 		clientNick = nick client
   178 processAction (clID, serverInfo, clients, rooms) (RoomRemoveThisClient) = do
   182 processAction (clID, serverInfo, clients, rooms) (RoomRemoveThisClient) = do
   179 	when (rID /= 0) $ (processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["LEFT", nick client, "part"]) >> return ()
   183 	when (rID /= 0) $ (processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["LEFT", nick client, "part"]) >> return ()
   180 	return (
   184 	return (
   181 		clID,
   185 		clID,
   182 		serverInfo,
   186 		serverInfo,
   183 		adjust (\cl -> cl{roomID = 0}) clID clients,
   187 		adjust (\cl -> cl{roomID = 0, isMaster = False, isReady = False}) clID clients,
   184 		adjust (\r -> r{
   188 		adjust (\r -> r{
   185 				playersIDs = IntSet.delete clID (playersIDs r),
   189 				playersIDs = IntSet.delete clID (playersIDs r),
   186 				playersIn = (playersIn r) - 1,
   190 				playersIn = (playersIn r) - 1,
   187 				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
   191 				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
   188 				}) rID $
   192 				}) rID $