question

robert avatar image
robert asked

onLogin Cloudscript

Is there a simple way to execute a cloud script function in the context of a player login?

Background:
1.
With every logi nmethod call we can specify the InfoRequestParameters to get various data like Title Data, User Data, etc... as a result of the login progress.

We would like to handle additional stuff when the user logins, like handling daily rewards, checking statistics, granting items, etc...

It would be great if such things can be performed "in the context of the user login", so that the initial result from the login method already reflects this changes.

2.
Optionally we could of course call method manually once the user is logged in, but this would create additional data to transfer and requires something like a "updating profile...." message and let the user wait until all functions returned a result.

3.
Optionally we could also use playstream events (we do this now with player_logged_in). But this has the downside that as we don't know when the play stream event triggered and executed, we have to query manually for possibly updated data once in a while.

Thanks!

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

If you're dependent upon knowing when the changes are complete so that you are only querying for the updated information, you'll need to call into the OnLogin handler from the client. You could also then return the specific information you need from that call, rather than sending separate queries for the info you need. Another advantage to that would be that if the player is signing in frequently, you could skip that step if nothing would have changed (in a short period).

10 |1200

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

robertsze2 avatar image
robertsze2 answered

Just to clarify, its not possible to execute a cloud script method which for example updates the user data right before the Login method returns?

e.g.

1. LoginWithCustomID request is sent from the client

2. Playfab handles the login on the server

3. Run a cloud script method , something like an onLogin handler which updates user data

4. LoginWithCustomID result is received on the client with the just updated player data in its payload data

Thanks!

,

Just to clarify, its not possible to execute a cloud script method which for example updates the user data right before the Login method returns?

e.g.

1. LoginWithCustomID request is sent from the client
2. Playfab handles the login on the server
3. Run a cloud script method , something like an onLogin handler which updates user data
4. LoginWithCustomID result is received on the client with the just updated player data in its payload data

Thanks!

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

brendan avatar image brendan commented ·

No, all our API calls are designed to be as efficient as possible, so they're not designed for nested call dependencies.

0 Likes 0 ·
robert avatar image robert brendan commented ·

This means that updating user data or creating initial user data requires three calls, wouldn't it be more efficient to being able to this in just one call?

If I understand you correctly, right now we would have to do following:

1. Login the user (LoginWithCustomID for example)
2. Wait for the reply from the server
3. Call a cloud script function like PlayerLoggedIn and modify the user data there (e.g. daily rewards, version upgrade, etc.)
4. Wait for the reply from the server
5. Call GetUserData
6. Wait for the reply from the server

Is this correct? (optionally we could also return the user data for step 4 already though)

One more question. We also tried using the playstream event on_player_logged_in. This works fine for updating the user data, but how do we know on client side when to call GetUserData again? (can we be sure that the event triggered already when we call GetUserData right after the Login call was successful?)

We plan to update a few of our titles with around 5MMU+ with play fab integrated, so we try to keep everything as fast and bandwidth saving as possible.

0 Likes 0 ·
brendan avatar image brendan robert commented ·

No, I was recommending that you return the user data in the response from the Cloud Script, actually. So it would be: log in, then call the Cloud Script and use the data returned.

While you can trigger a Cloud Script from an event, that's designed for automation of live game operations. We do not maintain a persistent socket connection to the client currently, so there would be no way for us to notify the client of the completion of an event it didn't request. But that said, it is a great way to make sure that you are segmenting users appropriately, sending Push Notifications to let players know when it's their turn in an async game, etc.

0 Likes 0 ·
robertsze2 avatar image robertsze2 commented ·

Btw, Had to create a second account as login is not possible for some reason, always redirects to register page

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.