Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Basic match making system.

Discussion in 'Multiplayer' started by MadMenyo, Jan 26, 2015.

  1. MadMenyo

    MadMenyo

    Joined:
    May 15, 2013
    Posts:
    23
    Watched a couple of tutorials on Unity networking. They all use a system where we poll the MasterServer and create some buttons dynamically for the servers that are found. I foresee a big problem with this when more players want to get in on the action.

    Players will refresh the list and before they can click on a server button the game is already full or disbanded and they receive an error. We can probably work out the error and do a new poll on the server but still, this is kinda annoying. Since my game is 1v1 running into a full game will happen a lot using this system.

    So I created a system where there is just a "PLAY" button and the system decides if a server should be created or joined. But now I'm back with a timer, searching for X seconds and when no free game is found we create one. This does work but I'd rather get rid of the timer. That is where I'm stuck.

    Since MasterServer.RequestHostList needs time to return a list is there a way to tell the difference if an empty list has been returned or none at all?

    Currently doing this:
    Code (CSharp):
    1.  
    2.         if (refreshing)
    3.         {
    4.             if (MasterServer.PollHostList().GetLength(0) > 0)
    5.             {
    6.                 Debug.Log("Game found, populating host list.");
    7.                 refreshing = false;
    8.                 Debug.Log(MasterServer.PollHostList().GetLength(0));
    9.                 hostData = MasterServer.PollHostList();
    10.             }
    11.             else if (refreshTime + refreshTimeOut < Time.time)
    12.             {
    13.                 Debug.Log("No games found, stop refreshing.");
    14.                 refreshing = false;
    15.             }
    16.         }
    So after X time has past I move on to creating a server. I would like to know immediately when the MasterServer has no servers at all or wait for it to populate.
     
  2. jwatte-imvu

    jwatte-imvu

    Joined:
    Jan 26, 2015
    Posts:
    6
    If your join rules are simple -- any player joins any game -- then the algorithm is simple. You just need one "current room" to fill, and three parameters;
    • minimum number of players to start
    • maximum number of players per room
    • minimum time to wait for more players

    Each time a new player comes in, do this:

    If there is no room, create a new room, add this one player to it, and set a timer for max-time-to-wait-for-players.
    Else, add this player to the existing room. If the existing room has max players, start the room and set current room to null, and cancel the timer.
    When the minimum timer expires, check that the minimum number of players is met. If it is, start the room and set current room to null. Else, re-start the timer.

    That's it, really! (You're going to have to worry about player drops as well, plus a few other bits and bobs, but the algorithm in this case is super simple.)

    It's when you're trying to choose the "best" host (lowest latency, fastest PC, or whatever) or when you're trying to match players by some criteria (skill level, etc) that you start having to keep a queue of many rooms and periodically rip through it, looking for games to start.
     
  3. MadMenyo

    MadMenyo

    Joined:
    May 15, 2013
    Posts:
    23
    The problem is "If there is no room". How do i quickly find this out? I need to wait for the MasterServer once I request the list. Until X time the server will return no hosts with PollHostList.

    But now i'm thinking about it, this is only a problem when there are no matches running at all. Since then the server will continue to return 0 hosts. Whenever there are matches being played on the server it will always return those and the first statement will return true as soon as possible. Then I can check if the matches are valid for the player to join if not create one.

    So this should only be a problem when my game has a low player base. Then the server will keep returning false on the first statement so in order to create the "first" game I got to have a timelimit to breakout of searching and create it. Or is there a way to know whether the server really returned no hosts so I could use that instead of X time?
     
  4. BlackPanda

    BlackPanda

    Joined:
    Jan 24, 2014
    Posts:
    78
    Thanks man! I was stuck in this problem too - How to find out whether the room was already started or not. I think I can try your logic here. It makes sense.