Refers to a specific lobby (and type) on the server.
The name and type are the unique identifier for a lobby.
Join a lobby via PhotonNetwork.JoinLobby(TypedLobby lobby).
The current lobby is stored in PhotonNetwork.lobby.
    /// <summary>
    /// Don't use this method directly, unless you know how to cache and apply customActorProperties.
    /// The PhotonNetwork methods will handle player and room properties for you and call this method.
    /// </summary>
    public virtual bool OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, Hashtable playerProperties, bool onGameServer)
    {
        if (this.DebugOut >= DebugLevel.INFO)
        {
            this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
        }

        Dictionary<byte, object> op = new Dictionary<byte, object>();

        if (!string.IsNullOrEmpty(roomName))
        {
            op[ParameterCode.RoomName] = roomName;
        }
        if (lobby != null)
        {
            op[ParameterCode.LobbyName] = lobby.Name;
            op[ParameterCode.LobbyType] = (byte)lobby.Type;
        }

        if (onGameServer)
        {
            if (playerProperties != null && playerProperties.Count > 0)
            {
                op[ParameterCode.PlayerProperties] = playerProperties;
                op[ParameterCode.Broadcast] = true; // TODO: check if this also makes sense when creating a room?! // broadcast actor properties
            }


            if (roomOptions == null)
            {
                roomOptions = new RoomOptions();
            }

            Hashtable gameProperties = new Hashtable();
            op[ParameterCode.GameProperties] = gameProperties;
            gameProperties.MergeStringKeys(roomOptions.customRoomProperties);

            gameProperties[GameProperties.IsOpen] = roomOptions.isOpen; // TODO: check default value. dont send this then
            gameProperties[GameProperties.IsVisible] = roomOptions.isVisible; // TODO: check default value. dont send this then
            gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
            if (roomOptions.maxPlayers > 0)
            {
                gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
            }
            if (roomOptions.cleanupCacheOnLeave)
            {
                op[ParameterCode.CleanupCacheOnLeave] = true;               // this is actually setting the room's config
                gameProperties[GameProperties.CleanupCacheOnLeave] = true;  // this is only informational for the clients which join
            }
        }

        // UnityEngine.Debug.Log("CreateGame: " + SupportClass.DictionaryToString(op));
        return this.OpCustom(OperationCode.CreateGame, op, true);
    }
Ejemplo n.º 2
0
    void OnPhotonRandomJoinFailed()
    {
        Debug.Log("No Room!");
        
        RoomOptions option = new RoomOptions();
        option.isVisible = true;
        option.isOpen = true;
        option.maxPlayers = 20;
        TypedLobby typedLobby = new TypedLobby();

        PhotonNetwork.CreateRoom("MyRoom", option, typedLobby);
    }
Ejemplo n.º 3
0
    void OnPhotonRandomJoinFailed()
    {
        // ルームを作成、部屋名は今回はnullに設定
        //PhotonNetwork.CreateRoom(null);
        //PhotonNetwork.CreateRoom(mRoomName, new RoomOptions() { maxPlayers = 4 }, null);
        Debug.Log("Create");
        RoomOptions roomOptions = new RoomOptions ();
	    roomOptions.isVisible = true;
	    roomOptions.isOpen = true;
	    roomOptions.maxPlayers = 4;
        //roomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "CustomProperties", 0000 } };
        //roomOptions.customRoomPropertiesForLobby = new string[] { "CustomProperties" };
        TypedLobby sqlLobby = new TypedLobby("myLobby", LobbyType.SqlLobby);
        PhotonNetwork.CreateRoom(mRoomName, roomOptions, TypedLobby.Default);
        
    }
Ejemplo n.º 4
0
 public void JoinRoom()
 {
     if (PhotonNetwork.IsConnected)
     {
         string roomName = nombreServer.GetComponent <Text>().text;
         if (roomName == "")
         {
             Log.text += "\nIntroduce un nombre de sala ";
             return;
         }
         screenJoin.SetActive(false);
         screenServer.SetActive(true);
         RoomOptions roomOptions = new RoomOptions();
         TypedLobby  typedLobby  = new TypedLobby(roomName, LobbyType.Default);
         PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, typedLobby);
     }
 }
Ejemplo n.º 5
0
 public static bool JoinLobby(TypedLobby typedLobby)
 {
     if (connected && Server == ServerConnection.MasterServer)
     {
         if (typedLobby == null)
         {
             typedLobby = TypedLobby.Default;
         }
         bool flag = networkingPeer.OpJoinLobby(typedLobby);
         if (flag)
         {
             networkingPeer.lobby = typedLobby;
         }
         return(flag);
     }
     return(false);
 }
    public virtual bool OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, Hashtable playerProperties, bool onGameServer)
    {
        if (base.DebugOut >= DebugLevel.INFO)
        {
            base.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
        }
        Dictionary <byte, object> customOpParameters = new Dictionary <byte, object>();

        if (!string.IsNullOrEmpty(roomName))
        {
            customOpParameters[0xff] = roomName;
        }
        if (lobby != null)
        {
            customOpParameters[0xd5] = lobby.Name;
            customOpParameters[0xd4] = (byte)lobby.Type;
        }
        if (onGameServer)
        {
            if ((playerProperties != null) && (playerProperties.Count > 0))
            {
                customOpParameters[0xf9] = playerProperties;
                customOpParameters[250]  = true;
            }
            if (roomOptions == null)
            {
                roomOptions = new RoomOptions();
            }
            Hashtable target = new Hashtable();
            customOpParameters[0xf8] = target;
            target.MergeStringKeys(roomOptions.customRoomProperties);
            target[(byte)0xfd] = roomOptions.isOpen;
            target[(byte)0xfe] = roomOptions.isVisible;
            target[(byte)250]  = roomOptions.customRoomPropertiesForLobby;
            if (roomOptions.maxPlayers > 0)
            {
                target[(byte)0xff] = roomOptions.maxPlayers;
            }
            if (roomOptions.cleanupCacheOnLeave)
            {
                customOpParameters[0xf1] = true;
                target[(byte)0xf9]       = true;
            }
        }
        return(this.OpCustom(0xe3, customOpParameters, true));
    }
Ejemplo n.º 7
0
    public virtual bool OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, Hashtable playerProperties, bool onGameServer)
    {
        if (base.DebugOut >= DebugLevel.INFO)
        {
            base.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
        }
        Dictionary <byte, object> customOpParameters = new Dictionary <byte, object>();

        if (!string.IsNullOrEmpty(roomName))
        {
            customOpParameters[ParameterCode.RoomName] = roomName;
        }
        if (lobby != null)
        {
            customOpParameters[ParameterCode.LobbyName] = lobby.Name;
            customOpParameters[ParameterCode.LobbyType] = (byte)lobby.Type;
        }
        if (onGameServer)
        {
            if ((playerProperties != null) && (playerProperties.Count > 0))
            {
                customOpParameters[ParameterCode.PlayerProperties] = playerProperties;
                customOpParameters[ParameterCode.Broadcast]        = true;
            }
            if (roomOptions == null)
            {
                roomOptions = new RoomOptions();
            }
            Hashtable target = new Hashtable();
            customOpParameters[ParameterCode.GameProperties] = target;
            target.MergeStringKeys(roomOptions.customRoomProperties);
            target[RoomProperty.Joinable]   = roomOptions.isOpen;
            target[RoomProperty.Visibility] = roomOptions.isVisible;
            target[RoomProperty.PropertiesListedInLobby] = roomOptions.customRoomPropertiesForLobby;
            if (roomOptions.maxPlayers > 0)
            {
                target[RoomProperty.MaxPlayers] = roomOptions.maxPlayers;
            }
            if (roomOptions.cleanupCacheOnLeave)
            {
                customOpParameters[ParameterCode.CleanupCacheOnLeave] = true;
                target[RoomProperty.CleanUpCacheOnLeave] = true;
            }
        }
        return(SendOperation(OperationCode.CreateGame, customOpParameters, SendOptions.SendReliable));
    }
