Right now I am following Brackeys tutorials on fps multiplayer game and I am stuck on lobby and matchmacking phase. I would like to implement a password option for a “room”, but it seems like whenever I create a new room with password – it does not show up in the matchmaking list and can’t be joined by other clients. also I can’t understand how to check if password is correct when joining.
I am using C sharp
function CreateRoom() is used to create a room with OR without password,
using System;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class NetworkingScript: NetworkBehaviour
{
[SerializeField]
private uint roomSize;
private string roomName;
private string roomPass = "";
private NetworkManager networkManager;
public Dropdown NumofPlayers;
void Start()
{
networkManager = NetworkManager.singleton;
if (networkManager.matchMaker == null)
{
networkManager.StartMatchMaker();
}
}
public void SetRoomName (string _name)
{
roomName = _name;
}
public void SetRoomPassword(string _pass)
{
roomPass = _pass;
}
public void SetNumOfPlayers()
{
roomSize = Convert.ToUInt32(NumofPlayers.value) + 1;
Debug.Log("roomSize is set to: " + roomSize);
}
public void CreateRoom ()
{
if (roomName != "" && roomName !=null)
{
Debug.Log("Name of the game: " + roomName + "| Max players: " + roomSize + "| Room password: " + roomPass);
networkManager.matchMaker.CreateMatch(roomName, roomSize, true, roomPass, "", "", 0, 0, networkManager.OnMatchCreate);
}
}
}
Here is another script down below (in my UI option – sort of a dialog between a client who wants to join a room)
so my question is how to I modify JoinRoom() so it would check if a client inputs a correct password and alow him to join a room.
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
using UnityEngine.Networking.Match;
public class RoomlistItemSetup : MonoBehaviour
{
public delegate void JoinRoomDelegate(MatchInfoSnapshot _match);
private JoinRoomDelegate joinRoomCallback;
[SerializeField]
private Text roomNameText;
public InputField passwordText;
private MatchInfoSnapshot match;
public void Setup(MatchInfoSnapshot _match, JoinRoomDelegate _joinRoomCallback)
{
match = _match;
joinRoomCallback = _joinRoomCallback;
roomNameText.text = match.name + " (" + match.currentSize + "/" + match.maxSize + ")";
}
public void JoinRoom()
{
if(passwordText = <strong>PASSWORD FROM ROOM</strong>)
{
joinRoomCallback.Invoke(match);
}
}
}