Search Unity

Third Party Help Photon Cloud Join and Create Room

Discussion in 'Multiplayer' started by PrMoH, Jan 17, 2014.

  1. PrMoH

    PrMoH

    Joined:
    May 30, 2013
    Posts:
    2
    Hello everybody
    I have simple question i hope some people can help so !!
    What i need is :
    I want when the player run the game connecting to the server and firstly check if they are room with name for ex "test" well if they are will get in the room "test" if they are not room with this name will create room with name "test".
    I try to do it before but i failed every time i hope i will find who can help me and thank you before .
     
    unity_JOY9NRxMfhqhZA likes this.
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
  3. alarm656

    alarm656

    Joined:
    Jul 6, 2013
    Posts:
    111
    if there is already "test" room? Can he create another "test" room?
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,070
    @alarm656: The roomnames are the IDs of rooms. Each name exists only once per cluster and title version.
    Means: A room "test" can exist for each AppId, region and gameversion.
     
  5. alarm656

    alarm656

    Joined:
    Jul 6, 2013
    Posts:
    111
    I'm sorry Tobias, but how can I create rooms. I just need like this: Player1 connects to photon and creates room if there are no rooms, Player2 connects to photon and joined to the room which has been created by Player1. So the room is full (because I set maxPlayers to 2)
    Now there is a new player Player3. Is Player3 will create a new room? because when I have used codes from "Sky Arena" my Player3 couldn't created a new room. Unity Editor console says "The Room is Full". Now I'm creating my own simple Photon Authentication and creating room code. There are no options, buttons in game like [Create Room], [Join Room]. Just only one [PLAY] button. When player pressed [PLAY] button it's creates room if there are no rooms or joints if there is available rooms. My new code:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class NetworkManager : MonoBehaviour {
    5.  
    6.     public string roomName = "CannonBlast";
    7.  
    8.     public static bool IsConnected
    9.     {
    10.         get
    11.         {
    12.             return PhotonNetwork.offlineMode == false && PhotonNetwork.connectionState == ConnectionState.Connected;
    13.         }
    14.     }
    15.  
    16.  
    17.     void Start ()
    18.     {
    19.         DontDestroyOnLoad( gameObject );
    20.     }
    21.  
    22.     public void Connect()
    23.     {
    24.         if( PhotonNetwork.connectionState != ConnectionState.Disconnected )
    25.         {
    26.             return;
    27.         }
    28.        
    29.         try
    30.         {
    31.             PhotonNetwork.ConnectUsingSettings( "1.0" );
    32.             PhotonNetwork.autoJoinLobby = true;
    33.         }
    34.         catch
    35.         {
    36.             Debug.LogWarning( "Couldn't connect to server" );
    37.         }
    38.     }
    39.  
    40.     void OnJoinedLobby ()
    41.     {
    42.         RoomOptions roomOptions = new RoomOptions () { isVisible = true, maxPlayers = 2 };
    43.         PhotonNetwork.JoinOrCreateRoom (roomName, roomOptions, TypedLobby.Default);
    44.         Debug.Log ("OnJoinedLobby");
    45.     }
    46.  
    47.     void OnJoinedRoom ()
    48.     {
    49.         Application.LoadLevel ("Room");
    50.         Debug.Log ("OnJoinedRoom");
    51.     }
    52.  
    53. }
     
  6. alarm656

    alarm656

    Joined:
    Jul 6, 2013
    Posts:
    111
  7. alarm656

    alarm656

    Joined:
    Jul 6, 2013
    Posts:
    111
    Operation failed: OperationResponse 226: ReturnCode: 32765 (Game full). Parameters: {} Server: MasterServer
    UnityEngine.Debug:LogError(Object)

    Player3 can't create a new room:(
     

    Attached Files:

  8. alarm656

    alarm656

    Joined:
    Jul 6, 2013
    Posts:
    111
  9. alarm656

    alarm656

    Joined:
    Jul 6, 2013
    Posts:
    111
    works great! thank you Tobias Снимок экрана 2016-05-03 в 4.09.27.png
     
    Alekxss and tobiass like this.
  10. vet-cat

    vet-cat

    Joined:
    May 29, 2013
    Posts:
    37
    Code (CSharp):
    1. string mapName = "test";
    2. var allRooms = PhotonNetwork.GetRoomList();
    3. var aviableRooms = allRooms.ToList().FindAll(f => f.MaxPlayers > f.PlayerCount && f.Name.Contains(mapName));
    4. var connectedRoom = aviableRooms.FirstOrDefault();
    5. if (connectedRoom != null)
    6. {
    7. PhotonNetwork.JoinOrCreateRoom(connectedRoom.Name, roomOptions, TypedLobby.Default);
    8. }
    9. else
    10. {
    11. PhotonNetwork.JoinOrCreateRoom(mapName + Guid.NewGuid().ToString("N"), roomOptions, TypedLobby.Default);
    12. }