Ejemplo n.º 8
0
        /// <summary>
        /// Joins the lobby on the Master Server, where you get a list of RoomInfos of currently open rooms.
        /// This is an async request which triggers a OnOperationResponse() call.
        /// </summary>
        /// <returns>If the operation could be sent (has to be connected).</returns>
        public virtual bool OpJoinLobby(TypedLobby lobby)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinLobby()");
            }

            Dictionary<byte, object> parameters = null;
            if (lobby != null && !lobby.IsDefault)
            {
                parameters = new Dictionary<byte, object>();
                parameters[(byte)ParameterCode.LobbyName] = lobby.Name;
                parameters[(byte)ParameterCode.LobbyType] = (byte)lobby.Type;
            }

            return this.OpCustom(OperationCode.JoinLobby, parameters, true);
        }
Ejemplo n.º 9
0
    public virtual bool OpJoinLobby(TypedLobby lobby)
    {
        if (DebugOut >= DebugLevel.INFO)
        {
            Listener.DebugReturn(DebugLevel.INFO, "OpJoinLobby()");
        }

        Dictionary <byte, object> customOpParameters = null;

        if (lobby != null && !lobby.IsDefault)
        {
            customOpParameters      = new Dictionary <byte, object>();
            customOpParameters[213] = lobby.Name;
            customOpParameters[212] = (byte)lobby.Type;
        }

        return(SendOperation(229, customOpParameters, SendOptions.SendReliable));
    }
Ejemplo n.º 10
0
    /// <summary>
    /// A method to create a room.
    /// </summary>
    /// <param name="input">
    /// The name of the room.
    /// </param>
    public void CreateRoom(InputField input)
    {
        roomNameText = input.name;

        if (input.text == "")
        {
            roomNameText = "Funeral_Room";
            //return;
        }
        RoomOptions roomOptions = new RoomOptions();

        roomOptions.isVisible  = true;
        roomOptions.isOpen     = true;
        roomOptions.maxPlayers = (byte)25;
        TypedLobby typedLobby = new TypedLobby();

        PhotonNetwork.CreateRoom(input.text, roomOptions, typedLobby);
    }
Ejemplo n.º 11
0
    void SqlSearchStringDemonstration()
    {
        TypedLobby newLobby = new TypedLobby("SkyArenaLobby", LobbyType.SqlLobby);



        string possibleSqlSearch = "( C5 = \"Map2\" OR C5 = \"Map5\" ) AND C2 < 20 AND C2 > 10";



        PhotonNetwork.JoinRandomRoom(
            null,
            0,
            MatchmakingMode.FillRoom,
            newLobby,
            possibleSqlSearch
            );
    }
Ejemplo n.º 12
0
    public static bool JoinLobby(TypedLobby typedLobby)
    {
        bool flag;

        if (!connected || (Server != ServerConnection.MasterServer))
        {
            return(false);
        }
        if (typedLobby == null)
        {
            typedLobby = TypedLobby.Default;
        }
        if (flag = networkingPeer.OpJoinLobby(typedLobby))
        {
            networkingPeer.lobby = typedLobby;
        }
        return(flag);
    }
Ejemplo n.º 13
0
    public static bool RejoinRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby, bool createIfNotExists, Hashtable Hash)
    {
        bool onGameServer = PhotonNetwork.networkingPeer.server == ServerConnection.GameServer;

        if (!onGameServer)
        {
            Room mRoomToGetInto = new Room(roomName, roomOptions);
            PhotonNetwork.networkingPeer.mRoomToEnterLobby = null;
            if (createIfNotExists)
            {
                if (typedLobby == null)
                {
                }
                PhotonNetwork.networkingPeer.mRoomToEnterLobby = !PhotonNetwork.networkingPeer.insideLobby ? null : PhotonNetwork.networkingPeer.lobby;
            }
        }
        return(PhotonNetwork.networkingPeer.OpJoinRoom(roomName, roomOptions, PhotonNetwork.networkingPeer.mRoomToEnterLobby, createIfNotExists, Hash, onGameServer));
    }
Ejemplo n.º 14
0
        public void OnHostServerButton()
        {
            if (string.IsNullOrEmpty(m_HostServerName))
            {
                return;
            }

            RoomOptions roomOptions = new RoomOptions();

            roomOptions.MaxPlayers = MAX_PLAYER_COUNT;

            //Create room with the lobby
            TypedLobby sqlLobby = new TypedLobby(LOBBY_NAME, LobbyType.Default);

            PhotonNetwork.CreateRoom(m_HostServerName, roomOptions, sqlLobby);

            SetBlockingMessage("Creating room...");
        }
Ejemplo n.º 15
0
    public void CreateRoom()
    {
        if (playerName == null || roomNameCreated == null)
        {
            Debug.Log("you have to privide the player name and the room name!");
            return;
        }

        controlPanel.SetActive(false);
        backButton.SetActive(true);
        progressLabel.text = "status: waiting for other players";

        PhotonNetwork.LocalPlayer.NickName = playerName;
        RoomOptions roomOptions = new RoomOptions();
        TypedLobby  typedLobby  = new TypedLobby(roomNameCreated, LobbyType.Default);

        PhotonNetwork.CreateRoom(roomNameCreated, roomOptions, typedLobby);
    }
Ejemplo n.º 16
0
    /// <summary>
    /// Joins the lobby on the Master Server, where you get a list of RoomInfos of currently open rooms.
    /// This is an async request which triggers a OnOperationResponse() call.
    /// </summary>
    /// <returns>If the operation could be sent (has to be connected).</returns>
    public virtual bool OpJoinLobby(TypedLobby lobby)
    {
        if (this.DebugOut >= DebugLevel.INFO)
        {
            this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinLobby()");
        }

        Dictionary <byte, object> parameters = null;

        if (lobby != null && !lobby.IsDefault)
        {
            parameters = new Dictionary <byte, object>();
            parameters[(byte)ParameterCode.LobbyName] = lobby.Name;
            parameters[(byte)ParameterCode.LobbyType] = (byte)lobby.Type;
        }

        return(this.OpCustom(OperationCode.JoinLobby, parameters, true));
    }
Ejemplo n.º 17
0
    /// <summary>
    /// Method to be called when the user wants to create a new room.
    /// </summary>
    public void CreateNewRoom(int numberOfPlayers, ProjectDelegates.RoomInfoCallback RoomCreatedCallback, int level)
    {
        OnJoinedRoomCallback = RoomCreatedCallback;

        ExitGames.Client.Photon.Hashtable customParams = new ExitGames.Client.Photon.Hashtable();
        customParams.Add("C0", level);

        RoomOptions options = new RoomOptions();

        options.maxPlayers = numberOfPlayers;

        TypedLobby typedLobby = new TypedLobby("GameLobby", LobbyType.Default);

        //PhotonNetwork.CreateRoom ("",options,typedLobby);
        //PhotonNetwork.CreateRoom ("", true, true, numberOfPlayers);
        // testing this to git rid of the build warning
        PhotonNetwork.CreateRoom("", options, typedLobby);
    }
Ejemplo n.º 18
0
        private void JoinOrCreateRoom(string roomName)
        {
            lobbyGO.SetActive(false);


            RoomOptions roomOption = new RoomOptions();

            roomOption.MaxPlayers           = 2;
            roomOption.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable()
            {
                { "C0", "Hello" }
            };
            roomOption.CustomRoomPropertiesForLobby = new string[] { "C0" };


            TypedLobby typedLobby = new TypedLobby("XD", LobbyType.SqlLobby);

            PhotonNetwork.JoinOrCreateRoom(roomName, roomOption, typedLobby);
        }
