Sign In Register

How can we help you today?

Start a new topic
Answered

Cloud code request/response flow

I'm trying to wrap my head around what information is available at what points during the DeviceAuthentication request and response in Cloud Code. My picture of the flow so far is this (I don't think this is documented anywhere):

  1. Device sends HTTP request to Gamesparks. Described by following, notably requiring "deviceOS": https://api.gamesparks.net/#deviceauthenticationrequest
  2. Spark.getData() object is initialized with appropriate fields, but they're left undefined
  3. DeviceAuthenticationRequest is called with input Spark.
  4. Body is parsed as JSON and attached to Spark.getData(). 
  5. Player object is created in Mongo. Segments specified in getData are populated into SparkPlayer.getSegment*
  6. DeviceAuthenticationResponse is called with input Spark.
  7. Gamesparks delivers HTTP response to device.
AFAICT, while deviceOS is a required parameter, it isn't actually recorded anywhere (except as part of the userId?), at least nowhere accessible in Cloud Code. 

Okay, that's weird, but I devise a workaround: "I'll just get it from GetData() myself and attach it to the player". Two problems: 
  • since DeviceAuthReq happens before the input JSON is parsed or available, I can't get deviceOS
  • the SparkPlayer object is not yet initialized, so I have no persistent place to put it (except a new Mongo collection maybe... no thanks)
(Seems to me like DeviceAuthReq is rather pointless then since it has no inputs to operate on really.)

Next workaround: "I'll deal with it in DeviceAuthResponse instead." At this point, SparkPlayer is initialized, so I can attach data to it. However, getData() is now the response object, and the deviceOS is evaporated into the ether.

Next workaround: "I'll add it as a segmentValue, since that's data I can control from the client and it will be available during the response phase." Okay, that works! Finally! Definitely a hack, but whatever.

I'd like to validate it before I use it though. Fine, I can do that, but what do I do if it fails validation? I can throw an exception to bail out of the script, sure, but this leaves me with a player that exists in the database and doesn't yield an HTTP 5xx or some error code. I guess I could do a Mongo remove() to find him...

The real answer is to validate all the inputs before writing to the database at all IMO. And I can't do that in the Req handler because it runs before I have any real data to make a decision with!

And it's not just deviceOS that I want to validate. I want to attach an app version number to the request and be able to validate that as well.

TLDR: I want to get the deviceOS in Cloud Code, but it never seems to be available. What's up with that?

(Likewise, the optional fields in the Request.)




Best Answer

Actually, I found some documentation about Cloud Code flow: https://docs.gamesparks.net/documentation/cloud-code-concepts


And I figured out that my code for parsing inspecting the getData() was just bad :P


So we're all good! Never mind me.

1 Comment

Answer

Actually, I found some documentation about Cloud Code flow: https://docs.gamesparks.net/documentation/cloud-code-concepts


And I figured out that my code for parsing inspecting the getData() was just bad :P


So we're all good! Never mind me.


1 person likes this
Login to post a comment