question

software1103 avatar image
software1103 asked

How to join group for new player

Hello, everyone.

I need to allow new player to join entity group, but can't find a way to do it.

At first, I used InviteToGroup for this, but the issue was thrown like this:

"The claim was not allowed to perform the requested action based on the entity's access policy. Policy comment: By default, all requests are denied. If you expected this request to succeed, you may be missing a policy."

So I tried out JSON like this

{
        "Action": "Read",
        "Effect": "Allow",
        "Resource": "pfrn:group--group!*/Members/*",
        "Principal": {
            "ChildOf": {
                "EntityType": "title",
                "EntityId": "F5AD"
            }
        },
        "Comment": "Allow all players to read group members",
        "Condition": null
    },
    {
        "Action": "Read",
        "Effect": "Allow",
        "Resource": "pfrn:group--group!*/Roles/*",
        "Principal": {
            "ChildOf": {
                "EntityType": "title",
                "EntityId": "F5AD"
            }
        },
        "Comment": "Allow all players to read group roles",
        "Condition": null
    }

But no success.

After on work, I found out this thread

https://community.playfab.com/questions/23938/way-to-join-entity-group.html

So I used AddMembers to solve my problem and at that time the issue like this.

"Only requests using a Title principal may directly add members to groups".

I know that only title claimants may add them to the group, and others must use the group application or invite system to add new members to a group.

But I don't know what "title claimant" is and how to use this.

And in the case of using InviteToGroup, I don't also know correct additional JSON.

Thanks...

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JayZuo avatar image
JayZuo answered

As I've said in your previous question, for your scenario, you can use AddMembers in Cloud Script. Cloud Script is hosted on PlayFab's server which identifies that process as a Title entity (title claimant). In the Cloud Script, you can use some code like the following:

handlers.addMember = function (args, context) {
    let group = { Id: args.GroupId, Type: "group" };
    let entityProfile = context.currentEntity;
    //... Some logic to determine whether the player can join this group...
    
    //If the user can, call AddMembers
    try {
        entity.AddMembers({ Group: group, Members: [entityProfile.Entity] });
    }
    catch (error) {
        log.error(error);
        return false;
    }
    return true;
}

And in client, you need call ExecuteEntityCloudScript to execute this function like

Besides, the policy you've posted is used for allowing all players to list members in the group not for invitation, so it won't work for your scenario.


4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

software1103 avatar image software1103 commented ·

I am sorry my reply is very late.

I really appreciate to your kind help. Thanks for your guide. I learn a lot about playfab today because I am new to playfab.

By the way, I am really sorry to say that the new player isn't still added to the group. What I want to know is how to send the new player's entity(id and entity type) to the cloudscript, but I dont know the reason.

Would you like to teach the resolution to me?

Besides, I am using Unity c# in client, so I use PlayFabClientAPI.ExecuteCloudScript to call handler.function.

Thanks @JayZuo..

0 Likes 0 ·
JayZuo avatar image JayZuo ♦ software1103 commented ·

For Unity, the code might like

PlayFabCloudScriptAPI.ExecuteEntityCloudScript(new PlayFab.CloudScriptModels.ExecuteEntityCloudScriptRequest
{
    FunctionName = "addMember",
    FunctionParameter = new { GroupId = "Id of the group to join" },
    GeneratePlayStreamEvent = true
}, result =>
{
    if ((bool)result.FunctionResult == true)
    {
        //Add into group successfully
    }
    else
    {
        //Can't join this group, maybe blocked by your logic or an error occurred in AddMembers call.
    }
}, error => { Debug.LogError(error.GenerateErrorReport()); });

Before using this method, you need to login the new player first and if you didn't set the Entity property, it will use the logged-in player's "title_player_account" entity by default. For your scenario, I think you don't need to set it as this method should be called by the player who want to join this group when he click the "room name".

-1 Like -1 ·
software1103 avatar image software1103 JayZuo ♦ commented ·

THANK YOU VERY AND VERY MUCH FOR YOUR GREAT HELP, @JayZuo!!!

My engine works well. This results because of your guide. Thanks.

You are the uppermost. I don't forget your help.Because I am new to playfab, I depend on the documentation of playfab a lot in many case. But I can not find out your guide data. What is the reason?

I want for you to answer to my question in the future.Thank you.

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.