Ejemplo n.º 19
0
        public override void OnJoinRandomFailed(short returnCode, string message)
        {
            Debug.Log("Fail join room :  " + message + " Creating...");

            RoomOptions ro = new RoomOptions
            {
                MaxPlayers    = 2,
                PublishUserId = true,
                IsOpen        = true,
                IsVisible     = true,
                EmptyRoomTtl  = 1000
            };

            TypedLobby tl = new TypedLobby
            {
                Name = "Ranked"
            };

            PhotonNetwork.CreateRoom("Ranked", ro, tl);
        }
Ejemplo n.º 20
0
    void CreateRoom(TypedLobby type)
    {
        Debug.Log("Creating room");
        int randomRoomNumber = Random.Range(0, 10000);

        RoomOptions roomOps;

        roomOps = type.Name == "Survival" ?
                  new RoomOptions()
        {
            IsVisible = true, IsOpen = true, MaxPlayers = (byte)survivalRoomSize
        } :
        new RoomOptions()
        {
            IsVisible = true, IsOpen = true, MaxPlayers = (byte)faceoffRoomSize
        };

        PhotonNetwork.CreateRoom("Room" + randomRoomNumber, roomOps, type);
        Debug.Log(randomRoomNumber);
    }
Ejemplo n.º 21
0
        private IEnumerator CheckConnectionToLobby()
        {
            while (true)
            {
                yield return(new WaitForSeconds(1.0f));

                if (!PhotonNetwork.IsConnected)
                {
                    mc.ConnectToPhoton();
                }
                else if (!PhotonNetwork.InLobby)
                {
                    TypedLobby tl = new TypedLobby
                    {
                        Name = "private"
                    };

                    PhotonNetwork.JoinLobby(tl);
                }
            }
        }
Ejemplo n.º 22
0
        public TypedLobby GetTypedLobby()
        {
            if (name.IsNone && type.IsNone)
            {
                return(TypedLobby.Default);
            }

            TypedLobby _t = new TypedLobby();

            if (!name.IsNone)
            {
                _t.Name = name.Value;
            }

            if (!type.IsNone)
            {
                _t.Type = (LobbyType)type.Value;
            }

            return(_t);
        }
Ejemplo n.º 23
0
 public static bool CreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
 {
     if (offlineMode)
     {
         if (offlineModeRoom != null)
         {
             Debug.LogError("CreateRoom failed. In offline mode you still have to leave a room to enter another.");
             return(false);
         }
         offlineModeRoom = new Room(roomName, roomOptions);
         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom, 0, new object[0]);
         NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom, 0, new object[0]);
         return(true);
     }
     if ((networkingPeer.server == ServerConnection.MasterServer) && connectedAndReady)
     {
         return(networkingPeer.OpCreateGame(roomName, roomOptions, typedLobby));
     }
     Debug.LogError("CreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
     return(false);
 }
Ejemplo n.º 24
0
    // マスターサーバ接続時のコールバック
    // ↑ ConnectUsingSettings() を呼んだ時に
    void OnJoinedLobby()
    {
        string userName = "******";
        //string userId = "ID : 000" + count++;
        string userId = "ID : 000" + ClientManager.Instance.number_;

        PhotonNetwork.autoCleanUpPlayerObjects = false;

        // ルームプロパティ
        ExitGames.Client.Photon.Hashtable customProp = new ExitGames.Client.Photon.Hashtable();
        customProp.Add("userName", userName);
        customProp.Add("userId", userId);
        PhotonNetwork.SetPlayerCustomProperties(customProp);


        // ルームオプションの設定
        RoomOptions myOptions = new RoomOptions();


        myOptions.CustomRoomProperties         = customProp;
        myOptions.CustomRoomPropertiesForLobby = new string[] { "userName", "userId" };
        myOptions.IsOpen    = true;
        myOptions.IsVisible = true;


        myOptions.MaxPlayers = 6; // 20人まで

        // IDの公開
        myOptions.PublishUserId = true;

        // ロビーの設定
        TypedLobby myTypedLobby = new TypedLobby();

        myTypedLobby.Name = "Default";
        myTypedLobby.Type = LobbyType.Default;

        // ルームを任意の設定で作る
        PhotonNetwork.JoinOrCreateRoom("DefaultRoom", myOptions, myTypedLobby);
    }
Ejemplo n.º 25
0
    public override void OnConnectedToMaster()
    {
        base.OnConnectedToMaster();
        if (MyLobby == null)
        {
            MyLobby = new TypedLobby();
        }

        MyLobby.Type = LobbyType.SqlLobby;
        PhotonNetwork.JoinLobby(MyLobby);

        //MyOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "C0", 1 } };
        //MyOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "C1", 2 } };
        //MyOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "M0", 3 } };
        //MyOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "M1", 4 } };
        //MyOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "M2", 5 } };
        //MyOptions.CustomRoomPropertiesForLobby = new string[] { "C0" };



        Debug.Log("cONECTADO");
    }
Ejemplo n.º 26
0
    public IEnumerator SetupVideo(System.Action OnComplete)
    {
        VideoChat.framerate = framerate;
        RoomOptions roomOptions = new RoomOptions();

        roomOptions.MaxPlayers          = 2;
        roomOptions.CleanupCacheOnLeave = true;
        roomOptions.IsVisible           = true;
        roomOptions.IsOpen = true;
        TypedLobby typedLobby = new TypedLobby();

        typedLobby.Name = "chat";
        typedLobby.Type = LobbyType.Default;
        //PhotonNetwork.JoinLobby(typedLobby);

        PhotonNetwork.JoinOrCreateRoom("MidnightVideoChat", roomOptions, (null != PhotonNetwork.lobby) ? PhotonNetwork.lobby : typedLobby);

        while (!roomJoined)
        {
            yield return(null);
        }

        if (PhotonNetwork.GetRoomList().Length > 0)
        {
            UnityEngine.Debug.Log("ROOM EXISTS");
        }


        //PhotonNetwork.CreateRoom("MidnightVideoChat", roomOptions, typedLobby);
        PhotonNetwork.NetworkStatisticsEnabled = true;
        //PhotonNetwork.GetRoomList()
        VideoChat.echoCancellation = echoCancellation;

        if (Application.platform == RuntimePlatform.Android)
        {
            VideoChat.deviceIndex++;
        }
        OnComplete();
    }
Ejemplo n.º 27
0
        /// <summary>
        /// Joins a specific room by name and creates it on demand. Will callback: OnJoinedRoom or OnJoinRoomFailed.
        /// </summary>
        /// <remarks>
        /// Useful when players make up a room name to meet in:
        /// All involved clients call the same method and whoever is first, also creates the room.
        ///
        /// When successful, the client will enter the specified room.
        /// The client which creates the room, will callback both OnCreatedRoom and OnJoinedRoom.
        /// Clients that join an existing room will only callback OnJoinedRoom.
        /// In all error cases, OnJoinRoomFailed gets called.
        ///
        /// Joining a room will fail, if the room is full, closed or when the user
        /// already is present in the room (checked by userId).
        ///
        /// To return to a room, use OpRejoinRoom.
        ///
        /// This method can only be called while the client is connected to a Master Server so you should
        /// implement the callback OnConnectedToMaster.
        /// Check the return value to make sure the operation will be called on the server.
        /// Note: There will be no callbacks if this method returned false.
        ///
        ///
        /// If you set room properties in roomOptions, they get ignored when the room is existing already.
        /// This avoids changing the room properties by late joining players.
        ///
        /// You can define an array of expectedUsers, to block player slots in the room for these users.
        /// The corresponding feature in Photon is called "Slot Reservation" and can be found in the doc pages.
        ///
        ///
        /// More about PUN matchmaking:
        /// https://doc.photonengine.com/en-us/pun/v2/lobby-and-matchmaking/matchmaking-and-lobby
        /// </remarks>
        /// <param name="roomName">Name of the room to join. Must be non null.</param>
        /// <param name="roomOptions">Options for the room, in case it does not exist yet. Else these values are ignored.</param>
        /// <param name="typedLobby">Lobby you want a new room to be listed in. Ignored if the room was existing and got joined.</param>
        /// <param name="expectedUsers">Optional list of users (by UserId) who are expected to join this game and who you want to block a slot for.</param>
        /// <returns>True will be returned when you are the first user.</returns>>
        public static async UniTask <bool> JoinOrCreateRoomAsync(
            string roomName,
            RoomOptions roomOptions,
            TypedLobby typedLobby,
            string[] expectedUsers  = null,
            CancellationToken token = default)
        {
            var createdRoomTask = Pun2TaskCallback.OnCreatedRoomAsync().GetAwaiter();
            var task            = UniTask.WhenAny(
                Pun2TaskCallback.OnJoinedRoomAsync().AsAsyncUnitUniTask(),
                Pun2TaskCallback.OnCreateRoomFailedAsync(),
                Pun2TaskCallback.OnJoinRoomFailedAsync());

            var valid = PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, typedLobby, expectedUsers);

            if (!valid)
            {
                throw new InvalidRoomOperationException("It is not ready to join a room.");
            }

            var(winIndex,
                _,
                (createFailedCode, createFailedMessage),
                (joinFailedCode, joinFailedMessage)) = await task.WithCancellation(token);

            if (winIndex == 0)
            {
                return(createdRoomTask.IsCompleted);
            }

            if (winIndex == 1)
            {
                throw new FailedToCreateRoomException(createFailedCode, createFailedMessage);
            }
            else
            {
                throw new FailedToJoinRoomException(createFailedCode, createFailedMessage);
            }
        }
