Beispiel #1
0
    public void CreateGroup(string adminUsername, string password, string groupName)
    {
        var loginWithPlayFabRequest = new LoginWithPlayFabRequest {
            Username = adminUsername, Password = password
        };

        PlayFabClientAPI.LoginWithPlayFab(loginWithPlayFabRequest,
                                          delegate(LoginResult loginResult)
        {
            PlayFabAuthenticationAPI.GetEntityToken(new PlayFab.AuthenticationModels.GetEntityTokenRequest(),
                                                    delegate(GetEntityTokenResponse getEntityTokenResponse)
            {
                var createGroupRequest = new CreateGroupRequest {
                    GroupName = groupName,
                    Entity    = ConvertEntityKey(getEntityTokenResponse.Entity)
                };

                PlayFabGroupsAPI.CreateGroup(createGroupRequest,
                                             delegate(CreateGroupResponse response)
                {
                    Debug.Log("Group was successfully created: " + response.GroupName + " -  " + response.Group.Id);
                },
                                             SharedError.OnSharedError);
            },
                                                    SharedError.OnSharedError);
        },
                                          SharedError.OnSharedError);
    }
Beispiel #2
0
        public void ListMembershipOpportunities(Action <ListMembershipOpportunitiesResponse> callback)
        {
            var request = new ListMembershipOpportunitiesRequest {
                Entity = PlayFabManager.Instance.GetUserGroupEntity()
            };

            PlayFabGroupsAPI.ListMembershipOpportunities(request, callback, (PlayFabError e) => callback(null));
        }
Beispiel #3
0
        public void ListGroupApplications(string groupId, Action <ListGroupApplicationsResponse> callback)
        {
            var request = new ListGroupApplicationsRequest {
                Group = EntityKeyMaker(groupId)
            };

            PlayFabGroupsAPI.ListGroupApplications(request, callback, (PlayFabError e) => callback(null));
        }
Beispiel #4
0
        public void DeleteGroup(string groupId)
        {
            // A title, or player-controlled entity with authority to do so, decides to destroy an existing group
            var request = new DeleteGroupRequest {
                Group = EntityKeyMaker(groupId)
            };

            PlayFabGroupsAPI.DeleteGroup(request, OnDeleteGroup, OnSharedError);
        }
Beispiel #5
0
        public void CreateGroup(string groupName, EntityKey entityKey)
        {
            // A player-controlled entity creates a new group
            var request = new CreateGroupRequest {
                GroupName = groupName, Entity = EntityKeyMaker(PlayFabManager.Instance.CurrentEntity.Id)
            };

            PlayFabGroupsAPI.CreateGroup(request, OnCreateGroup, OnSharedError);
        }
Beispiel #6
0
        public void ApplyToGroup(string groupId, EntityKey entityKey)
        {
            // A player-controlled entity applies to join an existing group (of which they are not already a member)
            var request = new ApplyToGroupRequest {
                Group = EntityKeyMaker(groupId), Entity = entityKey
            };

            PlayFabGroupsAPI.ApplyToGroup(request, OnApply, OnSharedError);
        }
Beispiel #7
0
        public void InviteToGroup(string groupId, EntityKey entityKey)
        {
            // A player-controlled entity invites another player-controlled entity to an existing group
            var request = new InviteToGroupRequest {
                Group = EntityKeyMaker(groupId), Entity = entityKey
            };

            PlayFabGroupsAPI.InviteToGroup(request, OnInvite, OnSharedError);
        }
Beispiel #8
0
        public void KickMember(string groupId, EntityKey entityKey)
        {
            var request = new RemoveMembersRequest {
                Group = EntityKeyMaker(groupId), Members = new List <EntityKey> {
                    entityKey
                }
            };

            PlayFabGroupsAPI.RemoveMembers(request, OnKickMembers, OnSharedError);
        }
Beispiel #9
0
        public void OnApply(ApplyToGroupResponse response)
        {
            var prevRequest = (ApplyToGroupRequest)response.Request;

            // Presumably, this would be part of a separate process where the recipient reviews and accepts the request
            var request = new AcceptGroupApplicationRequest {
                Group = prevRequest.Group, Entity = prevRequest.Entity
            };

            PlayFabGroupsAPI.AcceptGroupApplication(request, OnAcceptApplication, OnSharedError);
        }
