Monday, January 19, 2009

How to Run Your Game From Your Server Only?

Suppose you made your own flash game and want it to be played from your server only and no where else on the internet.

This code may help you:

__________________code start____________________

if (this.root.loaderInfo.url.indexOf("YOUR SITE GOES HERE") != -1) {
//OK THATS WHAT I WANT
}
else {
var myURL:URLRequest = new URLRequest("YOUR SITE GOES HERE");
navigateToURL(myURL);
//if the game is not played from my server redirect the player to my site!
}

__________________code end____________________

Description of the code:

We are using the this.root.loaderInfo.url property that returns the full path of the SWF file, starting with http:// , so we are checking if the path of the game has your web address in it or not. It will return -1 if it doesnt and will return a positive value if it does.


1- if (this.root.loaderInfo.url.indexOf("YOUR SITE GOES HERE") != -1) {
//OK THATS WHAT I WANT
}


The value is not -1, so the game is running from my server.

2- else {
var myURL:URLRequest = new URLRequest("YOUR SITE GOES HERE");
navigateToURL(myURL);
//if the game is not played from my server redirect the player to my site!
}


The value is -1, then someone downloaded the game and running it from his server so you will need to redirect the player to the original place of the game which is your website, the following two lines will do that

var myURL:URLRequest = new URLRequest("YOUR SITE GOES HERE");
navigateToURL(myURL);



You can do this check before the game starts, if it is running from your server then start the game, otherwise dont start the game and redirect the player to your website.

Learn more about game protection here

No comments:

Post a Comment