I want to save the player's current session ticket and its timestamp in Player Internal Data but I don't know how to get the timestamp of the session ticket.
I know that I can get the session ticket in the client like this after the player logged in:
string playersessionTicket = task.Result.Result.SessionTicket;
But how can I get its timestamp? I need to find out if the session ticket is still valid.
In addition, how can I compare in Cloud Script if the session ticket is still valid?
For example, the player calls PlayFabClientAPI.LoginWithPlayFab or PlayFabClientAPI.LoginWithIOSDeviceID on a second device. Then, I want to call my cloud script on this second device to find out if the currently saved session ticket(in Player Internal Data) is still valid before the player can make any other API calls on this second device.
I don't know how to find out in Cloud Script if the saved session ticket is still valid. How can I do that?
args.NewSessionTicket gets its value from playersessionTicket = task.Result.Result.SessionTicket.
handlers.GetSessionTicketInternalData = function (args, context) { var resultdata = server.GetUserInternalData({PlayFabId: currentPlayerId, Keys: "PlayerSessionTicket"}); var newsessionticket = args.NewSessionTicket; var currentsessionticket = ""; var isplayerloggedin = ""; if ((resultdata.Data.hasOwnProperty("PlayerSessionTicket")) && (resultdata.Data.PlayerSessionTicket.Value != "") && (resultdata.Data.PlayerSessionTicket.Value != null)) { log.info("Player has already saved a session ticket before."); currentsessionticket = resultdata.Data.PlayerSessionTicket.Value; // How can I find out if currentsessionticket is still valide? if (currentsessionticket <= time ???) isplayerloggedin = true; else { isplayerloggedin = false; // Update Player Internal Data with the value of newsessionticket because currentsessionticket is already expired. // ... } } else { CreateSessionTicketInternalData(newsessionticket); isplayerloggedin = false; log.info("Player created a new session ticket."); } // The player should only be able to login and play the game if "playercanlogin" is false. return isplayerloggedin; } function CreateSessionTicketInternalData(newticket) { server.UpdateUserInternalData({ PlayFabId: currentPlayerId, Data: { "PlayerSessionTicket": newticket }, Permission: UserDataPermission.Private }); log.info("Created internal PlayerSessionTicket data."); }