How can I kick off an asynchronous event from inside my RegistrationResponse cloud code? I need it to start, but don't want to hold up the response waiting for it.
The reason for this is that the event includes SparkHttp.get(), which may take some time, and I need the initial registration to complete all of its writing to mongoDB while the SparkHttp.get() does its work, because the webpage will be accessing that data using REST.
Thanks Steve. Padraig has suggested that I use my game client to fire a new event after completion of the RegistrationResponse. I'm currently working on testing this approach.
However, I am intrigued by your mention of a callback from cloud code. I am unsure how this would work, however. Would the callback be executed DURING, or AFTER the completion of the RegistrationResponse? Specifically, I need any player data modified in the RegistrationResponse to be available to the callback code, and fully synchronized in the mongoDB.
Following up, I was able to successfully implement Padraig's solution, and the original problem is solved.
What advantages would this approach have, as compared with using REST API, or custom Callbacks, from my webserver? Would it allow me to do updates to System.player documents that will synchronize quickly (i.e. in near real time) with the main data cache? I would like my webserver to be able to manipulate System.player in ways that do not disrupt gamesparks data integrity. Mostly things like setting, unsetting, incrementing, etc. on player scriptData values.
What exactly are you trying to achieve from your webserver, we may be able to help further if the use case is explained.
I'm trying to set or unset player data whenever needed. I'm sure there will be many uses for this, but in this specific case, I want the webserver to be able to query System.player to determine if a security nonce was created by my cloud code and stored in the player's scriptData. If the nonce is found, that would confirm that the request actually came from gamesparks (and not some hacker man-in-the-middle). Having confirmed that the request is genuine, there's no need for the nonce any more, so I would have the webserver simply unset that value in the player record.
Does that explain?
In addition to the above, there are many other potential uses for such capability. I'm in the process of building an online multiplayer game, and my webserver will be a vital part of the larger "system" of servers and clients. At this point, I'm trying to find the most efficient way to do important things, like working with player data.
I think I understand your use case. I think a potent route for this might be to utilize custom events.
The first of these events could take two parameters for a key and value, then in the cloud code for this event you could do something like the following below. This will set data on the player like you've described above.
var player = Spark.getPlayer();
The second event could check for a given set piece of data given the key you're search for in a very similar vein as above. Does this seem like a viable solution to you?
Thanks Steve. I've already got custom events working from my game client, so the mechanics of getting data in/out of a player's scriptData or privateData is not the problem. The problem is how to fire those events from my webserver.
My webserver is not going to be where players connect for game play. It's administrative only. All game play will be done using my Unity client application, which uses the Unity SDK to trigger events. No problem there.
But how can my webserver trigger those same events (without having any specific player logged in)? As far as I can see, there's no way to call LogEventRequest remotely without using SDK access. And without any specific player logged in, I'd need to create a "fake" user so that the webserver could authenticate itself at any time.
Or am I misunderstanding something?