{"assets":[{"original":"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-3.48.16-PM.png","local":"\/data\/posts\/2014\/05\/77f7f1f55aae3b094303b90f6a0b7bf4.png"}],"author_link":"author\/coinflipgames\/","author_name":"Coin Flip Games","cat":"LD #29","categories":["LD #29"],"comments":[],"epoch":1398957300,"event":"LD29","likes":6,"metadata":{"p_key":"82134","p_author":"Coin Flip Games","p_authorkey":"0","p_urlkey":"292866","p_title":"Bitmite Blitz! A Postmortem of sorts","p_cat":"LD #29","p_event":"LD29","p_time":"1398957300","p_likes":"6","p_comments":"0","p_status":"WAYBACK","us_key":null,"us_name":null,"us_username":null,"event_start":"1398384000","event_key":"22","event_name":"LD29"},"source_url":"2014\/05\/01\/bitmite-blitz-a-postmortem-of-sorts\/","text":"<p><img alt=\"31135-shot0\" class=\"aligncenter wp-image-359047 size-medium\" height=\"187\" sizes=\"(max-width: 300px) 100vw, 300px\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/31135-shot0-300x187.png\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/31135-shot0-300x187.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/31135-shot0-550x343.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/31135-shot0.png 960w\" width=\"300\"\/>Hey, folks. Coin Flip Games here to tell you about our entry for LD29, Bitmite Blitz. We\u2019re incredibly proud of this game and wanted to make sure YOU got a chance to play it. If you\u2019re not convinced, here\u2019s some of our favorite reviews we\u2019ve gotten so far!<\/p>\n<blockquote><p><span style=\"color: #000000\">\u201cSuper fun game. I have highscore! for now :P\u201d \u2013\u00a0<strong><a href=\"http:\/\/www.ludumdare.com\/compo\/ludum-dare-29\/?action=preview&amp;uid=34623\" style=\"color: #4444cc\">tehryanx<\/a>\u00a0(Still has the high score, btw)<\/strong><\/span><\/p>\n<p>\u201c<span style=\"color: #000000\">I love games that put me in a perspective I never would have thought to explore. Great game!\u201d \u2013\u00a0<strong><a href=\"http:\/\/www.ludumdare.com\/compo\/ludum-dare-29\/?action=preview&amp;uid=22521\" style=\"color: #4444cc\">greysphere<\/a><\/strong><\/span><\/p>\n<p>\u201c<span style=\"color: #000000\">This is definitely one of the most polished games I\u2019ve seen in the LD. Having an achievement system is an impressive addition, given the time constraint.\u201d \u2013\u00a0<strong><a href=\"http:\/\/www.ludumdare.com\/compo\/ludum-dare-29\/?action=preview&amp;uid=36095\" style=\"color: #4444cc\">StencylTuo<\/a><\/strong><\/span><\/p>\n<p>\u201c<span style=\"color: #000000\">Good game, it gives me the same feeling as Flappy bird which is a good thing.<\/span>\u201d \u2013\u00a0<strong style=\"color: #000000\"><a href=\"http:\/\/www.ludumdare.com\/compo\/ludum-dare-29\/?action=preview&amp;uid=7423\" style=\"color: #4444cc\">Sparrow<\/a><\/strong><\/p><\/blockquote>\n<p><a href=\"http:\/\/www.ludumdare.com\/compo\/ludum-dare-29\/?action=preview&amp;uid=31135\" target=\"_blank\">So go give it a shot already!<\/a><\/p>\n<p>\u00a0<\/p>\n<p>Back? Okay. I wanted to talk a bit about how we accomplished the global leaderboard. I\u2019d love to see more games with this feature because I think it adds a whole new dimension. \u00a0So, to start, you can implement this in any language or game engine you would already be using. Some (like Unity) will make it easy than others, however. You need 3 things, a server to host the scoreboard api and scores, you game and a communication layer between them. Ideally, you want to have something in place to prevent people from adding fake scores as well.\u00a0<a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-2.46.38-PM.png\"><img alt=\"Screen Shot 2014-05-01 at 2.46.38 PM\" class=\"aligncenter wp-image-359051 size-large\" height=\"234\" sizes=\"(max-width: 550px) 100vw, 550px\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-2.46.38-PM-550x234.png\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-2.46.38-PM-300x128.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-2.46.38-PM-550x234.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-2.46.38-PM.png 752w\" width=\"550\"\/><\/a><\/p>\n<p>\u00a0<\/p>\n<p>Set up a database of some sort. Use whatever you would feel comfortable with and if you\u2019re not comfortable with anything, use MySQL or sqlite. You can get away with, as a bare minimum, a single table: scores, but that\u2019s not so much fun, is it? You can easily use this in a bunch of games if you do it right the first time.<\/p>\n<ol>\n<li>Set up your database engine (mysql in our case)<\/li>\n<li>Add a database and user. Make sure that the user permissions make sense. Don\u2019t give them GRANT access to anything. Ever.<\/li>\n<li>Add the tables as below:<\/li>\n<\/ol>\n<p><a href=\"\/data\/posts\/2014\/05\/77f7f1f55aae3b094303b90f6a0b7bf4.png\"><img alt=\"Screen Shot 2014-05-01 at 3.48.16 PM\" class=\"aligncenter size-full wp-image-359098\" height=\"168\" sizes=\"(max-width: 546px) 100vw, 546px\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-3.48.16-PM.png\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-3.48.16-PM-300x92.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-3.48.16-PM.png 546w\" width=\"546\"\/><\/a><\/p>\n<p>Alright! Done with the database for now. Now we need to setup the API. I\u2019m going to leave the actual implementation up to you (as an exercise or something), but the functionality you\u2019ll need is\u2026<\/p>\n<ol>\n<li>To receive input from the web in some well defined format. I used PHP to get data as JSON. You could use Ruby, Python or whatever fancy language you want. You could use XML too if that\u2019s what you\u2019re into.<\/li>\n<li>Check the input to ensure that it\u2019s valid. (Did this come from a legitimate source? Does the input make sense?)<\/li>\n<li>Sanitize the input. (Can\u2019t stress this one enough)<\/li>\n<li>Perform some action on the data. (Run the command \u2018getScores\u2019)<\/li>\n<li>Return results in some well defined format. (Package up the results of the command as JSON and pass it back)<\/li>\n<\/ol>\n<p>And on the client-side (game) we need to do the same thing, but in reverse. The client needs to build these requests and be able to parse the responses. Since I used JSON, I\u2019ll show our request as an example.<\/p>\n<p>{<\/p>\n<p>cmd: \u2018Leaderboard\/getScores\u2019,<\/p>\n<p>api_key: \u2018\u2026\u2019, (I\u2019ll get back to these)<\/p>\n<p>signature: \u2018\u2026\u2019,<\/p>\n<p>time\/token: \u2018\u2026\u2019<\/p>\n<p>}<\/p>\n<p>And the server would spit back<\/p>\n<p>{<\/p>\n<p>[\u2018name\u2019: \u2018Awesome Bitmite Blitz Player\u2019, \u2018score\u2019: 100000],<\/p>\n<p>[\u2018name\u2019: \u2018Awesome Bitmite Blitz Player 2\u2019, \u2018score\u2019: 10000],<\/p>\n<p>\u2026<\/p>\n<p>}<\/p>\n<p>\u00a0<\/p>\n<p>Easy enough. The trickiest part is ensuring that the scoreboard can\u2019t be tricked into allowing scores that aren\u2019t legitimate. That\u2019s where the API key and secret come in. For every game that will use this leaderboard, generate some random string for the API key and some random, hard to guess string for the secret. The database knows what these are and your API can check them out no problem. You\u2019ll also need to let your game know what these are and if you\u2019re lucky enough to have a compiled language, they\u2019ll be safe from curious eyes. (if you release the source code for your game, strip both out).<\/p>\n<p>So now the server API and the game both know the API key and secret. Great. Now let\u2019s use them to generate a signature for all the requests that the game client will make.<\/p>\n<p>\u00a0<\/p>\n<p><a href=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-4.06.22-PM.png\"><img alt=\"Screen Shot 2014-05-01 at 4.06.22 PM\" class=\"aligncenter size-large wp-image-359106\" height=\"160\" sizes=\"(max-width: 550px) 100vw, 550px\" src=\"http:\/\/www.ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-4.06.22-PM-550x160.png\" srcset=\"http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-4.06.22-PM-300x87.png 300w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-4.06.22-PM-550x160.png 550w, http:\/\/ludumdare.com\/compo\/wp-content\/uploads\/2014\/05\/Screen-Shot-2014-05-01-at-4.06.22-PM.png 561w\" width=\"550\"\/><\/a><\/p>\n<p>So the idea is that both the client and server can construct the signature independently and compare them, but prying eyes cannot. The key, secret and a time\/token are needed so that requests to the same API resource (getScores) won\u2019t always generate the same signature. It\u2019s secure because the secret is\u2026 well\u2026 secret.<\/p>\n<blockquote><p>(There might be some of you that recognize this pattern. It\u2019s basically the same model that Amazon Web Services uses.)<\/p><\/blockquote>\n<p>So that\u2019s the basic idea. Here\u2019s some resources to use if you want to implement it yourself:<\/p>\n<ul>\n<li><a href=\"http:\/\/www.mysql.com\/\" target=\"_blank\">MySQL<\/a><\/li>\n<li><a href=\"php.net\" target=\"_blank\">PHP<\/a>\u00a0(<a href=\"http:\/\/www.php.net\/manual\/en\/book.pdo.php\">PDO<\/a>)<\/li>\n<li><a href=\"http:\/\/wiki.unity3d.com\/index.php\/SimpleJSON\" target=\"_blank\">Unity SimpleJSON<\/a><\/li>\n<li><a href=\"https:\/\/docs.unity3d.com\/Documentation\/ScriptReference\/WWW.html\" target=\"_blank\">Unity WWW<\/a><\/li>\n<li><a href=\"https:\/\/docs.unity3d.com\/Documentation\/Manual\/SecuritySandbox.html\" target=\"_blank\">Unity crossdomain.xml<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/5821677\/md5-hashing-does-not-match-in-c-sharp-and-php\" target=\"_blank\">Matching PHP md5() to C#<\/a><\/li>\n<\/ul>\n<p>Cheers! I hope someone can get some use out of this!<\/p>\n<p>Tags: <a href=\"http:\/\/ludumdare.com\/compo\/tag\/ld29\/\" rel=\"tag\">ld29<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/postmortem\/\" rel=\"tag\">postmortem<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/unity\/\" rel=\"tag\">unity<\/a>, <a href=\"http:\/\/ludumdare.com\/compo\/tag\/unity3d\/\" rel=\"tag\">unity3d<\/a><\/p>","time":"May 1st, 2014 3:15 pm","title":"Bitmite Blitz! A Postmortem of sorts","title_was_empty":false}