Ejemplo n.º 28
0
        /* ============================== INTERFACE ============================== */

        public void InitMenu()
        {
            if (listRoom == null)
            {
                listRoom = new Dictionary <string, GameObject>();
            }
            else
            {
                ClearRoom();
            }

            TypedLobby tl = new TypedLobby
            {
                Name = "private"
            };

            PhotonNetwork.JoinLobby(tl);

            joinRoomButton.interactable = false;

            StartCoroutine(CheckConnectionToLobby());
        }
Ejemplo n.º 29
0
    public IEnumerator Connect()
    {
        NetworkView = gameObject.AddComponent <PhotonView>();
        NetworkView.synchronization = ViewSynchronization.Off;
        NetworkView.viewID          = 3;

        if (Application.internetReachability != NetworkReachability.NotReachable)
        {
            PhotonNetwork.ConnectUsingSettings("1.0");
        }

        while (!connectedToMaster)
        {
            yield return(null);
        }

        RoomOptions roomOptions = new RoomOptions();

        roomOptions.MaxPlayers          = 2;
        roomOptions.CleanupCacheOnLeave = true;
        roomOptions.IsVisible           = true;
        roomOptions.IsOpen = true;
        TypedLobby typedLobby = new TypedLobby();

        typedLobby.Name = "chat";
        typedLobby.Type = LobbyType.Default;
        PhotonNetwork.JoinLobby(typedLobby);

        if (PhotonNetwork.GetRoomList().Length > 0)
        {
            UnityEngine.Debug.Log("ROOM EXISTS");
        }

        //PhotonNetwork.JoinOrCreateRoom("MidnightVideoChat", roomOptions, typedLobby);
        //PhotonNetwork.CreateRoom("MidnightVideoChat", roomOptions, typedLobby);
        PhotonNetwork.NetworkStatisticsEnabled = true;
        //PhotonNetwork.GetRoomList()
    }
Ejemplo n.º 30
0
        private void CreateRoomAction()
        {
            if (roomNameField.text == "")
            {
                return;
            }

            RoomOptions ro = new RoomOptions
            {
                MaxPlayers    = (byte)nbPlayersSlider.value,
                PublishUserId = true,
                IsOpen        = true,
                IsVisible     = true,
                EmptyRoomTtl  = 1000
            };

            TypedLobby tl = new TypedLobby
            {
                Name = "private"
            };

            PhotonNetwork.CreateRoom(roomNameField.text, ro, tl);
        }
Ejemplo n.º 31
0
    public void CreateRoom(GameOptions options)
    {
        if (!Rooms.ContainsKey(options.name))
        {
            RoomOptions roomOptions = new RoomOptions();
            roomOptions.IsVisible            = true;
            roomOptions.IsOpen               = true;
            roomOptions.Plugins              = new string[] { "MineSweepers" + options.plugin };
            roomOptions.CustomRoomProperties = new ExitGames.Client.Photon.Hashtable()
            {
                { "plugin", "MineSweepers" + options.plugin }, { "hight", options.hight }, { "width", options.width },
                { "maxPlayers", options.numOfPlayers }, { "mineRate", options.mineRate },
                { "firstSafe", options.firstSafe }, { "endOnExpload", options.endOnExpload },
                { "joinAfter", options.JoinAfterStart }
            };
            roomOptions.CustomRoomPropertiesForLobby = new string[] { "plugin", "hight", "width", "mineRate", "maxPlayers", "joinAfter" };

            roomOptions.MaxPlayers = (byte)options.numOfPlayers;

            TypedLobby lobby = new TypedLobby("Main", LobbyType.SqlLobby);
            PhotonNetwork.CreateRoom(options.name, roomOptions, lobby);
        }
    }
Ejemplo n.º 32
0
        // Start the connection process.
        // - If already connected, we attempt joining a random room.
        // - If not yet connected, Connect this application instance to Photon Cloud Network
        public void Connect()
        {
            CurrentState = GameConnectState.Disconnected;
            RoomOptions roomOptions = new RoomOptions();

            roomOptions.MaxPlayers = 2;

            TypedLobby typedLobby = new TypedLobby();

            typedLobby.Type = LobbyType.Default;

            if (PhotonNetwork.IsConnected)
            {
                //PhotonNetwork.JoinRandomRoom();
                Debug.Log("room name:" + roomName);
                PhotonNetwork.JoinOrCreateRoom(roomName, roomOptions, typedLobby);
            }
            else
            {
                PhotonNetwork.GameVersion = _gameVersion;
                PhotonNetwork.ConnectUsingSettings();
            }
        }
Ejemplo n.º 33
0
    // Token: 0x060002ED RID: 749 RVA: 0x00012F10 File Offset: 0x00011110
    public virtual bool OpGetGameList(TypedLobby lobby, string queryData)
    {
        if (this.DebugOut >= DebugLevel.INFO)
        {
            base.Listener.DebugReturn(DebugLevel.INFO, "OpGetGameList()");
        }
        if (lobby == null)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                base.Listener.DebugReturn(DebugLevel.INFO, "OpGetGameList not sent. Lobby cannot be null.");
            }
            return(false);
        }
        if (lobby.Type != LobbyType.SqlLobby)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                base.Listener.DebugReturn(DebugLevel.INFO, "OpGetGameList not sent. LobbyType must be SqlLobby.");
            }
            return(false);
        }
        if (lobby.IsDefault)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                base.Listener.DebugReturn(DebugLevel.INFO, "OpGetGameList not sent. LobbyName must be not null and not empty.");
            }
            return(false);
        }
        Dictionary <byte, object> dictionary = new Dictionary <byte, object>();

        dictionary[213] = lobby.Name;
        dictionary[212] = (byte)lobby.Type;
        dictionary[245] = queryData;
        return(this.SendOperation(217, dictionary, SendOptions.SendReliable));
    }
