Пример #1
0
        /// <summary>
        ///   Joins the peer to a <see cref = "LiteLobbyGame" />.
        ///   Called by <see cref = "HandleJoinOperation">HandleJoinOperation</see>.
        /// </summary>
        /// <param name = "joinOperation">
        ///   The join operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        protected virtual void HandleJoinGameWithLobby(JoinRequest joinOperation, SendParameters sendParameters)
        {
            // remove the peer from current game if the peer
            // allready joined another game
            this.RemovePeerFromCurrentRoom();

            RoomReference gameReference = null;
            if (joinOperation.ActorNr == 0)
            {
                // get a game reference from the game cache 
                // the game will be created by the cache if it does not exists allready
                gameReference = LiteLobbyGameCache.Instance.GetRoomReference(joinOperation.GameId, this, joinOperation.LobbyId);

            }
            else
            {
                if (!LiteLobbyGameCache.Instance.TryGetRoomReference(joinOperation.GameId, this, out gameReference))
                {
                    SendOperationResponse(
                        new OperationResponse
                        {
                            OperationCode = joinOperation.OperationRequest.OperationCode,
                            ReturnCode = -1,
                            DebugMessage = "the specified game is not exists."
                        },
                        sendParameters);
                    return;
                }
            }
            // save the game reference in peers state                    
            this.RoomReference = gameReference;

            // enqueue the operation request into the games execution queue
            gameReference.Room.EnqueueOperation(this, joinOperation.OperationRequest, sendParameters);
        }
Пример #2
0
        /// <summary>
        ///   Joins the peer to a <see cref = "LiteLobbyGame" />.
        ///   Called by <see cref = "HandleJoinOperation">HandleJoinOperation</see>.
        /// </summary>
        /// <param name = "joinOperation">
        ///   The join operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        protected virtual void HandleJoinGameWithLobby(JoinRequest joinOperation, SendParameters sendParameters)
        {
            // remove the peer from current game if the peer
            // allready joined another game
            this.RemovePeerFromCurrentRoom();

            // get a game reference from the game cache
            // the game will be created by the cache if it does not exists allready
            RoomReference gameReference = LiteLobbyGameCache.Instance.GetRoomReference(joinOperation.GameId, this, joinOperation.LobbyId);

            // save the game reference in peers state
            this.RoomReference = gameReference;

            // enqueue the operation request into the games execution queue
            gameReference.Room.EnqueueOperation(this, joinOperation.OperationRequest, sendParameters);
        }
Пример #3
0
        /// <summary>
        /// Dispatches the <see cref="JoinRequest"/> different from the base <see cref="LiteGame.ExecuteOperation">LiteGame.ExecuteOperation</see>.
        /// </summary>
        /// <param name="peer">
        /// The peer.
        /// </param>
        /// <param name="operationRequest">
        /// The operation request to execute.
        /// </param>
        /// <param name="sendParameters">
        /// The send Parameters.
        /// </param>
        protected override void ExecuteOperation(LitePeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            switch ((OperationCode)operationRequest.OperationCode)
            {
                case OperationCode.Join:
                    var joinOperation = new JoinRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(joinOperation, sendParameters) == false)
                    {
                        return;
                    }

                    this.HandleJoinOperation(peer, joinOperation, sendParameters);
                    return;
            }

            base.ExecuteOperation(peer, operationRequest, sendParameters);
        }
Пример #4
0
        /// <summary>
        ///   This override replaces the lite <see cref = "Lite.Operations.JoinRequest" /> with the lobby <see cref = "JoinRequest" /> and enables lobby support.
        /// </summary>
        /// <param name = "operationRequest">
        ///   The operation request.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        protected override void HandleJoinOperation(OperationRequest operationRequest, SendParameters sendParameters)
        {
            // create join operation from the operation request
            var joinRequest = new JoinRequest(this.Protocol, operationRequest);
            if (!this.ValidateOperation(joinRequest, sendParameters))
            {
                return;
            }

            // check the type of join operation
            if (joinRequest.GameId.EndsWith(LobbySuffix))
            {
                // the game name ends with the lobby suffix
                // the client wants to join a lobby
                this.HandleJoinLobby(joinRequest, sendParameters);
            }
            else if (string.IsNullOrEmpty(joinRequest.LobbyId) == false)
            {
                // the lobbyId is set
                // the client wants to join a game with a lobby
                this.HandleJoinGameWithLobby(joinRequest, sendParameters);
            }
            else
            {
                base.HandleJoinOperation(operationRequest, sendParameters);
            }
        }
