question

Dylan Ravel avatar image
Dylan Ravel asked

Grabbing IsBanned from UserTitleInfo

Is it possible to get user bans, similar to how I'm grabbing the username using InfoRequestParameters?

             var request = new LoginWithEmailAddressRequest
             {
                 Email = PlayerPrefs.GetString("savedPlayFabLogin", ""),
                 Password = PlayerPrefs.GetString("savedPlayFabPassword", ""),
                 InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
                 {
                     GetPlayerProfile = true
                 }
             };
    
             // * Sends a log in request to PlayFab
             PlayFabClientAPI.LoginWithEmailAddress(request, result => {
                 instance.playerUsername = result.InfoResultPayload.PlayerProfile.DisplayName;
             }, error => {
                 // handles error stuff
             });

Documentation for InfoRequestParameters: https://learn.microsoft.com/en-us/rest/api/playfab/client/authentication/login-with-playfab?view=playfab-rest#request-body

Documentation for UserTitleInfo and isBanned: https://learn.microsoft.com/en-us/rest/api/playfab/client/authentication/login-with-playfab?view=playfab-rest#usertitleinfo

I'm just confused what the syntax is for grabbing UserTitleInfo and then inside that checking "isBanned"

Player Dataunity3dsdksTitle Data
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

·
Neils Shi avatar image
Neils Shi answered

If you want to get the player's ban status, you can refer to my sample code, and please note that you need to enable “Allow client to view ban reason and duration” in Game Manager->Title Setting-> API Features.

 string playerUsername;
 bool isBanned;
     void Start()
     {
         var request = new LoginWithEmailAddressRequest
         {
             Email = "",
             Password = "",
             InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
             {
                 GetPlayerProfile = true,
                 GetUserAccountInfo = true,
             }
         };
    
         // * Sends a log in request to PlayFab
         PlayFabClientAPI.LoginWithEmailAddress(request, result => {
             Debug.Log("playerUsername:"+ result.InfoResultPayload.PlayerProfile.DisplayName);
             Debug.Log("IsBanned:" + result.InfoResultPayload.AccountInfo.TitleInfo.isBanned);
         }, error => {
             if (error.Error == PlayFabErrorCode.AccountBanned)
             {
                 isBanned = true;
             }
             Debug.Log("ErrorMessage:" + error.ErrorMessage);
             Debug.Log("isBanned:"+isBanned);
    
             foreach (KeyValuePair<string, List<string>> kvp in error.ErrorDetails)
             {
                 string BanReason = kvp.Key;
                 List<string> Expires = kvp.Value;
                 Debug.Log("BanReason: " + BanReason);
                 foreach (string value in Expires)
                 {
                     Debug.Log("Expires: " + value);
                 }
             }
         });
10 |1200

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

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.