コード例 #1
0
        /// <summary>
        /// Joins a specific room by name. If the room does not exist (yet), it will be created implicitly.
        /// </summary>
        /// <remarks>
        /// Unlike OpJoinRoom, this operation does not fail if the room does not exist.
        /// This can be useful when you send invitations to a room before actually creating it:
        /// Any invited player (whoever is first) can call this and on demand, the room gets created implicitly.
        ///
        /// 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. Only when the room gets created,
        /// the RoomOptions are set in this case.
        ///
        /// If this client returns to the room, set the previously used Player.ID as actorNumber.
        /// When you are using Custom Authentication with unique user IDs, the server will use the userID
        /// to find the previously assigned actorNumber in the room.
        ///
        /// For turnbased games, this is especially useful as rooms can be continued after hours or days.
        /// To return to a room, set the actorNumber to anything but 0. It's best practice to use -1 with
        /// Custom Authentication and unique user accounts.
        ///
        /// If the room is full or closed, this will fail. Override this class and implement
        /// OnOperationResponse(OperationResponse operationResponse) to get the errors.
        ///
        /// This method can only be called while the client is connected to a Master Server.
        /// You should check LoadBalancingClient.Server and LoadBalancingClient.IsConnectedAndReady before calling this method.
        /// Alternatively, check the returned bool value.
        ///
        /// While the server is joining the game, the State will be ClientState.Joining.
        /// It's set immediately when this method sends the Operation.
        ///
        /// If successful, the LoadBalancingClient will get a Game Server Address and use it automatically
        /// to switch servers and join the room. When you're in the room, this client's State will become
        /// ClientState.Joined (both, for joining or creating it).
        /// Set a OnStateChangeAction method to check for states.
        ///
        /// When entering the room, this client's Player Custom Properties will be sent to the room.
        /// Use LocalPlayer.SetCustomProperties to set them, even while not yet in the room.
        /// Note that the player properties will be cached locally and sent to any next room you would join, too.
        /// </remarks>
        /// <param name="roomName">The name of the room to join (might be created implicitly).</param>
        /// <param name="actorNumber">When returning to a room, use a non-0 value. For Turnbased games, set the previously assigned Player.ID or -1 when using Custom Authentication.</param>
        /// <param name="roomOptions">Contains the parameters and properties of the new room. See RoomOptions class for a description of each.</param>
        /// <param name="lobby">Typed lobby to be used if the roomname is not in use (and room gets created). If != null, it will also set CurrentLobby.</param>
        /// <returns>If the operation could be sent currently (requires connection to Master Server).</returns>
        public bool OpJoinOrCreateRoom(string roomName, int actorNumber, RoomOptions roomOptions, TypedLobby lobby)
        {
            if (roomOptions == null)
            {
                roomOptions = new RoomOptions();
            }
            this.State = ClientState.Joining;
            this.lastJoinType = JoinType.JoinOrCreateRoom;
            this.lastJoinActorNumber = actorNumber;
            this.createRoomOptions = roomOptions;
            this.CurrentRoom = CreateRoom(roomName, roomOptions);

            Hashtable playerPropsToSend = null;
            if (this.Server == ServerConnection.GameServer)
            {
                playerPropsToSend = this.LocalPlayer.AllProperties;
            }

            if (lobby != null) this.CurrentLobby = lobby;
            bool onGameServer = this.Server == ServerConnection.GameServer;
            return this.loadBalancingPeer.OpJoinRoom(roomName, playerPropsToSend, actorNumber, roomOptions, lobby, true, onGameServer);
        }