Beispiel #10
0
        public void OnInvite(InviteToGroupResponse response)
        {
            var prevRequest = (InviteToGroupRequest)response.Request;

            // Presumably, this would be part of a separate process where the recipient reviews and accepts the request
            var request = new AcceptGroupInvitationRequest {
                Group = EntityKeyMaker(prevRequest.Group.Id), Entity = prevRequest.Entity
            };

            PlayFabGroupsAPI.AcceptGroupInvitation(request, OnAcceptInvite, OnSharedError);
        }
Beispiel #11
0
    public void InvitePlayerToGroup(string adminUsername, string password, string groupName, string usernameToAdd)
    {
        var loginWithPlayFabRequest = new LoginWithPlayFabRequest {
            Username = adminUsername, Password = password
        };

        PlayFabClientAPI.LoginWithPlayFab(loginWithPlayFabRequest,
                                          delegate(LoginResult loginResult)
        {
            var getGroupRequest = new GetGroupRequest()
            {
                GroupName = groupName
            };

            PlayFabGroupsAPI.GetGroup(getGroupRequest,
                                      delegate(GetGroupResponse getGroupResponse)
            {
                var getAccountInfoRequest = new GetAccountInfoRequest()
                {
                    Username = usernameToAdd
                };

                PlayFabClientAPI.GetAccountInfo(getAccountInfoRequest,
                                                delegate(GetAccountInfoResult getAccountInfoResult)
                {
                    var inviteToGroupRequest = new InviteToGroupRequest()
                    {
                        Group  = getGroupResponse.Group,
                        Entity = ConvertEntityKey(getAccountInfoResult.AccountInfo.TitleInfo.TitlePlayerAccount)
                    };

                    PlayFabGroupsAPI.InviteToGroup(inviteToGroupRequest,
                                                   delegate(InviteToGroupResponse inviteToGroupResponse)
                    {
                        Debug.Log("Admin username: "******" successfully added username: "******" to group: " + groupName);
                    },
                                                   SharedError.OnSharedError);
                },
                                                SharedError.OnSharedError);
            },
                                      SharedError.OnSharedError);
        },
                                          SharedError.OnSharedError);
    }
Beispiel #12
0
    public void AcceptInvitationToGroup(string usernameToAccept, string password, string groupName)
    {
        var loginWithPlayFabRequest = new LoginWithPlayFabRequest {
            Username = usernameToAccept, Password = password
        };

        PlayFabClientAPI.LoginWithPlayFab(loginWithPlayFabRequest,
                                          delegate(LoginResult loginResult)
        {
            var getAccountInfoRequest = new GetAccountInfoRequest()
            {
                Username = usernameToAccept
            };

            PlayFabClientAPI.GetAccountInfo(getAccountInfoRequest,
                                            delegate(GetAccountInfoResult getAccountInfoResult)
            {
                var getGroupRequest = new GetGroupRequest()
                {
                    GroupName = groupName
                };

                PlayFabGroupsAPI.GetGroup(getGroupRequest,
                                          delegate(GetGroupResponse getGroupResponse)
                {
                    var acceptGroupInvitationRequest = new AcceptGroupInvitationRequest()
                    {
                        Entity = ConvertEntityKey(getAccountInfoResult.AccountInfo.TitleInfo.TitlePlayerAccount),
                        Group  = getGroupResponse.Group
                    };

                    PlayFabGroupsAPI.AcceptGroupInvitation(acceptGroupInvitationRequest,
                                                           delegate(EmptyResponse emptyResponse)
                    {
                        Debug.Log("Username: "******" has accepted an invitation to group: " + groupName);
                    },
                                                           SharedError.OnSharedError);
                },
                                          SharedError.OnSharedError);
            },
                                            SharedError.OnSharedError);
        },
                                          SharedError.OnSharedError);
    }
