Exemple #1
0
        public override JsonOperationResponseBase OnOperation(Arguments arguments, Authentication authentication)
        {
            Request request = new Request()
            {
                tags = arguments["tags"]
            };

            if (!authentication.IsSignedIn)
            {
                return(new Response()
                {
                    Error = "Not signed in"
                });
            }
            if (!authentication.HasAtLeastAuthenticationLevel(AuthenticationLevel.VerifiedUser))
            {
                return(new Response()
                {
                    Error = "You need to be verified to set your player tags"
                });
            }

            User user = UserManager.Instance.GetUserFromId(authentication.UserID);

            for (int i = 0; i < request.tags.Length; i++)
            {
                TagInfo tag = TagsManager.Instance.GetTag(request.tags[i]);
                if (!tag.Verified)
                {
                    return(new Response()
                    {
                        Error = "The tag \"" + tag.TagID + "\" is not verified, so you cant use it yet."
                    });
                }
                if (!tag.CanUseTag(user))
                {
                    return(new Response()
                    {
                        Error = "You're not authorized to use the \"" + tag.TagName + "\" tag."
                    });
                }
            }
            int maxTags = Utils.GetMaxPlayerTags(authentication);

            if (request.tags.Length > maxTags)
            {
                return(new Response()
                {
                    Error = "You can only have a max of " + maxTags + " tags"
                });
            }

            TagsManager.Instance.SaveUserTags(user.PlayfabID, new PlayerTagsInfo(request.tags));

            return(new Response()
            {
                message = "Updated tags for player with playfab id \"" + user.PlayfabID + "\""
            });
        }