Site lock and domain name
If you are selling licenses of your games, site locking is something that you just have to know. One of the mistakes I did early on was to simply use some piece of code I found on the web. It was something like this:
if(this.root.loaderInfo.url.indexOf("domain.com") != -1) trace("Good!"); // It's in the right domain else trace("Bad!"); // It's in the wrong domain
What this does is to get the index (aka position) of the string “domain.com” from the string that is returned by the loaderInfo.url. If it returns -1 then the string “domain.com” is not present in the loaderInfo.url.
This solution is fine, but it presentes two problems.
First, if someone really wants to use your site-locked game, they can! They just have to find a way of putting the “domain.com” string somewhere in the path to your swf since this code does not compare the domain name but rather the presence of a string on another string.
The second problem is that you don’t know the domain where the game is present. I need that information for other evil schemes of mine, so this was the perfect reason to write a small tool that would fetch me the domain name.
So I wrote this simple static function that lies inside a class Toolkit -name I shamelessly stolen from a chat with Andrew from Epic Shadow- and that simply returns the root domain and the top level domain, separated by a dot from the loaderInfo.url.
/*Returns the name of the domain without subdomain, e.g. vortixgames.com * instead of www.vortixgames.com.*/ public static function Domain(root:MovieClip):String { /* Splits the full path into an array of strings separated by "/" * and gets the index 2 value which is the full domain name.*/ var currentDomain:String = root.loaderInfo.url.split("/")[2]; /* Splits the result into an array of strings separated by "." and * checks the length of the array. If the array has a length of 3 * the domain contains a subdomain, for instance "www" and it must * be discarded. If the length is 2 then, there's no subdomain * present. */ var fqdn:Array = currentDomain.split("."); // FQDN in array form var rdi:int = 1; // Root Domain Index defaults to 1 var tli:int = 2; // Top Level Index defaults to 2 if (fqdn.length == 2) { rdi--; tli--; } return fqdn[rdi] + "." + fqdn[tli]; }
The only issue I have with this function is that I have to pass the root as a parameter to the function. Any idea on how I could solve this otherwise is most welcome.
Posted: March 2nd, 2009
at 12:00am by Vlad
Tagged with FlashGameBlogs, Snippets, Sponsorship and Licensing
Categories: The code of VGS
Comments: 3 comments
