コード例 #1
0
        /// <summary>
        /// Sets only custom game properties (which exclusively use strings as key-type in hash).
        /// </summary>
        /// <param name="gameProperties">The roomProperties to udpate or set.</param>
        /// <returns></returns>
        public bool OpSetCustomPropertiesOfRoom(Hashtable gameProperties)
        {
            Hashtable customGameProps = new Hashtable();
            customGameProps.MergeStringKeys(gameProperties);

            return this.OpSetPropertiesOfRoom(customGameProps);
        }
コード例 #2
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>
        /// <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);
        }
コード例 #3
0
        /// <summary>
        /// Sets custom properties of a player / actor (only passing on the string-typed custom properties).
        /// Use this only when in state Joined.
        /// </summary>
        /// <param name="actorNr">ID of player to update/set properties for.</param>
        /// <param name="actorProperties">The properties to set for target actor.</param>
        /// <returns>If sending the properties to the server worked (not if the operation was executed successfully).</returns>
        public bool OpSetCustomPropertiesOfActor(int actorNr, Hashtable actorProperties)
        {
            Hashtable customActorProperties = new Hashtable();
            customActorProperties.MergeStringKeys(actorProperties);

            return this.OpSetPropertiesOfActor(actorNr, customActorProperties);
        }
コード例 #4
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="isVisible">Defines if this room is listed in the lobby. If not, it also is not joined randomly.</param>
        /// <param name="isOpen">Defines if this room can be joined at all.</param>
        /// <param name="maxPlayers">Max number of players that can be in the room at any time. 0 means "no limit".</param>
        /// <param name="customGameProperties">The room's custom properties to set. Use string keys!</param>
        /// <param name="propsListedInLobby">Defines the custom room properties that get listed in the lobby. Null defaults to "none", a string[0].</param>
        /// <param name="playerProperties">This player's custom properties. Use string keys!</param>
        /// <returns>If the operation could be sent (requires connection).</returns>
        public virtual bool OpCreateRoom(string roomName, bool isVisible, bool isOpen, byte maxPlayers, Hashtable customGameProperties, string[] propsListedInLobby, Hashtable playerProperties)
        {
            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] = (propsListedInLobby == null) ? new string[0] : propsListedInLobby;
            gameProperties.MergeStringKeys(customGameProperties);
            if (maxPlayers > 0)
            {
                gameProperties[GameProperties.MaxPlayers] = maxPlayers;
            }

            Dictionary<byte, object> op = new Dictionary<byte, object>();
            op[ParameterCode.GameProperties] = gameProperties;
            op[ParameterCode.CleanupCacheOnLeave] = true;   // Note: This is not yet optional. It makes sense to get this into the API when caching is explained, too
            op[ParameterCode.Broadcast] = true;
            if (playerProperties != null)
            {
                op[ParameterCode.PlayerProperties] = playerProperties;
            }

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

            return this.OpCustom(OperationCode.CreateGame, op, true);
        }