예제 #1
0
        private void HandleTokenlessAuthenticateRequest(
            OperationRequest operationRequest,
            SendParameters sendParameters,
            AuthenticateRequest request)
        {
            this.SetupPeer(request.UserId);

            if (log.IsDebugEnabled)
            {
                log.DebugFormat("HandleTokenlessAuthenticateRequest - Token Authentication done. UserId: {0}", this.UserId);
            }

            var response = new OperationResponse { OperationCode = operationRequest.OperationCode };
            this.SendOperationResponse(response, sendParameters);
        }
예제 #2
0
        protected override void OnOperationRequest(OperationRequest request, SendParameters sendParameters)
        {
            if (log.IsDebugEnabled)
            {
                if (request.OperationCode != (byte)Photon.Hive.Operations.OperationCode.RaiseEvent)
                {
                    log.DebugFormat("OnOperationRequest: conId={0}, opCode={1}", this.ConnectionId, request.OperationCode);
                }
            }

            this.LastActivity = DateTime.UtcNow;
            this.LastOperation = request.OperationCode;
            IsAuthenticated = true;

            if (request.OperationCode == (byte) OperationCode.Authenticate)
            {
                if (this.IsAuthenticated)
                {
                    this.SendOperationResponse(new OperationResponse(request.OperationCode)
                    {
                        ReturnCode = (short) ErrorCode.OperationDenied,
                        DebugMessage = LBErrorMessages.AlreadyAuthenticated
                    }, sendParameters);
                    return;
                }

                this.HandleAuthenticateOperation(request, sendParameters);
                return;
            }

            if (!this.IsAuthenticated)
            {
                this.SendOperationResponse(new OperationResponse(request.OperationCode)
                {
                    ReturnCode = (short)ErrorCode.OperationDenied,
                    DebugMessage = LBErrorMessages.NotAuthorized
                }, sendParameters);
                return;
            }

            switch (request.OperationCode)
            {
                case 100:
                    this.HandleCreateGameOperation(request, sendParameters);
                    return;

                case 101:
                    this.HandleJoinGameOperation(request, sendParameters);
                    return;

                case (byte)Photon.Hive.Operations.OperationCode.Leave:
                    this.HandleLeaveOperation(request, sendParameters);
                    return;

                case (byte)Photon.Hive.Operations.OperationCode.Ping:
                    this.HandlePingOperation(request, sendParameters);
                    return;

                case (byte)OperationCode.DebugGame:
                    this.HandleDebugGameOperation(request, sendParameters);
                    return;

                case (byte)Photon.Hive.Operations.OperationCode.RaiseEvent:
                case (byte)Photon.Hive.Operations.OperationCode.GetProperties:
                case (byte)Photon.Hive.Operations.OperationCode.SetProperties:
                case (byte)Photon.Hive.Operations.OperationCode.ChangeGroups:
                    this.HandleGameOperation(request, sendParameters);
                    return;

                case (byte)Hive.Operations.OperationCode.Rpc:

                    this.HandleRpcOperation(request, sendParameters);
                    return;
                case 1:
                    RoomReference room;
                    this.TryGetRoomReference((string)request.Parameters[255], out room);
                    var game = (Game) room.Room;
                    this.application.BroadCastEvent(new EventData(1, new Dictionary<byte, object> { { 1, "Hello World!" } }), game.Actors.Select(_ => _.Peer), sendParameters);
                    //this.SendEvent(new EventData(1, new Dictionary<byte, object> { {1, "Hello World!"} }), sendParameters);
                    return;
                default:
                    this.HandleUnknownOperationCode(request, sendParameters);
                    return;
            }
        }
예제 #3
0
        protected void HandleUnknownOperationCode(OperationRequest operationRequest, SendParameters sendParameters)
        {
            if (log.IsDebugEnabled)
            {
                log.DebugFormat("Unknown operation code: OpCode={0}", operationRequest.OperationCode);
            }

            this.SendOperationResponse(
                new OperationResponse(operationRequest.OperationCode)
            {
                ReturnCode = (short)ErrorCode.OperationInvalid,
                DebugMessage = LBErrorMessages.UnknownOperationCode
            }, sendParameters);
        }
예제 #4
0
        protected virtual void HandleRpcOperation(OperationRequest request, SendParameters sendParameters)
        {
            if (this.WebRpcHandler != null)
            {
                this.WebRpcHandler.HandleCall(this, this.UserId, request, this.AuthCookie, sendParameters);
                return;
            }

            this.SendOperationResponse(new OperationResponse
            {
                OperationCode = request.OperationCode,
                ReturnCode = (short)ErrorCode.OperationInvalid,
                DebugMessage = LBErrorMessages.RpcIsNotEnabled,
            }, sendParameters);
        }
예제 #5
0
        protected virtual void HandleDebugGameOperation(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var debugRequest = new DebugGameRequest(this.Protocol, operationRequest);
            if (this.ValidateOperation(debugRequest, sendParameters) == false)
            {
                return;
            }

            string debug = string.Format("DebugGame called from PID {0}. {1}", this.ConnectionId, this.GetRoomCacheDebugString(debugRequest.GameId));
            operationRequest.Parameters.Add((byte)ParameterCode.Info, debug);

            if (this.RoomReference == null)
            {
                Room room;
                // get a room without obtaining a reference:
                if (!this.TryGetRoomWithoutReference(debugRequest.GameId, out room))
                {
                    var response = new OperationResponse
                    {
                        OperationCode = (byte)OperationCode.DebugGame,
                        ReturnCode = (short)ErrorCode.GameIdNotExists,
                        DebugMessage = HiveErrorMessages.GameIdDoesNotExist
                    };

                    this.SendOperationResponse(response, sendParameters);
                    return;
                }

                room.EnqueueOperation(this, operationRequest, sendParameters);
            }
            else
            {
                this.RoomReference.Room.EnqueueOperation(this, operationRequest, sendParameters);
            }
        }
예제 #6
0
        protected virtual void HandleAuthenticateOperation(OperationRequest operationRequest, SendParameters sendParameters)
        {
            var request = new AuthenticateRequest(this.Protocol, operationRequest);
            if (this.ValidateOperation(request, sendParameters) == false)
            {
                return;
            }

            if (request.ClientAuthenticationType == 255
                || !string.IsNullOrEmpty(request.Token)
                || AuthSettings.Default.Enabled
                )
            {
                var response = this.HandleAuthenticateTokenRequest(request);

                if (log.IsDebugEnabled)
                {
                    log.DebugFormat(
                        "HandleAuthenticateRequest - Token Authentication done. Result: {0}; msg={1}",
                        response.ReturnCode,
                        response.DebugMessage);
                }

                this.SendOperationResponse(response, sendParameters);
                return;
            }

            this.HandleTokenlessAuthenticateRequest(operationRequest, sendParameters, request);
        }