What you are talking about is matchmaking servers. It can add them to a queue based on any number of search criteria. When a match is found the matched players get an IP and they start joining that server. You should learn more about matchmaking and perhaps buy an existing matchmaking service.