Ejemplo n.º 34
0
    void OnGUI()
    {
        RoomOptions classRoomOptions = new RoomOptions();

        classRoomOptions.isOpen     = true;
        classRoomOptions.isVisible  = true;
        classRoomOptions.maxPlayers = 16;

        TypedLobby classLobby = new TypedLobby("Class Lobby", LobbyType.Default);

        if (!PhotonNetwork.connected)
        {
            GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
        }
        else if (PhotonNetwork.room == null)
        {
            // Create Room
            if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
            {
                // PhotonNetwork.CreateRoom(roomName + System.Guid.NewGuid().ToString("N"), true, true, 5);
                PhotonNetwork.CreateRoom(classRoomName, classRoomOptions, classLobby);
            }

            // Join Room
            if (roomsList != null)
            {
                for (int i = 0; i < roomsList.Length; i++)
                {
                    if (GUI.Button(new Rect(100, 250 + (110 * i), 250, 100), "Join " + roomsList[i].name))
                    {
                        PhotonNetwork.JoinRoom(roomsList[i].name);
                    }
                }
            }
        }
    }
    /// <summary>NetworkingPeer.OpJoinRoom</summary>
    public bool OpJoinRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby, bool createIfNotExists)
    {
        bool onGameServer = this.server == ServerConnection.GameServer;
        if (!onGameServer)
        {
            // roomOptions and typedLobby will be null, unless createIfNotExists is true
            this.mRoomOptionsForCreate = roomOptions;
            this.mRoomToGetInto = new Room(roomName, roomOptions);
            this.mRoomToEnterLobby = null;
            if (createIfNotExists)
            {
                this.mRoomToEnterLobby = typedLobby ?? ((this.insideLobby) ? this.lobby : null);  // use given lobby, or active lobby (if any active) or none
            }
        }

        this.mLastJoinType = (createIfNotExists) ? JoinType.JoinOrCreateOnDemand : JoinType.JoinGame;
        return base.OpJoinRoom(roomName, roomOptions, this.mRoomToEnterLobby, createIfNotExists, this.GetLocalActorProperties(), onGameServer);
    }
    /// <summary>NetworkingPeer.OpCreateGame</summary>
    public bool OpCreateGame(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
    {
        bool onGameServer = this.server == ServerConnection.GameServer;
        if (!onGameServer)
        {
            this.mRoomOptionsForCreate = roomOptions;
            this.mRoomToGetInto = new Room(roomName, roomOptions);
            this.mRoomToEnterLobby = typedLobby ?? ((this.insideLobby) ? this.lobby : null);  // use given lobby, or active lobby (if any active) or none
        }

        this.mLastJoinType = JoinType.CreateGame;
        return base.OpCreateRoom(roomName, roomOptions, this.mRoomToEnterLobby, this.GetLocalActorProperties(), onGameServer);
    }
    /// <summary>
    /// Method to be called when the user wants to create a new room.
    /// </summary>
    public void CreateNewRoom(int numberOfPlayers,ProjectDelegates.RoomInfoCallback RoomCreatedCallback, int level)
    {
        OnJoinedRoomCallback = RoomCreatedCallback;

        ExitGames.Client.Photon.Hashtable customParams = new ExitGames.Client.Photon.Hashtable();
        customParams.Add("C0", level);

        RoomOptions options = new RoomOptions();
        options.maxPlayers = numberOfPlayers;

        TypedLobby typedLobby = new TypedLobby("GameLobby",LobbyType.Default);

		//PhotonNetwork.CreateRoom ("",options,typedLobby);
		//PhotonNetwork.CreateRoom ("", true, true, numberOfPlayers);
		// testing this to git rid of the build warning
		PhotonNetwork.CreateRoom("", options, typedLobby);
		
    }
Ejemplo n.º 38
0
    /// <summary>
    /// Attempts to join an open room with fitting, custom properties but fails if none is currently available.
    /// </summary>
    /// <remarks>
    /// Rooms can be created in arbitrary lobbies which get created on demand.
    /// You can join rooms from any lobby without actually joining the lobby with this overload.
    ///
    /// This method will only match rooms attached to one lobby! If you use many lobbies, you
    /// might have to repeat JoinRandomRoom, to find some fitting room.
    /// This method looks up a room in the specified lobby or the currently active lobby (if none specified)
    /// or in the default lobby (if none active).
    ///
    /// If this fails, you can still create a room (and make this available for the next who uses JoinRandomRoom).
    /// Alternatively, try again in a moment.
    ///
    /// In offlineMode, a room will be created but no properties will be set and all parameters of this
    /// JoinRandomRoom call are ignored. The event/callback OnJoinedRoom gets called (see enum PhotonNetworkingMessage).
    /// </remarks>
    /// <param name="expectedCustomRoomProperties">Filters for rooms that match these custom properties (string keys and values). To ignore, pass null.</param>
    /// <param name="expectedMaxPlayers">Filters for a particular maxplayer setting. Use 0 to accept any maxPlayer value.</param>
    /// <param name="matchingType">Selects one of the available matchmaking algorithms. See MatchmakingMode enum for options.</param>
    /// <param name="typedLobby">The lobby in which you want to lookup a room. Pass null, to use the default lobby. This does not join that lobby and neither sets the lobby property.</param>
    /// <param name="sqlLobbyFilter">A filter-string for SQL-typed lobbies.</param>
    public static bool JoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
    {
        if (offlineMode)
        {
            if (offlineModeRoom != null)
            {
                Debug.LogError("JoinRandomRoom failed. In offline mode you still have to leave a room to enter another.");
                return false;
            }

            offlineModeRoom = new Room("offline room", null);
            offlineModeRoom.masterClientId = 1;
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
            return true;
        }

        if (networkingPeer.server != ServerConnection.MasterServer || !connectedAndReady)
        {
            Debug.LogError("JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
            return false;
        }

        return networkingPeer.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, null, matchingType, typedLobby, sqlLobbyFilter);
    }
Ejemplo n.º 39
0
    /// <summary>Lets you either join a named room or create it on the fly - you don't have to know if someone created the room already.</summary>
    /// <remarks>
    /// This makes it easier for groups of players to get into the same room. Once the group
    /// exchanged a roomName, any player can call JoinOrCreateRoom and it doesn't matter who
    /// actually joins or creates the room.
    ///
    /// The parameters roomOptions and typedLobby are only used when the room actually gets created by this client.
    /// You know if this client created a room, if you get a callback OnCreatedRoom (before OnJoinedRoom gets called as well).
    /// </remarks>
    /// <param name="roomName">Name of the room to join. Must be non null.</param>
    /// <param name="roomOptions">Options for the room, in case it does not exist yet. Else these values are ignored.</param>
    /// <param name="typedLobby">Lobby you want a new room to be listed in. Ignored if the room was existing and got joined.</param>
    /// <returns>If the operation got queued and will be sent.</returns>
    public static bool JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
    {
        if (offlineMode)
        {
            if (offlineModeRoom != null)
            {
                Debug.LogError("JoinOrCreateRoom failed. In offline mode you still have to leave a room to enter another.");
                return false;
            }

            offlineModeRoom = new Room(roomName, roomOptions);
            offlineModeRoom.masterClientId = 1;
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom);  // in offline mode you create, too for JoinOrCreateRoom
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
            return true;
        }

        if (networkingPeer.server != ServerConnection.MasterServer || !connectedAndReady)
        {
            Debug.LogError("JoinOrCreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
            return false;
        }

        if (string.IsNullOrEmpty(roomName))
        {
            Debug.LogError("JoinOrCreateRoom failed. A roomname is required. If you don't know one, how will you join?");
            return false;
        }

        return networkingPeer.OpJoinRoom(roomName, roomOptions, typedLobby, true);
    }
Ejemplo n.º 40
0
    /// <summary>On a Master Server you can join a lobby to get lists of available rooms.</summary>
    /// <remarks>
    /// The room list is sent and refreshed by the server. You can access this cached list by
    /// PhotonNetwork.GetRoomList().
    ///
    /// Any client can "make up" any lobby on the fly. Splitting rooms into multiple lobbies will
    /// keep each list shorter. However, having too many lists might ruin the matchmaking experience.
    ///
    /// In best case, you create a limited number of lobbies. For example, create a lobby per
    /// game-mode: "koth" for king of the hill and "ffa" for free for all, etc.
    ///
    /// There is no listing of lobbies at the moment.
    ///
    /// Sql-typed lobbies offer a different filtering model for random matchmaking. This might be more
    /// suited for skillbased-games. However, you will also need to follow the conventions for naming
    /// filterable properties in sql-lobbies! Both is explained in the matchmaking doc linked below.
    ///
    /// In best case, you make your clients join random games, as described here:
    /// http://confluence.exitgames.com/display/PTN/Op+JoinRandomGame
    ///
    ///
    /// Per room you should check if it's full or not before joining. Photon does list rooms that are
    /// full, unless you close and hide them (room.open = false and room.visible = false).
    ///
    /// You can show your games current players and room count without joining a lobby (but you must
    /// be on the master server). Use: countOfPlayers, countOfPlayersOnMaster, countOfPlayersInRooms and
    /// countOfRooms.
    ///
    /// When creating new rooms, they will be "attached" to the currently used lobby or the default lobby.
    ///
    /// You can use JoinRandomRoom without being in a lobby!
    /// Set autoJoinLobby = false before you connect, to not join a lobby. In that case, the
    /// connect-workflow will call OnConnectedToMaster (if you implement it) when it's done.
    /// </remarks>
    /// <param name="typedLobby">A typed lobby to join (must have name and type).</param>
    public static bool JoinLobby(TypedLobby typedLobby)
    {
        if (PhotonNetwork.connected && PhotonNetwork.Server == ServerConnection.MasterServer)
        {
            if (typedLobby == null)
            {
                typedLobby = TypedLobby.Default;
            }

            bool sending = networkingPeer.OpJoinLobby(typedLobby);
            if (sending)
            {
                networkingPeer.lobby = typedLobby;

            }
            return sending;
        }

        return false;
    }
Ejemplo n.º 41
0
    /// <summary>
    /// Creates a room but fails if this room is existing already. Can only be called on Master Server.
    /// </summary>
    /// <remarks>
    /// When successful, this calls the callbacks OnCreatedRoom and OnJoinedRoom (the latter, cause you join as first player).
    /// If the room can't be created (because it exists already), OnPhotonCreateRoomFailed gets called.
    ///
    /// If you don't want to create a unique room-name, pass null or "" as name and the server will assign a roomName (a GUID as string).
    ///
    /// Rooms can be created in any number of lobbies. Those don't have to exist before you create a room in them (they get
    /// auto-created on demand). Lobbies can be useful to split room lists on the server-side already. That can help keep the room
    /// lists short and manageable.
    /// If you set a typedLobby parameter, the room will be created in that lobby (no matter if you are active in any).
    /// If you don't set a typedLobby, the room is automatically placed in the currently active lobby (if any) or the
    /// default-lobby.
    ///
    /// Call this only on the master server.
    /// Internally, the master will respond with a server-address (and roomName, if needed). Both are used internally
    /// to switch to the assigned game server and roomName.
    ///
    /// PhotonNetwork.autoCleanUpPlayerObjects will become this room's autoCleanUp property and that's used by all clients that join this room.
    ///
    /// You can define an array of expectedUsers, to block player slots in the room for these users.
    /// The corresponding feature in Photon is called "Slot Reservation" and can be found in the doc pages.
    /// </remarks>
    /// <param name="roomName">Unique name of the room to create. Pass null or "" to make the server generate a name.</param>
    /// <param name="roomOptions">Common options for the room like MaxPlayers, initial custom room properties and similar. See RoomOptions type..</param>
    /// <param name="typedLobby">If null, the room is automatically created in the currently used lobby (which is "default" when you didn't join one explicitly).</param>
    /// <param name="expectedUsers">Optional list of users (by UserId) who are expected to join this game and who you want to block a slot for.</param>
    /// <returns>If the operation got queued and will be sent.</returns>
    public static bool CreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby, string[] expectedUsers)
    {
        if (offlineMode)
        {
            if (offlineModeRoom != null)
            {
                Debug.LogError("CreateRoom failed. In offline mode you still have to leave a room to enter another.");
                return false;
            }
            EnterOfflineRoom(roomName, roomOptions, true);
            return true;
        }
        if (networkingPeer.Server != ServerConnection.MasterServer || !connectedAndReady)
        {
            Debug.LogError("CreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
            return false;
        }

        typedLobby = typedLobby ?? ((networkingPeer.insideLobby) ? networkingPeer.lobby : null);  // use given lobby, or active lobby (if any active) or none

        EnterRoomParams opParams = new EnterRoomParams();
        opParams.RoomName = roomName;
        opParams.RoomOptions = roomOptions;
        opParams.Lobby = typedLobby;
        opParams.ExpectedUsers = expectedUsers;

        return networkingPeer.OpCreateGame(opParams);
    }
    /// <summary>
    /// Method to be called when the user wants to try to connect to an existing room.
    /// </summary>
    public void JoinRoom(byte maxPlayers, int level, ProjectDelegates.RoomInfoCallback JoinedRoomCallback)
    {
        this.maxPlayers = maxPlayers;
        this.level = level;
        OnJoinedRoomCallback = JoinedRoomCallback;

        string sqlFilter = "C0 > " + (level-3) + " AND C0 < " + (level+3);

		Debug.Log (sqlFilter);

        TypedLobby typedLobby = new TypedLobby("GameLobby",LobbyType.Default);


        PhotonNetwork.JoinRandomRoom(null,maxPlayers,MatchmakingMode.FillRoom,typedLobby,"");
		//PhotonNetwork.JoinRandomRoom (, MatchmakingMode.FillRoom, typedLobby, sqlFilter);
    }
Ejemplo n.º 43
0
        /// <summary>
        /// Operation to join a random, available room. Overloads take additional player properties.
        /// This is an async request which triggers a OnOperationResponse() call.
        /// If all rooms are closed or full, the OperationResponse will have a returnCode of ErrorCode.NoRandomMatchFound.
        /// If successful, the OperationResponse contains a gameserver address and the name of some room.
        /// </summary>
        /// <param name="expectedCustomRoomProperties">Optional. A room will only be joined, if it matches these custom properties (with string keys).</param>
        /// <param name="expectedMaxPlayers">Filters for a particular maxplayer setting. Use 0 to accept any maxPlayer value.</param>
        /// <param name="playerProperties">This player's properties (custom and well known).</param>
        /// <param name="matchingType">Selects one of the available matchmaking algorithms. See MatchmakingMode enum for options.</param>
        /// <returns>If the operation could be sent currently (requires connection).</returns>
        public virtual bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, Hashtable playerProperties, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinRandomRoom()");
            }

            Hashtable expectedRoomProperties = new Hashtable();
            expectedRoomProperties.MergeStringKeys(expectedCustomRoomProperties);
            if (expectedMaxPlayers > 0)
            {
                expectedRoomProperties[GameProperties.MaxPlayers] = expectedMaxPlayers;
            }

            Dictionary<byte, object> opParameters = new Dictionary<byte, object>();
            if (expectedRoomProperties.Count > 0)
            {
                opParameters[ParameterCode.GameProperties] = expectedRoomProperties;
            }

            if (playerProperties != null && playerProperties.Count > 0)
            {
                opParameters[ParameterCode.PlayerProperties] = playerProperties;
            }

            if (matchingType != MatchmakingMode.FillRoom)
            {
                opParameters[ParameterCode.MatchMakingType] = (byte)matchingType;
            }

            if (typedLobby != null)
            {
                opParameters[ParameterCode.LobbyName] = typedLobby.Name;
                opParameters[ParameterCode.LobbyType] = (byte)typedLobby.Type;
            }

            if (!string.IsNullOrEmpty(sqlLobbyFilter))
            {
                opParameters[ParameterCode.Data] = sqlLobbyFilter;
            }

            // UnityEngine.Debug.LogWarning("OpJoinRandom: " + opParameters.ToStringFull());
            return this.OpCustom(OperationCode.JoinRandomGame, opParameters, true);
        }
