6

I am looking to design a system where a player can

  1. Run the game, hit a button to enter the arena, which will send his IP Address/player profile/network stats up to the server.

  2. The matchmaking/lobby server will maintain a collection of all available players. It will continuously look for pairs of players that are a "match" (algorithm not important right now).

  3. When it finds two queued players that are a "match", based on the player profile data it will pick one of the players as the server and will then notify the game clients that a match has been found. Based on the notification the client receives, the client who was selected as the server will launch a server and the other player's client will connect to that initialized server when it's ready.

What is a good way to set this up? My first thought was to send the player stats up via an HTTP POST. But it could be minutes in some cases before the server finds a match and responds with what type of connection the player will have and who their opponent will be. Would HTTP be appropriate for this? Or should this be a lower level customized socket based approach? Or am I completely off here?

P.S The game is a being developed in Unity. I'd prefer answers that weren't just, "here's a link to a plugin that works" as I'm interested in understanding the architecture behind how this is typically implemented.

Any guidance would be appreciated.

mbradber
  • 489
  • 5
  • 17
  • Are you only looking for suggestions for the lobby? Do you have you ingame network architecture thought out? I'd imagine the easiest thing would be to use the same for both. – Steven Mills Mar 04 '14 at 09:22
  • I'm using Unity's customized UDP based networking system for in game networking. That wouldn't work very well for a matchmaking server which I'm thinking should be based on some TCP technology. The in game networking it fine, I'm just looking for a good way to setup this "enter arena" based matchmaking system, where all the user has to do is enter and they will be matched with another player. – mbradber Mar 04 '14 at 18:01
  • Unity has some match-making stuff built-in. Whether it's based on TCP or UDP is irrelevant, since Unity supports reliable-UDP. – BlueRaja - Danny Pflughoeft Mar 07 '14 at 16:59

1 Answers1

6

I've done quite a bit of work with these types of systems. If I was you, I would already have a http end point setup to handle situations like this. In game http post/get is a terrible idea, but in user interface it's really not bad. You could poll every 5 seconds, or have the server tell the client when to ask again.

You could also use UDP and send pings back and forth to determine if a client is connected instead of falling into the TCP well with timmy(It feels so safe, but don't let that hair fool you). The nice thing about this is the overhead is way less than http post/gets, the down side is fragmentation and order(of course if you have a proper state machine going the order isn't going to matter much).

So, taking all that into consideration, here are my suggestions using http(the same could be applied using udp with a few tweaks, but I'll go with http because then I don't have to get into the fragmentation stuff).

Set up and IIS server with a hosted {insert framework here (WCF, WebAPI, aspx pages, php even)}.

To make life easier, create a wrapper class with every possible api call you need.

I would imagine the calls you'd want would be something like this(-> Means to the server, <- is the http response from a get/post).

  • 1 -> Hello (player data. This is an initial arena handshake)
  • 1 R.1. <- Welcome (If the server likes the player, this tells them they're accepted)
  • 1 R.2. <- Error (This player was banned for lude behavior, no games for you)
  • 2 -> FindMatch (Matchmaking starts looking as soon as they say 'Hello', this is asking the server if it found anything yet. You can also bundle in stats like 'Expected Wait Time' etc. This acts as a ping to check if the client is still alive. The response to this will act as a ping to the user to tell them they're still connected to the server. You could implement a separate 'ping' call as well, it's really up to you)
  • 2 R.1 <- NothingYet (We found nothing, chill out and wait)
  • 2 R.2 <- GotOne (We found a match. You would tell the client if they should start up a server or connect at this point.)
  • 3 -> Leave (Wave goodbye to matchmaking)

Hopefully this helps. Also like I said, you could accomplish the same with UDP. I really wouldn't go into TCP though(from experience).

Kelly Elton
  • 4,373
  • 10
  • 53
  • 97
  • For the above solution, after a player has sent an HTTP request to "FindMatch", how will the server continue to pass updates back to the client such as "GotOne(We found a match)"? This wouldn't be done through an HTTP response would it? Because finding a match could take minutes. Should the server maintain a socket connection with the client to send these updates or stick to pure HTTP polling from the client? – mbradber Mar 07 '14 at 18:21
  • No no, the client would keep calling FindMatch on certain intervals. If a match is found, the response of FindMatch would tell the client, and it would react accordingly. – Kelly Elton Mar 07 '14 at 18:22
  • Having potentially thousands of players polling the matchmaking server with HTTP requests every few seconds is an accepted practice? Wouldn't it be more efficient to just have a socket connection open for them to communicate 2-way freely? – mbradber Mar 07 '14 at 18:25
  • There is no reason you can't do the same thing with UDP that I mentioned above. You don't need an open TCP connection for this. Also, if you get too many requests, dial it back. No on ever said matchmaking had to be sub second. 5, 10 15, 60 seconds are all acceptable. Hell some games take a few minutes to match you up, and realistically, the networking aside, it may take longer than that to find an acceptable match. – Kelly Elton Mar 07 '14 at 18:30
  • I forget the exact phrase, but you shouldn't be optimizing something and potentially making it more complicated than it needs to be at this stage, I assume you may not even know the volume of people you'll receive. – Kelly Elton Mar 07 '14 at 18:32
  • 1
    Also as a last thing here, if you abstract properly, you should be able to swap between UDP and http if it becomes a problem.(Sorry about the back to back messages, this is the last one for now) – Kelly Elton Mar 07 '14 at 18:33