Unity matchmaking rooms not showing up if they have passwords

Updated on July 12, 2017 in [A] Multiplayer
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
1 on September 1, 2016

As the title describes, im following the Multiplayer Shooter game tutorials and i decided to modify a bit some scripts so you can put a password, the thing is, the button to join prefab does’nt appear if the server has a password, but if it does’nt it works normally,

Here are the modified scripts if you guys are interested:

HostGame.cs


using UnityEngine;

using UnityEngine.Networking;

using System.Collections;
public class HostGame : MonoBehaviour

{
[SerializeField]

private uint roomSize = 5;

[SerializeField]

private string roomPassword;

[SerializeField]

private string roomName;
private NetworkManager networkManager;
void Update()

{
}
void Start()

{

networkManager = NetworkManager.singleton;

if (networkManager.matchMaker == null)

{

networkManager.StartMatchMaker();

}

}
public void SetRoomName(string _name)

{

roomName = _name;

}
public void SetRoomPassword(string _password)

{

roomPassword = _password;

}
public void CreateRoom()

{
if (roomPassword == null)

{

roomPassword = "";

}

if (roomName != "" && roomName != null)

{

Debug.Log("Creating Room: " + roomName + " with room for " + roomSize + " players, with the password: " + roomPassword);

networkManager.matchMaker.CreateMatch(roomName, roomSize, true, roomPassword, "", "", 0, 0, networkManager.OnMatchCreate);

// networkManager.matchMaker.CreateMatch(roomName, roomSize, true, "", "", "", 0, 0, networkManager.OnMatchCreate);

}

}
}

JoinGame.cs


using UnityEngine;

using UnityEngine.UI;

using System.Collections.Generic;

using UnityEngine.Networking;

using UnityEngine.Networking.Match;
public class JoinGame : MonoBehaviour

{
List<GameObject> roomList = new List<GameObject>();
[SerializeField]

private Text status;
[SerializeField]

private GameObject roomListItemPrefab;
[SerializeField]

private Transform roomListParent;

[SerializeField]

private string roomPassword;

private NetworkManager networkManager;
void Start()

{

networkManager = NetworkManager.singleton;

if (networkManager.matchMaker == null)

{

networkManager.StartMatchMaker();

}
RefreshRoomList();

}
public void RefreshRoomList()

{

ClearRoomList();

networkManager.matchMaker.ListMatches(0, 20, "", true, 0, 0, OnMatchList);

status.text = "Getting room list...";

}
public void OnMatchList(bool success, string extendedInfo, List<MatchInfoSnapshot> matchList)

{

status.text = "";
if (!success || matchList == null)

{

status.text = "Couldn't get room list.";

return;

}
foreach (MatchInfoSnapshot match in matchList)

{

GameObject _roomListItemGO = Instantiate(roomListItemPrefab);

_roomListItemGO.transform.SetParent(roomListParent);
RoomListItem _roomListItem = _roomListItemGO.GetComponent<RoomListItem>();

if (_roomListItem != null)

{

_roomListItem.Setup(match, JoinRoom);

}
// as well as setting up a callback function that will join the game.
roomList.Add(_roomListItemGO);

}
if (roomList.Count == 0)

{

status.text = "No rooms at the moment.";

}

}
void ClearRoomList()

{

for (int i = 0; i < roomList.Count; i++)

{

Destroy(roomList[i]);

}
roomList.Clear();

}
public void SetRoomPassword(string _password)

{

roomPassword = _password;

}
public void JoinRoom(MatchInfoSnapshot _match)

{
if (roomPassword == null)

{

roomPassword = "";

}

networkManager.matchMaker.JoinMatch(_match.networkId, roomPassword, "", "", 0, 0, networkManager.OnMatchJoined);

ClearRoomList();

status.text = "JOINING...";

}
}

  • Liked by
Reply
0 on July 12, 2017

In line 51, using the ListMatches function

(networkManager.matchMaker.ListMatches(0, 20, “”, true, 0, 0, OnMatchList);)

change the true value for a false. true means IGNORE MATCHES WITH PASSWORD

  • Liked by
Reply
Cancel