gameServer/Actions.hs
changeset 2245 c011aecc95e5
parent 2172 80d34c0b9dfe
child 2337 723f1cbe2ef3
equal deleted inserted replaced
2244:853a1db1cff6 2245:c011aecc95e5
   176 
   176 
   177 processAction (clID, serverInfo, clients, rooms) (RoomAddThisClient rID) = do
   177 processAction (clID, serverInfo, clients, rooms) (RoomAddThisClient rID) = do
   178 	processAction (
   178 	processAction (
   179 		clID,
   179 		clID,
   180 		serverInfo,
   180 		serverInfo,
   181 		adjust (\cl -> cl{roomID = rID}) clID clients,
   181 		adjust (\cl -> cl{roomID = rID, teamsInGame = if rID == 0 then teamsInGame cl else 0}) clID clients,
   182 		adjust (\r -> r{playersIDs = IntSet.insert clID (playersIDs r), playersIn = (playersIn r) + 1}) rID $
   182 		adjust (\r -> r{playersIDs = IntSet.insert clID (playersIDs r), playersIn = (playersIn r) + 1}) rID $
   183 			adjust (\r -> r{playersIDs = IntSet.delete clID (playersIDs r)}) 0 rooms
   183 			adjust (\r -> r{playersIDs = IntSet.delete clID (playersIDs r)}) 0 rooms
   184 		) joinMsg
   184 		) joinMsg
   185 	where
   185 	where
   186 		client = clients ! clID
   186 		client = clients ! clID
   202 					return (clID, serverInfo, clients, rooms)
   202 					return (clID, serverInfo, clients, rooms)
   203 	
   203 	
   204 	return (
   204 	return (
   205 		clID,
   205 		clID,
   206 		serverInfo,
   206 		serverInfo,
   207 		adjust (\cl -> cl{roomID = 0, isMaster = False, isReady = False}) clID newClients,
   207 		adjust (\cl -> cl{roomID = 0, isMaster = False, isReady = False, teamsInGame = undefined}) clID newClients,
   208 		adjust (\r -> r{
   208 		adjust (\r -> r{
   209 				playersIDs = IntSet.delete clID (playersIDs r),
   209 				playersIDs = IntSet.delete clID (playersIDs r),
   210 				playersIn = (playersIn r) - 1,
   210 				playersIn = (playersIn r) - 1,
   211 				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
   211 				readyPlayers = if isReady client then (readyPlayers r) - 1 else readyPlayers r
   212 				}) rID $
   212 				}) rID $
   242 processAction (clID, serverInfo, clients, rooms) (RemoveRoom) = do
   242 processAction (clID, serverInfo, clients, rooms) (RemoveRoom) = do
   243 	processAction (clID, serverInfo, clients, rooms) $ AnswerLobby ["ROOM", "DEL", name room]
   243 	processAction (clID, serverInfo, clients, rooms) $ AnswerLobby ["ROOM", "DEL", name room]
   244 	processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["ROOMABANDONED", name room]
   244 	processAction (clID, serverInfo, clients, rooms) $ AnswerOthersInRoom ["ROOMABANDONED", name room]
   245 	return (clID,
   245 	return (clID,
   246 		serverInfo,
   246 		serverInfo,
   247 		Data.IntMap.map (\cl -> if roomID cl == rID then cl{roomID = 0, isMaster = False, isReady = False} else cl) clients,
   247 		Data.IntMap.map (\cl -> if roomID cl == rID then cl{roomID = 0, isMaster = False, isReady = False, teamsInGame = undefined} else cl) clients,
   248 		delete rID $ adjust (\r -> r{playersIDs = IntSet.union (playersIDs room) (playersIDs r)}) 0 rooms
   248 		delete rID $ adjust (\r -> r{playersIDs = IntSet.union (playersIDs room) (playersIDs r)}) 0 rooms
   249 		)
   249 		)
   250 	where
   250 	where
   251 		room = rooms ! rID
   251 		room = rooms ! rID
   252 		rID = roomID client
   252 		rID = roomID client