Search Unity

Unet (room with password) how to get password + room visibility in matchmaker

Discussion in 'UNet' started by John-Void, May 21, 2017.

  1. John-Void

    John-Void

    Joined:
    Dec 13, 2014
    Posts:
    3
    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,
    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3. using UnityEngine.Networking;
    4. using UnityEngine.UI;
    5. public class NetworkingScript: NetworkBehaviour
    6. {
    7. [SerializeField]
    8. private uint roomSize;
    9. private string roomName;
    10. private string roomPass = "";
    11. private NetworkManager networkManager;
    12. public Dropdown NumofPlayers;
    13. void Start()
    14. {
    15. networkManager = NetworkManager.singleton;
    16. if (networkManager.matchMaker == null)
    17. {
    18. networkManager.StartMatchMaker();
    19. }
    20. }
    21. public void SetRoomName (string _name)
    22. {
    23. roomName = _name;
    24. }
    25. public void SetRoomPassword(string _pass)
    26. {
    27. roomPass = _pass;
    28. }
    29. public void SetNumOfPlayers()
    30. {
    31. roomSize = Convert.ToUInt32(NumofPlayers.value) + 1;
    32. Debug.Log("roomSize is set to: " + roomSize);
    33. }
    34. public void CreateRoom ()
    35. {
    36. if (roomName != "" && roomName !=null)
    37. {
    38. Debug.Log("Name of the game: " + roomName + "| Max players: " + roomSize + "| Room password: " + roomPass);
    39. networkManager.matchMaker.CreateMatch(roomName, roomSize, true, roomPass, "", "", 0, 0, networkManager.OnMatchCreate);
    40. }
    41. }
    42. }
    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.
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using UnityEngine.Networking;
    4. using UnityEngine.Networking.Match;
    5. public class RoomlistItemSetup : MonoBehaviour
    6. {
    7. public delegate void JoinRoomDelegate(MatchInfoSnapshot _match);
    8. private JoinRoomDelegate joinRoomCallback;
    9. [SerializeField]
    10. private Text roomNameText;
    11. public InputField passwordText;
    12. private MatchInfoSnapshot match;
    13. public void Setup(MatchInfoSnapshot _match, JoinRoomDelegate _joinRoomCallback)
    14. {
    15. match = _match;
    16. joinRoomCallback = _joinRoomCallback;
    17. roomNameText.text = match.name + " (" + match.currentSize + "/" + match.maxSize + ")";
    18. }
    19. public void JoinRoom()
    20. {
    21. if(passwordText = <strong>PASSWORD FROM ROOM</strong>)
    22. {
    23. joinRoomCallback.Invoke(match);
    24. }
    25. }
    26. }
     
    Last edited: Jun 2, 2017
  2. John-Void

    John-Void

    Joined:
    Dec 13, 2014
    Posts:
    3
  3. ZurdoRod

    ZurdoRod

    Joined:
    Mar 7, 2015
    Posts:
    2
    On ListMatches function, change the true value with a false. true will ignore matches with password (private matches)
     
    quyencntt and pKallv like this.
  4. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    So you cannot list matches with password?
     
  5. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    This is the correct answer :)
     
  6. quyencntt

    quyencntt

    Joined:
    Jul 6, 2017
    Posts:
    1
    Thank you very much!!!