Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Third Party How to Create Private Rooms with Photon Cloud?

Discussion in 'Multiplayer' started by jonkuze, Dec 25, 2012.

  1. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,713
    Hello all,

    I am using Photon Cloud with My Unity Game Projects.

    Photon Plugin is Integrated and Working, I am able to Join and Create Rooms, but I am curious about the Private Rooms.

    I read somewhere on the Photon ExitGames Website you can create Private Rooms, but I could Not find any documentation on how to enable Creating Private Rooms.

    Is Private Rooms only Feature for Dedicated Photon Servers, or can this be done using Photon Cloud?

    If so, what script do I need to add to Enable the Private Rooms in my Main Menu Lobby?

    Any leads, highly appreciated . = )
     
    Last edited: Dec 25, 2012
  2. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    Are you having your players type in the room name to join? If so... just don't list a room that is private... You could for instance do this...

    - Whenever someone makes a room and wants it to be private... make the room called "PRIVATE_WhateverTheRoomNameIs"
    - When you draw the list of rooms, don't list any Room Name that StartsWith("PRIVATE_")
    - When someone goes to join a room.. see if "TheRoomNameTheyTyped" exists AND "PRIVATE_TheRoomNameTheyTyped" exists..
     
  3. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,713
    Wow! Really it's that simple huh? i'll try it as soon as I can and let you know Results! = ) Really appreciate it.
     
  4. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,713
    Hi Carmine,

    This is what my Photon Code Looks Like (Join Room and Room Listing)



    Seems I am missing the Join Room Code in there, as my Photon was modified previously by a Developer I was working with, so I'll need to add back the Option of Join Room, or Replace Random Join with Join Room (I think I prefer that)

    Then I need the actual Line of Code Needed to don't list any Room Name that StartsWith("PRIVATE_"), as you stated.

    Sorry, I am not programmer, but I can get things working by going in and playing with it lol... So if you can assist with fixing my code! Would be Awesome!

    I'm sure maybe this Question may come up for others eventually. = )

    Thanks Carmine!
     
  5. carmine

    carmine

    Joined:
    Jan 4, 2012
    Posts:
    394
    You would need to change quite a bit of that code to make it work. You can't use join random room... because you might join a random PRIVATE room.

    I wrote "StartsWith" for a reason... you can do this:

    foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
    {
    if (roomInfo.name.StartsWith("PRIVATE_")) continue;


    You can use StartsWith and EndsWith on strings to find out if they start and end with something.

    You can't really use RoomCount because it would count rooms labeled as private..


    For creating a room... just add a checkbox/toggle for private/public.. if they select private.. then name the room "PRIVATE_"

    -Carmine
     
  6. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,713
    Thank you so much! really appreciate it! = )
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,086
    You can hide private rooms from the lobby listing and they will not be used in random matchmaking either.
    When you create a room, just set the "visible" option to false.
    You have to make sure another user will know your room's name or else your private players will stay alone forever. On the other hand, knowing the room's name is then as good as knowing a password.

    If the rooms are invisible, you can also keep on using random matchmaking, which is the preferred way to find games. It avoids issues that would arise when many clients try to join the same room cause it's first in the list. Let's say your room has space for just 2 players and 4 try to join the first room listed. Then 3 are rejected which is not too good.

    Hope this helps. Let me know if anyone needs details.
     
  8. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,713
    since i'm not much of a programmer, can you explain alittle more in detail such as provide the exact line of code needed to set this up? the part where you said "When you create a room, just set the "visible" option to false. "

    Would highly appreciate it!
     
  9. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,086
    I can only help with C# code but JS should be very similar. Hope this helps:

    Somewhere in your code are calls to CreateRoom. There are several variants of this same method with more or less parameters.
    One is defined as: CreateRoom(string roomName, bool isVisible, bool isOpen, int maxPlayers)

    So, to create an invisible (private) room for up to 4 players you could call:
    PhotonNetwork.CreateRoom(roomNameAllPlayersKnowAbout, false, true, 4);

    The variable roomNameAllPlayersKnowAbout must be a string your players know. Don't set isOpen to false, or else no one can join. You can replace 4 with any number that fits your game or 0 for "no limit".
     
  10. JITENDRA-RAJ

    JITENDRA-RAJ

    Joined:
    Jul 23, 2014
    Posts:
    3
  11. squished

    squished

    Joined:
    Mar 10, 2015
    Posts:
    3
    It's more traditional for the password protected room to be visible to the player. The player clicks it, is prompted for a password, and then allowed to join if the password is correct.

    One way to accomplish this is for the server to hash its password with SHA256 or whatever, and include the hashed password in the room's properties. The client computer can use this hash to verify the client's password is correct before allowing him to connect to the server.

    For a little more security, the server can re-verify the password on player join, and kick the player if it's incorrect. It's still not hack-proof, but it's no worse than a hidden room that can be guessed.
     
    dhruv_mv and mmmshuddup like this.