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?
Hi Walt,
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();
player.setPrivateData(Spark.getData().parameterOne, Spark.getData().parameterTwo);
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?
Kind regards,
- Steve
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.
Hi Walt,
The Javascript SDK is like any of our SDKs, it would allow to you to make calls to the GameSparks backend from the frontend side of your website. There would be no need to setup an additional game I don't think you could use the same credential (api key and secret) as your current game or setup a new credential specifically for this interface. There would also be no need for a "fake" player, each user can interact via the SDK to login to their own respective player account. This would have a distinct advantage over REST as our SDKs utilize web sockets rather then standard TCP connections, which make the overall overhead of communication a lot less cumbersome. When it comes to manipulating player data may I suggest doing so from cloud code? Doing so this way may prove to be a lot easier than doing these manipulates outside of the backend to then have to resync these changes.
What exactly are you trying to achieve from your webserver, we may be able to help further if the use case is explained.
Kind regards,
- Steve
Following up, I was able to successfully implement Padraig's solution, and the original problem is solved.
@Steve, can you tell me more about using the JavaScript SDK from my webserver? I'm trying to understand how that would work. Would I setup the webserver as an additional game client, with respect to gamesparks? So then I'd need to register a fake "player" for the webserver, and then always keep it logged in with AuthenticationRequest? Or am I misunderstanding what you mean?
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.
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.
Hi Walt,
Would you be able to explain your use case for this in more detail, we might be able to find an appropriate way to go about what your trying to achieve. Why exactly does the asynchronous event need to be async, would a callback from the RegistrationReponse suit here? This would then mean that the initial registration would have completed prior to the callback being called. Have you considered using our Javascript SDK (https://docs2.gamesparks.com/sdk-center/javascript-sdk.html) instead of REST directly from your webpage?
Kind regards,
- Steve
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.
Walt Collins
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.