コード例 #2
0
        /// <summary>Operation to join a random room if available. You can use room properties to filter accepted rooms.</summary>
        /// <remarks>
        /// You can use expectedCustomRoomProperties and expectedMaxPlayers as filters for accepting rooms.
        /// If you set expectedCustomRoomProperties, a room must have the exact same key values set at Custom Properties.
        /// You need to define which Custom Room Properties will be available for matchmaking when you create a room.
        /// See: OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby)
        ///
        /// This operation fails if no rooms are fitting or available (all full, closed or not visible).
        /// Override this class and implement OnOperationResponse(OperationResponse operationResponse).
        ///
        /// OpJoinRandomRoom can only be called while the client is connected to a Master Server.
        /// You should check LoadBalancingClient.Server and LoadBalancingClient.IsConnectedAndReady before calling this method.
        /// Alternatively, check the returned bool value.
        ///
        /// While the server is looking for a game, the State will be Joining.
        /// It's set immediately when this method sent the Operation.
        ///
        /// If successful, the LoadBalancingClient will get a Game Server Address and use it automatically
        /// to switch servers and join the room. When you're in the room, this client's State will become
        /// ClientState.Joined (both, for joining or creating it).
        /// Set a OnStateChangeAction method to check for states.
        ///
        /// When joining a room, this client's Player Custom Properties will be sent to the room.
        /// Use LocalPlayer.SetCustomProperties to set them, even while not yet in the room.
        /// Note that the player properties will be cached locally and sent to any next room you would join, too.
        ///
        /// The parameter lobby can be null (using the defaul lobby) or a typed lobby you make up.
        /// Lobbies are created on the fly, as required by the clients. If you organize matchmaking with lobbies,
        /// keep in mind that they also fragment your matchmaking. Using more lobbies will put less rooms in each.
        ///
        /// The parameter sqlLobbyFilter can only be combined with the LobbyType.SqlLobby. In that case, it's used
        /// to define a sql-like "WHERE" clause for filtering rooms. This is useful for skill-based matchmaking e.g..
        ///
        /// More about matchmaking:
        /// http://doc.photonengine.com/en/realtime/current/reference/matchmaking-and-lobby
        /// </remarks>
        /// <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="matchmakingMode">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">Can be used with LobbyType.SqlLobby only. This is a "where" clause of a sql statement. Use null for random game.</param>
        /// <returns>If the operation could be sent currently (requires connection to Master Server).</returns>
        public bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchmakingMode, TypedLobby lobby, string sqlLobbyFilter)
        {
            if (lobby == null )
            {
                lobby = TypedLobby.Default;
            }
            this.State = ClientState.Joining;
            this.lastJoinType = JoinType.JoinRandomRoom;
            this.lastJoinActorNumber = 0;
            this.CurrentRoom = CreateRoom(null, new RoomOptions());

            Hashtable playerPropsToSend = null;
            if (this.Server == ServerConnection.GameServer)
            {
                playerPropsToSend = this.LocalPlayer.AllProperties;
            }

            this.CurrentLobby = lobby;
            return this.loadBalancingPeer.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, playerPropsToSend, matchmakingMode, lobby, sqlLobbyFilter);
        }
コード例 #3
0
        public bool OpJoinLobby(string name, LobbyType lobbyType)
        {
            TypedLobby lobby = new TypedLobby(name, lobbyType);
            bool sent = this.loadBalancingPeer.OpJoinLobby(lobby);
            if (sent)
            {
                this.CurrentLobby = lobby;
            }

            return sent;
        }
コード例 #4
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>
        /// <param name="lobby">The lobby join to. Use null for default lobby.</param>
        /// <returns>If the operation could be sent (has to be connected).</returns>
        public bool OpJoinLobby(TypedLobby lobby)
        {
            if (lobby == null)
            {
                lobby = TypedLobby.Default;
            }
            bool sent = this.loadBalancingPeer.OpJoinLobby(lobby);
            if (sent)
            {
                this.CurrentLobby = lobby;
            }

            return sent;
        }
