question

max avatar image
max asked

Friend List - Get online status or last activity

What would be the best way to show whether a friend is currently (most likely) online or show their last active time?

Is there a last activity date (when somebody did their last request to PlayFab) saved in some of the friend list data?

Friends
10 |1200

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

brendan avatar image
brendan answered

The profile contains the last logged in time, which you can use to extrapolate on the user's status, but no, there is no "log out" API call, because for many games (in particular, for all mobile games), that's not reliable. Even in cases where the game is exited normally, there's no guarantee on most devices that the app would still get enough CPU time to make the call to tell us. We will be providing a "presence" style system in a future update, though we don't have a specific date for that just yet.

One thing you could do for now is to write to a statistic in the player account once every five minutes or so, to use that statistic as a "timestamp". That way, you could use the data returned via the profile constraints to check if the player was online in that period. But you definitely could not do a realtime presence system that way - updating a statistic frequently would be outside the scope of our fair use policy, and could get your title blocked. If you need a realtime system before one is available in PlayFab, you would need to use an external data store for that.

3 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.

max avatar image max commented ·

Okay, I see. Actually, I was wondering if PlayFab is currently already saving the time of the last request (of whatever form) the user sent to PlayFab. This way one could have like a semi-real-time online status without the need of writing an additional statistic.

If that does not exist, we could probably also do with the statistic setting every 5 minutes. Statistics can currently not be read with the friend list, right? At least the ProfileConstraint page says that the statistics are reserved for future development:

https://api.playfab.com/documentation/Client/datatype/PlayFab.Client.Models/PlayFab.Client.Models.PlayerProfileViewConstraints

Since you just mentioned it: If we accidentally do something that might get our title blocked / outside of the fair use - do we actually get a notification before, so we can fix it - is there a process for that? We are certainly not doing anything nearly dangerous here right now - just wondering what happens if we create a really stupid bug or anything ;)

0 Likes 0 ·
brendan avatar image brendan max commented ·

No, we do not have a timestamp that we update based upon any API call on behalf of the player at this time.

Also, yes, you are correct that returning the statistics as part of the GetFriendsList query. However, you can get them from the GetFriendLeaderboard call. Just make sure to set ShowStatistics to true in the ProfileConstraints, and that you've set the option to return the statistics to the client in Settings->Client Profile Options.

For usage, we're working on adding a usage meter to the titles, to provide more feedback on that. Obviously, given that different API calls have different resource requirements, it's not a simple calculation. But our goal is to make it as simple as possible. For titles that - whether intentionally, due to a hacker attack, or for any other reason - exceed our fair use limits, we always reach out to let the developer know of the issue and what steps are being taken.

0 Likes 0 ·
max avatar image max brendan commented ·

Okay perfect, that really helped me - thanks! :)

0 Likes 0 ·
contrejo27 avatar image
contrejo27 answered

Necro'ing this post. I'm thinking of setting an entity object with a list of all the players online, then I can just ask for that object and check who is online. I'm already setting an entity object in each player to be online or offline so I'm just thinking of transferring that to some game entity object of sorts.

Would something like this work?

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.

Seth Du avatar image Seth Du ♦ commented ·

I think it should work, but please remember that shared resources are cached and the changes won't apply to every shards immediately, which means it will take a few seconds or very few minutes to sync and sometimes players cannot get the latest states. It will be ok if your game the rare-time and doesn't care about getting the state in real-time.

0 Likes 0 ·
chorustempo avatar image
chorustempo answered

Necro v.2: Could this be done by a rule that assigns a currency on event logged_in ('1LogIn Coin' or something). Then removes the currency on log out. Then have a segment that shows all players with >0 of that currency?

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.