Beispiel #1
0
        protected virtual OperationResponse HandleJoinLobby(MasterClientPeer peer, JoinLobbyRequest operation, SendParameters sendParameters)
        {
            try
            {
                // special handling for game properties send by AS3/Flash (Amf3 protocol) clients
                if (peer.Protocol.ProtocolType == ProtocolType.Amf3V152 || peer.Protocol.ProtocolType == ProtocolType.Json)
                {
                    Utilities.ConvertAs3WellKnownPropertyKeys(operation.GameProperties, null);
                }

                peer.GameChannelSubscription = null;

                var subscription = this.GameList.AddSubscription(peer, operation.GameProperties, operation.GameListCount);
                peer.GameChannelSubscription = subscription;
                peer.SendOperationResponse(new OperationResponse(operation.OperationRequest.OperationCode), sendParameters);


                // publish game list to peer after the response has been sent
                var gameList = subscription.GetGameList();
                var e = new GameListEvent { Data = gameList };
                var eventData = new EventData((byte)EventCode.GameList, e);
                peer.SendEvent(eventData, new SendParameters());

                return null;
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return null;
            }
        }
Beispiel #2
0
        protected virtual void ExecuteOperation(MasterClientPeer peer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            try
            {
                OperationResponse response;

                switch ((OperationCode)operationRequest.OperationCode)
                {
                    default:
                        response = new OperationResponse(operationRequest.OperationCode) { ReturnCode = -1, DebugMessage = "Unknown operation code" };
                        break;

                    case OperationCode.JoinLobby:
                        var joinLobbyRequest = new JoinLobbyRequest(peer.Protocol, operationRequest);
                        if (OperationHelper.ValidateOperation(joinLobbyRequest, log, out response))
                        {
                            response = this.HandleJoinLobby(peer, joinLobbyRequest, sendParameters);
                        }
                        break;

                    case OperationCode.LeaveLobby:
                        response = this.HandleLeaveLobby(peer, operationRequest);
                        break;

                    case OperationCode.CreateGame:
                        response = this.HandleCreateGame(peer, operationRequest);
                        break;

                    case OperationCode.JoinGame:
                        response = this.HandleJoinGame(peer, operationRequest);
                        break;

                    case OperationCode.JoinRandomGame:
                        response = this.HandleJoinRandomGame(peer, operationRequest);
                        break;

                    case OperationCode.DebugGame:
                        response = this.HandleDebugGame(peer, operationRequest);
                        break;
                }

                if (response != null)
                {
                    peer.SendOperationResponse(response, sendParameters);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
            }
        }
        public OperationResponse HandleJoinLobby(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var joinLobbyRequest = new JoinLobbyRequest(this.Protocol, operationRequest);

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

            if (joinLobbyRequest.LobbyType > 3)
            {
                return new OperationResponse
                {
                    OperationCode = operationRequest.OperationCode,
                    ReturnCode = (short)ErrorCode.OperationInvalid,
                    DebugMessage = "Invalid lobby type " + joinLobbyRequest.LobbyType
                };
            }

            // remove peer from the currently joined lobby
            if (this.AppLobby != null)
            {
                this.AppLobby.RemovePeer(this);
                this.AppLobby = null;
            }

            AppLobby lobby;
            if (!this.Application.LobbyFactory.GetOrCreateAppLobby(joinLobbyRequest.LobbyName, (AppLobbyType)joinLobbyRequest.LobbyType , out lobby))
            {
                // getting here should never happen
                if (log.IsWarnEnabled)
                {
                    log.WarnFormat("Could not get or create lobby: name={0}, type={1}", joinLobbyRequest.LobbyName, (AppLobbyType)joinLobbyRequest.LobbyType);
                }
                return new OperationResponse
                    {
                        OperationCode = operationRequest.OperationCode,
                        ReturnCode = (short)ErrorCode.InternalServerError,
                        DebugMessage = LBErrorMessages.CanNotCreateLobby,
                    };
            }

            this.AppLobby = lobby;
            this.AppLobby.JoinLobby(this, joinLobbyRequest, sendParameters);

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Joined lobby: {0}, {1}, u:'{2}'", joinLobbyRequest.LobbyName, joinLobbyRequest.LobbyType, this.UserId);
            }

            return null;
        }
Beispiel #4
0
 public void JoinLobby(MasterClientPeer peer, JoinLobbyRequest joinLobbyrequest, SendParameters sendParameters)
 {
     this.ExecutionFiber.Enqueue(() => this.HandleJoinLobby(peer, joinLobbyrequest, sendParameters));
 }
        public OperationResponse HandleJoinLobby(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var joinLobbyRequest = new JoinLobbyRequest(this.Protocol, operationRequest);
            
            OperationResponse response;
            if (OperationHelper.ValidateOperation(joinLobbyRequest, log, out response) == false)
            {
                return response;
            }

            // remove peer from the currently joined lobby
            if (this.AppLobby != null)
            {
                this.AppLobby.RemovePeer(this);
                this.AppLobby = null;
            }

            AppLobby lobby;
            if (!this.Application.LobbyFactory.GetOrCreateAppLobby(joinLobbyRequest.LobbyName, (AppLobbyType)joinLobbyRequest.LobbyType , out lobby))
            {
                return new OperationResponse
                    {
                        OperationCode = operationRequest.OperationCode,
                        ReturnCode = (short)ErrorCode.OperationDenied,
                        DebugMessage = "Cannot create lobby"
                    };
            }

            this.AppLobby = lobby;
            this.AppLobby.JoinLobby(this, joinLobbyRequest, sendParameters);

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Joined lobby: {0}, {1}", joinLobbyRequest.LobbyName, joinLobbyRequest.LobbyType);
            }

            return null;
        }