コード例 #5
0
        /// <summary>
        /// Joins a room by name or creates new room if room with given name not exists.
        /// The OperationResponse depends on the server the peer is connected to:
        /// Master will return a Game Server to connect to.
        /// Game Server will return the joined Room's data.
        /// This is an async request which triggers a OnOperationResponse() call.
        /// </summary>
        /// <remarks>
        /// If the room is not existing (anymore), the OperationResponse will have a returnCode of ErrorCode.GameDoesNotExist.
        /// Other possible ErrorCodes are: GameClosed, GameFull.
        /// </remarks>
        /// <param name="roomName">The name of an existing room.</param>
        /// <param name="playerProperties">This player's custom properties.</param>
        /// <param name="actorId">To allow players to return to a game, they have to specify their actorId.</param>
        /// <param name="createRoomOptions">Options used for new room creation (only sent if createIfNotExists is true).</param>
        /// <param name="lobby">Typed lobby to be used if the roomname is not in use (and room gets created). It's never used when createIfNotExists is false.</param>
        /// <param name="createIfNotExists">Tells the server to create the room if it doesn't exist (if true).</param>
        /// <param name="onGameServer">Master- and Game-Server require different parameters. This allows us to optimize the requests based on the server type (unknown in peer).</param>
        /// <returns>If the operation could be sent (requires connection).</returns>
        public virtual bool OpJoinRoom(string roomName, Hashtable playerProperties, int actorId, RoomOptions createRoomOptions, TypedLobby lobby, bool createIfNotExists, bool onGameServer)
        {
            if (this.DebugOut >= DebugLevel.INFO)
            {
                this.Listener.DebugReturn(DebugLevel.INFO, "OpJoinOrCreateRoom()");
            }

            if (string.IsNullOrEmpty(roomName))
            {
                this.Listener.DebugReturn(DebugLevel.ERROR, "OpJoinOrCreateRoom() failed. Please specify a roomname.");
                return false;
            }

            Dictionary<byte, object> op = new Dictionary<byte, object>();
            op[ParameterCode.RoomName] = roomName;

            if (createIfNotExists)
            {
                op[ParameterCode.JoinMode] = (byte)JoinMode.CreateIfNotExists;
                if (lobby != null)
                {
                    op[ParameterCode.LobbyName] = lobby.Name;
                    op[ParameterCode.LobbyType] = (byte)lobby.Type;
                }
            }

            if (actorId != 0)
            {
                op[ParameterCode.JoinMode] = (byte)JoinMode.Rejoin;
                op[ParameterCode.ActorNr] = actorId;
            }

            if (onGameServer)
            {
                if (playerProperties != null)
                {
                    op[ParameterCode.PlayerProperties] = playerProperties;
                    op[ParameterCode.Broadcast] = true;
                }

                if (createIfNotExists)
                {
                    this.RoomOptionsToOpParameters(op, createRoomOptions);
                }
            }

            return this.OpCustom(OperationCode.JoinGame, op, true);
        }