Beispiel #13
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            // Update the PlayFabSettings with dev secret key and title ID
            if (string.IsNullOrEmpty(PlayFabSettings.staticSettings.DeveloperSecretKey))
            {
                PlayFabSettings.staticSettings.DeveloperSecretKey = Environment.GetEnvironmentVariable("PlayFab.TitleSecret", EnvironmentVariableTarget.Process);
            }

            if (string.IsNullOrEmpty(PlayFabSettings.staticSettings.TitleId))
            {
                PlayFabSettings.staticSettings.TitleId = Environment.GetEnvironmentVariable("PlayFab.TitleId", EnvironmentVariableTarget.Process);
            }

            var titleResponse = await PlayFabAuthenticationAPI.GetEntityTokenAsync(new PlayFab.AuthenticationModels.GetEntityTokenRequest());

            var title      = titleResponse.Result.Entity;
            var titleToken = titleResponse.Result.EntityToken;

            log.LogInformation($"Title is  : {title.Id}");
            log.LogInformation($"Token is  : {titleToken}");

            var request = new PlayFab.GroupsModels.ListMembershipRequest()
            {
                Entity = new PlayFab.GroupsModels.EntityKey
                {
                    Id   = "7B66887BFE1A76CE",
                    Type = "title_player_account",
                }
            };

            log.LogInformation($"Request is  : {JsonConvert.SerializeObject(request)}");

            var result = await PlayFabGroupsAPI.ListMembershipAsync(request);

            var groups = result.Result.Groups;
            var msg    = $"group is {JsonConvert.SerializeObject(groups)}\n";

            return((ActionResult) new OkObjectResult($"{msg}"));
        }
Beispiel #14
0
    /*
     *  Find the entity group for the player's wish list, or create one if does not exist
     *
     *  @param player_entityKeyId: the entity ID of the player; for a title entity the ID should be;
     *      in most cases, this can be found in LoginResult.EntityToken.Entity.Id
     *  @param player_entityKeyType: the entity type of the player whose wish list we are searching
     *      for; should be title_player_account entity in most cases
     *
     *  Upon login, this function examines all entity groups that the player belongs to. For each group,
     *  the group name is compared to the nomenclature for wish list groups. If the group is not found,
     *  then one is created
     */

    public static void FindOrCreateWishList(string player_entityKeyId, string player_entityKeyType)
    {
        /* Create entity key for the ListMembership request */

        PlayFab.GroupsModels.EntityKey entity = new PlayFab.GroupsModels.EntityKey {
            Id = player_entityKeyId, Type = player_entityKeyType
        };

        var request = new ListMembershipRequest {
            Entity = entity
        };

        PlayFabGroupsAPI.ListMembership(request, membershipResult => {
            bool found = false; // Will tell us whether the wish list entity group exists

            /*
             *  Iterate through all groups the player belongs to. If the wish list entity group exists,
             *  it should be one of these groups
             */

            for (int i = 0; i < membershipResult.Groups.Count; i++)
            {
                string group_name = LoginClass.getPlayerEntityKeyId() + "wishlist";

                /* Compare the name of the group to the nomenclature the wish list entity group name will follow */

                if (membershipResult.Groups[i].GroupName.Equals(group_name))
                {
                    found = true; // If the name matches, we found the wish list entity group

                    /* Set the wish list group's entity ID and entity type so we can access the group in other functions */
                    WishList.group_entityKeyId   = membershipResult.Groups[i].Group.Id;
                    WishList.group_entityKeyType = membershipResult.Groups[i].Group.Type;

                    PlayFab.DataModels.EntityKey group_ek = new PlayFab.DataModels.EntityKey {
                        Id = membershipResult.Groups[i].Group.Id, Type = membershipResult.Groups[i].Group.Type
                    };
                    GetObjectsRequest getObjectsRequest = new GetObjectsRequest {
                        Entity = group_ek
                    };

                    /*  This is the wish list entity group. To get the wish list CSV, we need to get the object in that entity
                     *  group with the "wishlist" key
                     */

                    PlayFabDataAPI.GetObjects(getObjectsRequest, objectResult => {
                        if (!string.IsNullOrEmpty((string)objectResult.Objects["wishlist"].DataObject))
                        {
                            string wl = (string)objectResult.Objects["wishlist"].DataObject;
                            /* Set up the Unity game store. Specifically, change colors and button text if an item is on the wishlist */
                            StoreSetup.SetUpStore(wl, false);
                        }
                    }, error => { Debug.LogError(error.GenerateErrorReport()); });
                }
            }

            // AddPlayFabIdToGroup(); // Where should this go?


            /* Wish list entity group does not exist, so create one */
            if (!found)
            {
                /*
                 *  Wish list entity groups should follow the following nomenclature:
                 *  [PlayFab title ID] + "wishlist.
                 *
                 *  This nomenclature allows us to find the group by name in the future.
                 */
                string group_name = LoginClass.getPlayerEntityKeyId() + "wishlist";
                CreateWishlist(group_name);
            }
        }, error => { Debug.LogError(error.GenerateErrorReport()); });
    }