Ejemplo n.º 44
0
        /// <summary>LoadBalancingPeer.OpJoinRoom</summary>
        public virtual bool OpJoinRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby, bool createIfNotExists, Hashtable playerProperties, bool onGameServer)
        {
            Dictionary<byte, object> op = new Dictionary<byte, object>();

            if (!string.IsNullOrEmpty(roomName))
            {
                op[ParameterCode.RoomName] = roomName;
            }
            if (createIfNotExists)
            {
                op[ParameterCode.CreateIfNotExists] = true;
                if (lobby != null)
                {
                    op[ParameterCode.LobbyName] = lobby.Name;
                    op[ParameterCode.LobbyType] = (byte)lobby.Type;
                }
            }

            if (onGameServer)
            {
                if (playerProperties != null && playerProperties.Count > 0)
                {
                    op[ParameterCode.PlayerProperties] = playerProperties;
                    op[ParameterCode.Broadcast] = true; // broadcast actor properties
                }


                if (createIfNotExists)
                {
                    if (roomOptions == null)
                    {
                        roomOptions = new RoomOptions();
                    }

                    Hashtable gameProperties = new Hashtable();
                    op[ParameterCode.GameProperties] = gameProperties;
                    gameProperties.MergeStringKeys(roomOptions.customRoomProperties);

                    gameProperties[GameProperties.IsOpen] = roomOptions.isOpen;
                    gameProperties[GameProperties.IsVisible] = roomOptions.isVisible;
                    gameProperties[GameProperties.PropsListedInLobby] = roomOptions.customRoomPropertiesForLobby;
                    if (roomOptions.maxPlayers > 0)
                    {
                        gameProperties[GameProperties.MaxPlayers] = roomOptions.maxPlayers;
                    }
                    if (roomOptions.cleanupCacheOnLeave)
                    {
                        op[ParameterCode.CleanupCacheOnLeave] = true;               // this is actually setting the room's config
                        gameProperties[GameProperties.CleanupCacheOnLeave] = true;  // this is only informational for the clients which join
                    }
                    if (roomOptions.suppressRoomEvents)
                    {
                        op[ParameterCode.SuppressRoomEvents] = true;
                    }
                }
            }

            // UnityEngine.Debug.Log("JoinGame: " + SupportClass.DictionaryToString(op));
            return this.OpCustom(OperationCode.JoinGame, op, true);
        }
