question

Kim Strasser avatar image
Kim Strasser asked

How can I get the ban expiration time and show it to the player?

I have a banned player who uses LoginWithIOSDevice to log in. But he can't log in because he is still banned. Is it possible to display the ban creation and expiration time to the player when he tries to log in with LoginWithIOSDeviceID or LoginWithPlayFab?

I have tried to call my CloudScript but the call is not executed because the player is still banned. In addition, I don't know how to check in CloudScript if the expiration time of an active ban is greater than the current time.

How can I get the ban creation and expiration time and show it to the player when he tries to log in?

Is it necessary to automatically log out the player after a ban is created?

Right now, I don't get the ban creation and expiration time in the log in result and my CloudScript is not executed when the player is banned:

Client code:

private void RegisterGuestPlayFabAccount()
{
    PlayerDeviceId = ReturnMobileID();
    var requestIOS = new LoginWithIOSDeviceIDRequest { DeviceId = PlayerDeviceId, CreateAccount = false };
    var loginTask = PlayFabClientAPI.LoginWithIOSDeviceIDAsync(requestIOS);
    loginTask.ContinueWith(OnPlayFabRegisterGuestAccountComplete);
}

private void OnPlayFabRegisterGuestAccountComplete(Task<PlayFabResult<LoginResult>> task)
{
    var newLabel = "Unknown failure";
    if (task.Result.Result != null)
    {
     ...
    }
    if (task.Result.Error != null)
    {
        UserBans();
    }
}

private async Task UserBans()
{
    var result = await PlayFabClientAPI.ExecuteCloudScriptAsync(new ExecuteCloudScriptRequest()
    {
        FunctionName = "GetUserBans",
        GeneratePlayStreamEvent = true
    });

    if (result.Error != null)
        Console.WriteLine(result.Error.Error.ToString());
    else
    {
        if (result.Result.FunctionResult != null)
            Console.WriteLine(result.Result.FunctionResult);
    }
}

CloudScript:

handlers.GetUserBans = function (args, context)
{
    var result = GetUserBansFromCloudScript(currentPlayerId);
    var userbanned = "";
    var currenttime = "";

    if ((result != null) && (result.Error == null))
    {
        result.BanData.forEach(element => {
           if ((element.Active == true) && (element.Expires >= currenttime))
               return userbanned = element.Created.toString() + " " + element.Expires.toString() + " : " + element.Reason;
           else
               userbanned = "No active user bans found."
        });
    }
    else
        userbanned = "Not possible to get user bans."
        
        return userbanned;
}  
    
function GetUserBansFromCloudScript(PlayFabId)
{
    var contentBodyTemp = {
        "PlayFabId": PlayFabId
    };
    
    let url = "https://xxx.playfabapi.com/Admin/GetUserBans";
    let method = "POST";
    let contentBody = `{"PlayFabId": "${PlayFabId}"}`;
    let contentType = "application/json";
    let headers = { "X-SecretKey": "..." };
    let responseString = http.request(url, method, contentBody, contentType, headers);
    let responseJSONObj = JSON.parse(responseString);
    return (responseJSONObj);
}
Account ManagementCloudScript
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

·
brandon@uprootstudios.com avatar image
brandon@uprootstudios.com answered

@Kim Strasser Unfortunately, as of now, I don't think there's a way to do this. There have been votes on this since 2016, but it doesn't seem to be implemented yet.

Since the login fails if the user is banned, there's no way to make any further calls (i.e. CloudScript) to get any more info. Theoretically, you could implement your own system where every Client call is instead called by CloudScript, and returns an error if the user has something like "Banned: True" in their Player Data.

The only other solution as of now seems to just display "You are banned. For more info, contact support at support@example.com"

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.

Kim Strasser avatar image Kim Strasser commented ·

Is it possible to get the ban creation and expiration time in the result of server.BanUsers?

It's not working with my CloudScript. I just get undefined in the result:

"Level": "Info",
"Message": "Adding ban successful.undefined undefined",
"Data": null
AddPlayerBan(false, 12, "Automatic 12 hour ban because of cheating with level score.");

function AddPlayerBan(banpermanently, banhours, banreason)
{
    var resultban = server.BanUsers({
        PlayFabId: currentPlayerId,
        PermanentBan : banpermanently,
        Bans : [{ DurationInHours : banhours, PlayFabId : currentPlayerId, Reason : banreason }]
        });
        
    if (resultban.Error == null)
        log.info("Adding ban successful." + resultban.BanData.Created + " " + resultban.BanData.Expires);
    else
        log.info("Adding ban not successful.");
}
0 Likes 0 ·
brandon@uprootstudios.com avatar image brandon@uprootstudios.com Kim Strasser commented ·

@Kim Strasser

From what I can see, BanUsers only takes a list of BanRequests

If I call it like this:

var request = {
    Bans: [
        {
            PlayFabId: currentPlayerId,
            Reason: "Test",
            DurationInHours: 1
        }
    ]
}
var banResult = server.BanUsers(request);    
return banResult;<br>

I get a valid response:

{
    "FunctionResult": {
        "BanData": [
            {
                "PlayFabId": "XYZ",
                "BanId": "XYZ",
                "Created": "2019-12-02T13:30:05.673Z",
                "Expires": "2019-12-02T14:30:05.673Z",
                "Reason": "Test",
                "Active": true
            }
        ]
    },
    ...
}<br>

However, to actually get/return one of the BanData members I had to do it like so:

...

var createdString = JSON.stringify(banResult.BanData[0]["Created"]);
    
return createdString;

Which returns:

{
    "FunctionResult": "2019-12-02T14:08:47.037Z",
    ...
}
0 Likes 0 ·
Kim Strasser avatar image Kim Strasser brandon@uprootstudios.com commented ·

Is BanData[0] always the current ban that was created? Even if there are already other active or inactive bans in the player's ban list in Game Manager?

What does "T" and "Z" mean in "2019-12-02T13:30:05.673Z"?

0 Likes 0 ·
Show more comments
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.