Ejemplo n.º 1
0
        private void CreateGameOnGameServer()
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("GAME: Create game {0}", this.gameId);
            }

            var operation = new CreateGameRequest { GameId = this.gameId };
            var request = new OperationRequest((byte)OperationCode.CreateGame, operation);
            this.gameServerClient.SendOperationRequest(request, new SendParameters());
        }
Ejemplo n.º 2
0
        public OperationResponse HandleCreateGame(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var createGameRequest = new CreateGameRequest(this.Protocol, operationRequest);

            OperationResponse response;
            if (OperationHelper.ValidateOperation(createGameRequest, log, out response) == false)
            {
                return response;
            }


            if (string.IsNullOrEmpty(createGameRequest.LobbyName) && this.AppLobby != null)
            {
                this.AppLobby.EnqueueOperation(this, operationRequest, sendParameters);
                return null;
            }

            AppLobby lobby;
            if (!this.Application.LobbyFactory.GetOrCreateAppLobby(createGameRequest.LobbyName, (AppLobbyType)createGameRequest.LobbyType , out lobby))
            {
                return new OperationResponse
                    {
                        OperationCode = operationRequest.OperationCode,
                        ReturnCode = (short)ErrorCode.OperationDenied,
                        DebugMessage = "Lobby does not exists"
                    };
            }

            lobby.EnqueueOperation(this, operationRequest, sendParameters);
            return null;
        }
Ejemplo n.º 3
0
        protected virtual OperationResponse HandleCreateGame(MasterClientPeer peer, OperationRequest operationRequest)
        {
            // validate the operation request
            OperationResponse response;
            var operation = new CreateGameRequest(peer.Protocol, operationRequest);
            if (OperationHelper.ValidateOperation(operation, log, out response) == false)
            {
                return response;
            }

            // special handling for game properties send by AS3/Flash (Amf3 protocol) or JSON clients
            var protocol = peer.Protocol.ProtocolType;
            if (protocol == ProtocolType.Amf3V152 || protocol == ProtocolType.Json)
            {
                Utilities.ConvertAs3WellKnownPropertyKeys(operation.GameProperties, null);   // special treatment for game properties sent by AS3/Flash
            }

            // if no gameId is specified by the client generate a unique id 
            if (string.IsNullOrEmpty(operation.GameId))
            {
                operation.GameId = Guid.NewGuid().ToString();
            }
           
            // try to create game
            GameState gameState;
            bool gameCreated;
            if (!this.TryCreateGame(operation, operation.GameId, false, operation.GameProperties, out gameCreated, out gameState, out response))
            {
                return response;
            }

            // add peer to game
            gameState.AddPeer(peer);

            this.ScheduleCheckJoinTimeOuts();

            // publish operation response
            object createGameResponse = this.GetCreateGameResponse(peer, gameState);
            return new OperationResponse(operationRequest.OperationCode, createGameResponse);
        }
Ejemplo n.º 4
0
        protected virtual OperationResponse HandleCreateGame(MasterClientPeer peer, OperationRequest operationRequest)
        {
            // validate operation
            OperationResponse response;
            var operation = new CreateGameRequest(peer.Protocol, operationRequest);
            if (OperationHelper.ValidateOperation(operation, log, out response) == false)
            {
                return response;
            }

            // if no gameId is specified by the client generate a unique id
            if (string.IsNullOrEmpty(operation.GameId))
            {
                operation.GameId = Guid.NewGuid().ToString();
            }
            else
            {
                // check if a game with the specified id already exists
                if (this.GameList.ContainsGameId(operation.GameId))
                {
                    return new OperationResponse(operationRequest.OperationCode)
                        {
                            ReturnCode = (int)ErrorCode.GameIdAlreadyExists,
                            DebugMessage = "A game with the specified id already exist."
                        };
                }
            }

            // try to create game
            GameState gameState;
            if (!this.TryCreateGame(operation, operation.GameId, operation.GameProperties, out gameState, out response))
            {
                return response;
            }

            // add peer to game
            gameState.AddPeer(peer);

            // publish operation response
            object createGameResponse = this.GetCreateGameResponse(peer, gameState);
            return new OperationResponse(operationRequest.OperationCode, createGameResponse);
        }