Exemple #1
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)
    {
        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;
        }

        return(this.OpCustom(OperationCode.JoinRandomGame, opParameters, true));
    }
Exemple #2
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
                }
            }
        }

        // UnityEngine.Debug.Log("JoinGame: " + SupportClass.DictionaryToString(op));
        return(this.OpCustom(OperationCode.JoinGame, op, true));
    }
Exemple #3
0
    /// <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));
    }
Exemple #4
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));
    }
    /// <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 gameID, bool isVisible, bool isOpen, byte maxPlayers, bool autoCleanUp, Hashtable customGameProperties, Hashtable customPlayerProperties, string[] customRoomPropertiesForLobby)
    {
        Debug.Log(string.Format("OpCreateRoom:,gameid:{0},max:{1}", gameID, maxPlayers));
        if (this.DebugOut >= DebugLevel.INFO)
        {
            this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
        }

        Hashtable gameProperties = new Hashtable();

        gameProperties[GameProperties.IsOpen]             = isOpen;
        gameProperties[GameProperties.IsVisible]          = isVisible;
        gameProperties[GameProperties.PropsListedInLobby] = customRoomPropertiesForLobby;
        gameProperties.MergeStringKeys(customGameProperties);
        if (maxPlayers > 0)
        {
            gameProperties[GameProperties.MaxPlayers] = maxPlayers;
        }

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

        op[ParameterCode.GameProperties] = gameProperties;
        op[ParameterCode.Broadcast]      = true;

        if (customPlayerProperties != null)
        {
            op[ParameterCode.PlayerProperties] = customPlayerProperties;
        }

        if (!string.IsNullOrEmpty(gameID))
        {
            op[ParameterCode.RoomName] = gameID;
        }

        // server's default is 'false', so we actually only need to send this when 'true'
        if (autoCleanUp)
        {
            op[ParameterCode.CleanupCacheOnLeave] = autoCleanUp;
            gameProperties[GameProperties.CleanupCacheOnLeave] = autoCleanUp;
        }
        if (PhotonHandler.IsShowLog())
        {
            PhotonHandler.ShowLog("OpCreateRoom()");
        }
        return(this.OpCustom(OperationCode.CreateGame, op, true));
    }
    /// <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 gameID, bool isVisible, bool isOpen, byte maxPlayers, bool autoCleanUp, Hashtable customGameProperties, Hashtable customPlayerProperties, string[] customRoomPropertiesForLobby)
    {
        if (this.DebugOut >= DebugLevel.INFO)
        {
            this.Listener.DebugReturn(DebugLevel.INFO, "OpCreateRoom()");
        }

        Hashtable gameProperties = new Hashtable();
        gameProperties[GameProperties.IsOpen] = isOpen;
        gameProperties[GameProperties.IsVisible] = isVisible;
        gameProperties[GameProperties.PropsListedInLobby] = customRoomPropertiesForLobby;
        gameProperties.MergeStringKeys(customGameProperties);
        if (maxPlayers > 0)
        {
            gameProperties[GameProperties.MaxPlayers] = maxPlayers;
        }

        Dictionary<byte, object> op = new Dictionary<byte, object>();
        op[ParameterCode.GameProperties] = gameProperties;
        op[ParameterCode.Broadcast] = true;

        if (customPlayerProperties != null)
        {
            op[ParameterCode.PlayerProperties] = customPlayerProperties;
        }

        if (!string.IsNullOrEmpty(gameID))
        {
            op[ParameterCode.RoomName] = gameID;
        }

        // server's default is 'false', so we actually only need to send this when 'true'
        if (autoCleanUp)
        {
            op[ParameterCode.CleanupCacheOnLeave] = autoCleanUp;
            gameProperties[GameProperties.CleanupCacheOnLeave] = autoCleanUp;
        }

        return this.OpCustom(OperationCode.CreateGame, op, true);
    }
        private void RoomOptionsToOpParameters(Dictionary<byte, object> op, RoomOptions roomOptions)
        {
            if (roomOptions == null)
            {
                roomOptions = new RoomOptions();
            }

            Hashtable gameProperties = new Hashtable();
            gameProperties[GamePropertyKey.IsOpen] = roomOptions.isOpen;
            gameProperties[GamePropertyKey.IsVisible] = roomOptions.isVisible;
            gameProperties[GamePropertyKey.PropsListedInLobby] = (roomOptions.customRoomPropertiesForLobby == null) ? new string[0] : roomOptions.customRoomPropertiesForLobby;
            gameProperties.MergeStringKeys(roomOptions.customRoomProperties);
            if (roomOptions.maxPlayers > 0)
            {
                gameProperties[GamePropertyKey.MaxPlayers] = roomOptions.maxPlayers;
            }

            op[ParameterCode.GameProperties] = gameProperties;

            op[ParameterCode.CleanupCacheOnLeave] = roomOptions.cleanupCacheOnLeave;	// this is actually setting the room's config
            if (roomOptions.cleanupCacheOnLeave)
            {
                gameProperties[GamePropertyKey.CleanupCacheOnLeave] = true;  			// this is only informational for the clients which join
            }

            if (roomOptions.PlayerTtl > 0 || roomOptions.PlayerTtl == -1)
            {
                op[ParameterCode.CheckUserOnJoin] = true;               // this affects rejoining a room. requires a userId to be used. added in v1.67
                op[ParameterCode.PlayerTTL] = roomOptions.PlayerTtl;    // TURNBASED
                op[ParameterCode.EmptyRoomTTL] = roomOptions.PlayerTtl;
            }

            //if (roomOptions.EmptyRoomTtl > 0)
            //{
            //    op[ParameterCode.EmptyRoomTTL] = roomOptions.EmptyRoomTtl;   //TURNBASED
            //}
            if (roomOptions.suppressRoomEvents)
            {
                op[ParameterCode.SuppressRoomEvents] = true;
            }
            if (roomOptions.plugins != null)
            {
                op[ParameterCode.Plugins] = roomOptions.plugins;
            }
            if (roomOptions.publishUserId)
            {
                op[ParameterCode.PublishUserId] = true;
            }
        }
        /// <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>
        /// <returns>If the operation could be sent currently (requires connection).</returns>
        public virtual bool OpJoinRandomRoom(OpJoinRandomRoomParams opJoinRandomRoomParams)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinRandomRoom()");
            }

            Hashtable expectedRoomProperties = new Hashtable();
            expectedRoomProperties.MergeStringKeys(opJoinRandomRoomParams.ExpectedCustomRoomProperties);
            if (opJoinRandomRoomParams.ExpectedMaxPlayers > 0)
            {
                expectedRoomProperties[GamePropertyKey.MaxPlayers] = opJoinRandomRoomParams.ExpectedMaxPlayers;
            }

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

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

            if (opJoinRandomRoomParams.TypedLobby != null && !string.IsNullOrEmpty(opJoinRandomRoomParams.TypedLobby.Name))
            {
                opParameters[ParameterCode.LobbyName] = opJoinRandomRoomParams.TypedLobby.Name;
                opParameters[ParameterCode.LobbyType] = (byte) opJoinRandomRoomParams.TypedLobby.Type;
            }

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

            if (opJoinRandomRoomParams.ExpectedUsers != null && opJoinRandomRoomParams.ExpectedUsers.Length > 0)
            {
                opParameters[ParameterCode.Add] = opJoinRandomRoomParams.ExpectedUsers;
            }

            // UnityEngine.Debug.LogWarning("OpJoinRandom: " + opParameters.ToStringFull());
            return this.OpCustom(OperationCode.JoinRandomGame, opParameters, true);
        }
    /// <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);
            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;
        }

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

        return networkingPeer.OpJoinRandomRoom(expectedRoomProperties, 0, null, matchingType, typedLobby, sqlLobbyFilter);
    }
    /// <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)
    {
        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;
        }

        return this.OpCustom(OperationCode.JoinRandomGame, opParameters, true);
    }
        /// <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
                }
                if (roomOptions.suppressRoomEvents)
                {
                    op[ParameterCode.SuppressRoomEvents] = true;
                }
            }

            // UnityEngine.Debug.Log("CreateGame: " + SupportClass.DictionaryToString(op));
            return this.OpCustom(OperationCode.CreateGame, op, true);
        }
        /// <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);
        }