コード例 #6
0
        /// <summary>
        /// Creates a new room on the server (or fails if the name is already in use).
        /// </summary>
        /// <remarks>
        /// 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). Room names are unique.
        ///
        /// A room will be attached to the specified lobby. Use null as lobby to attach the
        /// room to the lobby you are now in. If you are in no lobby, the default lobby is used.
        ///
        /// Multiple lobbies can help separate players by map or skill or game type. Each room can only be found
        /// in one lobby (no matter if defined by name and type or as default).
        ///
        /// This method can only be called while the client is connected to a Master Server.
        /// You should check LoadBalancingClient.Server and LoadBalancingClient.IsConnectedAndReady before calling this method.
        /// Alternatively, check the returned bool value.
        ///
        /// Even when sent, the Operation will fail (on the server) if the roomName is in use.
        /// Override this class and implement  OnOperationResponse(OperationResponse operationResponse) to get the errors.
        ///
        ///
        /// While the server is creating the game, the State will be ClientState.Joining.
        /// The state Joining is used because the client is on the way to enter a room (no matter if joining or creating).
        /// It's set immediately when this method sends the Operation.
        ///
        /// If successful, the LoadBalancingClient will get a Game Server Address and use it automatically
        /// to switch servers and enter the room. When you're in the room, this client's State will become
        /// ClientState.Joined (both, for joining or creating it).
        /// Set a OnStateChangeAction method to check for states.
        ///
        /// When entering the room, this client's Player Custom Properties will be sent to the room.
        /// Use LocalPlayer.SetCustomProperties to set them, even while not yet in the room.
        /// Note that the player properties will be cached locally and sent to any next room you would join, too.
        /// </remarks>
        /// <param name="roomName">The name to create a room with. Must be unique and not in use or can't be created. If null, the server will assign a GUID as name.</param>
        /// <param name="roomOptions">Contains the parameters and properties of the new room. See RoomOptions class for a description of each.</param>
        /// <param name="lobby">The lobby (name and type) in which to create the room. Null uses the current lobby or the default lobby (if not in a lobby).</param>
        /// <returns>If the operation could be sent currently (requires connection to Master Server).</returns>
        public bool OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby)
        {
            this.State = ClientState.Joining;
            this.lastJoinType = JoinType.CreateRoom;
            this.lastJoinActorNumber = 0;
            this.createRoomOptions = roomOptions;
            this.CurrentRoom = this.CreateRoom(roomName, roomOptions);

            Hashtable playerPropsToSend = null;
            if (this.Server == ServerConnection.GameServer)
            {
                playerPropsToSend = this.LocalPlayer.AllProperties;
            }

            this.CurrentLobby = lobby;
            bool onGameServer = this.Server == ServerConnection.GameServer;
            return this.loadBalancingPeer.OpCreateRoom(roomName, roomOptions, lobby, playerPropsToSend, onGameServer);
        }
コード例 #7
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>
        /// <param name="lobby">The lobby join to.</param>
        /// <returns>If the operation could be sent (has to be connected).</returns>
        public virtual bool OpJoinLobby(TypedLobby lobby)
        {
            if (lobby == null)
            {
                lobby = TypedLobby.Default;
            }
            Dictionary<byte, object> 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);
        }
コード例 #8
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 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);
        }
コード例 #9
0
        /// <summary>
        /// Creates a room (on either Master or Game Server).
        /// The OperationResponse depends on the server the peer is connected to:
        /// Master will return a Game Server to connect to.
        /// Game Server will return the joined Room's data.
        /// This is an async request which triggers a OnOperationResponse() call.
        /// </summary>
        /// <remarks>
        /// If the room is already existing, the OperationResponse will have a returnCode of ErrorCode.GameAlreadyExists.
        /// </remarks>
        /// <param name="roomName">The name of this room. Must be unique. Pass null to make the server assign a name.</param>
        /// <param name="roomOptions">Room creation options. Pass null for defaults.</param>
        /// <param name="lobby">Lobby this room gets added to. If null, current lobby (or default lobby) is used.</param>
        /// <param name="playerProperties">This player's custom properties. Use string keys!</param>
        /// <param name="onGameServer">This operation sends more parameters to the GameServer than to the MasterServer to optimize traffic.</param>
        /// <returns>If the operation could be sent (requires connection).</returns>
        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 && !string.IsNullOrEmpty(lobby.Name))
            {
                op[ParameterCode.LobbyName] = lobby.Name;
                op[ParameterCode.LobbyType] = lobby.Type;
            }

            // room- and player-props are only needed by the GameServer
            if (onGameServer)
            {
                if (playerProperties != null)
                {
                    op[ParameterCode.PlayerProperties] = playerProperties;
                    op[ParameterCode.Broadcast] = true;
                }

                this.RoomOptionsToOpParameters(op, roomOptions);
            }

            return this.OpCustom(OperationCode.CreateGame, op, true);
        }
