question

software1103 avatar image
software1103 asked

How to remove player with "admin" role in group manager?

Hi, everyone.

I want to manage the players in group. In one word, I want not only to add new player, but also to remove existing player from the group.

I can remove the existing player with member role, but removing the player with admin role from group is difficult.

Is this so difficult to remove the player with admin role from group?

Is this possible? I want your guide to this.

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.

JayZuo avatar image
JayZuo answered

I understand your flow, that's why I said it's weird as this should work. And the following is the code I used to test

PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest { CustomId = "JayTest", CreateAccount = true },
        result =>
        {
            //Debug.Log(result.SessionTicket);
            //Id = result.PlayFabId;
            TitlePlayerEntityKey = result.EntityToken.Entity;
            Debug.Log("PlayFabID: " + result.PlayFabId + (result.NewlyCreated ? " is NewlyCreated at " : " logged in at ") + System.DateTime.Now.ToString());
            var Entity = new PlayFab.GroupsModels.EntityKey { Id = TitlePlayerEntityKey.Id, Type = TitlePlayerEntityKey.Type };
            PlayFabGroupsAPI.CreateGroup(new PlayFab.GroupsModels.CreateGroupRequest { Entity = Entity, GroupName = Random.Range(1000, 9999).ToString() },
                groupResponse =>
                {
                    Debug.Log("New Group: " + groupResponse.GroupName + " created with ID: " + groupResponse.Group.Id);
                    PlayFabGroupsAPI.RemoveMembers(new PlayFab.GroupsModels.RemoveMembersRequest { Group = groupResponse.Group, Members = new List<PlayFab.GroupsModels.EntityKey> { Entity } },
                        r => { Debug.Log("Player removed!"); },
                        error => { Debug.LogError(error.GenerateErrorReport()); });

                },
                error => { Debug.LogError(error.GenerateErrorReport()); });
        },
        error => { Debug.LogError(error.GenerateErrorReport()); });

I can remove the player who created the group. Although, I didn't add other players into this group, but it should also work.

1 comment
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 ·

Thanks Mr.@JayZuo for your help again.

I really and really appreciate to your sincere help. You are really uppermost.

I admire your skill and kind.

Thanks.

(My greeting is very late, I am sorry.)

0 Likes 0 ·
JayZuo avatar image
JayZuo answered

May I know how you remove existing players in a group? Usually, you should use RemoveMembers. As the document said, a member can always remove themselves from a group, regardless of permissions. So if it is the player himself want to leave the group, he can all RemoveMembers with no issue even he is "admin". If the player want to remove others in the group, then he should to be a "admin" as you won't want anyone in the group can remove others. By default, only the player who created the group will be "admin", others are "members". And "admin" can remove all others with RemoveMembers.

So I'm not sure what you mean it is difficult to remove the player with admin role from group. If you still have any problem, please share your scenario in detail and the error you encountered.

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 answered

Thanks @JayZuo.

I really appreciate to your help. And I am sorry my response is very late.

Above the post, you are right and I use RemoveMembers.

In this case, my idea is simple but I met a issue, and then I don't know the reason.

My scenario is like:

1. Player "A" creates the new group called "first". "A"'s role is "Admin".

2. Player "B" and "C" are added to the group (using your guide). The roles of "B" and "C" are "Members".

3. Remove the player from group.

3.1 And then "A" is removed from the group "first" and the other players are still remained in this group.

3.2 Or "B" or "C" is removed from the group and "A" is remained in this group.

I finished step 1, 2 and 3.2 but I met a problem in 3.1.

My problem is that Player "A" isn't removed from the group at all.

Is my idea impossible? Here is my remove function. Help me...

    /// <summary>
    /// Delete any player item from given group.
    /// </summary>
    /// <param name="groupId">GroupID of group deleting any player</param>
    /// <param name="entityKey">Entitykey of deleted player</param>
    public void RemoveMember(string groupId, EntityKey entityKey)
    {
        var request = new RemoveMembersRequest { Group = EntityKeyMaker(groupId), Members = new List<EntityKey> { entityKey } };
        PlayFab.PlayFabGroupsAPI.RemoveMembers(new RemoveMembersRequest
        {
            Group = EntityKeyMaker(groupId),
            Members = new List<EntityKey> { entityKey }
        },
        result =>
        {
            var prevRequest = (RemoveMembersRequest)result.Request;
            Debug.Log("Entity kicked from Group: " + prevRequest.Members[0].Id + " to " + prevRequest.Group.Id);
            EntityGroupPairs.Remove(new KeyValuePair<string, string>(prevRequest.Members[0].Id, prevRequest.Group.Id));
        },
        error => { Debug.LogError(error.GenerateErrorReport()); });
    }
2 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.

JayZuo avatar image JayZuo ♦ commented ·

That's weird, I can't reproduce your issue. Have you checked in Game Manager to see if "A" still in the group? Besides, are you sure you are using player "A" to call "RemoveMember"? If "B" or "C" tries to remove "A", this won't work and you may get an error.

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

Thanks for your reply.

-Have you checked in Game Manager to see if "A" still in the group?

Yes. I checked "A" was still in the group at the game manager.

It seems like you don't understand me correctly because of my wrong description.

What I want to make is:

At first, "A" creates the new game "room" (this means new group) to play with other players.

Next, "B" and "C" join to this room created by "A" and they play together.

And then, Because "A" want to escape from the game for a while, he click "Exit" button and then function above is called. So "A" is removed.

Because of this reason, I think that I use "A" to call "RemoveMember". But I can't remove "A" from the group in game manager. Why?

0 Likes 0 ·

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.