Пример #5
0
        /// <summary>
        /// Executes the base <see cref="LiteGame.HandleJoinOperation">HandleJoinOperation</see> and then sends an updated game list to all <see cref="Actor"/>s in the lobby.
        /// </summary>
        /// <param name="peer">
        /// The peer.
        /// </param>
        /// <param name="joinRequest">
        /// The join request.
        /// </param>
        /// <param name="sendParameters">
        /// The send Parameters.
        /// </param>
        /// <returns>
        /// The new actor
        /// </returns>
        protected virtual Actor HandleJoinOperation(LitePeer peer, JoinRequest joinRequest, SendParameters sendParameters)
        {
            Actor actor = base.HandleJoinOperation(peer, joinRequest, sendParameters);
            if (actor != null)
            {
                this.PublishGameList(actor);
            }

            return actor;
        }
Пример #6
0
        //overritten to inject discussion lobby cache 
        /// <summary>
        ///   Joins the peer to a <see cref = "LiteLobby" />.
        ///   Called by <see cref = "HandleJoinOperation">HandleJoinOperation</see>.
        /// </summary>
        /// <param name = "joinRequest">
        ///   The join operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        protected override void HandleJoinLobby(JoinRequest joinRequest, SendParameters sendParameters)
        {
            _dbId = (int) joinRequest.ActorProperties[(byte) ActProps.DbId];
            var devType = (int) joinRequest.ActorProperties[(byte) ActProps.DevType];

            handleOnlineStatus(_photonPer, _dbId, true, devType);

            // remove the peer from current game if the peer
            // allready joined another game
            this.RemovePeerFromCurrentRoom();

            // get a lobby reference from the game cache 
            // the lobby will be created by the cache if it does not exists allready
            RoomReference lobbyReference = DiscussionLobbyCache.Instance.GetRoomReference(joinRequest.GameId);

            // save the lobby(room) reference in peers state                    
            this.RoomReference = lobbyReference;

            // enqueue the operation request into the games execution queue
            lobbyReference.Room.EnqueueOperation(this, joinRequest.OperationRequest, sendParameters);

            lobbyReference.Room.EnqueueOperation(this, new OperationRequest((byte) DiscussionOpCode.NotifyLeaveUser),
                                                 sendParameters);
        }
Пример #7
0
        /// <summary>
        ///   Joins the peer to a <see cref = "LiteLobbyGame" />.
        ///   Called by <see cref = "HandleJoinOperation">HandleJoinOperation</see>.
        ///   Overridden to inject custom discussion rooms
        /// </summary>
        /// <param name = "joinOperation">
        ///   The join operation.
        /// </param>
        /// <param name = "sendParameters">
        ///   The send Parameters.
        /// </param>
        protected override void HandleJoinGameWithLobby(JoinRequest joinOperation, SendParameters sendParameters)
        {
            _dbId = (int) joinOperation.ActorProperties[(byte) ActProps.DbId];
            var devType = (int) joinOperation.ActorProperties[(byte) ActProps.DevType];

            handleOnlineStatus(_photonPer, _dbId, true, devType);

            // remove the peer from current game if the peer
            // allready joined another game
            this.RemovePeerFromCurrentRoom();

            // get a game reference from the game cache 
            // the game will be created by the cache if it does not exists allready 
            RoomReference gameReference = DiscussionGameCache.Instance.GetRoomReference(joinOperation.GameId,
                                                                                        joinOperation.LobbyId);

            // save the game reference in peers state                    
            this.RoomReference = gameReference;

            // enqueue the operation request into the games execution queue
            gameReference.Room.EnqueueOperation(this, joinOperation.OperationRequest, sendParameters);

            ////no base.HandleJoinGameWithLobby(), we've duplicated all its code here    

            RoomReference lobbyReference = DiscussionLobbyCache.Instance.GetRoomReference(joinOperation.LobbyId);
            var discLobby = lobbyReference.Room as DiscussionLobby;
            if (discLobby != null)
                discLobby.SaveRoomName(joinOperation.GameId);
        }