コード例 #10
0
 void OnJoinLobby(TypedLobby lobby)
 {
     if (CurrentState != EntryState.Connecting) {
         // If it is not in connecting state, return
         return;
     }
     OutputRoomList();
     GameClientWrapper.ClientInstance.JoinRandomRoom(RoomPwd);
 }
コード例 #11
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>
        /// <param name="lobby">The lobby join to.</param>
        /// <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);
        }
コード例 #12
0
        /// <summary>Operation to join a random room if available. You can use room properties to filter accepted rooms.</summary>
        /// <remarks>
        /// You can use expectedCustomRoomProperties and expectedMaxPlayers as filters for accepting rooms.
        /// If you set expectedCustomRoomProperties, a room must have the exact same key values set at Custom Properties.
        /// You need to define which Custom Room Properties will be available for matchmaking when you create a room.
        /// See: OpCreateRoom(string roomName, RoomOptions roomOptions, TypedLobby lobby)
        ///
        /// This operation fails if no rooms are fitting or available (all full, closed or not visible).
        /// Override this class and implement OnOperationResponse(OperationResponse operationResponse).
        ///
        /// OpJoinRandomRoom can only be called while the client is connected to a Master Server.
        /// You should check LoadBalancingClient.Server and LoadBalancingClient.IsConnectedAndReady before calling this method.
        /// Alternatively, check the returned bool value.
        ///
        /// While the server is looking for a game, the State will be Joining.
        /// It's set immediately when this method sent the Operation.
        ///
        /// If successful, the LoadBalancingClient will get a Game Server Address and use it automatically
        /// to switch servers and join the room. When you're in the room, this client's State will become
        /// ClientState.Joined (both, for joining or creating it).
        /// Set a OnStateChangeAction method to check for states.
        ///
        /// When joining a room, this client's Player Custom Properties will be sent to the room.
        /// Use LocalPlayer.SetCustomProperties to set them, even while not yet in the room.
        /// Note that the player properties will be cached locally and sent to any next room you would join, too.
        ///
        /// The parameter lobby can be null (using the defaul lobby) or a typed lobby you make up.
        /// Lobbies are created on the fly, as required by the clients. If you organize matchmaking with lobbies,
        /// keep in mind that they also fragment your matchmaking. Using more lobbies will put less rooms in each.
        ///
        /// The parameter sqlLobbyFilter can only be combined with the LobbyType.SqlLobby. In that case, it's used
        /// to define a sql-like "WHERE" clause for filtering rooms. This is useful for skill-based matchmaking e.g..
        ///
        /// More about matchmaking:
        /// http://doc.photonengine.com/en/realtime/current/reference/matchmaking-and-lobby
        /// </remarks>
        /// <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="matchmakingMode">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">Can be used with LobbyType.SqlLobby only. This is a "where" clause of a sql statement. Use null for random game.</param>
        /// <returns>If the operation could be sent currently (requires connection to Master Server).</returns>
        public bool OpJoinRandomRoom(Hashtable expectedCustomRoomProperties, byte expectedMaxPlayers, MatchmakingMode matchmakingMode, TypedLobby lobby, string sqlLobbyFilter)
        {
            if (lobby == null)
            {
                lobby = TypedLobby.Default;
            }

            this.State = ClientState.Joining;
            this.lastJoinType = JoinType.JoinRandomRoom;
            this.CurrentLobby = lobby;

            this.enterRoomParamsCache = new LoadBalancingPeer.EnterRoomParams();
            this.enterRoomParamsCache.Lobby = lobby;

            LoadBalancingPeer.OpJoinRandomRoomParams opParams = new LoadBalancingPeer.OpJoinRandomRoomParams();
            opParams.ExpectedCustomRoomProperties = expectedCustomRoomProperties;
            opParams.ExpectedMaxPlayers = expectedMaxPlayers;
            opParams.MatchingType = matchmakingMode;
            opParams.TypedLobby = lobby;
            opParams.SqlLobbyFilter = sqlLobbyFilter;
            return this.loadBalancingPeer.OpJoinRandomRoom(opParams);

            //return this.loadBalancingPeer.OpJoinRandomRoom(expectedCustomRoomProperties, expectedMaxPlayers, playerPropsToSend, matchmakingMode, lobby, sqlLobbyFilter);
        }
