Sunday, March 16, 2014

Cross-Origin Resource Sharing (CORS)

The first step to getting the game hooked up was making sure that just the simple name/secret HTTP messages were being received and interpreted correctly.  We did this by creating a scene that loaded two models based on dummy unit data I created on the client.  After we had the super model parser working this part came together in just a few hours.

We pushed a few new versions up to Github and had our dummy scene up in no time.  The next step is where my end crapped out.  Zach's end works great though and he is currently de-optimizing the threading down to one thread for the all of the game logic.  Turns out when all you're doing is sending a few hundred coordinates you can run it all in the same place.  Hee hee.  We'll need them later though, we'll make sure of it.

Back to my end and the topic of this blog: Cross-Origin Resource Sharing  or CORS.

Official Mozilla documentation:
https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS

Put simply, it's when the origin of the request is not the owner of the resource.  This happens whenever you have downloaded the content for a game and then log in to the server to have it feed the game logic.  You know, buy/download and install the game, play it online.  Tons of games do this; W.O.W., Neverwinter, The Sims, Planetary Annihilation, etc...

Our game will be browser based and will not require the client to contain any content.  Sites like Kongregate host these kinds of games but examples can be found all over the web.

I only bring up this point to illustrate the different functionality that web platforms require for development versus play.  While I may not need this exact functionality for this particular game.  It is a necessary tool in the web development kit of any good programmer so I'm going to add it properly instead of just hacking my browser permissions to allow cross-origin requests.   Which if you are a fellow designer reading this I would strongly suggest you do not do either!  You can look this up for yourself on stackoverflow.com if you don't believe me.  Yes, it's a little extra work, but you should know how to do this kind of stuff anyway so just learn it now and keep your computer safe during development.

I'm not 100% sure on the correctness of this information but from what I can gather from the above Mozilla link this seems to be exactly what I need to do.  I'll let you know if this works in the next few hours.
http://abdiassoftware.com/blog/2013/11/how-to-use-cross-origin-resource-sharing-cors-with-canvas/

Once I get this CORS issue worked out it's full steam ahead for iterative development.

Wish us luck. Thanks for reading,
-Clay

No comments:

Post a Comment