Ejemplo n.º 45
0
    /// <summary>
    /// Attempts to join an open room with fitting, custom properties but fails if none is currently available.
    /// </summary>
    /// <remarks>
    /// Rooms can be created in arbitrary lobbies which get created on demand.
    /// You can join rooms from any lobby without actually joining the lobby with this overload.
    ///
    /// This method will only match rooms attached to one lobby! If you use many lobbies, you
    /// might have to repeat JoinRandomRoom, to find some fitting room.
    /// This method looks up a room in the specified lobby or the currently active lobby (if none specified)
    /// or in the default lobby (if none active).
    ///
    /// If this fails, you can still create a room (and make this available for the next who uses JoinRandomRoom).
    /// Alternatively, try again in a moment.
    ///
    /// In offlineMode, a room will be created but no properties will be set and all parameters of this
    /// JoinRandomRoom call are ignored. The event/callback OnJoinedRoom gets called (see enum PhotonNetworkingMessage).
    ///
    /// You can define an array of expectedUsers, to block player slots in the room for these users.
    /// The corresponding feature in Photon is called "Slot Reservation" and can be found in the doc pages.
    /// </remarks>
    /// <param name="expectedCustomRoomProperties">Filters for rooms that match these custom properties (string keys and values). To ignore, pass null.</param>
    /// <param name="expectedMaxPlayers">Filters for a particular maxplayer setting. Use 0 to accept any maxPlayer value.</param>
    /// <param name="matchingType">Selects one of the available matchmaking algorithms. See MatchmakingMode enum for options.</param>
    /// <param name="typedLobby">The lobby in which you want to lookup a room. Pass null, to use the default lobby. This does not join that lobby and neither sets the lobby property.</param>
    /// <param name="sqlLobbyFilter">A filter-string for SQL-typed lobbies.</param>
    /// <param name="expectedUsers">Optional list of users (by UserId) who are expected to join this game and who you want to block a slot for.</param>
    /// <returns>If the operation got queued and will be sent.</returns>
    public static bool JoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter, string[] expectedUsers = null)
    {
        if (offlineMode)
        {
            if (offlineModeRoom != null)
            {
                Debug.LogError("JoinRandomRoom failed. In offline mode you still have to leave a room to enter another.");
                return false;
            }
            EnterOfflineRoom("offline room", null, true);
            return true;
        }
        if (networkingPeer.Server != ServerConnection.MasterServer || !connectedAndReady)
        {
            Debug.LogError("JoinRandomRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
            return false;
        }

        typedLobby = typedLobby ?? ((networkingPeer.insideLobby) ? networkingPeer.lobby : null);  // use given lobby, or active lobby (if any active) or none

        OpJoinRandomRoomParams opParams = new OpJoinRandomRoomParams();
        opParams.ExpectedCustomRoomProperties = expectedCustomRoomProperties;
        opParams.ExpectedMaxPlayers = expectedMaxPlayers;
        opParams.MatchingType = matchingType;
        opParams.TypedLobby = typedLobby;
        opParams.SqlLobbyFilter = sqlLobbyFilter;
        opParams.ExpectedUsers = expectedUsers;

        return networkingPeer.OpJoinRandomRoom(opParams);
    }
Ejemplo n.º 46
0
    /// <summary>Lets you either join a named room or create it on the fly - you don't have to know if someone created the room already.</summary>
    /// <remarks>
    /// This makes it easier for groups of players to get into the same room. Once the group
    /// exchanged a roomName, any player can call JoinOrCreateRoom and it doesn't matter who
    /// actually joins or creates the room.
    ///
    /// The parameters roomOptions and typedLobby are only used when the room actually gets created by this client.
    /// You know if this client created a room, if you get a callback OnCreatedRoom (before OnJoinedRoom gets called as well).
    ///
    /// You can define an array of expectedUsers, to block player slots in the room for these users.
    /// The corresponding feature in Photon is called "Slot Reservation" and can be found in the doc pages.
    /// </remarks>
    /// <param name="roomName">Name of the room to join. Must be non null.</param>
    /// <param name="roomOptions">Options for the room, in case it does not exist yet. Else these values are ignored.</param>
    /// <param name="typedLobby">Lobby you want a new room to be listed in. Ignored if the room was existing and got joined.</param>
    /// <param name="expectedUsers">Optional list of users (by UserId) who are expected to join this game and who you want to block a slot for.</param>
    /// <returns>If the operation got queued and will be sent.</returns>
    public static bool JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby, string[] expectedUsers)
    {
        if (offlineMode)
        {
            if (offlineModeRoom != null)
            {
                Debug.LogError("JoinOrCreateRoom failed. In offline mode you still have to leave a room to enter another.");
                return false;
            }
            EnterOfflineRoom(roomName, roomOptions, true);  // in offline mode, JoinOrCreateRoom assumes you create the room
            return true;
        }
        if (networkingPeer.Server != ServerConnection.MasterServer || !connectedAndReady)
        {
            Debug.LogError("JoinOrCreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
            return false;
        }
        if (string.IsNullOrEmpty(roomName))
        {
            Debug.LogError("JoinOrCreateRoom failed. A roomname is required. If you don't know one, how will you join?");
            return false;
        }

        typedLobby = typedLobby ?? ((networkingPeer.insideLobby) ? networkingPeer.lobby : null);  // use given lobby, or active lobby (if any active) or none

        EnterRoomParams opParams = new EnterRoomParams();
        opParams.RoomName = roomName;
        opParams.RoomOptions = roomOptions;
        opParams.Lobby = typedLobby;
        opParams.CreateIfNotExists = true;
        opParams.PlayerProperties = player.customProperties;
        opParams.ExpectedUsers = expectedUsers;

        return networkingPeer.OpJoinRoom(opParams);
    }
Ejemplo n.º 47
0
 /// <summary>Lets you either join a named room or create it on the fly - you don't have to know if someone created the room already.</summary>
 /// <remarks>
 /// This makes it easier for groups of players to get into the same room. Once the group
 /// exchanged a roomName, any player can call JoinOrCreateRoom and it doesn't matter who
 /// actually joins or creates the room.
 ///
 /// The parameters roomOptions and typedLobby are only used when the room actually gets created by this client.
 /// You know if this client created a room, if you get a callback OnCreatedRoom (before OnJoinedRoom gets called as well).
 /// </remarks>
 /// <param name="roomName">Name of the room to join. Must be non null.</param>
 /// <param name="roomOptions">Options for the room, in case it does not exist yet. Else these values are ignored.</param>
 /// <param name="typedLobby">Lobby you want a new room to be listed in. Ignored if the room was existing and got joined.</param>
 /// <returns>If the operation got queued and will be sent.</returns>
 public static bool JoinOrCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
 {
     return JoinOrCreateRoom(roomName, roomOptions, typedLobby, null);
 }
    /// <summary>NetworkingPeer.OpJoinRandomRoom</summary>
    /// <remarks>this override just makes sure we have a mRoomToGetInto, even if it's blank (the properties provided in this method are filters. they are not set when we join the game)</remarks>
    public override bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, Hashtable playerProperties, MatchmakingMode matchingType, TypedLobby typedLobby, string sqlLobbyFilter)
    {
        this.mRoomToGetInto = new Room(null, null);
        this.mRoomToEnterLobby = null;  // join random never stores the lobby. the following join will not affect the room lobby
        // if typedLobby is null, the server will automatically use the active lobby or default, which is what we want anyways

        this.mLastJoinType = JoinType.JoinRandomGame;
        return base.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, playerProperties, matchingType, typedLobby, sqlLobbyFilter);
    }