コード例 #13
0
        /// <summary>
        /// Joins a specific room by name. If the room does not exist (yet), it will be created implicitly.
        /// </summary>
        /// <remarks>
        /// Unlike OpJoinRoom, this operation does not fail if the room does not exist.
        /// This can be useful when you send invitations to a room before actually creating it:
        /// Any invited player (whoever is first) can call this and on demand, the room gets created implicitly.
        ///
        /// 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. Only when the room gets created,
        /// the RoomOptions are set in this case.
        ///
        /// If this client returns to the room, set the previously used Player.ID as actorNumber.
        /// When you are using Custom Authentication with unique user IDs, the server will use the userID
        /// to find the previously assigned actorNumber in the room.
        ///
        /// For turnbased games, this is especially useful as rooms can be continued after hours or days.
        /// To return to a room, set the actorNumber to anything but 0. It's best practice to use -1 with
        /// Custom Authentication and unique user accounts.
        ///
        /// If the room is full or closed, this will fail. Override this class and implement
        /// OnOperationResponse(OperationResponse operationResponse) to get the errors.
        ///
        /// This method can only be called while the client is connected to a Master Server.
        /// You should check LoadBalancingClient.Server and LoadBalancingClient.IsConnectedAndReady before calling this method.
        /// Alternatively, check the returned bool value.
        ///
        /// While the server is joining the game, the State will be ClientState.Joining.
        /// It's set immediately when this method sends the Operation.
        ///
        /// If successful, the LoadBalancingClient will get a Game Server Address and use it automatically
        /// to switch servers and join the room. When you're in the room, this client's State will become
        /// ClientState.Joined (both, for joining or creating it).
        /// Set a OnStateChangeAction method to check for states.
        ///
        /// When entering the room, this client's Player Custom Properties will be sent to the room.
        /// Use LocalPlayer.SetCustomProperties to set them, even while not yet in the room.
        /// Note that the player properties will be cached locally and sent to any next room you would join, too.
        /// </remarks>
        /// <param name="roomName">The name of the room to join (might be created implicitly).</param>
        /// <param name="actorNumber">When returning to a room, use a non-0 value. For Turnbased games, set the previously assigned Player.ID or -1 when using Custom Authentication.</param>
        /// <param name="roomOptions">Contains the parameters and properties of the new room. See RoomOptions class for a description of each.</param>
        /// <param name="lobby">Typed lobby to be used if the roomname is not in use (and room gets created). If != null, it will also set CurrentLobby.</param>
        /// <returns>If the operation could be sent currently (requires connection to Master Server).</returns>
        public bool OpJoinOrCreateRoom(string roomName, int actorNumber, RoomOptions roomOptions, TypedLobby lobby)
        {
            this.State = ClientState.Joining;
            this.lastJoinType = JoinType.JoinOrCreateRoom;
            this.CurrentLobby = lobby;
            bool onGameServer = this.Server == ServerConnection.GameServer;

            LoadBalancingPeer.EnterRoomParams opParams = new LoadBalancingPeer.EnterRoomParams();
            this.enterRoomParamsCache = opParams;
            opParams.RoomName = roomName;
            opParams.ActorNumber = actorNumber;
            opParams.RoomOptions = roomOptions;
            opParams.Lobby = lobby;
            opParams.CreateIfNotExists = true;
            opParams.OnGameServer = onGameServer;

            return this.loadBalancingPeer.OpJoinRoom(opParams);
            //return this.loadBalancingPeer.OpJoinRoom(roomName, playerPropsToSend, actorNumber, roomOptions, lobby, true, onGameServer);
        }