


February 20, 2015 – Blocking your flash game in some domain
This article will help you to protect your flash game by blocking it in some domain, the script will contact an external blacklist managed by you, to determine if the domain is allowed to use your game. The script works only with Actionscript 3.
But, why developers need to block a game in some domain? Well, some developers have good reasons to do that, like domains blocking outgoing links for example, these domains use the game without permission because they block the only source of profit from developers.
So, let's start. This is probably the best way to protect your flash game.
1) Create a .txt file (example: domains.txt) and host in your server.
2) Write the domains that you want to block (comma separated).
3) Update the red line from the code below, with the address of your list.
4) Upload the crossdomain.xml file in your server (this file can be downloaded below).
5) Use the code below in the first frame of your game:
var currentdomain:String;
var blockeddomains:String;
var checkdomains:URLLoader = new URLLoader();
var currentdomain2:Array;
var ck1:Number = 0;
var ck2:Number = 0;
function Replace(p1, p2, p3) {
var array = p3.split(p1);
return array.join(p2);
}
function onLoaded(e:Event):void {
blockeddomains = e.target.data;
ck1 = blockeddomains.length;
ck2 = Replace(currentdomain, "", blockeddomains).length;
if (ck1 > ck2) {
// domain blocked, show the message
domaintxt.text = "The domain: " + currentdomain + " is not authorized to use this game";
}
else {
// domain ok, start the game
gotoAndPlay(2);
}
}
currentdomain = Replace("http://", "", stage.loaderInfo.url);
currentdomain = Replace("https://", "", currentdomain);
currentdomain2 = currentdomain.split("/");
currentdomain = currentdomain2[0];
/*
now we have the domain in currentdomain variable
let's check our list, when the script opens our list, it will run the function onLoaded() above.
*/
checkdomains.load(new URLRequest("https://www.playgb.com/domains.txt" + "?" + Math.random()*1000));
checkdomains.addEventListener(Event.COMPLETE, onLoaded);
stop();
Now, let's test! The .swf file below is hosted in a blocked domain: playgb.com, yes, we blocked our own domain in our blacklist file.
Now, let's host the same .swf file in another domain not blocked by our blacklist, the file will appear below.
So, if a domain is using your game without your permission, you can put the domain in your blacklist and the game will no longer work for that domain. Make sure to put the domain in two formats: with www and without www (example: blockeddomain.com and www.blockeddomain.com), if the blocked domain uses some subdomain, you will need to write this subdomain too (example: subdomain.blockeddomain.com).
Download complete source code
But, why developers need to block a game in some domain? Well, some developers have good reasons to do that, like domains blocking outgoing links for example, these domains use the game without permission because they block the only source of profit from developers.

So, let's start. This is probably the best way to protect your flash game.
1) Create a .txt file (example: domains.txt) and host in your server.
2) Write the domains that you want to block (comma separated).
3) Update the red line from the code below, with the address of your list.
4) Upload the crossdomain.xml file in your server (this file can be downloaded below).
5) Use the code below in the first frame of your game:
var currentdomain:String;
var blockeddomains:String;
var checkdomains:URLLoader = new URLLoader();
var currentdomain2:Array;
var ck1:Number = 0;
var ck2:Number = 0;
function Replace(p1, p2, p3) {
var array = p3.split(p1);
return array.join(p2);
}
function onLoaded(e:Event):void {
blockeddomains = e.target.data;
ck1 = blockeddomains.length;
ck2 = Replace(currentdomain, "", blockeddomains).length;
if (ck1 > ck2) {
// domain blocked, show the message
domaintxt.text = "The domain: " + currentdomain + " is not authorized to use this game";
}
else {
// domain ok, start the game
gotoAndPlay(2);
}
}
currentdomain = Replace("http://", "", stage.loaderInfo.url);
currentdomain = Replace("https://", "", currentdomain);
currentdomain2 = currentdomain.split("/");
currentdomain = currentdomain2[0];
/*
now we have the domain in currentdomain variable
let's check our list, when the script opens our list, it will run the function onLoaded() above.
*/
checkdomains.load(new URLRequest("https://www.playgb.com/domains.txt" + "?" + Math.random()*1000));
checkdomains.addEventListener(Event.COMPLETE, onLoaded);
stop();
Now, let's test! The .swf file below is hosted in a blocked domain: playgb.com, yes, we blocked our own domain in our blacklist file.
Now, let's host the same .swf file in another domain not blocked by our blacklist, the file will appear below.
So, if a domain is using your game without your permission, you can put the domain in your blacklist and the game will no longer work for that domain. Make sure to put the domain in two formats: with www and without www (example: blockeddomain.com and www.blockeddomain.com), if the blocked domain uses some subdomain, you will need to write this subdomain too (example: subdomain.blockeddomain.com).
Download complete source code
© PlayGB.com - Free online games - Blog
