Exemplo n.º 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();

            // 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);
        }
Exemplo n.º 2
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 (operationRequest.OperationCode)
            {
                case (byte)OperationCode.Join:
                    var joinOperation = new JoinRequest(peer.Protocol, operationRequest);
                    if (peer.ValidateOperation(joinOperation, sendParameters) == false)
                    {
                        return;
                    }

                    this.HandleJoinOperation(peer, joinOperation, sendParameters);

                    return;
                case (byte)OperationCode.StartGame:
                    game.loadingServerToStartGame();
                    this.PublishGameData();
                    return;
            }
            //Log.Debug("OperationCode Registred " + operationRequest.OperationCode.ToString());
            base.ExecuteOperation(peer, operationRequest, sendParameters);
        }
Exemplo n.º 3
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);
            }

            // Real Add actor in Game Logic
            game.addPlayer(actor);
            return actor;
        }
Exemplo n.º 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);
            }
        }