ActionScript: Protect your Flash games on the web, sitelock all your games.

If you want to submit your games on one game portals DO NOT UPLOAD YOUR GAMES WITHOUT A SITELOCK SCRIPT.

WHY ?

Your games can be “stolen” by game portals. Or if you didn’t finish your game it’s a really a “pain in the ass” to update your games spread on all the web.

I tried lot of code for sitelocking my games but some of them are in ActionScript 2.0 or totally out of date. Some of them can’t work with the “https” or without the “www” characters.
Another example when you to want to test your game on your local computer you have to comment the script. And you can forget to uncomment the sitelock script when you submit your game on the web.

So I decided to create my own script.

This is a short version of my script.
But this one is perfect for all uses.

Installation

Copy and Paste this code and add your domains into the array “[ ]” separated by commas :

[“kongregate.com”, …, …]

You can lock the local mode by adding a second parameter : false
The default value is set to true.

sitelock(["kongregate.com","benoitfreslon.com"]);

/**
* Sitelock your swf file on domains
*
* @param arrDomain List of all authorized domains
* @param local This swf can be played on local computer ?
*/
function sitelock(arrDomain:Array, local:Boolean = true):void
{

	var isAut:Boolean = false;

	var url:String = root.loaderInfo.url;
	var arr:Array = root.loaderInfo.url.split("://");

	var domain:String = arr[1].split("/")[0];

	// localmode
	if (url.split("file://").length > 1)
	{
		if (local)
		{
			//trace("Local mode is autorized");
			return;
		}
		else
		{
			destroy();
			return;
		}
	}
	for (var i:String in arrDomain)
	{
		arr = domain.split(arrDomain[i]);
		if (arr.length > 1)
		{
			isAut = true;
			domain = arrDomain[i];
			//trace("*** Sitelock: Domain found");
			break;
		}

	}
	if (! isAut)
	{
		//trace("*** Sitelock: Not authentified");
		destroy();
	}
	return;
}
/**
* This function is called when the game is locked.
*/
function destroy()
{
	// Domain error
	trace("*** Domain Error ***");
	root.alpha = 0;
}