Ejemplo n.º 49
0
    void OnGUI() // da alte GUI haben wir dies im Projekt nicht verwendet, war nur zu testzwecken
    {

        //zeigt Details über den derzeitigen Status im Photonnetzwerk an
        GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());

        //GUILayout.Label (PhotonNetwork.GetPing ().ToString ());

        //überprüft ob ich im Netzwerk und Lobby bin
        if (PhotonNetwork.insideLobby == true)
        {

            //Zeigt die Lobby Room-List und gestattet es Räume selbst zu erstellen
            GUI.Box(new Rect(Screen.width / 2.5f, Screen.height / 3, 400, 550), "");
            GUILayout.BeginArea(new Rect(Screen.width / 2.5f, Screen.height / 3f, 400, 500));
            GUI.color = Color.red;
            GUILayout.Box("Lobby");
            GUI.color = Color.white;

            GUILayout.Label("Room Name:");
            roomName = GUILayout.TextField(roomName); //hier kann man seinen Raumnamen eintragen
            GUILayout.Label("Max Amount of player 1-20:");
            maxPlayerString = GUILayout.TextField(maxPlayerString, 2); //Eingabe der max. SPieleranzahl in dem Raum

            //überprüft ob im maxplayerstring etwas eingetragen wurde
            if (maxPlayerString != "")
            {

                maxPlayer = int.Parse(maxPlayerString); // wandelt den maxPlayerString in ein Int um es folgend auszuwerten

                if (maxPlayer % 2 == 1) maxPlayer += 1; // wenn ungleiche Zahl dann +1 maxplayer
                if (maxPlayer > 20) maxPlayer = 20; // es können nicht mehr als 20 Spieler in den Raum
                if (maxPlayer == 0) maxPlayer = 2; // das Minimum an SPielern beträgt immer 2

            }
            else
            {
                maxPlayer = 2; // wenn nichts eingetragen wurde setzt es Standartwert von 2 Spielern
            }

            if (GUILayout.Button("Create Room"))
            {

                if (roomName != "" && maxPlayer > 0) //überprüft ob es einen Raumnamen gibt und ob die max Player Anzahl stimmt
                {

                    RoomOptions options = new RoomOptions(); ;
                    options.isOpen = true;
                    options.isVisible = true;
                    options.maxPlayers = maxPlayer;

                    TypedLobby lobby = new TypedLobby();
                    lobby.Type = LobbyType.Default;

                    PhotonNetwork.CreateRoom(roomName,options, lobby); // erstellt den Photonraum mit derzeitigen einstellungen
                    

                }
            }

            GUILayout.Space(20);
            GUI.color = Color.red;
            GUILayout.Box("Game Rooms");
            GUI.color = Color.white;
            GUILayout.Space(20);

            scrollPosition = GUILayout.BeginScrollView(scrollPosition, false, true, GUILayout.Width(400), GUILayout.Height(300));

            foreach (RoomInfo game in PhotonNetwork.GetRoomList()) // geht durch die anzahl an vorhandenen und offenen Räume
            {
                
                GUI.color = Color.green;
                GUILayout.Box(game.name + " " + game.playerCount + "/" + game.maxPlayers); //zeigt für jeden Raum Spieleranzahl und Name des RAums an
                GUI.color = Color.white;

                if (GUILayout.Button("Join Room"))
                {

                    PhotonNetwork.JoinRoom(game.name); //neben jedem Raum ist ein Button um diesem zu joinen
                }
            }

            GUILayout.EndScrollView();
            GUILayout.EndArea();


        }
    }
Ejemplo n.º 50
0
    /// <summary>
    /// Creates a room but fails if this room is existing already. Can only be called on Master Server.
    /// </summary>
    /// <remarks>
    /// When successful, this calls the callbacks OnCreatedRoom and OnJoinedRoom (the latter, cause you join as first player).
    /// If the room can't be created (because it exists already), OnPhotonCreateRoomFailed gets called.
    ///
    /// If you don't want to create a unique room-name, pass null or "" as name and the server will assign a roomName (a GUID as string).
    ///
    /// Rooms can be created in any number of lobbies. Those don't have to exist before you create a room in them (they get
    /// auto-created on demand). Lobbies can be useful to split room lists on the server-side already. That can help keep the room
    /// lists short and manageable.
    /// If you set a typedLobby parameter, the room will be created in that lobby (no matter if you are active in any).
    /// If you don't set a typedLobby, the room is automatically placed in the currently active lobby (if any) or the
    /// default-lobby.
    ///
    /// Call this only on the master server.
    /// Internally, the master will respond with a server-address (and roomName, if needed). Both are used internally
    /// to switch to the assigned game server and roomName.
    ///
    /// PhotonNetwork.autoCleanUpPlayerObjects will become this room's autoCleanUp property and that's used by all clients that join this room.
    /// </remarks>
    /// <param name="roomName">Unique name of the room to create. Pass null or "" to make the server generate a name.</param>
    /// <param name="roomOptions">Common options for the room like maxPlayers, initial custom room properties and similar. See RoomOptions type..</param>
    /// <param name="typedLobby">If null, the room is automatically created in the currently used lobby (which is "default" when you didn't join one explicitly).</param>
    public static bool CreateRoom(string roomName, RoomOptions roomOptions, TypedLobby typedLobby)
    {
        if (offlineMode)
        {
            if (offlineModeRoom != null)
            {
                Debug.LogError("CreateRoom failed. In offline mode you still have to leave a room to enter another.");
                return false;
            }

            offlineModeRoom = new Room(roomName, roomOptions);
            offlineModeRoom.masterClientId = 1;
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnCreatedRoom);
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
            return true;
        }

        if (networkingPeer.server != ServerConnection.MasterServer || !connectedAndReady)
        {
            Debug.LogError("CreateRoom failed. Client is not on Master Server or not yet ready to call operations. Wait for callback: OnJoinedLobby or OnConnectedToMaster.");
            return false;
        }

        return networkingPeer.OpCreateGame(roomName, roomOptions, typedLobby);
    }