question

Muhammad Roshaan Tariq avatar image
Muhammad Roshaan Tariq asked

How to check if User is part of a group at the same time when using ListMembership function

Hi,

I have developed Clan System in my game and I have coded everything on server-side to make it more secure and I have used ListMembership function in which Title is the admin and using this function I am listing all the available or created groups to my players.

here's my server side code:

handlers.getAllGroupsList = function(args,context){
  var groupMembersList = entity.ListMembership({
          Entity:{
              Id: args.Id,
              Type: "title",
              TypeString: "title"
          }
      });
       
      return groupMembersList;
};


handlers.checkIfGroupMember = function(args,context){
  var checkMemberRequest = {
      "Group": {
          "Id": args.groupID
      },
      "Entity":{
          "Id": args.userID,
          "Type": "title_player_account",
          "TypeString": "title_player_account"
      }
  };
  
  var response = entity.IsMember(checkMemberRequest);
  return response;
};

The next step I am doing is to show the users if they are part of the group or not? So I used IsMember function and it returns the value on which I modify my UI/UX

Now when I am doing this on client side using a loop in which I call my function against each groupID and check if the current player is the member or not.

here's my client side code:

public void ShowAvailableClans()
{
    ObjectUtilities.Instance.DeleteAllInstantiatedObjects(clanPrefabList);
    StartCoroutine(ShowClanAsync());
}


private IEnumerator ShowClanAsync()
{
    Home.Instance.BlurCanvasForBlocking(true);
    PlayfabClan.Instance.GetAllGroupsList();
    yield return new WaitUntil(() => PlayfabClan.Instance.requestCompleted == true);


    for(int i = 0; i < PlayfabClan.Instance.myGroups.Groups.Count; i++)
    {
        int index = i;
        GameObject temp = Instantiate(joinClanPrefab, joinClanParent);
        clanPrefabList.Add(temp);


        temp.transform.GetChild(0).GetComponent<Text>().text = PlayfabClan.Instance.myGroups.Groups[index].GroupName;
        PlayfabClan.Instance.CheckGroupMembership(PlayfabClan.Instance.myGroups.Groups[index].Group.Id);
        yield return new WaitUntil(() => PlayfabClan.Instance.requestCompleted == true);


        if (PlayfabClan.Instance.groupMemberInfo.IsMember)
        {
            temp.transform.GetChild(1).GetComponentInChildren<Text>().text = "Leave";


            Button button = temp.GetComponentInChildren<Button>();
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => LeaveGroup(PlayfabClan.Instance.myGroups.Groups[index].Group.Id));
        }


        else
        {
            temp.transform.GetChild(1).GetComponentInChildren<Text>().text = "Join";


            Button button = temp.GetComponentInChildren<Button>();
            button.onClick.RemoveAllListeners();
            button.onClick.AddListener(() => JoinGroup(PlayfabClan.Instance.myGroups.Groups[index].Group.Id));
        }
    }


    Home.Instance.BlurCanvasForBlocking(false);
    StopCoroutine(ShowClanAsync());
}

Now it is a time taking process and I want to do something in which I send the list of groupID and it returns me the list of booleans indicating my player's membership in each group.

apissdksCloudScriptentities
10 |1200

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

Sarah Zhang avatar image
Sarah Zhang answered

Currently, IsMember is the only PlayFab API that can directly check to see if an entity is a member of a group or role within the group. You can combine it with your custom code to encapsulate your own functions on CloudScript to implement the batch checking feature. Please refer to the limitations of Cloud Script of your title(navigate to https://developer.playfab.com/en-US/[TitleId]/limits to check them)to design this method.

10 |1200

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

Muhammad Roshaan Tariq avatar image
Muhammad Roshaan Tariq answered

@Sarah Zhang

Can you please guide me through how can I combine APIs?

5 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.

Sarah Zhang avatar image Sarah Zhang commented ·

I checked your question again. Actually, if what you are concerned about is the long execution time. Writing a custom method on CloudScript cannot solve the problem. To improve execution efficiency, we should play multithreaded performance on the client or server. Could you please tell us which is the platform of the client? Is it Unity? Besides, please provide the current execution time as a reference.

0 Likes 0 ·
Muhammad Roshaan Tariq avatar image Muhammad Roshaan Tariq Sarah Zhang commented ·

@Sarah Zhang

Yes the platform is Unity and about execution time is 19 seconds approx on my PC. And total number of groups loaded are 19 which makes it 1 second per group

(This is the time in which I load the group from server and then also check it's membership from server)

This is why I'm looking for a way to combine these two functions into one so that I don't have to use a loop as mentioned above in question

0 Likes 0 ·
Sarah Zhang avatar image Sarah Zhang Muhammad Roshaan Tariq commented ·

We test to call the getAllGroupsList function once on the client, add the GroupID to a list manually then call checkIfGroupMember asynchronously (just call this function in the loop but don't use WaitUntil). The execution time can be greatly reduced.

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.