question

Leonard Schultze avatar image
Leonard Schultze asked

How can I show the player if he is banned, for how long and why?

Hello, I want to show the player if, why and how long he is banned this is my code: if(error.Error == PlayFabErrorCode.AccountBanned) { foreach (var item in error.ErrorDetails) { string banReason = item.Key; string banTime = item.Value[0]; } } I always get this error message because of the first line: NullReferenceException: Object reference not set to an instance of an object.

Account Management
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

·
Seth Du avatar image
Seth Du answered

To be clear, if a player is banned, it is not allowed for this player to make any client API calls. Hence, during the active ban, they cannot query the ban details, unless you have external website that will show this information via server/admin API. Please not that Player can only get the AccountBanned error and there areno further details.

Since ban related APIs are contained in Admin and Server API, if you want to implement a system that players can review the ban history, you may implement the query on Cloud Script/Azure Function, and the ban details are provided in the success callback instead of error callback.

PlayFabServerAPI.GetUserBans( 
new PlayFab.ServerModels.GetUserBansRequest { 
PlayFabId = "xxxxxx" 
}, 
success=> {//for example 
print(success.BanData[0].Reason); 
print(success.BanData[0].Expires); 
}, 
fail=> { });  }
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.

Leonard Schultze avatar image Leonard Schultze commented ·

Thanks, now it works

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.