/// <summary>
        /// Generate a player PlayStream event for the provided function result.
        /// </summary>
        public void PostFunctionResultForPlayerTriggeredAction(PostFunctionResultForPlayerTriggeredActionRequest request, Action <EmptyResult> resultCallback, Action <PlayFabError> errorCallback, object customData = null, Dictionary <string, string> extraHeaders = null)
        {
            var context      = (request == null ? null : request.AuthenticationContext) ?? authenticationContext;
            var callSettings = apiSettings ?? PlayFabSettings.staticSettings;

            if (!context.IsEntityLoggedIn())
            {
                throw new PlayFabException(PlayFabExceptionCode.NotLoggedIn, "Must be logged in to call this method");
            }
            PlayFabHttp.MakeApiCall("/CloudScript/PostFunctionResultForPlayerTriggeredAction", request, AuthType.EntityToken, resultCallback, errorCallback, customData, extraHeaders, context, callSettings, this);
        }
Exemplo n.º 2
0
        public static Task PostResults(PlayerPlayStreamFunctionExecutionContext ctx, string functionName, object functionResult, int executionTime, ILogger log)
        {
            var request = new PostFunctionResultForPlayerTriggeredActionRequest
            {
                Entity = new EntityKey
                {
                    Id   = ctx.PlayerProfile.PlayerId,
                    Type = "master_player_account"
                },
                PlayerProfile           = ctx.PlayerProfile,
                PlayStreamEventEnvelope = ctx.PlayStreamEventEnvelope,
                FunctionResult          = new ExecuteFunctionResult
                {
                    ExecutionTimeMilliseconds = executionTime,
                    Error          = null,
                    FunctionName   = functionName,
                    FunctionResult = functionResult
                }
            };

            // TODO: Replace this code with an SDK call once an SDK is published that supports PostFunctionResultForPlayerTriggeredAction
            return(CallPostResultApi("PostFunctionResultForPlayerTriggeredAction", ctx.TitleAuthenticationContext, request, log));
        }
        /// <summary>
        /// Generate a player PlayStream event for the provided function result.
        /// </summary>
        public async Task <PlayFabResult <EmptyResult> > PostFunctionResultForPlayerTriggeredActionAsync(PostFunctionResultForPlayerTriggeredActionRequest request, object customData = null, Dictionary <string, string> extraHeaders = null)
        {
            await new PlayFabUtil.SynchronizationContextRemover();

            var requestContext  = request?.AuthenticationContext ?? authenticationContext;
            var requestSettings = apiSettings ?? PlayFabSettings.staticSettings;

            if (requestContext.EntityToken == null)
            {
                throw new PlayFabException(PlayFabExceptionCode.EntityTokenNotSet, "Must call Client Login or GetEntityToken before calling this method");
            }

            var httpResult = await PlayFabHttp.DoPost("/CloudScript/PostFunctionResultForPlayerTriggeredAction", request, "X-EntityToken", requestContext.EntityToken, extraHeaders, requestSettings);

            if (httpResult is PlayFabError)
            {
                var error = (PlayFabError)httpResult;
                PlayFabSettings.GlobalErrorHandler?.Invoke(error);
                return(new PlayFabResult <EmptyResult> {
                    Error = error, CustomData = customData
                });
            }

            var resultRawJson = (string)httpResult;
            var resultData    = PluginManager.GetPlugin <ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject <PlayFabJsonSuccess <EmptyResult> >(resultRawJson);
            var result        = resultData.data;

            return(new PlayFabResult <EmptyResult> {
                Result = result, CustomData = customData
            });
        }