Search Unity

[$25 Bounty] Using the NetworkLobbyManager component, how do I create/list matches?

Discussion in 'Multiplayer' started by MrLucid72, Dec 5, 2016.

  1. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    988
    EDIT: RESOLVED! ..by myself :p ...by something stupid:


    ___________________________________________

    The Question: How come I never get a list of games returned for MatchMaking (in the lobby)?


    $25 PayPal (or Google Wallet) bounty for an answer (Unity devs, too)! Must use the new-ish NetworkLobbyManager component/class
    . For the $25, I must test working. Best working answer wins.
    ___________________________________________

    TL;DR flow:
    1. Click a btn, start matchmaking. // StartMatchMaker appears to have sync issues?
    2. List matches
    3. No match? Create a game.
    4. Match? Join a game.
    ___________________________________________

    What happens when I test:

    1. "A" launches game and clicks MMBtn.
    2. "A" match list found no matches, so created a game.
    3. "B" launches game and clicks MMBtn.
    4. "B" match list found no matches, so created a game // Should have found 1 match
      * Both are awkwardly waiting, when B SHOULD have joined A's game).
      * Both hosts have the same networkId, hinting sync/instance issues.
    ___________________________________________

    Code flow (apologies for typos, not copy+pasting for simplicity):

    Code (CSharp):
    1. public class myLobbyScript : NetworkLobbyManager {
    2. [SerializeField] NetworkLobbyManager lobbyMgr
    3. ...
    4.  
    5. // ........................................................
    6. void calledFromBtnClick()
    7. {
    8.     lobbyMgr.StartMatchMaker();
    9.     lobbyMgr.matchMaker.ListMatches(0, 20, "", true, 0, 0, OnMatchList);
    10.     // Issue starts @ callback above?
    11. }
    12.  
    13. // ........................................................
    14. public override void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matchList)
    15. {
    16.     If (matchList.Count <= 0) // No match found, create match (ALWAYS 0 matches)
    17.     {
    18.         lobbyMgr.matchMaker.CreateMatch(
    19.             "MM", 15, true, "", Network.player.externalIP, Network.player.ipAddress,
    20.             0, 1, OnMatchCreate);
    21.     }
    22.     else
    23.     {
    24.         // Match found, join match
    25.         MatchInfoSnapshot firstMatchFound = matchList[0];
    26.         lobbyMgr.matchMaker.JoinMatch(
    27.             firstMatchFound.networkId, "", Network.player.externalIP,
    28.             Network.player.ipAddress, 0, 0);
    29.     }
    30. }
    31.  
    32. // ........................................................
    33. public override void OnMatchCreate(bool success, string extendedInfo, MatchInfo matchInfo)
    34. {
    35.     Debug.Log("@ OnMatchCreate");
    36. }
    37.  
    38. // ........................................................
    39. public override void OnMatchJoined(bool success, string extendedInfo, MatchInfo matchInfo)
    40. {
    41.     Debug.Log("@ OnMatchJoined");
    42. }
    ___________________________________________

    NOTES:

    1. The script attached to the NetworkLobbyManager component's parent gameObj is called myLobbyMgr and is derived from NetworkLobbyManager (I tried Mono, and can do everything by lobbyMgr.Whatever EXCEPT for overrides. However, when I override, it seems to make things out-of-sync.
    2. Found this bitbucket with obsolete code, but a hint, nonetheless.
    3. My Unity Answers post is here with more info than you probably want (trial+err results)
    4. Ultimately, I feel that the issue is caused with the callbacks. The docs (AND the bitbucket src for the NetworkGUI), although old, put the callback param as lobbyMgr.OnMatchList - however, there is NO WAY (that I know of) to actually catch that specific instance: it doesn't seem to be sync'd with the standard override from the NetworkLobbyManager class, but only with the object instance (lobbyMgr) itself. So how do I ultimately do the following, but without a syntax err:

      Code (csharp):
      1. // Syntax Err
      2. public override void lobbyMgr.OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matchList){}
    5. 12/16: When I created a match and request the access token, it's the SAME token on both hosts -- what does this mean? I thought the token is based off the match, not just me? Does this mean 2 players created an identical match? Something is not sync'ing here.
    6. 12/16: The extremely outdated Network Lobby demo matchmaking isn't working for me, after following the instructions: The list is always empty! Can anyone else test this?
    7. 12/16: Notable find - when I create a match on both PC "A" and PC "B", both the match.networkId are identical. Is this normal?
    8. 12/16: When a game is CREATED, all the matchInfo is there like it should be. When I attempt to LIST the matches, I'm always returned an empty (not null, but count == 0) list, even when a game is hosted on another PC.
    9. 12/16: Our senior dev also took a look at this and suspects the issues start at StartMatchMaker(), that does't seem to be sync'd with where it's supposed to. Not 100% sure, just a suspicion.
    10. 12/16: The NetworkManager class singleton (NetworkManager.singleton) is supposed to trigger as soon as anything on the network is happening. However, when I call the NetworkManager.singleton.GetInstanceID, it's null. Perhaps this is where the out-of-sync action occurs. Not sure, but worth noting.
    11. 12/16: Both lobbyMgr.matchMaker.instanceId && NetworkManager.singleton.instanceId MATCH! Maybe it's something else...
     
    Last edited: Dec 6, 2016
  2. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    988
  3. TheWesselGames

    TheWesselGames

    Joined:
    Aug 31, 2016
    Posts:
    31
    I had the same problem yesterday, after a little bit for trying I wrote this, it works perfectly for me.


    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using System;
    6. using System.ComponentModel;
    7. using UnityEngine.Networking.Match;
    8. using UnityEngine.Networking;
    9.     [RequireComponent(typeof(NetworkManager))]
    10.     [EditorBrowsable(EditorBrowsableState.Never)]
    11.     public class UIMANAGER : MonoBehaviour
    12.     {
    13.         public NetworkManager manager;
    14.         NetworkMatch matchMaker;
    15.         bool search;
    16.         public static bool lan;
    17.    
    18.         // Use this for initialization
    19.         void Start()
    20.         {
    21.             manager = GetComponent<NetworkManager>();
    22.             matchMaker = gameObject.AddComponent<NetworkMatch>();
    23.         }
    24.  
    25.     public void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matches)
    26.  
    27.         {
    28.             if (success && matches.Count > 0)
    29.             {
    30.              
    31.                 matchMaker.JoinMatch(matches[0].networkId, "", "", "", 0, 0, manager.OnMatchJoined);
    32.             } else
    33.             {
    34.                 matchMaker.CreateMatch(manager.matchName, 2, true, "", "", "", 0, 0, manager.OnMatchCreate);
    35.                
    36.             }
    37.         }
    38.  
    39.         public void startmultiplayer()
    40.         {
    41.             manager.StartMatchMaker();
    42.             matchMaker.ListMatches(0, 20, "", false, 0, 0, OnMatchList);
    43.             search = true;
    44.      
    45.    
    46.  
    47.         }
    48.         public void startsingeplayer()
    49.         {
    50.             manager.StartHost();
    51.          lan = true;
    52.          
    53.         }
    54.  
    55.     }
    56.  
    57.  
    With startmultiplayer being called when pressing the multiplayer button.'

    Startsingleplayer hosts a lan-game.
     
    MrLucid72 likes this.
  4. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    988
    That's for the Unity sample project, right? Good catch ~

    Did you ever happen to write a script using the 5.4+ NetworkLobbyManager class? If you got one working that you'd like to share, I'll give you $25 :) my template is above in the original post, there has to be something small I'm missing (unless it's bugged, which has become a possibility)~

    The NetworkLobbyManager, in a nutshell, derives from NetworkBehaviour but includes EVERYTHING all in 1 place -- lobbyPlayer, gamePlayer, match list, match info, and uses the new callback system for lobby events like `OnMatchList(p1, p2, p3)`
     
    Last edited: Dec 6, 2016
  5. TheWesselGames

    TheWesselGames

    Joined:
    Aug 31, 2016
    Posts:
    31
    Uh it isn't from any tutorial and there is basically one thing you need to chance in your template. Create a new matchmaker component and use that tot list your matches. Just like I did in my script. I'm mobile now so atm I can't rewrite tour template. Will do tonight.
     
  6. MrLucid72

    MrLucid72

    Joined:
    Jan 12, 2016
    Posts:
    988
    I figured it out. And it was something unbelievably stupid. So easy to miss, and it was even in my code above. Check this out (I almost don't want to show you because it's quite shameful):



    /facepalm

    Well, this is still the most complete 5.4+ lobby guide i've ever seen. I'll make a cleaner one and post later once more things are working.