Search Unity

Matchmaker matches not received

Discussion in 'Multiplayer' started by IchBinJager, May 13, 2016.

  1. IchBinJager

    IchBinJager

    Joined:
    Dec 23, 2014
    Posts:
    127
    upload_2016-5-13_17-21-41.png

    Hey. For some reason when I host a game, the match isn't sent to other people though I can see my own match when I host a game and launch another instance of the game and check the server list.

    When I have another person host, I don't see the button for their match being made. I also added a Debug.LogError for if another match is found at least, but when they host and I look for them I don't get so I know it's not a matter of the button being made and not visible.

    What am I doing wrong? I know I have it connected in the services window.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.SceneManagement;
    4. using UnityEngine.Networking;
    5. using UnityEngine.Networking.Match;
    6. using UnityEngine.Networking.Types;
    7.  
    8. public class NetCtrl: NetworkLobbyManager
    9. {
    10.    
    11.     NetworkMatch this_match;
    12.    
    13.     public GameObject Lobby_Screen, Match_L_Screen;
    14.    
    15.     public GameObject Match_Disp_Button; // The button prefab for a listed match.
    16.    
    17.     public InputField InputBar;
    18.    
    19.     void Start()
    20.     {
    21.         this_match = gameObject.AddComponent<NetworkMatch>();
    22.     }
    23.    
    24.    
    25.     public void Quit_Game()
    26.     {
    27.         Application.Quit();
    28.     }
    29.    
    30.    
    31.     public void Refresh_Servers( )
    32.     {
    33.        
    34.         Clear_Server_List();
    35.         Update_Match_List();
    36.     }
    37.    
    38.     void Update_Match_List()
    39.     {
    40.         this_match.ListMatches(0, 20, "", OnMatchList);
    41.     }
    42.    
    43.    
    44.    
    45.     public void Host_New()
    46.     {
    47.         CreateMatchRequest new_room = new CreateMatchRequest();
    48.         new_room.name = PlayerPrefs.GetString("Soldier Name") + "'s game";
    49.         new_room.size = 4;
    50.         new_room.advertise = true;
    51.         new_room.password = "";
    52.        
    53.        
    54.        
    55.        
    56.         this_match.CreateMatch(new_room, OnMatchCreate );
    57.         StartHost();
    58.     }
    59.    
    60.    
    61.    
    62.    
    63.     void Clear_Server_List()
    64.     {
    65.         Transform new_g_Button = GameObject.Find("New Game").transform;
    66.    
    67.         for ( int toRemove = 0; toRemove < new_g_Button.transform.childCount - 1; toRemove ++ )
    68.         {
    69.             Destroy ( new_g_Button.GetChild(toRemove + 1).gameObject );
    70.         }
    71.     }
    72.    
    73.    
    74.    
    75.    
    76.     void OnMatchCreate( CreateMatchResponse matchMakeReply )
    77.     {
    78.         if ( matchMakeReply.success )
    79.         {
    80.             Utility.SetAccessTokenForNetwork( matchMakeReply.networkId, new NetworkAccessToken(matchMakeReply.accessTokenString) );
    81.             NetworkServer.Listen ( new MatchInfo(matchMakeReply), 27015 );
    82.             Toggle_Lobby_Screen();
    83.         }
    84.     }
    85.    
    86.     void OnMatchList( ListMatchResponse matchListReply )
    87.     {
    88.         float offset = 0;
    89.        
    90.         foreach ( MatchDesc Sent_Match in matchListReply.matches )
    91.         {
    92.             Debug.LogError("We found a match!");
    93.             Debug.LogError("They're name is: " + Sent_Match.name );
    94.             offset += 30;
    95.             GameObject this_matchB = Instantiate ( Match_Disp_Button );
    96.             this_matchB.transform.parent = GameObject.Find("New Game").transform;
    97.             this_matchB.transform.localPosition = Vector3.zero;
    98.             this_matchB.GetComponent<RectTransform>().anchoredPosition = Vector3.zero + new Vector3(0, -offset, 0);
    99.             this_matchB.GetComponent<Displayed_Match_Btn>().listed_match_ID = Sent_Match.networkId;
    100.             this_matchB.GetComponentInChildren<Text>().text = Sent_Match.name;
    101.         }
    102.     }
    103.    
    104.     void OnMatchJoined( JoinMatchResponse matchJoin )
    105.     {
    106.         if ( !matchJoin.success )
    107.         {
    108.             return;
    109.         }
    110.         else
    111.         {
    112.             Toggle_Lobby_Screen();
    113.         }
    114.     }
    115.    
    116.     public void Join ( NetworkID toJoinID )
    117.     {
    118.         this_match.JoinMatch ( toJoinID, "", OnMatchJoined );
    119.     }
    120.    
    121.     void Toggle_Lobby_Screen()
    122.     {
    123.         Lobby_Screen.SetActive(true); Match_L_Screen.SetActive(false);
    124.     }
    125.    
    126.    
    127.     public void Update_Online_Name()
    128.     {
    129.         GameObject.Find("Current Online Name").GetComponent<Text>().text = PlayerPrefs.GetString("Soldier Name","Carlos Hathcock");
    130.     }
    131.    
    132.     public void Change_Online_Name( string new_name )
    133.     {
    134.         string written_name = GameObject.Find("New Name Txt").GetComponent<Text>().text;
    135.         PlayerPrefs.SetString("Soldier Name", written_name);
    136.     }
    137.    
    138.     public void To_Multiplayer()
    139.     {
    140.         Update_Online_Name();
    141.         Refresh_Servers();
    142.     }
    143.    
    144.     /*
    145.    
    146.    
    147.     Things for when actually in the lobby.
    148.    
    149.    
    150.     */
    151.    
    152.     public void Ply_Toggle_Ready()
    153.     {
    154.         foreach ( GameObject LPly in GameObject.FindGameObjectsWithTag("Player") )
    155.         {
    156.             LobPly this_Ply = LPly.GetComponent<LobPly>();
    157.            
    158.             if ( this_Ply == null )
    159.             {
    160.                 continue;
    161.             }
    162.            
    163.             if ( this_Ply.isLocalPlayer )
    164.             {
    165.                 // this_LPly.Toggle_Ready();
    166.             }
    167.         }
    168.     }
    169.    
    170.     public void Ready()
    171.     {
    172.         foreach ( GameObject LPlyr in GameObject.FindGameObjectsWithTag("Player") )
    173.         {
    174.             LobPly this_LPlay = LPlyr.GetComponent<LobPly>();
    175.            
    176.             if ( this_LPlay == null )
    177.             {
    178.                 continue;
    179.             }
    180.            
    181.             if ( this_LPlay.isLocalPlayer )
    182.             {
    183.                 this_LPlay.SendReadyToBeginMessage();
    184.             }
    185.         }
    186.     }
    187.    
    188.    
    189.     public void Send_Chat_Msg( string to_send )
    190.     {
    191.         foreach ( GameObject LPlyr in GameObject.FindGameObjectsWithTag("Player") )
    192.         {
    193.             LobPly this_LPlay = LPlyr.GetComponent<LobPly>();
    194.            
    195.             if ( this_LPlay == null )
    196.             {
    197.                 continue;
    198.             }
    199.            
    200.             if ( this_LPlay.isLocalPlayer )
    201.             {
    202.                 // string our_msg = GameObject.Find("Current Txt Msg").GetComponent<Text>().text;
    203.                 InputBar.text = "";
    204.                 this_LPlay.CmdSend_Chat_Msg( to_send );
    205.             }
    206.         }
    207.     }
    208.    
    209.    
    210.    
    211.    
    212.     public void Force_Start()
    213.     {
    214.         foreach ( GameObject LPly in GameObject.FindGameObjectsWithTag("Player") )
    215.         {
    216.             LobPly this_LPlay = LPly.GetComponent<LobPly>();
    217.            
    218.             if ( this_LPlay == null )
    219.             {
    220.                 continue;
    221.             }
    222.            
    223.             if ( this_LPlay.isLocalPlayer && this_LPlay.isServer ) // Host
    224.             {
    225.                 ServerChangeScene( "Debug" );
    226.             }
    227.         }
    228.     }
    229.    
    230.    
    231.    
    232.    
    233.    
    234.    
    235.    
    236.    
    237.    
    238.    
    239.     void OnLobbyServerSceneLoadedForPlayer ( GameObject LPlay, GameObject GPlay )
    240.     {
    241.    
    242.         Debug.Log("Scene has been loaded");
    243.     }
    244.    
    245.    
    246.    
    247. }