question

MoonHeonYoung avatar image
MoonHeonYoung asked

Criteria for getting a new ticket

Hello

Through many search results

I learned that I should log in again within 24 hours to play the game seamlessly without failing the function call.

I think it is correct to log in again within 24 hours

1. Is there a timestamp in the client code to compare to enable relogin before 24 hours have elapsed?

E.g. lastLogin or timeSinceGameLoaded...

What conditional statement should I use to call the relogin function 24 hours ago?

(if statement)

10 |1200

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

Citrus Yan avatar image
Citrus Yan answered

You can use the “TokenExpiration” property returned from login calls, for instance, the one returned from the LoginWithCustomId API to tell when the session ticket will expire. In a live service like PlayFab, it's always possible that a condition could occur requiring that we invalidate active sessions out of band to the expiration time on the ticket. Therefore, the best practice would be to always check the response from a call to our service, so that if the ticket should be expired (you'd get a 401 - Unauthorized response, with a 1074 - Not Authenticated error in most cases), you can sign the player back in silently, or notify the player as needed. You can combine both ways discussed above to implement your logic.

10 |1200

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

MoonHeonYoung avatar image
MoonHeonYoung answered

Thank you for answer!

Sorry for being inexperienced,

can you provide code examples?

1.TokenExpiration was obtained and printed.

I got a result like 12/29/2020 11:33:48.

How can I change this value to a form that can be compared using an if statement?

(E.g. if(datetime <24) ??

2. In the answer, what are the circumstances in which the active session ticket must expire?

Is it the case of banning users?

3.401-Unauthorized response, with a 1074-Not Authenticated error

How to capture the above two errors in client code?

thanks

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.

Citrus Yan avatar image Citrus Yan commented ·

1.Assuming that you're using our Unity(C#) SDK, TokenExpiration is returned as the DateTime struct: DateTime Struct (System) | Microsoft Docs, you can use easily use its built-in method DateTimeCompare(DateTime t1, DateTime t2) to compare with the current date: DateTime.Compare(DateTime, DateTime) Method (System) | Microsoft Docs, please check out this doc for more details. For instance, if the current date is later than the expiration date, then the following statement:

if (DateTime.Compare(currentdate, expirationdate)) 

will return true because DateTime.Compare(currentdate, expirationdate) is greater than zero.

2.In normal cases, the session ticket will be valid for 24 hours, if you find that is not the case in some rare circumstances , please contact us for help. Right now you don't need to worry about it.

3. Take Unity SDK for example, if a API call failed, you can find all the error details PlayFabError from the error callback:https://github.com/PlayFab/UnitySDK/blob/6ace55d8826b057c720f03d18497f486399b877c/ExampleTestProject/Assets/PlayFabSDK/Shared/Internal/PlayFabErrors.cs#L633

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.