Exemple #13
0
    /// <summary>
    /// Attempts to join an open room with fitting, custom properties but fails if none is currently available.
    /// </summary>
    /// <remarks>
    /// 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.
    /// </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>
    public static void JoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchingType)
    {
        if (connectionStateDetailed == PeerState.Joining || connectionStateDetailed == PeerState.Joined || connectionStateDetailed == PeerState.ConnectedToGameserver)
        {
            Debug.LogError("JoinRandomRoom aborted: You can only join a room while not currently connected/connecting to a room.");
            return;
        }

        if (room != null)
        {
            Debug.LogError("JoinRandomRoom aborted: You are already in a room!");
            return;
        }

        if (offlineMode)
        {
            offlineMode_inRoom = true;
            NetworkingPeer.SendMonoMessage(PhotonNetworkingMessage.OnJoinedRoom);
        }
        else
        {
            Hashtable expectedRoomProperties = new Hashtable();
            expectedRoomProperties.MergeStringKeys(expectedCustomRoomProperties);
            if (expectedMaxPlayers > 0)
            {
                expectedRoomProperties[GameProperties.MaxPlayers] = expectedMaxPlayers;
            }

            networkingPeer.OpJoinRandomRoom(expectedRoomProperties, 0, null, matchingType);
        }
    }
        /// <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 alike).</param>
        /// <param name="matchingType">Selects one of the available matchmaking algorithms. See MatchmakingMode enum for options.</param>
        /// <param name="lobby">The lobby in which to find a room. Use null for default lobby.</param>
        /// <param name="sqlLobbyFilter">Basically the "where" clause of a sql statement. Use null for random game. Examples: "C0 = 1 AND C2 > 50". "C5 = \"Map2\" AND C2 > 10 AND C2 < 20"</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 lobby, string sqlLobbyFilter)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinRandomRoom()");
            }
            if (lobby == null)
            {
                lobby = TypedLobby.Default;
            }
            Hashtable expectedRoomProperties = new Hashtable();
            expectedRoomProperties.MergeStringKeys(expectedCustomRoomProperties);
            if (expectedMaxPlayers > 0)
            {
                expectedRoomProperties[GamePropertyKey.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 (!string.IsNullOrEmpty(lobby.Name))
            {
                opParameters[ParameterCode.LobbyName] = lobby.Name;
                opParameters[ParameterCode.LobbyType] = (byte)lobby.Type;
            }

            if (!string.IsNullOrEmpty(sqlLobbyFilter))
            {
                opParameters[ParameterCode.Data] = sqlLobbyFilter;
            }
            return this.OpCustom(OperationCode.JoinRandomGame, opParameters, true);
        }
        private void RoomOptionsToOpParameters(Dictionary<byte, object> op, RoomOptions roomOptions)
        {
            if (roomOptions == null)
            {
                roomOptions = new RoomOptions();
            }

            Hashtable gameProperties = new Hashtable();
            gameProperties[GamePropertyKey.IsOpen] = roomOptions.IsOpen;
            gameProperties[GamePropertyKey.IsVisible] = roomOptions.IsVisible;
            gameProperties[GamePropertyKey.PropsListedInLobby] = (roomOptions.CustomRoomPropertiesForLobby == null) ? new string[0] : roomOptions.CustomRoomPropertiesForLobby;
            gameProperties.MergeStringKeys(roomOptions.CustomRoomProperties);
            if (roomOptions.MaxPlayers > 0)
            {
                gameProperties[GamePropertyKey.MaxPlayers] = roomOptions.MaxPlayers;
            }
            op[ParameterCode.GameProperties] = gameProperties;

            op[ParameterCode.CleanupCacheOnLeave] = roomOptions.CleanupCacheOnLeave;

            if (roomOptions.CheckUserOnJoin)
            {
                op[ParameterCode.CheckUserOnJoin] = true;   //TURNBASED
            }

            if (roomOptions.PlayerTtl > 0 || roomOptions.PlayerTtl == -1)
            {
                op[ParameterCode.PlayerTTL] = roomOptions.PlayerTtl;   //TURNBASED
            }
            if (roomOptions.EmptyRoomTtl > 0)
            {
                op[ParameterCode.EmptyRoomTTL] = roomOptions.EmptyRoomTtl;   //TURNBASED
            }
            if (roomOptions.SuppressRoomEvents)
            {
                op[ParameterCode.SuppressRoomEvents] = true;
            }
            if (roomOptions.Plugins != null)
            {
                op[ParameterCode.Plugins] = roomOptions.Plugins;
            }
        }