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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to make a random matchmaking system

Discussion in 'Multiplayer' started by lostudo, Sep 10, 2016.

  1. lostudo

    lostudo

    Joined:
    Jul 25, 2013
    Posts:
    14
    This is actually a general question. I'm trying to make a random matchmaking system that two random players matches on a lobby scene and after they see each other's name and attributes, the scene changes to the game scene by the server(Serverchangescene). What is the best way to do it. I'm basically using a code like below for the matching. This works well for few users like we tested on 10 devices at the same time but we're not sure will it work for lots of CCU.
    Code (CSharp):
    1.  public void onAllMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches)
    2.     {
    3.         Debug.Log("Matches Listed");
    4.         if (matches.Count == 0)
    5.         {
    6.             lobbyManager.matchMaker.CreateMatch(arenaType + "Match" + Random.Range(100, 1000), 2, true, "", "", "", 0, 0, OnMatchCreate);
    7.         }
    8.         else
    9.         {
    10.             OpponentFinder.Instance.isJoiningToALobby = true;
    11.             lobbyManager.matchMaker.JoinMatch(matches[0].networkId, "", "", "", 0, 0, OnClientJoinedToMatch);
    12.             Debug.LogError("Joining to match: " + matches[0].name);
    13.         }
    14.     }
    Also there is a time limit for searching an opponent and when it finishes the scene returns to the previous scene. So when a client joins to a match i'm telling to the server to stop searching and also ignore the time limit. But if the client joins to the match at the very end one or two seconds, the game starts anyway but server tries to return to previous scene and some view bugs happens. I need to tell the server in the earliest way that there is a client trying to join to match so ignore time limit. I'm using OnLobbyServerConnect to warn server but it callbacks when the client fully joins to the match. I've also tried OnStartLocalPlayer but it's working almost same time with the OnLobbyServerConnect. Below is also my code for those actions. WHAT IS THE FASTEST WAY TO WARN THE SERVER WHEN A CLİENT TRYİNG TO JOİN TO THE MATCH.
    Code (CSharp):
    1.  public override void OnLobbyServerConnect(NetworkConnection conn)
    2.     {
    3.         base.OnLobbyServerConnect(conn);
    4.         if (conn.connectionId == 1)
    5.         {
    6.             Debug.LogError("A client connected to game");
    7.      
    8.             isClientConnected = true;
    9.         }
    10.     }
    11.  
    12. public override void OnStartLocalPlayer()
    13.     {
    14.         if (!isServer)
    15.         {
    16.             CmdSendClientName(VariableKeeper.Instance.playerName0);
    17.         }
    18.     }
    19.  
    20. [Command]
    21.     public void CmdSendClientName(string clientName)
    22.     {
    23.         VariableKeeper.Instance.playerName1 = clientName;
    24.         OppenentFinder.Instance.isClientJoined = true;
    25.         OppenentFinder.Instance.opponentNameText.text = clientName;
    26.         RpcSendServerName(VariableKeeper.Instance.playerName0);
    27.     }
    Thanks a lot for your suggestions.
     
  2. Narlix

    Narlix

    Joined:
    Jul 3, 2009
    Posts:
    111
    Hi, did you solve this one?
     
  3. lostudo

    lostudo

    Joined:
    Jul 25, 2013
    Posts:
    14
    It's been almost 5 months since we stopped the project but the reason we stop the projects is inconsistency of Unity Network system. I've made a custom matchmaking system that works from long distance matching that we matched from USA to Europe but sudden disconnections, timeouts and scene change problems were still there so we stopped working on it.