question

Kim Strasser avatar image
Kim Strasser asked

CloudScript: Is it possible to create restrictions for player title display name and account username/password?

I don't want to support all ascii characters for title display name and the player's account username and password. In addition, I want to create restrictions for the length(for example up to 20 characters) in CloudScript. Is it possible to only allow a range of ascii character, for example the range 32-512?

If the player uses characters other than ascii range 32-512, then I want to cancel creating/updating the PlayFab account and I want to display a message in my application. For example: "One or more characters are not supported. Please only use supported characters in your display name/username/password." or "Your display name/username/password is too long. It must be less than 21 characters."

For the moment, I only use client API calls like PlayFabClientAPI.UpdateUserTitleDisplayName, PlayFabClientAPI.AddUsernamePassword and PlayFabClientAPI.RegisterPlayFabUser. But I can't verify with these client API calls if a player uses unsupported characters or if the string is too long.

How can I find out in CloudScript if a string is too long or if a player only uses valid characters when he creates/updates a PlayFab (guest) account?

CloudScript
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

·
Sarah Zhang avatar image
Sarah Zhang answered

Yes, it is. PlayFab doesn’t provide such built-in API. You can use [YourTextString].charCodeAt([TheCharacterIndex]) get the string’s ASCII code and [YourTextString].length to get the string’s length.

Because these three API only have admin and client API, do not have server API. Even if you verify the length of entered text on the Cloud Script, you still need to send the request with client API from clients. So, a possible workaround is verifying the length of the text users send to the CloudScript. If they meet the restrictions let CloudScript return true, let the client judge the response then send the request, if they don’t, let CloudScript return tips, let the client judge the response then popup the failure tips.

In addition, please pay attention to the request frequency limitation. For example, limit the players' verification frequency in the client's code.

You can refer to the following Cloud Script code.

function VerifyTextLength(text) {
    if (text.length <= 20) {
        return true;
    } else {
        return false;
    }
}


function VerifyTextASCII(text) {


    var notSupportArray = new Array();
    for (var i = text.length - 1; i >= 0; i--) {
        var charCode = text.charCodeAt(i);
        if (charCode >= 32 && charCode <= 512) {


        } else {
            notSupportArray.push(charCode);
        }
    }
    if (notSupportArray.length == 0) {
        return true;
    } else {
        false;
    }


}


handlers.VerifyText = function (args, context) {
    if (VerifyTextLength(args.text) && VerifyTextASCII(args.text)) {
        log.info(args.text);
        return true;
    } else {
        if (!VerifyTextLength(args.text) && !VerifyTextASCII(args.text)) {
            log.info(args.text);
            return "too long & characters are not supported";
        }
        else {
            if (!VerifyTextLength(args.text)) {
                log.info(args.text);
                return "too long";
            }
            if (!VerifyTextASCII(args.text)) {
                log.info(args.text);
                return "characters are not supported";
            }
        }


    }
};
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.